2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2017 Intel Corporation.
|
2017-01-25 16:49:12 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2017-01-25 16:49:12 +00:00
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
#include "spdk/env.h"
|
2017-01-25 16:49:12 +00:00
|
|
|
#include "spdk/event.h"
|
2019-01-23 02:13:58 +00:00
|
|
|
#include "spdk/string.h"
|
2018-06-11 20:32:15 +00:00
|
|
|
#include "spdk/thread.h"
|
2017-01-25 16:49:12 +00:00
|
|
|
|
|
|
|
static int g_time_in_sec;
|
|
|
|
static int g_queue_depth;
|
2020-02-11 00:35:38 +00:00
|
|
|
static struct spdk_poller *g_test_end_poller;
|
2017-01-25 16:49:12 +00:00
|
|
|
static uint64_t g_call_count = 0;
|
|
|
|
|
2018-03-13 00:16:47 +00:00
|
|
|
static int
|
2017-01-25 16:49:12 +00:00
|
|
|
__test_end(void *arg)
|
|
|
|
{
|
|
|
|
printf("test_end\n");
|
2020-02-11 00:35:38 +00:00
|
|
|
spdk_poller_unregister(&g_test_end_poller);
|
2017-01-25 16:49:12 +00:00
|
|
|
spdk_app_stop(0);
|
2018-03-13 00:16:47 +00:00
|
|
|
return -1;
|
2017-01-25 16:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__submit_next(void *arg1, void *arg2)
|
|
|
|
{
|
|
|
|
struct spdk_event *event;
|
|
|
|
|
|
|
|
g_call_count++;
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
event = spdk_event_allocate(spdk_env_get_current_core(),
|
2017-01-25 16:49:12 +00:00
|
|
|
__submit_next, NULL, NULL);
|
|
|
|
spdk_event_call(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-04 20:52:59 +00:00
|
|
|
test_start(void *arg1)
|
2017-01-25 16:49:12 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("test_start\n");
|
|
|
|
|
|
|
|
/* Register a poller that will stop the test after the time has elapsed. */
|
2020-04-14 06:49:46 +00:00
|
|
|
g_test_end_poller = SPDK_POLLER_REGISTER(__test_end, NULL,
|
2020-02-11 00:35:38 +00:00
|
|
|
g_time_in_sec * 1000000ULL);
|
2017-01-25 16:49:12 +00:00
|
|
|
|
|
|
|
for (i = 0; i < g_queue_depth; i++) {
|
|
|
|
__submit_next(NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_cleanup(void)
|
|
|
|
{
|
|
|
|
printf("test_abort\n");
|
|
|
|
|
2020-02-11 00:35:38 +00:00
|
|
|
spdk_poller_unregister(&g_test_end_poller);
|
2017-01-25 16:49:12 +00:00
|
|
|
spdk_app_stop(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(const char *program_name)
|
|
|
|
{
|
|
|
|
printf("%s options\n", program_name);
|
|
|
|
printf("\t[-q Queue depth (default: 1)]\n");
|
|
|
|
printf("\t[-t time in seconds]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct spdk_app_opts opts;
|
|
|
|
int op;
|
2018-02-22 23:50:51 +00:00
|
|
|
int rc;
|
2019-01-23 02:13:58 +00:00
|
|
|
long int val;
|
2017-01-25 16:49:12 +00:00
|
|
|
|
2020-11-30 11:38:37 +00:00
|
|
|
spdk_app_opts_init(&opts, sizeof(opts));
|
2017-01-25 16:49:12 +00:00
|
|
|
opts.name = "reactor_perf";
|
|
|
|
|
|
|
|
g_time_in_sec = 0;
|
|
|
|
g_queue_depth = 1;
|
|
|
|
|
2019-02-12 23:09:29 +00:00
|
|
|
while ((op = getopt(argc, argv, "q:t:")) != -1) {
|
2019-01-23 02:13:58 +00:00
|
|
|
if (op == '?') {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
val = spdk_strtol(optarg, 10);
|
|
|
|
if (val < 0) {
|
|
|
|
fprintf(stderr, "Converting a string to integer failed\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
2017-01-25 16:49:12 +00:00
|
|
|
switch (op) {
|
|
|
|
case 'q':
|
2019-01-23 02:13:58 +00:00
|
|
|
g_queue_depth = val;
|
2017-01-25 16:49:12 +00:00
|
|
|
break;
|
|
|
|
case 't':
|
2019-01-23 02:13:58 +00:00
|
|
|
g_time_in_sec = val;
|
2017-01-25 16:49:12 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_time_in_sec) {
|
|
|
|
usage(argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.shutdown_cb = test_cleanup;
|
|
|
|
|
2019-02-28 21:42:07 +00:00
|
|
|
rc = spdk_app_start(&opts, test_start, NULL);
|
2017-01-25 16:49:12 +00:00
|
|
|
|
|
|
|
spdk_app_fini();
|
|
|
|
|
|
|
|
printf("Performance: %8ju events per second\n", g_call_count / g_time_in_sec);
|
|
|
|
|
2018-02-22 23:50:51 +00:00
|
|
|
return rc;
|
2017-01-25 16:49:12 +00:00
|
|
|
}
|