#include "string.h"
#include "buffer_tree.h"
#include "error.h"
+#include "sched.h"
struct btr_buffer {
struct list_head node;
/* The children nodes of this btr node are linked together in a list. */
struct list_head children;
+ /* Time of first data transfer. */
+ struct timeval start;
/**
* The input queue is a list of references to btr buffers. Each item on
* the list represents an input buffer which has not been completely
btrn->parent = parent;
btrn->execute = handler;
btrn->context = context;
+ btrn->start.tv_sec = 0;
+ btrn->start.tv_usec = 0;
if (parent)
list_add_tail(&btrn->node, &parent->children);
INIT_LIST_HEAD(&btrn->children);
{
struct btr_node *ch;
+ if (btrn->start.tv_sec == 0)
+ btrn->start = *now;
FOR_EACH_CHILD(ch, btrn) {
struct btr_buffer_reference *br = para_malloc(sizeof(*br));
br->btrb = btrb;
br->consumed = consumed;
list_add_tail(&br->node, &ch->input_queue);
btrb->refcount++;
+ if (ch->start.tv_sec == 0)
+ ch->start = *now;
}
}
}
/* make a new btrb that combines the two buffers and a br to it. */
sz = szs[0] + szs[1];
- //PARA_CRIT_LOG("merging input buffers: (%zu, %zu) -> %zu\n",
- // szs[0], szs[1], sz);
+ PARA_DEBUG_LOG("merging input buffers: (%zu, %zu) -> %zu\n",
+ szs[0], szs[1], sz);
buf = para_malloc(sz);
/* TODO: Avoid this memcopy by introducing btr buffer pool. */
memcpy(buf, bufs[0], szs[0]);
size_t len = btr_next_buffer(btrn, &buf);
if (len >= dest_size)
return;
+ PARA_DEBUG_LOG("input size = %zu < %zu = dest\n", len, dest_size);
if (merge_input(btrn) < 2)
return;
}
/** 640K ought to be enough for everybody ;) */
#define BTRN_MAX_PENDING (640 * 1024)
-int btr_node_status(struct btr_node *btrn, size_t min_iqs)
+int btr_node_status(struct btr_node *btrn, size_t min_iqs,
+ enum btr_node_type type)
{
size_t iqs;
- if (btr_eof(btrn))
- return -E_BTR_EOF;
- if (btr_bytes_pending(btrn) > BTRN_MAX_PENDING)
- return 0;
- iqs = btr_get_input_queue_size(btrn);
- if (iqs == 0) /* we have a parent, because not eof */
- return 0;
- if (iqs < min_iqs && !btr_no_parent(btrn))
- return 0;
+ if (type != BTR_NT_LEAF) {
+ if (btr_no_children(btrn))
+ return -E_BTR_NO_CHILD;
+ if (btr_bytes_pending(btrn) > BTRN_MAX_PENDING)
+ return 0;
+ }
+ if (type != BTR_NT_ROOT) {
+ if (btr_eof(btrn))
+ return -E_BTR_EOF;
+ iqs = btr_get_input_queue_size(btrn);
+ if (iqs == 0) /* we have a parent, because not eof */
+ return 0;
+ if (iqs < min_iqs && !btr_no_parent(btrn))
+ return 0;
+ }
return 1;
}
+
+void btr_get_node_start(struct btr_node *btrn, struct timeval *tv)
+{
+ *tv = btrn->start;
+}