int main(void) { void *r; uint64_t s, e, a; unsigned int i; unsigned int j; ck_hp_fifo_entry_t hp_entry[ENTRIES]; ck_hp_fifo_entry_t hp_stub; ck_hp_record_t record; ck_hp_init(&fifo_hp, CK_HP_FIFO_SLOTS_COUNT, 1000000, NULL); r = malloc(CK_HP_FIFO_SLOTS_SIZE); if (r == NULL) { fprintf(stderr, "ERROR: Failed to allocate slots.\n"); exit(EXIT_FAILURE); } ck_hp_register(&fifo_hp, &record, r); a = 0; for (i = 0; i < STEPS; i++) { ck_hp_fifo_init(&fifo, &hp_stub); s = rdtsc(); for (j = 0; j < ENTRIES; j++) ck_hp_fifo_enqueue_mpmc(&record, &fifo, hp_entry + j, NULL); e = rdtsc(); a += e - s; } printf("ck_hp_fifo_enqueue_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); a = 0; for (i = 0; i < STEPS; i++) { ck_hp_fifo_init(&fifo, &hp_stub); for (j = 0; j < ENTRIES; j++) ck_hp_fifo_enqueue_mpmc(&record, &fifo, hp_entry + j, NULL); s = rdtsc(); for (j = 0; j < ENTRIES; j++) ck_hp_fifo_dequeue_mpmc(&record, &fifo, &r); e = rdtsc(); a += e - s; } printf("ck_hp_fifo_dequeue_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); return 0; }
int main(void) { ck_hp_record_t record; ck_stack_entry_t entry[ENTRIES]; uint64_t s, e, a; unsigned int i; unsigned int j; void *r; ck_hp_init(&stack_hp, CK_HP_STACK_SLOTS_COUNT, 1000000, NULL); r = malloc(CK_HP_STACK_SLOTS_SIZE); if (r == NULL) { ck_error("ERROR: Failed to allocate slots.\n"); } ck_hp_register(&stack_hp, &record, (void *)r); a = 0; for (i = 0; i < STEPS; i++) { ck_stack_init(&stack); s = rdtsc(); for (j = 0; j < ENTRIES; j++) ck_hp_stack_push_mpmc(&stack, entry + j); e = rdtsc(); a += e - s; } printf("ck_hp_stack_push_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); a = 0; for (i = 0; i < STEPS; i++) { ck_stack_init(&stack); for (j = 0; j < ENTRIES; j++) ck_hp_stack_push_mpmc(&stack, entry + j); s = rdtsc(); for (j = 0; j < ENTRIES; j++) { r = ck_hp_stack_pop_mpmc(&record, &stack); } e = rdtsc(); a += e - s; } printf(" ck_hp_stack_pop_mpmc: %16" PRIu64 "\n", a / STEPS / ENTRIES); return 0; }
int main(int argc, char *argv[]) { int i, r; struct context *context; pthread_t *thread; int threshold; if (argc != 5) { fprintf(stderr, "Usage: validate <threads> <affinity delta> <size> <threshold>\n"); exit(EXIT_FAILURE); } a.delta = atoi(argv[2]); nthr = atoi(argv[1]); assert(nthr >= 1); size = atoi(argv[3]); assert(size > 0); threshold = atoi(argv[4]); assert(threshold > 0); context = malloc(sizeof(*context) * nthr); assert(context); thread = malloc(sizeof(pthread_t) * nthr); assert(thread); ck_hp_init(&fifo_hp, 2, threshold, destructor); ck_hp_fifo_init(&fifo, malloc(sizeof(ck_hp_fifo_entry_t))); for (i = 0; i < nthr; i++) { context[i].tid = i; r = pthread_create(thread + i, NULL, test, context + i); assert(r == 0); } for (i = 0; i < nthr; i++) pthread_join(thread[i], NULL); return (0); }
int main(int argc, char** argv) { ck_hp_fifo_entry_t *stub; unsigned long element_count, i; pthread_t *thr; if (argc != 3) { ck_error("Usage: cktest <thread_count> <element_count>\n"); } /* Get element count from argument */ element_count = atoi(argv[2]); /* Get element count from argument */ thread_count = atoi(argv[1]); /* pthread handles */ thr = malloc(sizeof(pthread_t) * thread_count); /* array for local operation count */ count = malloc(sizeof(unsigned long *) * thread_count); /* * Initialize global hazard pointer safe memory reclamation to execute free() * when a fifo_entry is safe to be deleted. * Hazard pointer scan routine will be called when the thread local intern plist's * size exceed 100 entries. */ /* FIFO queue needs 2 hazard pointers */ ck_hp_init(&fifo_hp, CK_HP_FIFO_SLOTS_COUNT, 100, destructor); /* The FIFO requires one stub entry on initialization. */ stub = malloc(sizeof(ck_hp_fifo_entry_t)); /* Behavior is undefined if stub is NULL. */ if (stub == NULL) { exit(EXIT_FAILURE); } /* This is called once to initialize the fifo. */ ck_hp_fifo_init(&fifo, stub); /* Create threads */ for (i = 0; i < thread_count; i++) { count[i] = (element_count + i) / thread_count; if (pthread_create(&thr[i], NULL, queue_50_50, (void *) &count[i]) != 0) { exit(EXIT_FAILURE); } } /* start barrier */ ck_pr_inc_uint(&start_barrier); while (ck_pr_load_uint(&start_barrier) < thread_count + 1); /* end barrier */ ck_pr_inc_uint(&end_barrier); while (ck_pr_load_uint(&end_barrier) < thread_count + 1); /* Join threads */ for (i = 0; i < thread_count; i++) pthread_join(thr[i], NULL); return 0; }