void cyclic_dump_node(cyc_cpu_t *cpu, cyc_index_t *heap, char **c, size_t w, int ndx, int l, int r, int depth) { int heap_left, heap_right; int me; int i, x = l + (r - l) / 2; size_t n = w - (x - 1); /* n bytes left for snprintf after c[][x - 1] */ heap_left = CYC_HEAP_LEFT(ndx); heap_right = CYC_HEAP_RIGHT(ndx); me = heap[ndx]; if (ndx >= cpu->cyp_nelems) return; if (me < 10) { (void) mdb_snprintf(&c[depth][x - 1], n, " %d", me); } else if (me >= 100) { (void) mdb_snprintf(&c[depth][x - 1], n, "%3d", me); } else { (void) mdb_snprintf(&c[depth][x - 1], n, "%s%2d%s", CYC_HEAP_LEFT(CYC_HEAP_PARENT(ndx)) == ndx ? " " : "", me, CYC_HEAP_LEFT(CYC_HEAP_PARENT(ndx)) == ndx ? "" : " "); } if (r - l > 5) { c[++depth][x] = '|'; depth++; for (i = l + (r - l) / 4; i < r - (r - l) / 4; i++) c[depth][i] = '-'; c[depth][l + (r - l) / 4] = '+'; c[depth][r - (r - l) / 4 - 1] = '+'; c[depth][x] = '+'; } else { if (heap_left >= cpu->cyp_nelems) return; (void) mdb_snprintf(&c[++depth][x - 1], n, "L%d", heap[heap_left]); if (heap_right >= cpu->cyp_nelems) return; (void) mdb_snprintf(&c[++depth][x - 1], n, "R%d", heap[heap_right]); return; } if (heap_left < cpu->cyp_nelems) cyclic_dump_node(cpu, heap, c, w, heap_left, l, x, depth + 1); if (heap_right < cpu->cyp_nelems) cyclic_dump_node(cpu, heap, c, w, heap_right, x, r, depth + 1); }
/* * Returns 1 if the upheap propagated to the root, 0 if it did not. This * allows the caller to reprogram the backend only when the root has been * modified. */ static int cyclic_upheap(cyc_cpu_t *cpu, cyc_index_t ndx) { cyclic_t *cyclics; cyc_index_t *heap; cyc_index_t heap_parent, heap_current = ndx; cyc_index_t parent, current; if (heap_current == 0) return (1); heap = cpu->cyp_heap; cyclics = cpu->cyp_cyclics; heap_parent = CYC_HEAP_PARENT(heap_current); for (;;) { current = heap[heap_current]; parent = heap[heap_parent]; /* * We have an expiration time later than our parent; we're * done. */ if (cyclics[current].cy_expire >= cyclics[parent].cy_expire) return (0); /* * We need to swap with our parent, and continue up the heap. */ heap[heap_parent] = current; heap[heap_current] = parent; /* * If we just reached the root, we're done. */ if (heap_parent == 0) return (1); heap_current = heap_parent; heap_parent = CYC_HEAP_PARENT(heap_current); } }