2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2016 Intel Corporation.
|
2016-05-24 18:04:20 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2016-08-18 19:52:48 +00:00
|
|
|
#include "spdk/env.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
#include "spdk/event.h"
|
|
|
|
#include "spdk/log.h"
|
2019-01-23 02:13:58 +00:00
|
|
|
#include "spdk/string.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
static uint64_t g_tsc_rate;
|
2017-06-06 06:31:47 +00:00
|
|
|
static uint64_t g_tsc_end;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
static int g_time_in_sec;
|
|
|
|
|
2017-12-28 17:15:04 +00:00
|
|
|
static uint64_t *call_count;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-11-03 17:41:07 +00:00
|
|
|
static bool g_app_stopped = false;
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
static void
|
2017-01-05 01:19:02 +00:00
|
|
|
submit_new_event(void *arg1, void *arg2)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
2017-01-05 01:19:02 +00:00
|
|
|
struct spdk_event *event;
|
2017-12-28 17:15:04 +00:00
|
|
|
static __thread uint32_t next_lcore = UINT32_MAX;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
if (spdk_get_ticks() > g_tsc_end) {
|
2017-11-03 17:41:07 +00:00
|
|
|
if (__sync_bool_compare_and_swap(&g_app_stopped, false, true)) {
|
2017-10-25 13:58:02 +00:00
|
|
|
spdk_app_stop(0);
|
|
|
|
}
|
2017-06-06 06:31:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-28 17:15:04 +00:00
|
|
|
if (next_lcore == UINT32_MAX) {
|
|
|
|
next_lcore = spdk_env_get_next_core(spdk_env_get_current_core());
|
|
|
|
if (next_lcore == UINT32_MAX) {
|
|
|
|
next_lcore = spdk_env_get_first_core();
|
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
call_count[next_lcore]++;
|
2017-01-05 01:40:14 +00:00
|
|
|
event = spdk_event_allocate(next_lcore, submit_new_event, NULL, NULL);
|
2016-05-24 18:04:20 +00:00
|
|
|
spdk_event_call(event);
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
static void
|
|
|
|
event_work_fn(void *arg1, void *arg2)
|
2016-05-24 18:04:20 +00:00
|
|
|
{
|
|
|
|
|
2017-01-05 01:19:02 +00:00
|
|
|
submit_new_event(NULL, NULL);
|
|
|
|
submit_new_event(NULL, NULL);
|
|
|
|
submit_new_event(NULL, NULL);
|
|
|
|
submit_new_event(NULL, NULL);
|
2017-06-06 06:31:47 +00:00
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
static void
|
2019-03-04 20:52:59 +00:00
|
|
|
event_perf_start(void *arg1)
|
2017-06-06 06:31:47 +00:00
|
|
|
{
|
|
|
|
uint32_t i;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-12-28 17:15:04 +00:00
|
|
|
call_count = calloc(spdk_env_get_last_core() + 1, sizeof(*call_count));
|
|
|
|
if (call_count == NULL) {
|
|
|
|
fprintf(stderr, "call_count allocation failed\n");
|
|
|
|
spdk_app_stop(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
g_tsc_rate = spdk_get_ticks_hz();
|
|
|
|
g_tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
printf("Running I/O for %d seconds...", g_time_in_sec);
|
|
|
|
fflush(stdout);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
|
|
|
spdk_event_call(spdk_event_allocate(i, event_work_fn,
|
|
|
|
NULL, NULL));
|
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(char *program_name)
|
|
|
|
{
|
|
|
|
printf("%s options\n", program_name);
|
|
|
|
printf("\t[-m core mask for distributing I/O submission/completion work\n");
|
|
|
|
printf("\t\t(default: 0x1 - use core 0 only)]\n");
|
|
|
|
printf("\t[-t time in seconds]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
performance_dump(int io_time)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
|
2017-12-28 17:15:04 +00:00
|
|
|
if (call_count == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
printf("\n");
|
2017-04-03 22:02:49 +00:00
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
2016-05-24 18:04:20 +00:00
|
|
|
printf("lcore %2d: %8ju\n", i, call_count[i] / g_time_in_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
fflush(stdout);
|
2017-12-28 17:15:04 +00:00
|
|
|
free(call_count);
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2017-06-06 06:31:47 +00:00
|
|
|
struct spdk_app_opts opts = {};
|
2016-05-24 18:04:20 +00:00
|
|
|
int op;
|
2018-02-22 23:50:51 +00:00
|
|
|
int rc = 0;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
spdk_app_opts_init(&opts, sizeof(opts));
|
2017-01-20 22:21:18 +00:00
|
|
|
opts.name = "event_perf";
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
g_time_in_sec = 0;
|
|
|
|
|
|
|
|
while ((op = getopt(argc, argv, "m:t:")) != -1) {
|
|
|
|
switch (op) {
|
|
|
|
case 'm':
|
|
|
|
opts.reactor_mask = optarg;
|
|
|
|
break;
|
|
|
|
case 't':
|
2019-01-23 02:13:58 +00:00
|
|
|
g_time_in_sec = spdk_strtol(optarg, 10);
|
|
|
|
if (g_time_in_sec < 0) {
|
|
|
|
fprintf(stderr, "Invalid run time\n");
|
|
|
|
return g_time_in_sec;
|
|
|
|
}
|
2016-05-24 18:04:20 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_time_in_sec) {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Running I/O for %d seconds...", g_time_in_sec);
|
|
|
|
fflush(stdout);
|
|
|
|
|
2019-02-28 21:42:07 +00:00
|
|
|
rc = spdk_app_start(&opts, event_perf_start, NULL);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-06-06 06:31:47 +00:00
|
|
|
spdk_app_fini();
|
2016-05-24 18:04:20 +00:00
|
|
|
performance_dump(g_time_in_sec);
|
|
|
|
|
|
|
|
printf("done.\n");
|
2018-02-22 23:50:51 +00:00
|
|
|
return rc;
|
2016-05-24 18:04:20 +00:00
|
|
|
}
|