Skip to content

Commit

Permalink
test: sched_perf: add user area touch
Browse files Browse the repository at this point in the history
Added options to read (-u) and modify (-U) user area content
per event reception.

Signed-off-by: Petri Savolainen <[email protected]>
  • Loading branch information
psavol committed Jan 16, 2024
1 parent abf2bb6 commit 2b80933
Showing 1 changed file with 68 additions and 14 deletions.
82 changes: 68 additions & 14 deletions test/performance/odp_sched_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ typedef struct test_options_t {
uint32_t ctx_size;
uint32_t ctx_rd_words;
uint32_t ctx_rw_words;
uint32_t uarea_rd;
uint32_t uarea_rw;
uint32_t uarea_size;
uint64_t wait_ns;
int verbose;

Expand Down Expand Up @@ -135,6 +138,8 @@ static void print_usage(void)
" -l, --ctx_rw_words Number of queue context words (uint64_t) to modify on every event. Default: 0.\n"
" -n, --rd_words Number of event data words (uint64_t) to read before enqueueing it. Default: 0.\n"
" -m, --rw_words Number of event data words (uint64_t) to modify before enqueueing it. Default: 0.\n"
" -u, --uarea_rd Number of user area words (uint64_t) to read on every event. Default: 0.\n"
" -U, --uarea_rw Number of user area words (uint64_t) to modify on every event. Default: 0.\n"
" -p, --pool_type Pool type. 0: buffer, 1: packet. Default: 0.\n"
" -v, --verbose Verbose output.\n"
" -h, --help This help\n"
Expand Down Expand Up @@ -167,13 +172,15 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options)
{"ctx_rw_words", required_argument, NULL, 'l'},
{"rd_words", required_argument, NULL, 'n'},
{"rw_words", required_argument, NULL, 'm'},
{"uarea_rd", required_argument, NULL, 'u'},
{"uarea_rw", required_argument, NULL, 'U'},
{"pool_type", required_argument, NULL, 'p'},
{"verbose", no_argument, NULL, 'v'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};

static const char *shortopts = "+c:q:L:H:d:e:s:g:j:b:t:f:a:w:k:l:n:m:p:vh";
static const char *shortopts = "+c:q:L:H:d:e:s:g:j:b:t:f:a:w:k:l:n:m:p:u:U:vh";

test_options->num_cpu = 1;
test_options->num_queue = 1;
Expand All @@ -192,6 +199,8 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options)
test_options->ctx_rw_words = 0;
test_options->rd_words = 0;
test_options->rw_words = 0;
test_options->uarea_rd = 0;
test_options->uarea_rw = 0;
test_options->wait_ns = 0;
test_options->verbose = 0;

Expand Down Expand Up @@ -253,6 +262,12 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options)
case 'm':
test_options->rw_words = atoi(optarg);
break;
case 'u':
test_options->uarea_rd = atoi(optarg);
break;
case 'U':
test_options->uarea_rw = atoi(optarg);
break;
case 'p':
pool_type = atoi(optarg);
break;
Expand Down Expand Up @@ -345,6 +360,7 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options)
ctx_size = ROUNDUP(ctx_size, ODP_CACHE_LINE_SIZE);

test_options->ctx_size = ctx_size;
test_options->uarea_size = 8 * (test_options->uarea_rd + test_options->uarea_rw);

return ret;
}
Expand Down Expand Up @@ -385,7 +401,7 @@ static int create_pool(test_global_t *global)
odp_pool_capability_t pool_capa;
odp_pool_param_t pool_param;
odp_pool_t pool;
uint32_t max_num, max_size;
uint32_t max_num, max_size, max_uarea;
test_options_t *test_options = &global->test_options;
uint32_t num_cpu = test_options->num_cpu;
uint32_t num_queue = test_options->num_queue;
Expand All @@ -403,6 +419,7 @@ static int create_pool(test_global_t *global)
uint32_t event_size = 16;
int touch_data = test_options->touch_data;
uint32_t ctx_size = test_options->ctx_size;
uint32_t uarea_size = test_options->uarea_size;

if (touch_data) {
event_size = test_options->rd_words + test_options->rw_words;
Expand Down Expand Up @@ -434,22 +451,22 @@ static int create_pool(test_global_t *global)
printf(" max burst size %u\n", max_burst);
printf(" total events %u\n", tot_event);
printf(" event size %u bytes", event_size);
if (touch_data) {
printf(" (rd: %u, rw: %u)\n",
8 * test_options->rd_words,
8 * test_options->rw_words);
} else {
printf("\n");
}
if (touch_data)
printf(" (rd: %u, rw: %u)", 8 * test_options->rd_words, 8 * test_options->rw_words);
printf("\n");

printf(" context size %u bytes", ctx_size);
if (test_options->ctx_rd_words || test_options->ctx_rw_words) {
printf(" (rd: %u, rw: %u)\n",
printf(" (rd: %u, rw: %u)",
8 * test_options->ctx_rd_words,
8 * test_options->ctx_rw_words);
} else {
printf("\n");
}
printf("\n");

printf(" user area size %u bytes", uarea_size);
if (uarea_size)
printf(" (rd: %u, rw: %u)", 8 * test_options->uarea_rd, 8 * test_options->uarea_rw);
printf("\n");

if (odp_pool_capability(&pool_capa)) {
ODPH_ERR("Error: pool capa failed\n");
Expand All @@ -460,11 +477,12 @@ static int create_pool(test_global_t *global)
printf(" pool type buffer\n");
max_num = pool_capa.buf.max_num;
max_size = pool_capa.buf.max_size;

max_uarea = pool_capa.buf.max_uarea_size;
} else {
printf(" pool type packet\n");
max_num = pool_capa.pkt.max_num;
max_size = pool_capa.pkt.max_seg_len;
max_uarea = pool_capa.pkt.max_uarea_size;
}

if (max_num && tot_event > max_num) {
Expand All @@ -477,18 +495,25 @@ static int create_pool(test_global_t *global)
return -1;
}

if (uarea_size > max_uarea) {
ODPH_ERR("Error: max supported user area size %u\n", max_uarea);
return -1;
}

odp_pool_param_init(&pool_param);
if (test_options->pool_type == ODP_POOL_BUFFER) {
pool_param.type = ODP_POOL_BUFFER;
pool_param.buf.num = tot_event;
pool_param.buf.size = event_size;
pool_param.buf.align = 8;
pool_param.buf.uarea_size = uarea_size;
} else {
pool_param.type = ODP_POOL_PACKET;
pool_param.pkt.num = tot_event;
pool_param.pkt.len = event_size;
pool_param.pkt.seg_len = event_size;
pool_param.pkt.align = 8;
pool_param.pkt.uarea_size = uarea_size;
}

pool = odp_pool_create("sched perf", &pool_param);
Expand Down Expand Up @@ -861,6 +886,28 @@ static int destroy_groups(test_global_t *global)
return 0;
}

static uint64_t rw_uarea(odp_event_t ev[], int num, uint32_t rd_words, uint32_t rw_words)
{
uint64_t *data;
int i;
uint32_t j;
uint64_t sum = 0;

for (i = 0; i < num; i++) {
data = odp_event_user_area(ev[i]);

for (j = 0; j < rd_words; j++)
sum += data[j];

for (; j < rd_words + rw_words; j++) {
sum += data[j];
data[j] += 1;
}
}

return sum;
}

static inline uint64_t rw_ctx_data(void *ctx, uint32_t offset,
uint32_t rd_words, uint32_t rw_words)
{
Expand Down Expand Up @@ -929,12 +976,16 @@ static int test_sched(void *arg)
uint32_t ctx_size = test_options->ctx_size;
uint32_t ctx_rd_words = test_options->ctx_rd_words;
uint32_t ctx_rw_words = test_options->ctx_rw_words;
uint32_t uarea_size = test_options->uarea_size;
uint32_t uarea_rd = test_options->uarea_rd;
uint32_t uarea_rw = test_options->uarea_rw;
odp_pool_type_t pool_type = test_options->pool_type;
int touch_ctx = ctx_rd_words || ctx_rw_words;
uint32_t ctx_offset = 0;
uint32_t sched_retries = 0;
uint64_t data_sum = 0;
uint64_t ctx_sum = 0;
uint64_t uarea_sum = 0;
uint64_t wait_ns = test_options->wait_ns;
odp_event_t ev[max_burst];

Expand Down Expand Up @@ -998,6 +1049,9 @@ static int test_sched(void *arg)
events += num;
i = 0;

if (odp_unlikely(uarea_size))
uarea_sum += rw_uarea(ev, num, uarea_rd, uarea_rw);

if (odp_unlikely(ctx_size)) {
queue_context_t *ctx = odp_queue_context(queue);

Expand Down Expand Up @@ -1085,7 +1139,7 @@ static int test_sched(void *arg)
global->stat[thr].nsec = nsec;
global->stat[thr].cycles = cycles;
global->stat[thr].waits = waits;
global->stat[thr].dummy_sum = data_sum + ctx_sum;
global->stat[thr].dummy_sum = data_sum + ctx_sum + uarea_sum;
global->stat[thr].failed = ret;

if (odp_atomic_fetch_dec_u32(&global->num_worker) == 1) {
Expand Down

0 comments on commit 2b80933

Please sign in to comment.