예제 #1
0
파일: RBT.c 프로젝트: Nesokas/sampleProject
void rbt_insert(struct rbt* tree, int vruntime, struct _sthread *thread){

	struct node *add_item = create_node(tree, vruntime, thread);

	if(rbt_is_empty(tree)) {
		add_item->color = BLACK;
		tree->root = add_item;
		tree->first = tree->root;
		return;
	}

	struct node *current_node = tree->root;
	
	if(vruntime == tree->root->vruntime)
		add_thread(current_node, add_item);
	
	else if(vruntime < current_node->vruntime)
		insert_node_left(tree, current_node->left, current_node, add_item);
	else insert_node_right(tree, current_node->right, current_node, add_item);

	correctDoubleRed(tree, add_item);
	treeRoot(tree);
	lower(tree);

}
예제 #2
0
void
dump_page_alloc(FILE* f) {
    if (!alloc_info) {
        fprintf(f, "not initialized yet\n");
        fflush(f);
        return;
    }

    /* dump the buddy system */
    fprintf (f, "Buddy system: max-order=%d, id - idx = %d\n",
             alloc_info->max_order, alloc_info->idx_2_id_adj);

    int i, e;
    char* page_start_addr = alloc_info->first_page;
    int page_sz_log = alloc_info->page_size_log2;

    for (i = 0, e = alloc_info->max_order; i <= e; i++) {
        rb_tree_t* free_blks = &alloc_info->free_blks[i];

        if (rbt_is_empty(free_blks))
            continue;

        fprintf(f, "Order = %3d: ", i);
        rb_iter_t iter, iter_e;
        for (iter = rbt_iter_begin(free_blks),
                iter_e = rbt_iter_end(free_blks);
             iter != iter_e;
             iter = rbt_iter_inc(free_blks, iter)) {
            rb_node_t* node = rbt_iter_deref(iter);
            page_idx_t page_idx = node->key;
            char* addr = page_start_addr + (page_idx << page_sz_log);
            fprintf(f, "pg_idx:%d (%p, len=%d), ", page_idx,
                    addr, (int)node->value);
            verify_order(page_idx, i);
        }
        fputs("\n", f);
    }

    fprintf(f, "\nAllocated blocks:\n");
    {
        rb_tree_t* rbt = &alloc_info->alloc_blks;
        rb_iter_t iter, iter_e;
        int idx = 0;
        for (iter = rbt_iter_begin(rbt), iter_e = rbt_iter_end(rbt);
             iter != iter_e;
             iter = rbt_iter_inc(rbt, iter)) {
            rb_node_t* nd = rbt_iter_deref(iter);
            int blk = nd->key;
            fprintf(f, "%3d: pg_idx:%d, size:%ld, order = %d\n",
                    idx, blk, nd->value, alloc_info->page_info[blk].order);
            idx++;
        }
    }
}