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 : 9430204 : __submit_next(void *arg1, void *arg2) 29 : : { 30 : : struct spdk_event *event; 31 : : 32 : 9430204 : g_call_count++; 33 : : 34 : 9430204 : event = spdk_event_allocate(spdk_env_get_current_core(), 35 : : __submit_next, NULL, NULL); 36 : 9430204 : spdk_event_call(event); 37 : 9430204 : } 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 : : 83 : 21 : g_time_in_sec = 0; 84 : 21 : g_queue_depth = 1; 85 : : 86 [ + + + + : 42 : while ((op = getopt(argc, argv, "q:t:")) != -1) { + + ] 87 [ - + ]: 21 : if (op == '?') { 88 : 0 : usage(argv[0]); 89 : 0 : exit(1); 90 : : } 91 : 21 : val = spdk_strtol(optarg, 10); 92 [ - + ]: 21 : if (val < 0) { 93 [ # # # # ]: 0 : fprintf(stderr, "Converting a string to integer failed\n"); 94 : 0 : exit(1); 95 : : } 96 [ - + - ]: 21 : switch (op) { 97 : 0 : case 'q': 98 : 0 : g_queue_depth = val; 99 : 0 : break; 100 : 21 : case 't': 101 : 21 : g_time_in_sec = val; 102 : 21 : break; 103 : 0 : default: 104 : 0 : usage(argv[0]); 105 : 0 : exit(1); 106 : : } 107 : : } 108 : : 109 [ - + ]: 21 : if (!g_time_in_sec) { 110 : 0 : usage(argv[0]); 111 : 0 : exit(1); 112 : : } 113 : : 114 : 21 : opts.shutdown_cb = test_cleanup; 115 : : 116 : 21 : rc = spdk_app_start(&opts, test_start, NULL); 117 : : 118 : 21 : spdk_app_fini(); 119 : : 120 [ - + - + ]: 21 : printf("Performance: %8ju events per second\n", g_call_count / g_time_in_sec); 121 : : 122 : 21 : return rc; 123 : : }