void *perftest_thread(void *arg) { thread_data_t *thread_data = (thread_data_t *)arg; int thread_index = thread_data->thread_index; int write_elem = thread_data->write_elem; int read_elem; unsigned long random_seed = 1234; unsigned long *value_ptr; unsigned long *new_value_ptr; unsigned long value; unsigned long long reads = 0; unsigned long long writes = 0; set_affinity(thread_index); rcu_register_thread(); rcu_defer_register_thread(); lock_mb(); while (goflag == GOFLAG_INIT) poll(NULL, 0, 10); switch (thread_data->mode) { case MODE_READONLY: while (goflag == GOFLAG_RUN) { read_elem = get_random(&random_seed) % Tree_Scale; value = *Values[read_elem]; reads++; } break; case MODE_WRITE: while (goflag == GOFLAG_RUN) { write_elem = get_random(&random_seed) % Tree_Size; value_ptr = Values[write_elem]; value = get_random(&random_seed) % Tree_Scale + 1; new_value_ptr = (unsigned long *)malloc(sizeof(unsigned long *)); *new_value_ptr = value; rcu_assign_pointer(Values[write_elem], new_value_ptr); defer_rcu(free, value_ptr); writes++; } break; } rcu_unregister_thread(); rcu_defer_unregister_thread(); printf("thread %d reads %lld writes %lld\n", thread_index, reads, writes); return NULL; }
void *thr_dequeuer(void *_count) { unsigned long long *count = _count; int ret; printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n", "dequeuer", pthread_self(), (unsigned long)gettid()); set_affinity(); ret = rcu_defer_register_thread(); if (ret) { printf("Error in rcu_defer_register_thread\n"); exit(-1); } rcu_register_thread(); while (!test_go) { } cmm_smp_mb(); for (;;) { struct cds_lfq_node_rcu *qnode; struct test *node; rcu_read_lock(); qnode = cds_lfq_dequeue_rcu(&q); node = caa_container_of(qnode, struct test, list); rcu_read_unlock(); if (node) { call_rcu(&node->rcu, free_node_cb); nr_successful_dequeues++; } nr_dequeues++; if (caa_unlikely(!test_duration_dequeue())) break; if (caa_unlikely(rduration)) loop_sleep(rduration); } rcu_unregister_thread(); rcu_defer_unregister_thread(); printf_verbose("dequeuer thread_end, thread id : %lx, tid %lu, " "dequeues %llu, successful_dequeues %llu\n", pthread_self(), (unsigned long)gettid(), nr_dequeues, nr_successful_dequeues); count[0] = nr_dequeues; count[1] = nr_successful_dequeues; return ((void*)2); }