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 : 15180075 : submit_new_event(void *arg1, void *arg2)
24 : : {
25 : : struct spdk_event *event;
26 : : static __thread uint32_t next_lcore = UINT32_MAX;
27 : :
28 [ + + ]: 15180075 : if (spdk_get_ticks() > g_tsc_end) {
29 [ + + ]: 336 : if (__sync_bool_compare_and_swap(&g_app_stopped, false, true)) {
30 : 21 : spdk_app_stop(0);
31 : : }
32 : 336 : return;
33 : : }
34 : :
35 [ + + ]: 15179739 : if (next_lcore == UINT32_MAX) {
36 : 84 : next_lcore = spdk_env_get_next_core(spdk_env_get_current_core());
37 [ + + ]: 84 : if (next_lcore == UINT32_MAX) {
38 : 21 : next_lcore = spdk_env_get_first_core();
39 : : }
40 : : }
41 : :
42 : 15179739 : call_count[next_lcore]++;
43 : 15179739 : event = spdk_event_allocate(next_lcore, submit_new_event, NULL, NULL);
44 : 15179739 : spdk_event_call(event);
45 : : }
46 : :
47 : : static void
48 : 84 : event_work_fn(void *arg1, void *arg2)
49 : : {
50 : :
51 : 84 : submit_new_event(NULL, NULL);
52 : 84 : submit_new_event(NULL, NULL);
53 : 84 : submit_new_event(NULL, NULL);
54 : 84 : submit_new_event(NULL, NULL);
55 : 84 : }
56 : :
57 : : static void
58 : 21 : event_perf_start(void *arg1)
59 : : {
60 : : uint32_t i;
61 : :
62 : 21 : call_count = calloc(spdk_env_get_last_core() + 1, sizeof(*call_count));
63 [ - + ]: 21 : 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 : 21 : g_tsc_rate = spdk_get_ticks_hz();
70 : 21 : g_tsc_end = spdk_get_ticks() + g_time_in_sec * g_tsc_rate;
71 : :
72 [ - + ]: 21 : printf("Running I/O for %d seconds...", g_time_in_sec);
73 : 21 : fflush(stdout);
74 : :
75 [ + + ]: 105 : SPDK_ENV_FOREACH_CORE(i) {
76 : 84 : 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 : 21 : performance_dump(int io_time)
93 : : {
94 : : uint32_t i;
95 : :
96 [ - + ]: 21 : if (call_count == NULL) {
97 : 0 : return;
98 : : }
99 : :
100 : 21 : printf("\n");
101 [ + + ]: 105 : SPDK_ENV_FOREACH_CORE(i) {
102 [ - + - + ]: 84 : printf("lcore %2d: %8ju\n", i, call_count[i] / g_time_in_sec);
103 : : }
104 : :
105 : 21 : fflush(stdout);
106 : 21 : free(call_count);
107 : : }
108 : :
109 : : int
110 : 21 : main(int argc, char **argv)
111 : : {
112 : 21 : struct spdk_app_opts opts = {};
113 : : int op;
114 : 21 : int rc = 0;
115 : :
116 : 21 : spdk_app_opts_init(&opts, sizeof(opts));
117 : 21 : opts.name = "event_perf";
118 : :
119 : 21 : g_time_in_sec = 0;
120 : :
121 [ + + + + : 63 : while ((op = getopt(argc, argv, "m:t:")) != -1) {
+ + ]
122 [ + + - ]: 42 : switch (op) {
123 : 21 : case 'm':
124 : 21 : opts.reactor_mask = optarg;
125 : 21 : break;
126 : 21 : case 't':
127 : 21 : g_time_in_sec = spdk_strtol(optarg, 10);
128 [ - + ]: 21 : if (g_time_in_sec < 0) {
129 [ # # # # ]: 0 : fprintf(stderr, "Invalid run time\n");
130 : 0 : return g_time_in_sec;
131 : : }
132 : 21 : break;
133 : 0 : default:
134 : 0 : usage(argv[0]);
135 : 0 : exit(1);
136 : : }
137 : : }
138 : :
139 [ - + ]: 21 : if (!g_time_in_sec) {
140 : 0 : usage(argv[0]);
141 : 0 : exit(1);
142 : : }
143 : :
144 [ - + ]: 21 : printf("Running I/O for %d seconds...", g_time_in_sec);
145 : 21 : fflush(stdout);
146 : :
147 : 21 : rc = spdk_app_start(&opts, event_perf_start, NULL);
148 : :
149 : 21 : spdk_app_fini();
150 : 21 : performance_dump(g_time_in_sec);
151 : :
152 [ - + ]: 21 : printf("done.\n");
153 : 21 : return rc;
154 : : }
|