Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH v2] test: queue_perf: fix pair mode issues #2148

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions test/performance/odp_queue_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ typedef struct test_global_t {
odp_instance_t instance;
odp_shm_t shm;
odp_pool_t pool;
odp_atomic_u32_t workers_finished;
odp_queue_t queue[MAX_QUEUES];
odph_thread_t thread_tbl[ODP_THREAD_COUNT_MAX];
thread_args_t thread_args[ODP_THREAD_COUNT_MAX];
Expand Down Expand Up @@ -233,6 +234,7 @@ static int create_queues(test_global_t *global)
uint32_t num_event = test_options->num_event;
uint32_t num_round = test_options->num_round;
uint32_t tot_event = num_queue * num_event;
uint32_t queue_size = test_options->mode == TEST_MODE_PAIR ? 2 * num_event : num_event;
int ret = 0;
odp_queue_t *queue = global->queue;
odp_event_t event[tot_event];
Expand All @@ -248,6 +250,7 @@ static int create_queues(test_global_t *global)
printf(" num rounds %u\n", num_round);
printf(" num queues %u\n", num_queue);
printf(" num events per queue %u\n", num_event);
printf(" queue size %u\n", queue_size);
printf(" max burst size %u\n", test_options->max_burst);

for (i = 0; i < num_queue; i++)
Expand All @@ -273,7 +276,7 @@ static int create_queues(test_global_t *global)
}

max_size = queue_capa.plain.max_size;
if (max_size && num_event > max_size) {
if (max_size && queue_size > max_size) {
ODPH_ERR("Max queue size supported %u.\n", max_size);
return -1;
}
Expand All @@ -290,7 +293,7 @@ static int create_queues(test_global_t *global)
}

max_size = queue_capa.plain.lockfree.max_size;
if (max_size && num_event > max_size) {
if (max_size && queue_size > max_size) {
ODPH_ERR("Max lockfree queue size supported %u.\n", max_size);
return -1;
}
Expand All @@ -307,7 +310,7 @@ static int create_queues(test_global_t *global)
}

max_size = queue_capa.plain.waitfree.max_size;
if (max_size && num_event > max_size) {
if (max_size && queue_size > max_size) {
ODPH_ERR("Max waitfree queue size supported %u.\n", max_size);
return -1;
}
Expand Down Expand Up @@ -339,7 +342,7 @@ static int create_queues(test_global_t *global)
odp_queue_param_init(&queue_param);
queue_param.type = ODP_QUEUE_TYPE_PLAIN;
queue_param.nonblocking = nonblock;
queue_param.size = num_event;
queue_param.size = queue_size;

if (test_options->single) {
queue_param.enq_mode = ODP_QUEUE_OP_MT_UNSAFE;
Expand Down Expand Up @@ -444,6 +447,7 @@ static int run_test(void *arg)
uint64_t events = 0;
const uint32_t num_queue = thr_args->num_queues;
const uint32_t num_round = thr_args->options->num_round;
const uint32_t num_workers = thr_args->options->num_cpu;
const uint32_t max_burst = thr_args->options->max_burst;
uint32_t queue_idx = 0;
odp_event_t ev[max_burst];
Expand Down Expand Up @@ -499,6 +503,32 @@ static int run_test(void *arg)
c2 = odp_cpu_cycles();
t2 = odp_time_local_strict();

odp_atomic_inc_u32(&global->workers_finished);

/* Keep forwarding events in pair mode until all workers have completed */
while (thr_args->options->mode == TEST_MODE_PAIR &&
odp_atomic_load_u32(&global->workers_finished) < num_workers) {
int num_enq = 0;

src_queue = src_queue_tbl[queue_idx];
dst_queue = dst_queue_tbl[queue_idx];

queue_idx++;
if (queue_idx == num_queue)
queue_idx = 0;

num_ev = odp_queue_deq_multi(src_queue, ev, max_burst);

while (num_enq < num_ev) {
int num = odp_queue_enq_multi(dst_queue, &ev[num_enq], num_ev - num_enq);

if (odp_unlikely(num < 0))
ODPH_ABORT("odp_queue_enq_multi() failed\n");

num_enq += num;
}
}

nsec = odp_time_diff_ns(t2, t1);
cycles = odp_cpu_cycles_diff(c2, c1);

Expand Down Expand Up @@ -809,6 +839,7 @@ int main(int argc, char **argv)

memset(global, 0, sizeof(test_global_t));
global->common_options = common_options;
odp_atomic_init_u32(&global->workers_finished, 0);

if (parse_options(argc, argv, &global->options))
return -1;
Expand Down