⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 it_test.c

📁 lustre 1.6.5 source code
💻 C
📖 第 1 页 / 共 2 页
字号:
        int i, count = 10;        struct interval_node_extent ext, ext2;        struct it_node *n;        __u64 low = 0, high = ~0;        do {                if (--count == 0)                        return 0;                ext.start = random() % max_count;                ext.end = ext.start;        } while (interval_is_overlapped(root, &ext));        ext2 = ext;        interval_expand(root, &ext, NULL);        dprintf("Extending "__S" to .."__S"\n", __F(&ext2), __F(&ext));        for (i = 0; i < it_count; i++) {                n = &it_array[i];                if (n->valid == 0)                        continue;                if (extent_overlapped(&ext, &n->node.in_extent)) {                        error("Extending "__S" to .."__S" overlaps node"__S"\n",                                __F(&ext2), __F(&ext), __F(&n->node.in_extent));                }                if (n->node.in_extent.end < ext2.start)                        low = max_u64(n->node.in_extent.end + 1, low);                if (n->node.in_extent.start > ext2.end)                        high = min_u64(n->node.in_extent.start - 1, high);        }        /* only expanding high right now */        if (ext2.start != ext.start || high != ext.end) {                ext2.start = low, ext2.end = high;                error("Real extending result:"__S", expected:"__S"\n",                       __F(&ext), __F(&ext2));        }        return 0;}static int contended_count = 0; #define LOOP_COUNT 1000static enum interval_iter perf_cb(struct interval_node *n, void *args){        unsigned long count = LOOP_COUNT;        while (count--);        contended_count++;        return INTERVAL_ITER_CONT;}static inline long tv_delta(struct timeval *s, struct timeval *e){        long c = e->tv_sec - s->tv_sec;        c *= 1000;        c += (long int)(e->tv_usec - s->tv_usec) / 1000;        dprintf("\tStart: %lu:%lu -> End: %lu:%lu\n",                 s->tv_sec, s->tv_usec, e->tv_sec, e->tv_usec);        return c;}static int it_test_performance(struct interval_node *root, unsigned long len){        int i = 0, interval_time, list_time;        struct interval_node_extent ext;        struct it_node *n;        struct timeval start, end;        unsigned long count;                ext.start = (random() % (max_count - len)) & ALIGN_MASK;        ext.end = (ext.start + len) & ALIGN_MASK;        if (have_wide_lock) {                ext.start = (max_count - len) & ALIGN_MASK;                ext.end = max_count;        }        dprintf("Extent search"__S"\n", __F(&ext));        /* list */        contended_count = 0;        gettimeofday(&start, NULL);        list_for_each_entry(n, &header, list) {                if (extent_overlapped(&ext, &n->node.in_extent)) {                        count = LOOP_COUNT;                        while (count--);                        contended_count++;                }        }        gettimeofday(&end, NULL);        list_time = tv_delta(&start, &end);        i = contended_count;        /* interval */        contended_count = 0;        gettimeofday(&start, NULL);        interval_search(root, &ext, perf_cb, &contended_count);        gettimeofday(&end, NULL);        interval_time = tv_delta(&start, &end);        if (i != contended_count)                error("count of contended lock don't match(%d: %d)\n",                      i, contended_count);        printf("\tList vs Int. search: \n\t\t"               "(%d vs %d)ms, %d contended lock.\n",                list_time, interval_time, contended_count);        return 0;}static struct interval_node *it_test_helper(struct interval_node *root){        int idx, count = 0;        struct it_node *n;        count = random() % it_count;        while (count--) {                idx = random() % it_count;                n = &it_array[idx];                if (n->valid) {                        if (!interval_find(root, &n->node.in_extent))                                error("Cannot find an existent node\n");                        dprintf("Erasing a node "__S"\n",                                 __F(&n->node.in_extent));                        interval_erase(&n->node, &root);                        n->valid = 0;                        list_del_init(&n->list);                } else {                        __u64 low, high;                        low = (random() % max_count) & ALIGN_MASK;                        high = ((random() % max_count + 1) & ALIGN_MASK) + low;                        if (high > max_count)                                high = max_count;                        interval_set(&n->node, low, high);                        while (interval_insert(&n->node, &root))                                interval_set(&n->node, low, ++high);                        dprintf("Adding a node "__S"\n",                                 __F(&n->node.in_extent));                        n->valid = 1;                        list_add(&n->list, &header);                }        }        return root;}static struct interval_node *it_test_init(int count){        int i;        uint64_t high, low, len;        struct it_node *n;        struct interval_node *root = NULL;        it_count = count;        it_array = (struct it_node *)malloc(sizeof(struct it_node) * count);        if (it_array == NULL)                error("it_array == NULL, no memory\n");        have_wide_lock = 0;        for (i = 0; i < count; i++) {                n = &it_array[i];                do {                        low = (random() % max_count + 1) & ALIGN_MASK;                        len = (random() % 256 + 1) * ALIGN_SIZE;                        if (!have_wide_lock && !(random() % count)) {                                low = 0;                                len = max_count;                                have_wide_lock = 1;                        }                        high = low + (len & ALIGN_MASK);                        interval_set(&n->node, low, high);                } while (interval_insert(&n->node, &root));                n->hit = 0;                n->valid = 1;                if (i == 0)                        list_add_tail(&n->list, &header);                else                        list_add_tail(&n->list, &it_array[rand()%i].list);        }        return root;}static void it_test_fini(void){        free(it_array);        it_array = NULL;        it_count = 0;        max_count = 0;}int main(int argc, char *argv[]){        int count = 5, perf = 0;        struct interval_node *root;        struct timeval tv;        gettimeofday(&tv, NULL);        srandom(tv.tv_usec);        if (argc == 2) {                if (strcmp(argv[1], "-p"))                        error("Unknow options, usage: %s [-p]\n", argv[0]);                perf = 1;                count = 1;        }        if (perf) {                int M = 1024 * 1024;                root = it_test_init(1000000);                printf("1M locks with 4K request size\n");                it_test_performance(root, 4096);                printf("1M locks with 128K request size\n");                it_test_performance(root, 128 * 1024);                printf("1M locks with 256K request size\n");                it_test_performance(root, 256 * 1024);                printf("1M locks with 1M request size\n");                it_test_performance(root, 1 * M);                printf("1M locks with 16M request size\n");                it_test_performance(root, 16 * M);                printf("1M locks with 32M request size\n");                it_test_performance(root, 32 * M);                printf("1M locks with 64M request size\n");                it_test_performance(root, 64 * M);                printf("1M locks with 128M request size\n");                it_test_performance(root, 128 * M);                printf("1M locks with 256M request size\n");                it_test_performance(root, 256 * M);                printf("1M locks with 512M request size\n");                it_test_performance(root, 512 * M);                printf("1M locks with 1G request size\n");                it_test_performance(root, 1024 * M);                printf("1M locks with 2G request size\n");                it_test_performance(root, 2048 * M);                printf("1M locks with 3G request size\n");                it_test_performance(root, 3072 * M);                printf("1M locks with 4G request size\n");                it_test_performance(root, max_count - 1);                it_test_fini();                return 0;        }        root = it_test_init(random() % 100000 + 1000);        while (count--) {                it_test_sanity(root);                it_test_iterate(root);                it_test_iterate_reverse(root);                it_test_find(root);                it_test_search_hole(root);                it_test_search(root);                root = it_test_helper(root);        }        it_test_fini();        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -