Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2016 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/log.h"
11 : : #include "spdk/string.h"
12 : :
13 : : static uint64_t g_tsc_rate;
14 : : static uint64_t g_tsc_end;
15 : :
16 : : static int g_time_in_sec;
17 : :
18 : : static uint64_t *call_count;
19 : :
20 : : static bool g_app_stopped = false;
21 : :
22 : : static void
23 : 14951653 : submit_new_event(void *arg1, void *arg2)
24 : : {
25 : : struct spdk_event *event;
26 : : static __thread uint32_t next_lcore = UINT32_MAX;
27 : :
28 [ + + ]: 14951653 : if (spdk_get_ticks() > g_tsc_end) {
29 [ + + ]: 304 : if (__sync_bool_compare_and_swap(&g_app_stopped, false, true)) {
30 : 19 : spdk_app_stop(0);
31 : : }
32 : 304 : return;
33 : : }
34 : :
35 [ + + ]: 14951349 : if (next_lcore == UINT32_MAX) {
36 : 76 : next_lcore = spdk_env_get_next_core(spdk_env_get_current_core());
37 [ + + ]: 76 : if (next_lcore == UINT32_MAX) {
38 : 19 : next_lcore = spdk_env_get_first_core();
39 : : }
40 : : }
41 : :
42 : 14951349 : call_count[next_lcore]++;
43 : 14951349 : event = spdk_event_allocate(next_lcore, submit_new_event, NULL, NULL);
44 : 14951349 : spdk_event_call(event);
45 : : }
46 : :
47 : : static void
48 : 76 : event_work_fn(void *arg1, void *arg2)
49 : : {
50 : :
51 : 76 : submit_new_event(NULL, NULL);
52 : 76 : submit_new_event(NULL, NULL);
53 : 76 : submit_new_event(NULL, NULL);
54 : 76 : submit_new_event(NULL, NULL);
55 : 76 : }
56 : :
57 : : static void
58 : 19 : event_perf_start(void *arg1)
59 : : {
60 : : uint32_t i;
61 : :
62 : 19 : call_count = calloc(spdk_env_get_last_core() + 1, sizeof(*call_count));
63 [ - + ]: 19 : if (call_count == NULL) {
64 [ # # # # ]: 0 : fprintf(stderr, "call_count allocation failed\n");
65 : 0 : spdk_app_stop(1);
66 : 0 : return;
67 : : }
68 : :
69 : 19 : g_tsc_rate = spdk_get_ticks_hz();
70 : 19 : g_tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate;
71 : :
72 [ - + ]: 19 : printf("Running I/O for %d seconds...", g_time_in_sec);
73 : 19 : fflush(stdout);
74 : :
75 [ + + ]: 95 : SPDK_ENV_FOREACH_CORE(i) {
76 : 76 : spdk_event_call(spdk_event_allocate(i, event_work_fn,
77 : : NULL, NULL));
78 : : }
79 : :
80 : : }
81 : :
82 : : static void
83 : 0 : usage(char *program_name)
84 : : {
85 [ # # ]: 0 : printf("%s options\n", program_name);
86 [ # # ]: 0 : printf("\t[-m core mask for distributing I/O submission/completion work\n");
87 [ # # ]: 0 : printf("\t\t(default: 0x1 - use core 0 only)]\n");
88 [ # # ]: 0 : printf("\t[-t time in seconds]\n");
89 : 0 : }
90 : :
91 : : static void
92 : 19 : performance_dump(int io_time)
93 : : {
94 : : uint32_t i;
95 : :
96 [ - + ]: 19 : if (call_count == NULL) {
97 : 0 : return;
98 : : }
99 : :
100 : 19 : printf("\n");
101 [ + + ]: 95 : SPDK_ENV_FOREACH_CORE(i) {
102 [ - + - + ]: 76 : printf("lcore %2d: %8ju\n", i, call_count[i] / g_time_in_sec);
103 : : }
104 : :
105 : 19 : fflush(stdout);
106 : 19 : free(call_count);
107 : : }
108 : :
109 : : int
110 : 19 : main(int argc, char **argv)
111 : : {
112 : 19 : struct spdk_app_opts opts = {};
113 : : int op;
114 : 19 : int rc = 0;
115 : :
116 : 19 : spdk_app_opts_init(&opts, sizeof(opts));
117 : 19 : opts.name = "event_perf";
118 : 19 : opts.rpc_addr = NULL;
119 : :
120 : 19 : g_time_in_sec = 0;
121 : :
122 [ + + + + : 57 : while ((op = getopt(argc, argv, "m:t:")) != -1) {
+ + ]
123 [ + + - ]: 38 : switch (op) {
124 : 19 : case 'm':
125 : 19 : opts.reactor_mask = optarg;
126 : 19 : break;
127 : 19 : case 't':
128 : 19 : g_time_in_sec = spdk_strtol(optarg, 10);
129 [ - + ]: 19 : if (g_time_in_sec < 0) {
130 [ # # # # ]: 0 : fprintf(stderr, "Invalid run time\n");
131 : 0 : return g_time_in_sec;
132 : : }
133 : 19 : break;
134 : 0 : default:
135 : 0 : usage(argv[0]);
136 : 0 : exit(1);
137 : : }
138 : : }
139 : :
140 [ - + ]: 19 : if (!g_time_in_sec) {
141 : 0 : usage(argv[0]);
142 : 0 : exit(1);
143 : : }
144 : :
145 [ - + ]: 19 : printf("Running I/O for %d seconds...", g_time_in_sec);
146 : 19 : fflush(stdout);
147 : :
148 : 19 : rc = spdk_app_start(&opts, event_perf_start, NULL);
149 : :
150 : 19 : spdk_app_fini();
151 : 19 : performance_dump(g_time_in_sec);
152 : :
153 [ - + ]: 19 : printf("done.\n");
154 : 19 : return rc;
155 : : }
|