Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (C) 2017 Intel Corporation. 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #include "spdk/stdinc.h" 7 : : 8 : : #include "spdk/env.h" 9 : : #include "spdk/event.h" 10 : : #include "spdk/string.h" 11 : : #include "spdk/thread.h" 12 : : 13 : : static int g_time_in_sec; 14 : : static int g_queue_depth; 15 : : static struct spdk_poller *g_test_end_poller; 16 : : static uint64_t g_call_count = 0; 17 : : 18 : : static int 19 : 21 : __test_end(void *arg) 20 : : { 21 [ - + ]: 21 : printf("test_end\n"); 22 : 21 : spdk_poller_unregister(&g_test_end_poller); 23 : 21 : spdk_app_stop(0); 24 : 21 : return -1; 25 : : } 26 : : 27 : : static void 28 : 9628297 : __submit_next(void *arg1, void *arg2) 29 : : { 30 : : struct spdk_event *event; 31 : : 32 : 9628297 : g_call_count++; 33 : : 34 : 9628297 : event = spdk_event_allocate(spdk_env_get_current_core(), 35 : : __submit_next, NULL, NULL); 36 : 9628297 : spdk_event_call(event); 37 : 9628297 : } 38 : : 39 : : static void 40 : 21 : test_start(void *arg1) 41 : : { 42 : : int i; 43 : : 44 [ - + ]: 21 : printf("test_start\n"); 45 : : 46 : : /* Register a poller that will stop the test after the time has elapsed. */ 47 : 21 : g_test_end_poller = SPDK_POLLER_REGISTER(__test_end, NULL, 48 : : g_time_in_sec * 1000000ULL); 49 : : 50 [ + + ]: 42 : for (i = 0; i < g_queue_depth; i++) { 51 : 21 : __submit_next(NULL, NULL); 52 : : } 53 : 21 : } 54 : : 55 : : static void 56 : 0 : test_cleanup(void) 57 : : { 58 [ # # ]: 0 : printf("test_abort\n"); 59 : : 60 : 0 : spdk_poller_unregister(&g_test_end_poller); 61 : 0 : spdk_app_stop(0); 62 : 0 : } 63 : : 64 : : static void 65 : 0 : usage(const char *program_name) 66 : : { 67 [ # # ]: 0 : printf("%s options\n", program_name); 68 [ # # ]: 0 : printf("\t[-q Queue depth (default: 1)]\n"); 69 [ # # ]: 0 : printf("\t[-t time in seconds]\n"); 70 : 0 : } 71 : : 72 : : int 73 : 21 : main(int argc, char **argv) 74 : : { 75 : 10 : struct spdk_app_opts opts; 76 : : int op; 77 : : int rc; 78 : : long int val; 79 : : 80 : 21 : spdk_app_opts_init(&opts, sizeof(opts)); 81 : 21 : opts.name = "reactor_perf"; 82 : 21 : opts.rpc_addr = NULL; 83 : : 84 : 21 : g_time_in_sec = 0; 85 : 21 : g_queue_depth = 1; 86 : : 87 [ + + + + : 42 : while ((op = getopt(argc, argv, "q:t:")) != -1) { + + ] 88 [ - + ]: 21 : if (op == '?') { 89 : 0 : usage(argv[0]); 90 : 0 : exit(1); 91 : : } 92 : 21 : val = spdk_strtol(optarg, 10); 93 [ - + ]: 21 : if (val < 0) { 94 [ # # # # ]: 0 : fprintf(stderr, "Converting a string to integer failed\n"); 95 : 0 : exit(1); 96 : : } 97 [ - + - ]: 21 : switch (op) { 98 : 0 : case 'q': 99 : 0 : g_queue_depth = val; 100 : 0 : break; 101 : 21 : case 't': 102 : 21 : g_time_in_sec = val; 103 : 21 : break; 104 : 0 : default: 105 : 0 : usage(argv[0]); 106 : 0 : exit(1); 107 : : } 108 : : } 109 : : 110 [ - + ]: 21 : if (!g_time_in_sec) { 111 : 0 : usage(argv[0]); 112 : 0 : exit(1); 113 : : } 114 : : 115 : 21 : opts.shutdown_cb = test_cleanup; 116 : : 117 : 21 : rc = spdk_app_start(&opts, test_start, NULL); 118 : : 119 : 21 : spdk_app_fini(); 120 : : 121 [ - + - + ]: 21 : printf("Performance: %8ju events per second\n", g_call_count / g_time_in_sec); 122 : : 123 : 21 : return rc; 124 : : }