diff options
author | Matias Elo <matias.elo@nokia.com> | 2024-06-05 13:51:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-05 13:51:39 +0300 |
commit | 616034b9c9c789923f7ebe7f1c6d014c4ce8a5d2 (patch) | |
tree | dd1b579c93404d2d98b78944bbdf8313ec499bee /test/performance/odp_stress.c | |
parent | 8063101c4fac56e16c5a2bb9843f2fd9c5acbfd7 (diff) | |
parent | 87913e636da621d47a8d3bc91fbe131abc09c294 (diff) |
Merge ODP v1.45.0.0HEADv1.45.0.0_DPDK_22.11master
Merge ODP linux-generic v1.45.0.0 into linux-dpdk.
Diffstat (limited to 'test/performance/odp_stress.c')
-rw-r--r-- | test/performance/odp_stress.c | 131 |
1 files changed, 103 insertions, 28 deletions
diff --git a/test/performance/odp_stress.c b/test/performance/odp_stress.c index 3ec01df33..1f768b353 100644 --- a/test/performance/odp_stress.c +++ b/test/performance/odp_stress.c @@ -1,7 +1,5 @@ -/* Copyright (c) 2022, Nokia - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022-2024 Nokia */ /** @@ -23,6 +21,11 @@ #include <odp_api.h> #include <odp/helper/odph_api.h> +#define MODE_MEMCPY 0x1 +#define MODE_COPY_U32 0x2 +#define MODE_SQRT_U32 0x4 +#define MODE_SQRT_F32 0x8 + typedef struct test_options_t { uint32_t num_cpu; uint64_t period_ns; @@ -37,6 +40,7 @@ typedef struct test_stat_t { uint64_t rounds; uint64_t tot_nsec; uint64_t work_nsec; + uint64_t dummy_sum; } test_stat_t; @@ -61,7 +65,7 @@ typedef struct test_global_t { odp_timer_pool_t timer_pool; odp_pool_t tmo_pool; uint64_t period_ticks; - uint8_t *worker_mem; + void *worker_mem; odp_timer_t timer[ODP_THREAD_COUNT_MAX]; odp_queue_t tmo_queue[ODP_THREAD_COUNT_MAX]; odp_schedule_group_t group[ODP_THREAD_COUNT_MAX]; @@ -75,6 +79,35 @@ typedef struct test_global_t { test_global_t *test_global; +/* 250 random numbers: values between 100 and 20000 */ +static const uint32_t pseudo_rand[] = { + 14917, 9914, 5313, 4092, 16041, 7757, 17247, 14804, 3255, 7675, + 13149, 7288, 5665, 7095, 9594, 1296, 2058, 6013, 17779, 11788, + 14855, 760, 16891, 2483, 10937, 16385, 13593, 10674, 4080, 2392, + 12218, 11475, 6009, 5798, 7582, 8358, 4520, 14655, 10555, 6598, + 10598, 16097, 16634, 17102, 16296, 17142, 5748, 11079, 14569, 10961, + 16693, 17775, 19155, 14102, 16132, 19561, 8746, 4521, 8280, 355, + 10655, 14539, 5641, 2343, 19213, 9187, 570, 15096, 780, 1711, + 8007, 8128, 17416, 14123, 4713, 13774, 11450, 9031, 1194, 16531, + 9349, 3496, 19130, 19458, 12412, 9168, 9508, 10607, 5952, 19375, + 14934, 18276, 12116, 510, 14272, 10362, 4095, 6789, 1600, 18509, + 9274, 2815, 3175, 1122, 6495, 7991, 18831, 17550, 7056, 16185, + 18594, 19178, 10028, 1182, 13410, 16173, 3548, 8013, 6099, 2619, + 7359, 6889, 15227, 4910, 12341, 18904, 671, 5851, 9836, 18105, + 13624, 8138, 5751, 15590, 17415, 15330, 697, 11439, 7008, 10676, + 9863, 17163, 10885, 5581, 8078, 4689, 9870, 18370, 19323, 8831, + 11444, 3602, 10125, 6244, 13171, 19335, 15635, 19684, 17581, 9513, + 8444, 13724, 5243, 9987, 19886, 5087, 17292, 16294, 19627, 14985, + 1999, 9889, 1311, 5589, 10084, 911, 301, 2260, 15305, 8265, + 409, 1732, 1463, 17680, 15038, 2440, 4239, 9554, 14045, 924, + 13997, 3472, 18304, 4848, 10601, 18604, 6459, 19394, 2962, 11218, + 5405, 9869, 133, 2512, 13440, 4350, 625, 6580, 5082, 12908, + 11517, 8919, 354, 14216, 3190, 15515, 1277, 1028, 507, 9525, + 10115, 811, 1268, 17587, 5192, 7240, 17371, 4902, 19908, 1027, + 3475, 8658, 11782, 13701, 13034, 154, 4940, 12679, 14067, 2707, + 10180, 4669, 17756, 6602, 6727, 818, 8644, 580, 16988, 19127 +}; + static void print_usage(void) { printf("\n" @@ -83,9 +116,12 @@ static void print_usage(void) " -c, --num_cpu Number of CPUs (worker threads). 0: all available CPUs. Default: 1\n" " -p, --period_ns Timeout period in nsec. Default: 100 ms\n" " -r, --rounds Number of timeout rounds. Default: 2\n" - " -m, --mode Select test mode. Default: 1\n" - " 0: No stress, just wait for timeouts\n" - " 1: Memcpy\n" + " -m, --mode Test mode flags, multiple may be selected. Default: 0x1\n" + " 0: No stress, just wait for timeouts\n" + " 0x1: memcpy()\n" + " 0x2: Memory copy loop\n" + " 0x4: Integer square root\n" + " 0x8: Floating point square root\n" " -s, --mem_size Memory size per worker in bytes. Default: 2048\n" " -g, --group_mode Select schedule group mode: Default: 1\n" " 0: Use GROUP_ALL group. Scheduler load balances timeout events.\n" @@ -116,7 +152,7 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options) test_options->num_cpu = 1; test_options->period_ns = 100 * ODP_TIME_MSEC_IN_NS; test_options->rounds = 2; - test_options->mode = 1; + test_options->mode = MODE_MEMCPY; test_options->mem_size = 2048; test_options->group_mode = 1; @@ -137,7 +173,7 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options) test_options->rounds = atoll(optarg); break; case 'm': - test_options->mode = atoi(optarg); + test_options->mode = strtoul(optarg, NULL, 0); break; case 's': test_options->mem_size = atoll(optarg); @@ -155,8 +191,9 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options) } if (test_options->mode) { - if (test_options->mem_size < 2) { - ODPH_ERR("Too small memory size\n"); + if (test_options->mem_size < sizeof(uint32_t)) { + ODPH_ERR("Too small memory size. Minimum is %zu bytes.\n", + sizeof(uint32_t)); return -1; } } @@ -218,20 +255,25 @@ static int worker_thread(void *arg) odp_event_t ev; odp_timeout_t tmo; odp_timer_t timer; - uint64_t tot_nsec, work_sum, max_nsec; + uint64_t tot_nsec, work_sum, max_nsec, i; odp_timer_start_t start_param; odp_time_t t1, t2, max_time; odp_time_t work_t1, work_t2; uint8_t *src = NULL, *dst = NULL; + uint32_t *src_u32 = NULL, *dst_u32 = NULL; thread_arg_t *thread_arg = arg; int worker_idx = thread_arg->worker_idx; test_global_t *global = thread_arg->global; test_options_t *test_options = &global->test_options; - int mode = test_options->mode; - int group_mode = test_options->group_mode; - uint64_t mem_size = test_options->mem_size; - uint64_t copy_size = mem_size / 2; + const int group_mode = test_options->group_mode; + const int mode = test_options->mode; + const int data_mode = mode & (MODE_SQRT_U32 | MODE_SQRT_F32); + const uint64_t mem_size = test_options->mem_size; + const uint64_t copy_size = mem_size / 2; + const uint64_t num_words = mem_size / sizeof(uint32_t); + const uint64_t copy_words = num_words / 2; uint64_t rounds = 0; + uint64_t dummy_sum = 0; int ret = 0; uint32_t done = 0; uint64_t wait = ODP_SCHED_WAIT; @@ -255,8 +297,10 @@ static int worker_thread(void *arg) } if (mode) { - src = global->worker_mem + worker_idx * mem_size; + src = (uint8_t *)global->worker_mem + worker_idx * mem_size; dst = src + copy_size; + src_u32 = (uint32_t *)(uintptr_t)src; + dst_u32 = (uint32_t *)(uintptr_t)dst; } start_param.tick_type = ODP_TIMER_TICK_REL; @@ -316,7 +360,22 @@ static int worker_thread(void *arg) if (mode) { work_t1 = odp_time_local(); - memcpy(dst, src, copy_size); + if (mode & MODE_MEMCPY) + memcpy(dst, src, copy_size); + + if (mode & MODE_COPY_U32) + for (i = 0; i < copy_words; i++) + dst_u32[i] = src_u32[i]; + + if (data_mode) { + for (i = 0; i < num_words; i++) { + if (mode & MODE_SQRT_U32) + dummy_sum += odph_stress_sqrt_u32(src_u32[i]); + + if (mode & MODE_SQRT_F32) + dummy_sum += odph_stress_sqrt_f32(src_u32[i]); + } + } work_t2 = odp_time_local(); work_sum += odp_time_diff_ns(work_t2, work_t1); @@ -336,6 +395,7 @@ static int worker_thread(void *arg) global->stat[thr].rounds = rounds; global->stat[thr].tot_nsec = tot_nsec; global->stat[thr].work_nsec = work_sum; + global->stat[thr].dummy_sum = dummy_sum; return ret; } @@ -656,8 +716,8 @@ static void print_stat(test_global_t *global) test_stat_sum_t *sum = &global->stat_sum; double sec_ave, work_ave, perc; double round_ave = 0.0; - double copy_ave = 0.0; - double copy_tot = 0.0; + double rate_ave = 0.0; + double rate_tot = 0.0; double cpu_load = 0.0; const double mega = 1000000.0; const double giga = 1000000000.0; @@ -692,10 +752,16 @@ static void print_stat(test_global_t *global) cpu_load = 100.0 * (work_ave / sec_ave); if (mode) { - uint64_t copy_bytes = sum->rounds * test_options->mem_size / 2; + uint64_t data_bytes; + + if (mode == MODE_MEMCPY || mode == MODE_COPY_U32 || + mode == (MODE_COPY_U32 | MODE_MEMCPY)) + data_bytes = sum->rounds * test_options->mem_size / 2; + else + data_bytes = sum->rounds * test_options->mem_size; - copy_ave = copy_bytes / (sum->work_nsec / giga); - copy_tot = copy_ave * num_cpu; + rate_ave = data_bytes / (sum->work_nsec / giga); + rate_tot = rate_ave * num_cpu; } } @@ -705,8 +771,8 @@ static void print_stat(test_global_t *global) printf(" ave work: %.2f sec\n", work_ave); printf(" ave CPU load: %.2f\n", cpu_load); printf(" ave rounds per sec: %.2f\n", round_ave / sec_ave); - printf(" ave copy speed: %.2f MB/sec\n", copy_ave / mega); - printf(" total copy speed: %.2f MB/sec\n", copy_tot / mega); + printf(" ave data rate: %.2f MB/sec\n", rate_ave / mega); + printf(" total data rate: %.2f MB/sec\n", rate_tot / mega); printf("\n"); } @@ -798,6 +864,10 @@ int main(int argc, char **argv) /* Memory for workers */ if (mode) { + uint64_t num_words; + uint32_t *word; + uint32_t num_rand = ODPH_ARRAY_SIZE(pseudo_rand); + mem_size = test_options->mem_size * num_cpu; shm = odp_shm_reserve("Test memory", mem_size, ODP_CACHE_LINE_SIZE, 0); @@ -813,13 +883,18 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - memset(global->worker_mem, 0, mem_size); + num_words = mem_size / sizeof(uint32_t); + word = (uint32_t *)global->worker_mem; + + for (uint64_t j = 0; j < num_words; j++) + word[j] = pseudo_rand[j % num_rand]; + } printf("\n"); printf("Test parameters\n"); printf(" num workers %u\n", num_cpu); - printf(" mode %i\n", mode); + printf(" mode 0x%x\n", mode); printf(" group mode %i\n", test_options->group_mode); printf(" mem size per worker %" PRIu64 " bytes\n", test_options->mem_size); |