Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2016 Intel Corporation. All rights reserved.
3 : : * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
4 : : * Copyright (c) 2021, 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5 : : */
6 : :
7 : : #include "spdk/stdinc.h"
8 : : #include "spdk/version.h"
9 : :
10 : : #include "spdk_internal/event.h"
11 : :
12 : : #include "spdk/assert.h"
13 : : #include "spdk/env.h"
14 : : #include "spdk/init.h"
15 : : #include "spdk/log.h"
16 : : #include "spdk/thread.h"
17 : : #include "spdk/trace.h"
18 : : #include "spdk/string.h"
19 : : #include "spdk/scheduler.h"
20 : : #include "spdk/rpc.h"
21 : : #include "spdk/util.h"
22 : : #include "spdk/file.h"
23 : : #include "spdk/config.h"
24 : : #include "event_internal.h"
25 : :
26 : : #define SPDK_APP_DEFAULT_LOG_LEVEL SPDK_LOG_NOTICE
27 : : #define SPDK_APP_DEFAULT_LOG_PRINT_LEVEL SPDK_LOG_INFO
28 : : #define SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES SPDK_DEFAULT_NUM_TRACE_ENTRIES
29 : :
30 : : #define SPDK_APP_DPDK_DEFAULT_MEM_SIZE -1
31 : : #define SPDK_APP_DPDK_DEFAULT_MAIN_CORE -1
32 : : #define SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL -1
33 : : #define SPDK_APP_DPDK_DEFAULT_CORE_MASK "0x1"
34 : : #define SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR 0x200000000000
35 : : #define SPDK_APP_DEFAULT_CORE_LIMIT 0x140000000 /* 5 GiB */
36 : :
37 : : /* For core counts <= 63, the message memory pool size is set to
38 : : * SPDK_DEFAULT_MSG_MEMPOOL_SIZE.
39 : : * For core counts > 63, the message memory pool size is depended on
40 : : * number of cores. Per core, it is calculated as SPDK_MSG_MEMPOOL_CACHE_SIZE
41 : : * multiplied by factor of 4 to have space for multiple spdk threads running
42 : : * on single core (e.g iscsi + nvmf + vhost ). */
43 : : #define SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE (4 * SPDK_MSG_MEMPOOL_CACHE_SIZE)
44 : :
45 : : struct spdk_app {
46 : : void *json_data;
47 : : size_t json_data_size;
48 : : bool json_config_ignore_errors;
49 : : bool stopped;
50 : : const char *rpc_addr;
51 : : const char **rpc_allowlist;
52 : : FILE *rpc_log_file;
53 : : enum spdk_log_level rpc_log_level;
54 : : int shm_id;
55 : : spdk_app_shutdown_cb shutdown_cb;
56 : : int rc;
57 : : };
58 : :
59 : : static struct spdk_app g_spdk_app;
60 : : static spdk_msg_fn g_start_fn = NULL;
61 : : static void *g_start_arg = NULL;
62 : : static bool g_delay_subsystem_init = false;
63 : : static bool g_shutdown_sig_received = false;
64 : : static char *g_executable_name;
65 : : static struct spdk_app_opts g_default_opts;
66 : :
67 : : static int g_core_locks[SPDK_CONFIG_MAX_LCORES];
68 : :
69 : : static struct {
70 : : uint64_t irq;
71 : : uint64_t usr;
72 : : uint64_t sys;
73 : : } g_initial_stat[SPDK_CONFIG_MAX_LCORES];
74 : :
75 : : int
76 : 0 : spdk_app_get_shm_id(void)
77 : : {
78 [ # # ]: 0 : return g_spdk_app.shm_id;
79 : : }
80 : :
81 : : /* append one empty option to indicate the end of the array */
82 : : static const struct option g_cmdline_options[] = {
83 : : #define CONFIG_FILE_OPT_IDX 'c'
84 : : {"config", required_argument, NULL, CONFIG_FILE_OPT_IDX},
85 : : #define LIMIT_COREDUMP_OPT_IDX 'd'
86 : : {"limit-coredump", no_argument, NULL, LIMIT_COREDUMP_OPT_IDX},
87 : : #define TPOINT_GROUP_OPT_IDX 'e'
88 : : {"tpoint-group", required_argument, NULL, TPOINT_GROUP_OPT_IDX},
89 : : #define SINGLE_FILE_SEGMENTS_OPT_IDX 'g'
90 : : {"single-file-segments", no_argument, NULL, SINGLE_FILE_SEGMENTS_OPT_IDX},
91 : : #define HELP_OPT_IDX 'h'
92 : : {"help", no_argument, NULL, HELP_OPT_IDX},
93 : : #define SHM_ID_OPT_IDX 'i'
94 : : {"shm-id", required_argument, NULL, SHM_ID_OPT_IDX},
95 : : #define CPUMASK_OPT_IDX 'm'
96 : : {"cpumask", required_argument, NULL, CPUMASK_OPT_IDX},
97 : : #define MEM_CHANNELS_OPT_IDX 'n'
98 : : {"mem-channels", required_argument, NULL, MEM_CHANNELS_OPT_IDX},
99 : : #define MAIN_CORE_OPT_IDX 'p'
100 : : {"main-core", required_argument, NULL, MAIN_CORE_OPT_IDX},
101 : : #define RPC_SOCKET_OPT_IDX 'r'
102 : : {"rpc-socket", required_argument, NULL, RPC_SOCKET_OPT_IDX},
103 : : #define MEM_SIZE_OPT_IDX 's'
104 : : {"mem-size", required_argument, NULL, MEM_SIZE_OPT_IDX},
105 : : #define NO_PCI_OPT_IDX 'u'
106 : : {"no-pci", no_argument, NULL, NO_PCI_OPT_IDX},
107 : : #define VERSION_OPT_IDX 'v'
108 : : {"version", no_argument, NULL, VERSION_OPT_IDX},
109 : : #define PCI_BLOCKED_OPT_IDX 'B'
110 : : {"pci-blocked", required_argument, NULL, PCI_BLOCKED_OPT_IDX},
111 : : #define LOGFLAG_OPT_IDX 'L'
112 : : {"logflag", required_argument, NULL, LOGFLAG_OPT_IDX},
113 : : #define HUGE_UNLINK_OPT_IDX 'R'
114 : : {"huge-unlink", no_argument, NULL, HUGE_UNLINK_OPT_IDX},
115 : : #define PCI_ALLOWED_OPT_IDX 'A'
116 : : {"pci-allowed", required_argument, NULL, PCI_ALLOWED_OPT_IDX},
117 : : #define INTERRUPT_MODE_OPT_IDX 256
118 : : {"interrupt-mode", no_argument, NULL, INTERRUPT_MODE_OPT_IDX},
119 : : #define SILENCE_NOTICELOG_OPT_IDX 257
120 : : {"silence-noticelog", no_argument, NULL, SILENCE_NOTICELOG_OPT_IDX},
121 : : #define WAIT_FOR_RPC_OPT_IDX 258
122 : : {"wait-for-rpc", no_argument, NULL, WAIT_FOR_RPC_OPT_IDX},
123 : : #define HUGE_DIR_OPT_IDX 259
124 : : {"huge-dir", required_argument, NULL, HUGE_DIR_OPT_IDX},
125 : : #define NUM_TRACE_ENTRIES_OPT_IDX 260
126 : : {"num-trace-entries", required_argument, NULL, NUM_TRACE_ENTRIES_OPT_IDX},
127 : : #define JSON_CONFIG_OPT_IDX 262
128 : : {"json", required_argument, NULL, JSON_CONFIG_OPT_IDX},
129 : : #define JSON_CONFIG_IGNORE_INIT_ERRORS_IDX 263
130 : : {"json-ignore-init-errors", no_argument, NULL, JSON_CONFIG_IGNORE_INIT_ERRORS_IDX},
131 : : #define IOVA_MODE_OPT_IDX 264
132 : : {"iova-mode", required_argument, NULL, IOVA_MODE_OPT_IDX},
133 : : #define BASE_VIRTADDR_OPT_IDX 265
134 : : {"base-virtaddr", required_argument, NULL, BASE_VIRTADDR_OPT_IDX},
135 : : #define ENV_CONTEXT_OPT_IDX 266
136 : : {"env-context", required_argument, NULL, ENV_CONTEXT_OPT_IDX},
137 : : #define DISABLE_CPUMASK_LOCKS_OPT_IDX 267
138 : : {"disable-cpumask-locks", no_argument, NULL, DISABLE_CPUMASK_LOCKS_OPT_IDX},
139 : : #define RPCS_ALLOWED_OPT_IDX 268
140 : : {"rpcs-allowed", required_argument, NULL, RPCS_ALLOWED_OPT_IDX},
141 : : #define ENV_VF_TOKEN_OPT_IDX 269
142 : : {"vfio-vf-token", required_argument, NULL, ENV_VF_TOKEN_OPT_IDX},
143 : : #define MSG_MEMPOOL_SIZE_OPT_IDX 270
144 : : {"msg-mempool-size", required_argument, NULL, MSG_MEMPOOL_SIZE_OPT_IDX},
145 : : #define LCORES_OPT_IDX 271
146 : : {"lcores", required_argument, NULL, LCORES_OPT_IDX},
147 : : #define NO_HUGE_OPT_IDX 272
148 : : {"no-huge", no_argument, NULL, NO_HUGE_OPT_IDX},
149 : : #define NO_RPC_SERVER_OPT_IDX 273
150 : : {"no-rpc-server", no_argument, NULL, NO_RPC_SERVER_OPT_IDX},
151 : : #define ENFORCE_NUMA_OPT_IDX 274
152 : : {"enforce-numa", no_argument, NULL, ENFORCE_NUMA_OPT_IDX},
153 : : };
154 : :
155 : : static int
156 : 3561 : parse_proc_stat(unsigned int core, uint64_t *user, uint64_t *sys, uint64_t *irq)
157 : : {
158 : : FILE *f;
159 : 3561 : uint64_t i, soft_irq, cpu = 0;
160 : 3561 : int rc, found = 0;
161 : :
162 : 3561 : f = fopen("/proc/stat", "r");
163 [ + + ]: 3561 : if (!f) {
164 : 0 : return -1;
165 : : }
166 : :
167 [ + + ]: 16231 : for (i = 0; i <= core + 1; i++) {
168 : : /* scanf discards input with '*' in format,
169 : : * cpu;user;nice;system;idle;iowait;irq;softirq;steal;guest;guest_nice */
170 [ - + - + ]: 16431 : rc = fscanf(f, "cpu%li %li %*i %li %*i %*i %li %li %*i %*i %*i\n",
171 : 200 : &cpu, user, sys, irq, &soft_irq);
172 [ - + ]: 16231 : if (rc != 5) {
173 : 0 : continue;
174 : : }
175 : :
176 : : /* some cores can be disabled, list may not be in order */
177 [ + + ]: 16231 : if (cpu == core) {
178 : 3561 : found = 1;
179 : 3561 : break;
180 : : }
181 : 117 : }
182 : :
183 [ - + ]: 3561 : *irq += soft_irq;
184 : :
185 [ - + ]: 3561 : fclose(f);
186 [ + - ]: 3561 : return found ? 0 : -1;
187 : 83 : }
188 : :
189 : : static int
190 : 3433 : init_proc_stat(unsigned int core)
191 : : {
192 : 1247 : uint64_t usr, sys, irq;
193 : :
194 [ - + ]: 3433 : if (core >= SPDK_CONFIG_MAX_LCORES) {
195 : 0 : return -1;
196 : : }
197 : :
198 [ + + ]: 3433 : if (parse_proc_stat(core, &usr, &sys, &irq) < 0) {
199 : 0 : return -1;
200 : : }
201 : :
202 [ + - + - : 3433 : g_initial_stat[core].irq = irq;
+ - + - ]
203 [ + - + - : 3433 : g_initial_stat[core].usr = usr;
+ - + - ]
204 [ + - + - : 3433 : g_initial_stat[core].sys = sys;
+ - + - ]
205 : :
206 : 3433 : return 0;
207 : 83 : }
208 : :
209 : : int
210 : 128 : app_get_proc_stat(unsigned int core, uint64_t *usr, uint64_t *sys, uint64_t *irq)
211 : : {
212 : 0 : uint64_t _usr, _sys, _irq;
213 : :
214 [ - + ]: 128 : if (core >= SPDK_CONFIG_MAX_LCORES) {
215 : 0 : return -1;
216 : : }
217 : :
218 [ - + ]: 128 : if (parse_proc_stat(core, &_usr, &_sys, &_irq) < 0) {
219 : 0 : return -1;
220 : : }
221 : :
222 [ # # # # : 128 : *irq = _irq - g_initial_stat[core].irq;
# # # # #
# ]
223 [ # # # # : 128 : *usr = _usr - g_initial_stat[core].usr;
# # # # #
# ]
224 [ # # # # : 128 : *sys = _sys - g_initial_stat[core].sys;
# # # # #
# ]
225 : :
226 : 128 : return 0;
227 : 0 : }
228 : :
229 : : static void
230 : 1342 : app_start_shutdown(void *ctx)
231 : : {
232 [ + + + + ]: 1342 : if (g_spdk_app.shutdown_cb) {
233 [ + - - + : 407 : g_spdk_app.shutdown_cb();
- + ]
234 [ + - ]: 407 : g_spdk_app.shutdown_cb = NULL;
235 : 5 : } else {
236 : 935 : spdk_app_stop(0);
237 : : }
238 : 1342 : }
239 : :
240 : : void
241 : 1342 : spdk_app_start_shutdown(void)
242 : : {
243 : 1342 : spdk_thread_send_critical_msg(spdk_thread_get_app_thread(), app_start_shutdown);
244 : 1342 : }
245 : :
246 : : static void
247 : 1337 : __shutdown_signal(int signo)
248 : : {
249 [ + + + + ]: 1337 : if (!g_shutdown_sig_received) {
250 : 1337 : g_shutdown_sig_received = true;
251 : 1337 : spdk_app_start_shutdown();
252 : 26 : }
253 : 1337 : }
254 : :
255 : : static int
256 : 2282 : app_opts_validate(const char *app_opts)
257 : : {
258 : 2282 : int i = 0, j;
259 : :
260 [ + + + - : 21454 : for (i = 0; app_opts[i] != '\0'; i++) {
+ + + - ]
261 : : /* ignore getopt control characters */
262 [ + + + - : 19175 : if (app_opts[i] == ':' || app_opts[i] == '+' || app_opts[i] == '-') {
+ + + - +
- + - + -
+ - - + ]
263 : 7691 : continue;
264 : : }
265 : :
266 [ + + + - : 355914 : for (j = 0; SPDK_APP_GETOPT_STRING[j] != '\0'; j++) {
+ - + + +
- ]
267 [ + + + - : 344433 : if (app_opts[i] == SPDK_APP_GETOPT_STRING[j]) {
+ - + - +
- + - ]
268 [ # # # # ]: 3 : return app_opts[i];
269 : : }
270 : 7710 : }
271 : 257 : }
272 : 2279 : return 0;
273 : 61 : }
274 : :
275 : : static void
276 : 2330 : calculate_mempool_size(struct spdk_app_opts *opts,
277 : : struct spdk_app_opts *opts_user)
278 : : {
279 : 2330 : uint32_t core_count = spdk_env_get_core_count();
280 : :
281 [ + - + - : 2330 : if (!opts_user->msg_mempool_size) {
- + ]
282 : : /* The user didn't specify msg_mempool_size, so let's calculate it.
283 : : Set the default (SPDK_DEFAULT_MSG_MEMPOOL_SIZE) if less than
284 : : 64 cores, and use 4k per core otherwise */
285 [ + - + - : 2330 : opts->msg_mempool_size = spdk_max(SPDK_DEFAULT_MSG_MEMPOOL_SIZE,
+ - ]
286 : : core_count * SPDK_APP_PER_CORE_MSG_MEMPOOL_SIZE);
287 : 67 : } else {
288 [ # # # # : 0 : opts->msg_mempool_size = opts_user->msg_mempool_size;
# # # # ]
289 : : }
290 : 2330 : }
291 : :
292 : : void
293 : 4695 : spdk_app_opts_init(struct spdk_app_opts *opts, size_t opts_size)
294 : : {
295 [ + + ]: 4695 : if (!opts) {
296 : 0 : SPDK_ERRLOG("opts should not be NULL\n");
297 : 0 : return;
298 : : }
299 : :
300 [ + + ]: 4695 : if (!opts_size) {
301 : 0 : SPDK_ERRLOG("opts_size should not be zero value\n");
302 : 0 : return;
303 : : }
304 : :
305 [ + + ]: 4695 : memset(opts, 0, opts_size);
306 [ + - + - ]: 4695 : opts->opts_size = opts_size;
307 : :
308 : : #define SET_FIELD(field, value) \
309 : : if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= opts_size) { \
310 : : opts->field = value; \
311 : : } \
312 : :
313 [ + + + - : 4695 : SET_FIELD(enable_coredump, true);
+ - ]
314 [ + + + - : 4695 : SET_FIELD(shm_id, -1);
+ - ]
315 [ + + + - : 4695 : SET_FIELD(mem_size, SPDK_APP_DPDK_DEFAULT_MEM_SIZE);
+ - ]
316 [ + + + - : 4695 : SET_FIELD(main_core, SPDK_APP_DPDK_DEFAULT_MAIN_CORE);
+ - ]
317 [ + + + - : 4695 : SET_FIELD(mem_channel, SPDK_APP_DPDK_DEFAULT_MEM_CHANNEL);
+ - ]
318 [ + + + - : 4695 : SET_FIELD(base_virtaddr, SPDK_APP_DPDK_DEFAULT_BASE_VIRTADDR);
+ - ]
319 [ + + + - : 4695 : SET_FIELD(print_level, SPDK_APP_DEFAULT_LOG_PRINT_LEVEL);
+ - ]
320 [ + + + - : 4695 : SET_FIELD(rpc_addr, SPDK_DEFAULT_RPC_ADDR);
+ - ]
321 [ + + + - : 4695 : SET_FIELD(num_entries, SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
+ - ]
322 [ + + + - : 4695 : SET_FIELD(delay_subsystem_init, false);
+ - ]
323 [ + + + - : 4695 : SET_FIELD(disable_signal_handlers, false);
+ - ]
324 [ + + + - : 4695 : SET_FIELD(interrupt_mode, false);
+ - ]
325 [ + + + - : 4695 : SET_FIELD(enforce_numa, false);
+ - ]
326 : : /* Don't set msg_mempool_size here, it is set or calculated later */
327 [ + + + - : 4695 : SET_FIELD(rpc_allowlist, NULL);
+ - ]
328 [ + + + - : 4695 : SET_FIELD(rpc_log_file, NULL);
+ - ]
329 [ + + + - : 4695 : SET_FIELD(rpc_log_level, SPDK_LOG_DISABLED);
+ - ]
330 [ + + + - : 4695 : SET_FIELD(disable_cpumask_locks, false);
+ - ]
331 : : #undef SET_FIELD
332 : 133 : }
333 : :
334 : : static int
335 : 2288 : app_setup_signal_handlers(struct spdk_app_opts *opts)
336 : : {
337 : 929 : struct sigaction sigact;
338 : 929 : sigset_t sigmask;
339 : : int rc;
340 : :
341 [ + + ]: 2288 : sigemptyset(&sigmask);
342 [ + + ]: 2288 : memset(&sigact, 0, sizeof(sigact));
343 [ + + ]: 2288 : sigemptyset(&sigact.sa_mask);
344 : :
345 : 2288 : sigact.sa_handler = SIG_IGN;
346 : 2288 : rc = sigaction(SIGPIPE, &sigact, NULL);
347 [ + + ]: 2288 : if (rc < 0) {
348 : 0 : SPDK_ERRLOG("sigaction(SIGPIPE) failed\n");
349 : 0 : return rc;
350 : : }
351 : :
352 : : /* Install the same handler for SIGINT and SIGTERM */
353 : 2288 : g_shutdown_sig_received = false;
354 : 2288 : sigact.sa_handler = __shutdown_signal;
355 : 2288 : rc = sigaction(SIGINT, &sigact, NULL);
356 [ + + ]: 2288 : if (rc < 0) {
357 : 0 : SPDK_ERRLOG("sigaction(SIGINT) failed\n");
358 : 0 : return rc;
359 : : }
360 [ + + ]: 2288 : sigaddset(&sigmask, SIGINT);
361 : :
362 : 2288 : rc = sigaction(SIGTERM, &sigact, NULL);
363 [ + + ]: 2288 : if (rc < 0) {
364 : 0 : SPDK_ERRLOG("sigaction(SIGTERM) failed\n");
365 : 0 : return rc;
366 : : }
367 [ + + ]: 2288 : sigaddset(&sigmask, SIGTERM);
368 : :
369 : 2288 : pthread_sigmask(SIG_UNBLOCK, &sigmask, NULL);
370 : :
371 : 2288 : return 0;
372 : 65 : }
373 : :
374 : : static void
375 : 2216 : app_start_application(int rc, void *arg1)
376 : : {
377 [ + + # # ]: 2216 : assert(spdk_thread_is_app_thread(NULL));
378 : :
379 [ - + ]: 2216 : if (rc) {
380 : 0 : SPDK_ERRLOG("Failed to load subsystems for RUNTIME state with code: %d\n", rc);
381 : 0 : spdk_app_stop(rc);
382 : 0 : return;
383 : : }
384 : :
385 [ + + + + ]: 2216 : if (g_spdk_app.rpc_addr) {
386 [ + - ]: 1317 : spdk_rpc_server_resume(g_spdk_app.rpc_addr);
387 : 31 : }
388 : :
389 [ - + + - ]: 2216 : g_start_fn(g_start_arg);
390 : 64 : }
391 : :
392 : : static void
393 : 2216 : app_subsystem_init_done(int rc, void *arg1)
394 : : {
395 [ - + ]: 2216 : if (rc) {
396 : 0 : SPDK_ERRLOG("Subsystem initialization failed with code: %d\n", rc);
397 : 0 : spdk_app_stop(rc);
398 : 0 : return;
399 : : }
400 : :
401 [ + - ]: 2216 : spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);
402 : 2216 : spdk_rpc_set_state(SPDK_RPC_RUNTIME);
403 : :
404 [ + + ]: 2216 : if (g_spdk_app.json_data) {
405 : : /* Load SPDK_RPC_RUNTIME RPCs from config file */
406 [ + + # # ]: 684 : assert(spdk_rpc_get_state() == SPDK_RPC_RUNTIME);
407 [ + - ]: 718 : spdk_subsystem_load_config(g_spdk_app.json_data, g_spdk_app.json_data_size,
408 : : app_start_application, NULL,
409 [ + + + - ]: 684 : !g_spdk_app.json_config_ignore_errors);
410 : 684 : free(g_spdk_app.json_data);
411 : 684 : g_spdk_app.json_data = NULL;
412 : 34 : } else {
413 : 1532 : app_start_application(0, NULL);
414 : : }
415 : 64 : }
416 : :
417 : : static void
418 : 2287 : app_do_spdk_subsystem_init(int rc, void *arg1)
419 : : {
420 : 928 : struct spdk_rpc_opts opts;
421 : :
422 [ + + ]: 2287 : if (rc) {
423 : 49 : spdk_app_stop(rc);
424 : 181 : return;
425 : : }
426 : :
427 [ + + + + ]: 2238 : if (g_spdk_app.rpc_addr) {
428 : 1339 : opts.size = SPDK_SIZEOF(&opts, log_level);
429 [ + - + - ]: 1339 : opts.log_file = g_spdk_app.rpc_log_file;
430 [ + - + - ]: 1339 : opts.log_level = g_spdk_app.rpc_log_level;
431 : :
432 [ + - ]: 1339 : rc = spdk_rpc_initialize(g_spdk_app.rpc_addr, &opts);
433 [ + + ]: 1339 : if (rc) {
434 : 22 : spdk_app_stop(rc);
435 : 22 : return;
436 : : }
437 [ + + + + ]: 1317 : if (g_delay_subsystem_init) {
438 : 162 : return;
439 : : }
440 [ - + ]: 1155 : spdk_rpc_server_pause(g_spdk_app.rpc_addr);
441 : 30 : } else {
442 [ + + + + : 899 : SPDK_DEBUGLOG(app_rpc, "RPC server not started\n");
+ - ]
443 : : }
444 : 2054 : spdk_subsystem_init(app_subsystem_init_done, NULL);
445 : 65 : }
446 : :
447 : : static int
448 : 6 : app_opts_add_pci_addr(struct spdk_app_opts *opts, struct spdk_pci_addr **list, char *bdf)
449 : : {
450 [ # # ]: 6 : struct spdk_pci_addr *tmp = *list;
451 [ # # # # ]: 6 : size_t i = opts->num_pci_addr;
452 : :
453 : 6 : tmp = realloc(tmp, sizeof(*tmp) * (i + 1));
454 [ - + ]: 6 : if (tmp == NULL) {
455 : 0 : SPDK_ERRLOG("realloc error\n");
456 : 0 : return -ENOMEM;
457 : : }
458 : :
459 [ # # ]: 6 : *list = tmp;
460 [ - + # # : 6 : if (spdk_pci_addr_parse(*list + i, bdf) < 0) {
# # ]
461 : 0 : SPDK_ERRLOG("Invalid address %s\n", bdf);
462 : 0 : return -EINVAL;
463 : : }
464 : :
465 [ # # ]: 6 : opts->num_pci_addr++;
466 : 6 : return 0;
467 : 0 : }
468 : :
469 : : static int
470 : 2330 : app_setup_env(struct spdk_app_opts *opts)
471 : : {
472 : 2330 : struct spdk_env_opts env_opts = {};
473 : : int rc;
474 : :
475 [ + + ]: 2330 : if (opts == NULL) {
476 : 66 : rc = spdk_env_init(NULL);
477 [ - + ]: 66 : if (rc != 0) {
478 : 0 : SPDK_ERRLOG("Unable to reinitialize SPDK env\n");
479 : 0 : }
480 : :
481 : 66 : return rc;
482 : : }
483 : :
484 [ + - ]: 2264 : env_opts.opts_size = sizeof(env_opts);
485 : 2264 : spdk_env_opts_init(&env_opts);
486 : :
487 [ + - + - ]: 2264 : env_opts.name = opts->name;
488 [ + - + - : 2264 : env_opts.core_mask = opts->reactor_mask;
+ - ]
489 [ + - + - : 2264 : env_opts.lcore_map = opts->lcore_map;
+ - ]
490 [ + - + - : 2264 : env_opts.shm_id = opts->shm_id;
+ - ]
491 [ + - + - : 2264 : env_opts.mem_channel = opts->mem_channel;
+ - ]
492 [ + - + - : 2264 : env_opts.main_core = opts->main_core;
+ - ]
493 [ + - + - : 2264 : env_opts.mem_size = opts->mem_size;
+ - ]
494 [ + + + - : 2264 : env_opts.hugepage_single_segments = opts->hugepage_single_segments;
+ - ]
495 [ + + + - : 2264 : env_opts.unlink_hugepage = opts->unlink_hugepage;
+ - + - ]
496 [ + - + - : 2264 : env_opts.hugedir = opts->hugedir;
+ - ]
497 [ + + + - : 2264 : env_opts.no_pci = opts->no_pci;
+ - + - ]
498 [ + - + - : 2264 : env_opts.num_pci_addr = opts->num_pci_addr;
+ - ]
499 [ + - + - : 2264 : env_opts.pci_blocked = opts->pci_blocked;
+ - ]
500 [ + - + - : 2264 : env_opts.pci_allowed = opts->pci_allowed;
+ - ]
501 [ + - + - : 2264 : env_opts.base_virtaddr = opts->base_virtaddr;
+ - ]
502 [ + - + - : 2264 : env_opts.env_context = opts->env_context;
+ - ]
503 [ + - + - : 2264 : env_opts.iova_mode = opts->iova_mode;
+ - ]
504 [ + - + - : 2264 : env_opts.vf_token = opts->vf_token;
+ - ]
505 [ + + + - : 2264 : env_opts.no_huge = opts->no_huge;
+ - ]
506 [ + + + - : 2264 : env_opts.enforce_numa = opts->enforce_numa;
+ - + - ]
507 : :
508 : 2264 : rc = spdk_env_init(&env_opts);
509 [ + - ]: 2264 : free(env_opts.pci_blocked);
510 [ + - ]: 2264 : free(env_opts.pci_allowed);
511 : :
512 [ + + ]: 2264 : if (rc < 0) {
513 : 0 : SPDK_ERRLOG("Unable to initialize SPDK env\n");
514 : 0 : }
515 : :
516 : 2264 : return rc;
517 : 67 : }
518 : :
519 : : static int
520 : 2288 : app_setup_trace(struct spdk_app_opts *opts)
521 : : {
522 : 929 : char shm_name[64];
523 : 2288 : uint64_t tpoint_group_mask, tpoint_mask = -1ULL;
524 : 2288 : char *end = NULL, *tpoint_group_mask_str, *tpoint_group_str = NULL;
525 : : char *tp_g_str, *tpoint_group, *tpoints;
526 : 2288 : bool error_found = false;
527 : : uint64_t group_id;
528 : :
529 [ + + + - : 2288 : if (opts->shm_id >= 0) {
- + ]
530 [ # # # # ]: 340 : snprintf(shm_name, sizeof(shm_name), "/%s%s%d", opts->name,
531 [ # # # # ]: 0 : SPDK_TRACE_SHM_NAME_BASE, opts->shm_id);
532 : 0 : } else {
533 [ + - + - ]: 1948 : snprintf(shm_name, sizeof(shm_name), "/%s%spid%d", opts->name,
534 : 1948 : SPDK_TRACE_SHM_NAME_BASE, (int)getpid());
535 : : }
536 : :
537 [ + + + - : 2288 : if (spdk_trace_init(shm_name, opts->num_entries, 0) != 0) {
- + ]
538 : 0 : return -1;
539 : : }
540 : :
541 [ + + + - : 2288 : if (opts->tpoint_group_mask == NULL) {
+ + ]
542 : 2006 : return 0;
543 : : }
544 : :
545 [ + + + - : 282 : tpoint_group_mask_str = strdup(opts->tpoint_group_mask);
+ - ]
546 [ + + ]: 282 : if (tpoint_group_mask_str == NULL) {
547 : 0 : SPDK_ERRLOG("Unable to get string of tpoint group mask from opts.\n");
548 : 0 : return -1;
549 : : }
550 : : /* Save a pointer to the original value of the tpoint group mask string
551 : : * to free later, because spdk_strsepq() modifies given char*. */
552 : 282 : tp_g_str = tpoint_group_mask_str;
553 [ + + ]: 564 : while ((tpoint_group_str = spdk_strsepq(&tpoint_group_mask_str, ",")) != NULL) {
554 [ + + - + ]: 282 : if (strchr(tpoint_group_str, ':')) {
555 : : /* Get the tpoint group mask */
556 : 0 : tpoint_group = spdk_strsepq(&tpoint_group_str, ":");
557 : : /* Get the tpoint mask inside that group */
558 : 0 : tpoints = spdk_strsepq(&tpoint_group_str, ":");
559 : :
560 [ # # ]: 0 : errno = 0;
561 [ # # ]: 0 : tpoint_group_mask = strtoull(tpoint_group, &end, 16);
562 [ # # # # : 0 : if (*end != '\0' || errno) {
# # # # ]
563 : 0 : tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group);
564 [ # # ]: 0 : if (tpoint_group_mask == 0) {
565 : 0 : error_found = true;
566 : 0 : break;
567 : : }
568 : 0 : }
569 : : /* Check if tpoint group mask has only one bit set.
570 : : * This is to avoid enabling individual tpoints in
571 : : * more than one tracepoint group at once. */
572 [ # # ]: 0 : if (!spdk_u64_is_pow2(tpoint_group_mask)) {
573 : 0 : SPDK_ERRLOG("Tpoint group mask: %s contains multiple tpoint groups.\n", tpoint_group);
574 : 0 : SPDK_ERRLOG("This is not supported, to prevent from activating tpoints by mistake.\n");
575 : 0 : error_found = true;
576 : 0 : break;
577 : : }
578 : :
579 [ # # ]: 0 : errno = 0;
580 [ # # ]: 0 : tpoint_mask = strtoull(tpoints, &end, 16);
581 [ # # # # : 0 : if (*end != '\0' || errno) {
# # # # ]
582 : 0 : error_found = true;
583 : 0 : break;
584 : : }
585 : 0 : } else {
586 [ + - ]: 282 : errno = 0;
587 [ + + ]: 282 : tpoint_group_mask = strtoull(tpoint_group_str, &end, 16);
588 [ + + - + : 282 : if (*end != '\0' || errno) {
# # # # ]
589 : 25 : tpoint_group_mask = spdk_trace_create_tpoint_group_mask(tpoint_group_str);
590 [ + + ]: 25 : if (tpoint_group_mask == 0) {
591 : 0 : error_found = true;
592 : 0 : break;
593 : : }
594 : 1 : }
595 : 282 : tpoint_mask = -1ULL;
596 : : }
597 : :
598 [ + + ]: 5922 : for (group_id = 0; group_id < SPDK_TRACE_MAX_GROUP_ID; ++group_id) {
599 [ + + + + : 5640 : if (tpoint_group_mask & (1 << group_id)) {
+ + ]
600 : 4088 : spdk_trace_set_tpoints(group_id, tpoint_mask);
601 : 1 : }
602 : 20 : }
603 : : }
604 : :
605 [ + + - + ]: 282 : if (error_found) {
606 [ # # # # ]: 0 : SPDK_ERRLOG("invalid tpoint mask %s\n", opts->tpoint_group_mask);
607 : 0 : free(tp_g_str);
608 : 0 : return -1;
609 : : } else {
610 [ + - + - ]: 282 : SPDK_NOTICELOG("Tracepoint Group Mask %s specified.\n", opts->tpoint_group_mask);
611 [ + + + + : 282 : SPDK_NOTICELOG("Use 'spdk_trace -s %s %s %d' to capture a snapshot of events at runtime.\n",
+ - + - +
- + - - +
# # # # ]
612 : : opts->name,
613 : : opts->shm_id >= 0 ? "-i" : "-p",
614 : : opts->shm_id >= 0 ? opts->shm_id : getpid());
615 : : #if defined(__linux__)
616 : 282 : SPDK_NOTICELOG("'spdk_trace' without parameters will also work if this is the only\n");
617 : 282 : SPDK_NOTICELOG("SPDK application currently running.\n");
618 : 282 : SPDK_NOTICELOG("Or copy /dev/shm%s for offline analysis/debug.\n", shm_name);
619 : : #endif
620 : : }
621 : 282 : free(tp_g_str);
622 : :
623 : 282 : return 0;
624 : 65 : }
625 : :
626 : : static void
627 : 2287 : bootstrap_fn(void *arg1)
628 : : {
629 [ + - ]: 2287 : spdk_rpc_set_allowlist(g_spdk_app.rpc_allowlist);
630 : :
631 [ + + ]: 2287 : if (g_spdk_app.json_data) {
632 : : /* Load SPDK_RPC_STARTUP RPCs from config file */
633 [ + + # # ]: 733 : assert(spdk_rpc_get_state() == SPDK_RPC_STARTUP);
634 [ + - ]: 767 : spdk_subsystem_load_config(g_spdk_app.json_data, g_spdk_app.json_data_size,
635 : : app_do_spdk_subsystem_init, NULL,
636 [ + + + - ]: 733 : !g_spdk_app.json_config_ignore_errors);
637 : 34 : } else {
638 : 1554 : app_do_spdk_subsystem_init(0, NULL);
639 : : }
640 : 2287 : }
641 : :
642 : : static void
643 : 2352 : app_copy_opts(struct spdk_app_opts *opts, struct spdk_app_opts *opts_user, size_t opts_size)
644 : : {
645 : 2352 : spdk_app_opts_init(opts, sizeof(*opts));
646 [ + - + - ]: 2352 : opts->opts_size = opts_size;
647 : :
648 : : #define SET_FIELD(field) \
649 : : if (offsetof(struct spdk_app_opts, field) + sizeof(opts->field) <= (opts->opts_size)) { \
650 : : opts->field = opts_user->field; \
651 : : } \
652 : :
653 [ + - + - : 2352 : SET_FIELD(name);
- + + - +
- + - +
- ]
654 [ + - + - : 2352 : SET_FIELD(json_config_file);
- + + - +
- + - +
- ]
655 [ + - + + : 2352 : SET_FIELD(json_config_ignore_errors);
- + + - +
- + - + -
+ - ]
656 [ + - + - : 2352 : SET_FIELD(rpc_addr);
- + + - +
- + - +
- ]
657 [ + - + - : 2352 : SET_FIELD(reactor_mask);
- + + - +
- + - +
- ]
658 [ + - + - : 2352 : SET_FIELD(lcore_map);
- + + - +
- + - +
- ]
659 [ + - + - : 2352 : SET_FIELD(tpoint_group_mask);
- + + - +
- + - +
- ]
660 [ + - + - : 2352 : SET_FIELD(shm_id);
- + + - +
- + - +
- ]
661 [ + - + - : 2352 : SET_FIELD(shutdown_cb);
- + + - +
- + - +
- ]
662 [ + - + + : 2352 : SET_FIELD(enable_coredump);
- + + - +
- + - + -
+ - ]
663 [ + - + - : 2352 : SET_FIELD(mem_channel);
- + + - +
- + - +
- ]
664 [ + - + - : 2352 : SET_FIELD(main_core);
- + + - +
- + - +
- ]
665 [ + - + - : 2352 : SET_FIELD(mem_size);
- + + - +
- + - +
- ]
666 [ + - + + : 2352 : SET_FIELD(no_pci);
- + + - +
- + - + -
+ - ]
667 [ + - + + : 2352 : SET_FIELD(hugepage_single_segments);
- + + - +
- + - + -
+ - ]
668 [ + - + + : 2352 : SET_FIELD(unlink_hugepage);
- + + - +
- + - + -
+ - ]
669 [ + - + + : 2352 : SET_FIELD(no_huge);
- + + - +
- + - + -
+ - ]
670 [ + - + - : 2352 : SET_FIELD(hugedir);
- + + - +
- + - +
- ]
671 [ + - + - : 2352 : SET_FIELD(print_level);
- + + - +
- + - +
- ]
672 [ + - + - : 2352 : SET_FIELD(num_pci_addr);
- + + - +
- + - +
- ]
673 [ + - + - : 2352 : SET_FIELD(pci_blocked);
- + + - +
- + - +
- ]
674 [ + - + - : 2352 : SET_FIELD(pci_allowed);
- + + - +
- + - +
- ]
675 [ + - + - : 2352 : SET_FIELD(iova_mode);
- + + - +
- + - +
- ]
676 [ + - + + : 2352 : SET_FIELD(delay_subsystem_init);
- + + - +
- + - + -
+ - ]
677 [ + - + - : 2352 : SET_FIELD(num_entries);
- + + - +
- + - +
- ]
678 [ + - + - : 2352 : SET_FIELD(env_context);
- + + - +
- + - +
- ]
679 [ + - + - : 2352 : SET_FIELD(log);
- + + - +
- + - +
- ]
680 [ + - + - : 2352 : SET_FIELD(base_virtaddr);
- + + - +
- + - +
- ]
681 [ + - + + : 2352 : SET_FIELD(disable_signal_handlers);
- + + - +
- + - + -
+ - ]
682 [ + - + + : 2352 : SET_FIELD(interrupt_mode);
- + + - +
- + - + -
+ - ]
683 [ + - + + : 2352 : SET_FIELD(enforce_numa);
- + + - +
- + - + -
+ - ]
684 [ + - + - : 2352 : SET_FIELD(msg_mempool_size);
- + + - +
- + - +
- ]
685 [ + - + - : 2352 : SET_FIELD(rpc_allowlist);
- + + - +
- + - +
- ]
686 [ + - + - : 2352 : SET_FIELD(vf_token);
- + + - +
- + - +
- ]
687 [ + - + - : 2352 : SET_FIELD(rpc_log_file);
- + + - +
- + - +
- ]
688 [ + - + - : 2352 : SET_FIELD(rpc_log_level);
- + + - +
- + - +
- ]
689 [ + - + - : 2352 : SET_FIELD(json_data);
- + + - +
- + - +
- ]
690 [ + - + - : 2352 : SET_FIELD(json_data_size);
- + + - +
- + - +
- ]
691 [ + - + + : 2352 : SET_FIELD(disable_cpumask_locks);
- + + - +
- + - + -
+ - ]
692 : :
693 : : /* You should not remove this statement, but need to update the assert statement
694 : : * if you add a new field, and also add a corresponding SET_FIELD statement */
695 : : SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 253, "Incorrect size");
696 : :
697 : : #undef SET_FIELD
698 : 2352 : }
699 : :
700 : : static int
701 : 2436 : unclaim_cpu_cores(uint32_t *failed_core)
702 : : {
703 : 999 : char core_name[40];
704 : : uint32_t i;
705 : : int rc;
706 : :
707 [ + + ]: 310666 : for (i = 0; i < SPDK_CONFIG_MAX_LCORES; i++) {
708 [ + + + - : 308258 : if (g_core_locks[i] != -1) {
+ - + + ]
709 : 3344 : snprintf(core_name, sizeof(core_name), "/var/tmp/spdk_cpu_lock_%03d", i);
710 [ + - + - : 3344 : rc = close(g_core_locks[i]);
+ - ]
711 [ + + ]: 3344 : if (rc) {
712 [ # # ]: 0 : SPDK_ERRLOG("Failed to close lock fd for core %d, errno: %d\n", i, errno);
713 : 0 : goto error;
714 : : }
715 : :
716 [ + - + - : 3344 : g_core_locks[i] = -1;
+ - ]
717 [ + - ]: 3344 : rc = unlink(core_name);
718 [ + + ]: 3344 : if (rc) {
719 [ - + ]: 28 : SPDK_ERRLOG("Failed to unlink lock fd for core %d, errno: %d\n", i, errno);
720 : 28 : goto error;
721 : : }
722 : 79 : }
723 : 9088 : }
724 : :
725 : 2408 : return 0;
726 : :
727 : 27 : error:
728 [ + + ]: 28 : if (failed_core != NULL) {
729 : : /* Set number of core we failed to claim. */
730 [ # # ]: 0 : *failed_core = i;
731 : 0 : }
732 : 28 : return -1;
733 : 72 : }
734 : :
735 : : static int
736 : 2306 : claim_cpu_cores(uint32_t *failed_core)
737 : : {
738 : 939 : char core_name[40];
739 : : int core_fd, pid;
740 : : int *core_map;
741 : : uint32_t core;
742 : :
743 : 2306 : struct flock core_lock = {
744 : : .l_type = F_WRLCK,
745 : : .l_whence = SEEK_SET,
746 : : .l_start = 0,
747 : : .l_len = 0,
748 : : };
749 : :
750 [ + + ]: 5646 : SPDK_ENV_FOREACH_CORE(core) {
751 [ + + + - : 3403 : if (g_core_locks[core] != -1) {
+ - - + ]
752 : : /* If this core is locked already, do not try lock it again. */
753 : 0 : continue;
754 : : }
755 : :
756 : 3403 : snprintf(core_name, sizeof(core_name), "/var/tmp/spdk_cpu_lock_%03d", core);
757 [ + - ]: 3403 : core_fd = open(core_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
758 [ + + ]: 3403 : if (core_fd == -1) {
759 [ # # ]: 0 : SPDK_ERRLOG("Could not open %s (%s).\n", core_name, spdk_strerror(errno));
760 : : /* Return number of core we failed to claim. */
761 : 0 : goto error;
762 : : }
763 : :
764 [ + + ]: 3403 : if (ftruncate(core_fd, sizeof(int)) != 0) {
765 [ # # ]: 0 : SPDK_ERRLOG("Could not truncate %s (%s).\n", core_name, spdk_strerror(errno));
766 : 0 : close(core_fd);
767 : 0 : goto error;
768 : : }
769 : :
770 : 3403 : core_map = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, core_fd, 0);
771 [ + + ]: 3403 : if (core_map == MAP_FAILED) {
772 [ # # ]: 0 : SPDK_ERRLOG("Could not mmap core %s (%s).\n", core_name, spdk_strerror(errno));
773 : 0 : close(core_fd);
774 : 0 : goto error;
775 : : }
776 : :
777 [ + + ]: 3403 : if (fcntl(core_fd, F_SETLK, &core_lock) != 0) {
778 [ - + ]: 63 : pid = *core_map;
779 : 63 : SPDK_ERRLOG("Cannot create lock on core %" PRIu32 ", probably process %d has claimed it.\n",
780 : : core, pid);
781 : 63 : munmap(core_map, sizeof(int));
782 : 63 : close(core_fd);
783 : 63 : goto error;
784 : : }
785 : :
786 : : /* We write the PID to the core lock file so that other processes trying
787 : : * to claim the same core will know what process is holding the lock. */
788 [ + - ]: 3340 : *core_map = (int)getpid();
789 : 3340 : munmap(core_map, sizeof(int));
790 [ + - + - : 3340 : g_core_locks[core] = core_fd;
+ - ]
791 : : /* Keep core_fd open to maintain the lock. */
792 : 79 : }
793 : :
794 : 2243 : return 0;
795 : :
796 : 60 : error:
797 [ + + ]: 63 : if (failed_core != NULL) {
798 : : /* Set number of core we failed to claim. */
799 [ + - ]: 21 : *failed_core = core;
800 : 1 : }
801 : 63 : unclaim_cpu_cores(NULL);
802 : 63 : return -1;
803 : 66 : }
804 : :
805 : : int
806 : 2352 : spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
807 : : void *arg1)
808 : : {
809 : : int rc;
810 : : char *tty;
811 : 2352 : struct spdk_cpuset tmp_cpumask = {};
812 : : static bool g_env_was_setup = false;
813 : 2352 : struct spdk_app_opts opts_local = {};
814 : 2352 : struct spdk_app_opts *opts = &opts_local;
815 : : uint32_t i, core;
816 : :
817 [ + + ]: 2352 : if (!opts_user) {
818 : 0 : SPDK_ERRLOG("opts_user should not be NULL\n");
819 : 0 : return 1;
820 : : }
821 : :
822 [ + + + - : 2352 : if (!opts_user->opts_size) {
+ - ]
823 : 0 : SPDK_ERRLOG("The opts_size in opts_user structure should not be zero value\n");
824 : 0 : return 1;
825 : : }
826 : :
827 [ + + + - : 2352 : if (opts_user->name == NULL) {
+ - ]
828 : 0 : SPDK_ERRLOG("spdk_app_opts::name not specified\n");
829 : 0 : return 1;
830 : : }
831 : :
832 [ + - + - ]: 2352 : app_copy_opts(opts, opts_user, opts_user->opts_size);
833 : :
834 [ + + ]: 2352 : if (!start_fn) {
835 : 0 : SPDK_ERRLOG("start_fn should not be NULL\n");
836 : 0 : return 1;
837 : : }
838 : :
839 [ + + + + : 2352 : if (!opts->rpc_addr && opts->delay_subsystem_init) {
+ + + - +
- + - +
+ ]
840 : 22 : SPDK_ERRLOG("Cannot use '--wait-for-rpc' if no RPC server is going to be started.\n");
841 : 22 : return 1;
842 : : }
843 : :
844 [ + - + + : 2330 : if (!(opts->lcore_map || opts->reactor_mask)) {
+ - + - +
- + + ]
845 : : /* Set default CPU mask */
846 [ + - + - ]: 546 : opts->reactor_mask = SPDK_APP_DPDK_DEFAULT_CORE_MASK;
847 : 9 : }
848 : :
849 : 2330 : tty = ttyname(STDERR_FILENO);
850 [ + - + + : 4593 : if (opts->print_level > SPDK_LOG_WARN &&
+ - # # ]
851 [ - + ]: 2330 : isatty(STDERR_FILENO) &&
852 [ # # ]: 0 : tty &&
853 [ # # # # ]: 0 : !strncmp(tty, "/dev/tty", strlen("/dev/tty"))) {
854 : 0 : printf("Warning: printing stderr to console terminal without -q option specified.\n");
855 : 0 : printf("Suggest using --silence-noticelog to disable logging to stderr and\n");
856 : 0 : printf("monitor syslog, or redirect stderr to a file.\n");
857 : 0 : printf("(Delaying for 10 seconds...)\n");
858 : 0 : sleep(10);
859 : 0 : }
860 : :
861 [ + - + - ]: 2330 : spdk_log_set_print_level(opts->print_level);
862 : :
863 : : #ifndef SPDK_NO_RLIMIT
864 [ + + + - : 2330 : if (opts->enable_coredump) {
+ - - + ]
865 : 949 : struct rlimit core_limits;
866 : :
867 [ + - ]: 2330 : core_limits.rlim_cur = core_limits.rlim_max = SPDK_APP_DEFAULT_CORE_LIMIT;
868 [ + - ]: 2330 : setrlimit(RLIMIT_CORE, &core_limits);
869 : 67 : }
870 : : #endif
871 : :
872 [ + + + + : 2330 : if (opts->interrupt_mode) {
+ - + - ]
873 : 29 : spdk_interrupt_mode_enable();
874 : 0 : }
875 : :
876 [ + - ]: 2330 : memset(&g_spdk_app, 0, sizeof(g_spdk_app));
877 : :
878 [ + + + - : 2330 : g_spdk_app.json_config_ignore_errors = opts->json_config_ignore_errors;
+ - + - ]
879 [ + - + - : 2330 : g_spdk_app.rpc_addr = opts->rpc_addr;
+ - ]
880 [ + - + - : 2330 : g_spdk_app.rpc_allowlist = opts->rpc_allowlist;
+ - ]
881 [ + - + - : 2330 : g_spdk_app.rpc_log_file = opts->rpc_log_file;
+ - ]
882 [ + - + - : 2330 : g_spdk_app.rpc_log_level = opts->rpc_log_level;
+ - ]
883 [ + - + - : 2330 : g_spdk_app.shm_id = opts->shm_id;
+ - ]
884 [ + - + - : 2330 : g_spdk_app.shutdown_cb = opts->shutdown_cb;
+ - ]
885 [ + - ]: 2330 : g_spdk_app.rc = 0;
886 : 2330 : g_spdk_app.stopped = false;
887 : :
888 : 2330 : spdk_log_set_level(SPDK_APP_DEFAULT_LOG_LEVEL);
889 : :
890 : : /* Pass NULL to app_setup_env if SPDK app has been set up, in order to
891 : : * indicate that this is a reinitialization.
892 : : */
893 [ + + + + : 2330 : if (app_setup_env(g_env_was_setup ? NULL : opts) < 0) {
+ + ]
894 : 0 : return 1;
895 : : }
896 : :
897 : : /* Calculate mempool size now that the env layer has configured the core count
898 : : * for the application */
899 : 2330 : calculate_mempool_size(opts, opts_user);
900 : :
901 [ + - + - ]: 2330 : spdk_log_open(opts->log);
902 : :
903 : : /* Initialize each lock to -1 to indicate "empty" status */
904 [ + + ]: 300570 : for (i = 0; i < SPDK_CONFIG_MAX_LCORES; i++) {
905 [ + - + - : 298240 : g_core_locks[i] = -1;
+ - ]
906 : 8576 : }
907 : :
908 [ + + + + : 2330 : if (!opts->disable_cpumask_locks) {
+ - + + ]
909 [ + + ]: 2243 : if (claim_cpu_cores(NULL)) {
910 : 42 : SPDK_ERRLOG("Unable to acquire lock on assigned core mask - exiting.\n");
911 : 42 : return 1;
912 : : }
913 : 61 : } else {
914 : 87 : SPDK_NOTICELOG("CPU core locks deactivated.\n");
915 : : }
916 : :
917 : 2288 : SPDK_NOTICELOG("Total cores available: %d\n", spdk_env_get_core_count());
918 : :
919 [ + + + - : 2288 : if ((rc = spdk_reactors_init(opts->msg_mempool_size)) != 0) {
- + ]
920 : 0 : SPDK_ERRLOG("Reactor Initialization failed: rc = %d\n", rc);
921 : 0 : return 1;
922 : : }
923 : :
924 : 2288 : spdk_cpuset_set_cpu(&tmp_cpumask, spdk_env_get_current_core(), true);
925 : :
926 : : /* Now that the reactors have been initialized, we can create the app thread. */
927 : 2288 : spdk_thread_create("app_thread", &tmp_cpumask);
928 [ + + ]: 2288 : if (!spdk_thread_get_app_thread()) {
929 : 0 : SPDK_ERRLOG("Unable to create an spdk_thread for initialization\n");
930 : 0 : return 1;
931 : : }
932 : :
933 [ + + ]: 5721 : SPDK_ENV_FOREACH_CORE(core) {
934 : 3433 : rc = init_proc_stat(core);
935 [ + + ]: 3433 : if (rc) {
936 : 0 : SPDK_NOTICELOG("Unable to parse /proc/stat [core: %d].\n", core);
937 : 0 : }
938 : 83 : }
939 : : /*
940 : : * Disable and ignore trace setup if setting num_entries
941 : : * to be 0.
942 : : *
943 : : * Note the call to app_setup_trace() is located here
944 : : * ahead of app_setup_signal_handlers().
945 : : * That's because there is not an easy/direct clean
946 : : * way of unwinding alloc'd resources that can occur
947 : : * in app_setup_signal_handlers().
948 : : */
949 [ + - + + : 2288 : if (opts->num_entries != 0 && app_setup_trace(opts) != 0) {
+ - + - ]
950 : 0 : return 1;
951 : : }
952 : :
953 [ + + + + : 2288 : if (!opts->disable_signal_handlers && app_setup_signal_handlers(opts) != 0) {
+ + + - -
+ ]
954 : 0 : return 1;
955 : : }
956 : :
957 [ + + + - : 2288 : g_delay_subsystem_init = opts->delay_subsystem_init;
+ - ]
958 : 2288 : g_start_fn = start_fn;
959 : 2288 : g_start_arg = arg1;
960 : :
961 [ + + + - : 2288 : if (opts->json_config_file != NULL) {
+ + ]
962 [ + + + - : 734 : if (opts->json_data) {
- + ]
963 : 0 : SPDK_ERRLOG("App opts json_config_file and json_data are mutually exclusive\n");
964 : 0 : return 1;
965 : : }
966 : :
967 [ + - + - ]: 734 : g_spdk_app.json_data = spdk_posix_file_load_from_name(opts->json_config_file,
968 : : &g_spdk_app.json_data_size);
969 [ + + ]: 734 : if (!g_spdk_app.json_data) {
970 [ # # # # : 1 : SPDK_ERRLOG("Read JSON configuration file %s failed: %s\n",
# # ]
971 : : opts->json_config_file, spdk_strerror(errno));
972 : 1 : return 1;
973 : : }
974 [ + + + - : 1588 : } else if (opts->json_data) {
+ - ]
975 [ # # # # ]: 0 : g_spdk_app.json_data = calloc(1, opts->json_data_size);
976 [ # # ]: 0 : if (!g_spdk_app.json_data) {
977 : 0 : SPDK_ERRLOG("Failed to allocate JSON data buffer\n");
978 : 0 : return 1;
979 : : }
980 : :
981 [ # # # # : 0 : memcpy(g_spdk_app.json_data, opts->json_data, opts->json_data_size);
# # # # #
# # # ]
982 [ # # # # : 0 : g_spdk_app.json_data_size = opts->json_data_size;
# # ]
983 : 0 : }
984 : :
985 : 2287 : spdk_thread_send_msg(spdk_thread_get_app_thread(), bootstrap_fn, NULL);
986 : :
987 : : /* This blocks until spdk_app_stop is called */
988 : 2287 : spdk_reactors_start();
989 : :
990 : 2287 : g_env_was_setup = true;
991 : :
992 [ + - ]: 2287 : return g_spdk_app.rc;
993 : 68 : }
994 : :
995 : : void
996 : 2352 : spdk_app_fini(void)
997 : : {
998 : 2352 : spdk_trace_cleanup();
999 : 2352 : spdk_reactors_fini();
1000 : 2352 : spdk_env_fini();
1001 : 2352 : spdk_log_close();
1002 : 2352 : unclaim_cpu_cores(NULL);
1003 : 2352 : }
1004 : :
1005 : : static void
1006 : 2287 : subsystem_fini_done(void *arg1)
1007 : : {
1008 : 2287 : spdk_rpc_finish();
1009 : 2287 : spdk_reactors_stop(NULL);
1010 : 2287 : }
1011 : :
1012 : : static void
1013 : 2996 : _start_subsystem_fini(void *arg1)
1014 : : {
1015 [ + + + + ]: 2996 : if (g_scheduling_in_progress) {
1016 : 709 : spdk_thread_send_msg(spdk_thread_get_app_thread(), _start_subsystem_fini, NULL);
1017 : 709 : return;
1018 : : }
1019 : :
1020 : 2287 : spdk_subsystem_fini(subsystem_fini_done, NULL);
1021 : 199 : }
1022 : :
1023 : : static int
1024 : 21092 : log_deprecation_hits(void *ctx, struct spdk_deprecation *dep)
1025 : : {
1026 : 21092 : uint64_t hits = spdk_deprecation_get_hits(dep);
1027 : :
1028 [ + + ]: 21092 : if (hits == 0) {
1029 : 21086 : return 0;
1030 : : }
1031 : :
1032 : 6 : SPDK_WARNLOG("%s: deprecation '%s' scheduled for removal in %s hit %" PRIu64 " times\n",
1033 : : spdk_deprecation_get_tag(dep), spdk_deprecation_get_description(dep),
1034 : : spdk_deprecation_get_remove_release(dep), hits);
1035 : 6 : return 0;
1036 : 598 : }
1037 : :
1038 : : static void
1039 : 2294 : app_stop(void *arg1)
1040 : : {
1041 [ + + + - ]: 2294 : if (g_spdk_app.rc == 0) {
1042 [ + - ]: 2287 : g_spdk_app.rc = (int)(intptr_t)arg1;
1043 : 65 : }
1044 : :
1045 [ + + + + ]: 2294 : if (g_spdk_app.stopped) {
1046 : 7 : SPDK_NOTICELOG("spdk_app_stop called twice\n");
1047 : 7 : return;
1048 : : }
1049 : :
1050 : 2287 : free(g_spdk_app.json_data);
1051 : :
1052 : 2287 : g_spdk_app.stopped = true;
1053 : 2287 : spdk_log_for_each_deprecation(NULL, log_deprecation_hits);
1054 : 2287 : _start_subsystem_fini(NULL);
1055 : 65 : }
1056 : :
1057 : : void
1058 : 2294 : spdk_app_stop(int rc)
1059 : : {
1060 [ + + ]: 2294 : if (rc) {
1061 : 179 : SPDK_WARNLOG("spdk_app_stop'd on non-zero\n");
1062 : 1 : }
1063 : :
1064 : : /*
1065 : : * We want to run spdk_subsystem_fini() from the same thread where spdk_subsystem_init()
1066 : : * was called.
1067 : : */
1068 : 2294 : spdk_thread_send_msg(spdk_thread_get_app_thread(), app_stop, (void *)(intptr_t)rc);
1069 : 2294 : }
1070 : :
1071 : : static void
1072 : 20 : usage_memory_size(void)
1073 : : {
1074 : : #ifndef __linux__
1075 : : if (g_default_opts.mem_size <= 0) {
1076 : : printf("all hugepage memory)\n");
1077 : : } else
1078 : : #endif
1079 : : {
1080 [ - + ]: 20 : printf("%dMB)\n", g_default_opts.mem_size >= 0 ? g_default_opts.mem_size : 0);
1081 : : }
1082 : 20 : }
1083 : :
1084 : : static void
1085 : 20 : usage(void (*app_usage)(void))
1086 : : {
1087 [ - + ]: 20 : printf("%s [options]\n", g_executable_name);
1088 : : /* Keep entries inside categories roughly sorted by frequency of use. */
1089 [ - + ]: 20 : printf("\nCPU options:\n");
1090 [ - + ]: 20 : printf(" -m, --cpumask <mask or list> core mask (like 0xF) or core list of '[]' embraced for DPDK\n");
1091 [ - + ]: 20 : printf(" (like [0,1,10])\n");
1092 [ - + ]: 20 : printf(" --lcores <list> lcore to CPU mapping list. The list is in the format:\n");
1093 [ - + ]: 20 : printf(" <lcores[@CPUs]>[<,lcores[@CPUs]>...]\n");
1094 [ - + ]: 20 : printf(" lcores and cpus list are grouped by '(' and ')', e.g '--lcores \"(5-7)@(10-12)\"'\n");
1095 [ - + ]: 20 : printf(" Within the group, '-' is used for range separator,\n");
1096 [ - + ]: 20 : printf(" ',' is used for single number separator.\n");
1097 [ - + ]: 20 : printf(" '( )' can be omitted for single element group,\n");
1098 [ - + ]: 20 : printf(" '@' can be omitted if cpus and lcores have the same value\n");
1099 [ - + ]: 20 : printf(" --disable-cpumask-locks Disable CPU core lock files.\n");
1100 [ - + ]: 20 : printf(" --interrupt-mode set app to interrupt mode (Warning: CPU usage will be reduced only if all\n");
1101 [ - + ]: 20 : printf(" pollers in the app support interrupt mode)\n");
1102 [ - + ]: 20 : printf(" -p, --main-core <id> main (primary) core for DPDK\n");
1103 : :
1104 [ - + ]: 20 : printf("\nConfiguration options:\n");
1105 [ - + ]: 20 : printf(" -c, --config, --json <config> JSON config file\n");
1106 [ - + ]: 20 : printf(" -r, --rpc-socket <path> RPC listen address (default %s)\n", SPDK_DEFAULT_RPC_ADDR);
1107 [ - + ]: 20 : printf(" --no-rpc-server skip RPC server initialization. This option ignores '--rpc-socket' value.\n");
1108 [ - + ]: 20 : printf(" --wait-for-rpc wait for RPCs to initialize subsystems\n");
1109 [ - + ]: 20 : printf(" --rpcs-allowed comma-separated list of permitted RPCS\n");
1110 [ - + ]: 20 : printf(" --json-ignore-init-errors don't exit on invalid config entry\n");
1111 : :
1112 [ - + ]: 20 : printf("\nMemory options:\n");
1113 [ - + ]: 20 : printf(" --iova-mode <pa/va> set IOVA mode ('pa' for IOVA_PA and 'va' for IOVA_VA)\n");
1114 [ - + ]: 20 : printf(" --base-virtaddr <addr> the base virtual address for DPDK (default: 0x200000000000)\n");
1115 [ - + ]: 20 : printf(" --huge-dir <path> use a specific hugetlbfs mount to reserve memory from\n");
1116 [ - + ]: 20 : printf(" -R, --huge-unlink unlink huge files after initialization\n");
1117 [ - + ]: 20 : printf(" -n, --mem-channels <num> number of memory channels used for DPDK\n");
1118 [ - + ]: 20 : printf(" -s, --mem-size <size> memory size in MB for DPDK (default: ");
1119 : 20 : usage_memory_size();
1120 [ - + ]: 20 : printf(" --msg-mempool-size <size> global message memory pool size in count (default: %d)\n",
1121 : : SPDK_DEFAULT_MSG_MEMPOOL_SIZE);
1122 [ - + ]: 20 : printf(" --no-huge run without using hugepages\n");
1123 [ - + ]: 20 : printf(" --enforce-numa enforce NUMA allocations from the specified NUMA node\n");
1124 [ - + ]: 20 : printf(" -i, --shm-id <id> shared memory ID (optional)\n");
1125 [ - + ]: 20 : printf(" -g, --single-file-segments force creating just one hugetlbfs file\n");
1126 : :
1127 [ - + ]: 20 : printf("\nPCI options:\n");
1128 [ - + ]: 20 : printf(" -A, --pci-allowed <bdf> pci addr to allow (-B and -A cannot be used at the same time)\n");
1129 [ - + ]: 20 : printf(" -B, --pci-blocked <bdf> pci addr to block (can be used more than once)\n");
1130 [ - + ]: 20 : printf(" -u, --no-pci disable PCI access\n");
1131 [ - + ]: 20 : printf(" --vfio-vf-token VF token (UUID) shared between SR-IOV PF and VFs for vfio_pci driver\n");
1132 : :
1133 [ - + ]: 20 : printf("\nLog options:\n");
1134 : 20 : spdk_log_usage(stdout, "-L");
1135 [ - + ]: 20 : printf(" --silence-noticelog disable notice level logging to stderr\n");
1136 : :
1137 [ - + ]: 20 : printf("\nTrace options:\n");
1138 [ - + ]: 20 : printf(" --num-trace-entries <num> number of trace entries for each core, must be power of 2,\n");
1139 [ - + ]: 20 : printf(" setting 0 to disable trace (default %d)\n",
1140 : : SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES);
1141 [ - + ]: 20 : printf(" Tracepoints vary in size and can use more than one trace entry.\n");
1142 : 20 : spdk_trace_mask_usage(stdout, "-e");
1143 : :
1144 [ - + ]: 20 : printf("\nOther options:\n");
1145 [ - + ]: 20 : printf(" -h, --help show this usage\n");
1146 [ - + ]: 20 : printf(" -v, --version print SPDK version\n");
1147 [ - + ]: 20 : printf(" -d, --limit-coredump do not set max coredump size to RLIM_INFINITY\n");
1148 [ - + ]: 20 : printf(" --env-context Opaque context for use of the env implementation\n");
1149 : :
1150 [ + + ]: 20 : if (app_usage) {
1151 [ - + ]: 11 : printf("\nApplication specific:\n");
1152 [ # # # # ]: 11 : app_usage();
1153 : 0 : }
1154 : 20 : }
1155 : :
1156 : : spdk_app_parse_args_rvals_t
1157 : 2282 : spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
1158 : : const char *app_getopt_str, const struct option *app_long_opts,
1159 : : int (*app_parse)(int ch, char *arg),
1160 : : void (*app_usage)(void))
1161 : : {
1162 : 941 : int ch, rc, opt_idx, global_long_opts_len, app_long_opts_len;
1163 : : struct option *cmdline_options;
1164 : 2282 : char *cmdline_short_opts = NULL;
1165 : 2282 : char *shm_id_str = NULL;
1166 : 2282 : enum spdk_app_parse_args_rvals retval = SPDK_APP_PARSE_ARGS_FAIL;
1167 : : long int tmp;
1168 : :
1169 [ + - + - ]: 2282 : memcpy(&g_default_opts, opts, sizeof(g_default_opts));
1170 : :
1171 [ + + + + : 2282 : if (opts->json_config_file && access(opts->json_config_file, R_OK) != 0) {
- + # # #
# # # #
# ]
1172 [ # # # # ]: 0 : SPDK_WARNLOG("Can't read JSON configuration file '%s'\n", opts->json_config_file);
1173 [ # # # # ]: 0 : opts->json_config_file = NULL;
1174 : 0 : }
1175 : :
1176 [ + + ]: 2282 : if (app_long_opts == NULL) {
1177 : 1809 : app_long_opts_len = 0;
1178 : 61 : } else {
1179 [ # # ]: 473 : for (app_long_opts_len = 0;
1180 [ + + # # : 6586 : app_long_opts[app_long_opts_len].name != NULL;
# # ]
1181 [ # # ]: 6113 : app_long_opts_len++);
1182 : : }
1183 : :
1184 : 2282 : global_long_opts_len = SPDK_COUNTOF(g_cmdline_options);
1185 : :
1186 [ + - + - ]: 2282 : cmdline_options = calloc(global_long_opts_len + app_long_opts_len + 1, sizeof(*cmdline_options));
1187 [ + + ]: 2282 : if (!cmdline_options) {
1188 : 0 : SPDK_ERRLOG("Out of memory\n");
1189 : 0 : return SPDK_APP_PARSE_ARGS_FAIL;
1190 : : }
1191 : :
1192 [ + + + + : 2282 : memcpy(&cmdline_options[0], g_cmdline_options, sizeof(g_cmdline_options));
+ - ]
1193 [ + + ]: 2282 : if (app_long_opts) {
1194 [ - + - + : 473 : memcpy(&cmdline_options[global_long_opts_len], app_long_opts,
# # # # ]
1195 : 0 : app_long_opts_len * sizeof(*app_long_opts));
1196 : 0 : }
1197 : :
1198 [ + + ]: 2282 : if (app_getopt_str != NULL) {
1199 : 2282 : ch = app_opts_validate(app_getopt_str);
1200 [ + + ]: 2282 : if (ch) {
1201 : 3 : SPDK_ERRLOG("Duplicated option '%c' between app-specific command line parameter and generic spdk opts.\n",
1202 : : ch);
1203 : 3 : goto out;
1204 : : }
1205 : :
1206 [ - + ]: 2279 : if (!app_parse) {
1207 : 0 : SPDK_ERRLOG("Parse function is required when app-specific command line parameters are provided.\n");
1208 : 0 : goto out;
1209 : : }
1210 : 61 : }
1211 : :
1212 : 2279 : cmdline_short_opts = spdk_sprintf_alloc("%s%s", app_getopt_str, SPDK_APP_GETOPT_STRING);
1213 [ + + ]: 2279 : if (!cmdline_short_opts) {
1214 : 0 : SPDK_ERRLOG("Out of memory\n");
1215 : 0 : goto out;
1216 : : }
1217 : :
1218 [ + - + - ]: 2279 : g_executable_name = argv[0];
1219 : :
1220 [ + + + + : 10486 : while ((ch = getopt_long(argc, argv, cmdline_short_opts, cmdline_options, &opt_idx)) != -1) {
+ + ]
1221 [ + + + + : 8236 : switch (ch) {
+ + + + +
+ + + - +
+ - + + +
+ + + + +
+ - - - +
- + - + -
+ + ]
1222 : 708 : case CONFIG_FILE_OPT_IDX:
1223 : : case JSON_CONFIG_OPT_IDX:
1224 [ + - + - ]: 742 : opts->json_config_file = optarg;
1225 : 742 : break;
1226 : 0 : case JSON_CONFIG_IGNORE_INIT_ERRORS_IDX:
1227 [ # # # # ]: 0 : opts->json_config_ignore_errors = true;
1228 : 0 : break;
1229 : 16 : case LIMIT_COREDUMP_OPT_IDX:
1230 [ # # # # ]: 16 : opts->enable_coredump = false;
1231 : 16 : break;
1232 : 277 : case TPOINT_GROUP_OPT_IDX:
1233 [ + - + - ]: 278 : opts->tpoint_group_mask = optarg;
1234 : 278 : break;
1235 : 28 : case SINGLE_FILE_SEGMENTS_OPT_IDX:
1236 [ # # # # ]: 28 : opts->hugepage_single_segments = true;
1237 : 28 : break;
1238 : 4 : case HELP_OPT_IDX:
1239 : 4 : usage(app_usage);
1240 : 4 : retval = SPDK_APP_PARSE_ARGS_HELP;
1241 : 4 : goto out;
1242 : 334 : case SHM_ID_OPT_IDX:
1243 : 334 : shm_id_str = optarg;
1244 : : /* a negative shm-id disables shared configuration file */
1245 [ - + # # : 334 : if (optarg[0] == '-') {
# # ]
1246 [ # # ]: 0 : shm_id_str++;
1247 : 0 : }
1248 : : /* check if the positive value of provided shm_id can be parsed as
1249 : : * an integer
1250 : : */
1251 [ # # # # ]: 334 : opts->shm_id = spdk_strtol(shm_id_str, 0);
1252 [ - + # # : 334 : if (opts->shm_id < 0) {
# # ]
1253 : 0 : SPDK_ERRLOG("Invalid shared memory ID %s\n", optarg);
1254 : 0 : goto out;
1255 : : }
1256 [ - + # # : 334 : if (optarg[0] == '-') {
# # ]
1257 [ # # # # : 0 : opts->shm_id = -opts->shm_id;
# # # # #
# ]
1258 : 0 : }
1259 : 334 : break;
1260 : 1054 : case CPUMASK_OPT_IDX:
1261 [ + + + - : 1108 : if (opts->lcore_map) {
+ - ]
1262 : 0 : SPDK_ERRLOG("lcore map and core mask can't be set simultaneously\n");
1263 : 0 : goto out;
1264 : : }
1265 [ + - + - ]: 1108 : opts->reactor_mask = optarg;
1266 : 1108 : break;
1267 : 0 : case LCORES_OPT_IDX:
1268 [ # # # # : 0 : if (opts->reactor_mask) {
# # ]
1269 : 0 : SPDK_ERRLOG("lcore map and core mask can't be set simultaneously\n");
1270 : 0 : goto out;
1271 : : }
1272 [ # # # # ]: 0 : opts->lcore_map = optarg;
1273 : 0 : break;
1274 : 83 : case DISABLE_CPUMASK_LOCKS_OPT_IDX:
1275 [ + - + - ]: 87 : opts->disable_cpumask_locks = true;
1276 : 87 : break;
1277 : 0 : case MEM_CHANNELS_OPT_IDX:
1278 [ # # # # ]: 0 : opts->mem_channel = spdk_strtol(optarg, 0);
1279 [ # # # # : 0 : if (opts->mem_channel < 0) {
# # ]
1280 : 0 : SPDK_ERRLOG("Invalid memory channel %s\n", optarg);
1281 : 0 : goto out;
1282 : : }
1283 : 0 : break;
1284 : 73 : case MAIN_CORE_OPT_IDX:
1285 [ + - + - ]: 75 : opts->main_core = spdk_strtol(optarg, 0);
1286 [ + + + - : 75 : if (opts->main_core < 0) {
+ - ]
1287 : 3 : SPDK_ERRLOG("Invalid main core %s\n", optarg);
1288 : 3 : goto out;
1289 : : }
1290 : 72 : break;
1291 : 0 : case SILENCE_NOTICELOG_OPT_IDX:
1292 [ # # # # ]: 0 : opts->print_level = SPDK_LOG_WARN;
1293 : 0 : break;
1294 : 400 : case RPC_SOCKET_OPT_IDX:
1295 [ + - + - ]: 414 : opts->rpc_addr = optarg;
1296 : 414 : break;
1297 : 63 : case NO_RPC_SERVER_OPT_IDX:
1298 [ + - + - ]: 66 : opts->rpc_addr = NULL;
1299 : 66 : break;
1300 : 0 : case ENFORCE_NUMA_OPT_IDX:
1301 [ # # # # ]: 0 : opts->enforce_numa = true;
1302 : 0 : break;
1303 : 125 : case MEM_SIZE_OPT_IDX: {
1304 : 39 : uint64_t mem_size_mb;
1305 : 39 : bool mem_size_has_prefix;
1306 : :
1307 : 158 : rc = spdk_parse_capacity(optarg, &mem_size_mb, &mem_size_has_prefix);
1308 [ + + ]: 158 : if (rc != 0) {
1309 : 0 : SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg);
1310 : 0 : usage(app_usage);
1311 : 0 : goto out;
1312 : : }
1313 : :
1314 [ + + + + ]: 158 : if (mem_size_has_prefix) {
1315 : : /* the mem size is in MB by default, so if a prefix was
1316 : : * specified, we need to manually convert to MB.
1317 : : */
1318 [ # # ]: 0 : mem_size_mb /= 1024 * 1024;
1319 : 0 : }
1320 : :
1321 [ - + ]: 158 : if (mem_size_mb > INT_MAX) {
1322 : 0 : SPDK_ERRLOG("invalid memory pool size `-s %s`\n", optarg);
1323 : 0 : usage(app_usage);
1324 : 0 : goto out;
1325 : : }
1326 : :
1327 [ + - + - ]: 158 : opts->mem_size = (int) mem_size_mb;
1328 : 158 : break;
1329 : : }
1330 : 0 : case MSG_MEMPOOL_SIZE_OPT_IDX:
1331 : 0 : tmp = spdk_strtol(optarg, 10);
1332 [ # # ]: 0 : if (tmp <= 0) {
1333 : 0 : SPDK_ERRLOG("Invalid message memory pool size %s\n", optarg);
1334 : 0 : goto out;
1335 : : }
1336 : :
1337 [ # # # # ]: 0 : opts->msg_mempool_size = (size_t)tmp;
1338 : 0 : break;
1339 : :
1340 : 6 : case NO_PCI_OPT_IDX:
1341 [ # # # # ]: 6 : opts->no_pci = true;
1342 : 6 : break;
1343 : 182 : case WAIT_FOR_RPC_OPT_IDX:
1344 [ + - + - ]: 184 : opts->delay_subsystem_init = true;
1345 : 184 : break;
1346 : 6 : case PCI_BLOCKED_OPT_IDX:
1347 [ - + # # : 6 : if (opts->pci_allowed) {
# # ]
1348 [ # # # # ]: 0 : free(opts->pci_allowed);
1349 [ # # # # ]: 0 : opts->pci_allowed = NULL;
1350 : 0 : SPDK_ERRLOG("-B and -A cannot be used at the same time\n");
1351 : 0 : usage(app_usage);
1352 : 0 : goto out;
1353 : : }
1354 : :
1355 [ # # ]: 6 : rc = app_opts_add_pci_addr(opts, &opts->pci_blocked, optarg);
1356 [ - + ]: 6 : if (rc != 0) {
1357 [ # # # # ]: 0 : free(opts->pci_blocked);
1358 [ # # # # ]: 0 : opts->pci_blocked = NULL;
1359 : 0 : goto out;
1360 : : }
1361 : 6 : break;
1362 : :
1363 : 6 : case NO_HUGE_OPT_IDX:
1364 [ # # # # ]: 6 : opts->no_huge = true;
1365 : 6 : break;
1366 : :
1367 : 107 : case LOGFLAG_OPT_IDX:
1368 : 107 : rc = spdk_log_set_flag(optarg);
1369 [ - + ]: 107 : if (rc < 0) {
1370 : 0 : SPDK_ERRLOG("unknown flag: %s\n", optarg);
1371 : 0 : usage(app_usage);
1372 : 0 : goto out;
1373 : : }
1374 : : #ifdef DEBUG
1375 [ # # # # ]: 107 : opts->print_level = SPDK_LOG_DEBUG;
1376 : : #endif
1377 : 107 : break;
1378 : 1 : case HUGE_UNLINK_OPT_IDX:
1379 [ # # # # ]: 1 : opts->unlink_hugepage = true;
1380 : 1 : break;
1381 : 3 : case PCI_ALLOWED_OPT_IDX:
1382 [ + - # # : 3 : if (opts->pci_blocked) {
# # ]
1383 [ # # # # ]: 3 : free(opts->pci_blocked);
1384 [ # # # # ]: 3 : opts->pci_blocked = NULL;
1385 : 3 : SPDK_ERRLOG("-B and -W cannot be used at the same time\n");
1386 : 3 : usage(app_usage);
1387 : 3 : goto out;
1388 : : }
1389 : :
1390 [ # # ]: 0 : rc = app_opts_add_pci_addr(opts, &opts->pci_allowed, optarg);
1391 [ # # ]: 0 : if (rc != 0) {
1392 [ # # # # ]: 0 : free(opts->pci_allowed);
1393 [ # # # # ]: 0 : opts->pci_allowed = NULL;
1394 : 0 : goto out;
1395 : : }
1396 : 0 : break;
1397 : 0 : case BASE_VIRTADDR_OPT_IDX:
1398 : 0 : tmp = spdk_strtoll(optarg, 0);
1399 [ # # ]: 0 : if (tmp <= 0) {
1400 : 0 : SPDK_ERRLOG("Invalid base-virtaddr %s\n", optarg);
1401 : 0 : usage(app_usage);
1402 : 0 : goto out;
1403 : : }
1404 [ # # # # ]: 0 : opts->base_virtaddr = (uint64_t)tmp;
1405 : 0 : break;
1406 : 0 : case HUGE_DIR_OPT_IDX:
1407 [ # # # # ]: 0 : opts->hugedir = optarg;
1408 : 0 : break;
1409 : 0 : case IOVA_MODE_OPT_IDX:
1410 [ # # # # ]: 0 : opts->iova_mode = optarg;
1411 : 0 : break;
1412 : 2 : case NUM_TRACE_ENTRIES_OPT_IDX:
1413 : 2 : tmp = spdk_strtoll(optarg, 0);
1414 [ - + ]: 2 : if (tmp < 0) {
1415 : 0 : SPDK_ERRLOG("Invalid num-trace-entries %s\n", optarg);
1416 : 0 : usage(app_usage);
1417 : 0 : goto out;
1418 : : }
1419 [ # # # # ]: 2 : opts->num_entries = (uint64_t)tmp;
1420 [ + - - + : 2 : if (opts->num_entries > 0 && opts->num_entries & (opts->num_entries - 1)) {
# # # # #
# # # # #
# # ]
1421 : 0 : SPDK_ERRLOG("num-trace-entries must be power of 2\n");
1422 : 0 : usage(app_usage);
1423 : 0 : goto out;
1424 : : }
1425 : 2 : break;
1426 : 0 : case ENV_CONTEXT_OPT_IDX:
1427 [ # # # # ]: 0 : opts->env_context = optarg;
1428 : 0 : break;
1429 : 21 : case RPCS_ALLOWED_OPT_IDX:
1430 [ + - + - ]: 22 : opts->rpc_allowlist = (const char **)spdk_strarray_from_string(optarg, ",");
1431 [ + + + - : 22 : if (opts->rpc_allowlist == NULL) {
+ - ]
1432 : 0 : SPDK_ERRLOG("Invalid --rpcs-allowed argument\n");
1433 : 0 : usage(app_usage);
1434 : 0 : goto out;
1435 : : }
1436 : 22 : break;
1437 : 0 : case ENV_VF_TOKEN_OPT_IDX:
1438 [ # # # # ]: 0 : opts->vf_token = optarg;
1439 : 0 : break;
1440 : 29 : case INTERRUPT_MODE_OPT_IDX:
1441 [ # # # # ]: 29 : opts->interrupt_mode = true;
1442 : 29 : break;
1443 : 0 : case VERSION_OPT_IDX:
1444 [ # # ]: 0 : printf(SPDK_VERSION_STRING"\n");
1445 : 0 : retval = SPDK_APP_PARSE_ARGS_HELP;
1446 : 0 : goto out;
1447 : 13 : case '?':
1448 : : /*
1449 : : * In the event getopt() above detects an option
1450 : : * in argv that is NOT in the getopt_str,
1451 : : * getopt() will return a '?' indicating failure.
1452 : : */
1453 : 13 : usage(app_usage);
1454 : 13 : goto out;
1455 : 4372 : default:
1456 [ + + ]: 4547 : if (!app_parse) {
1457 : 0 : SPDK_ERRLOG("Unsupported app-specific command line parameter '%c'.\n", ch);
1458 : 0 : goto out;
1459 : : }
1460 : :
1461 [ - + + - ]: 4547 : rc = app_parse(ch, optarg);
1462 [ + + ]: 4547 : if (rc) {
1463 : 6 : SPDK_ERRLOG("Parsing app-specific command line parameter '%c' failed: %d\n", ch, rc);
1464 : 6 : goto out;
1465 : : }
1466 : 175 : }
1467 : : }
1468 : :
1469 : 2250 : retval = SPDK_APP_PARSE_ARGS_SUCCESS;
1470 : 2221 : out:
1471 [ + + ]: 2282 : if (retval != SPDK_APP_PARSE_ARGS_SUCCESS) {
1472 [ # # # # ]: 32 : free(opts->pci_blocked);
1473 [ # # # # ]: 32 : opts->pci_blocked = NULL;
1474 [ # # # # ]: 32 : free(opts->pci_allowed);
1475 [ # # # # ]: 32 : opts->pci_allowed = NULL;
1476 [ # # # # ]: 32 : spdk_strarray_free((char **)opts->rpc_allowlist);
1477 [ # # # # ]: 32 : opts->rpc_allowlist = NULL;
1478 : 0 : }
1479 : 2282 : free(cmdline_short_opts);
1480 : 2282 : free(cmdline_options);
1481 : 2282 : return retval;
1482 : 61 : }
1483 : :
1484 : : void
1485 : 0 : spdk_app_usage(void)
1486 : : {
1487 [ # # ]: 0 : if (g_executable_name == NULL) {
1488 : 0 : SPDK_ERRLOG("%s not valid before calling spdk_app_parse_args()\n", __func__);
1489 : 0 : return;
1490 : : }
1491 : :
1492 : 0 : usage(NULL);
1493 : 0 : }
1494 : :
1495 : : static void
1496 : 162 : rpc_framework_start_init_cpl(int rc, void *arg1)
1497 : : {
1498 : 162 : struct spdk_jsonrpc_request *request = arg1;
1499 : :
1500 [ + + # # ]: 162 : assert(spdk_thread_is_app_thread(NULL));
1501 : :
1502 [ - + ]: 162 : if (rc) {
1503 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
1504 : : "framework_initialization failed");
1505 : 0 : return;
1506 : : }
1507 : :
1508 : 162 : app_subsystem_init_done(0, NULL);
1509 : :
1510 : 162 : spdk_jsonrpc_send_bool_response(request, true);
1511 : 1 : }
1512 : :
1513 : : static void
1514 : 162 : rpc_framework_start_init(struct spdk_jsonrpc_request *request,
1515 : : const struct spdk_json_val *params)
1516 : : {
1517 [ - + ]: 162 : if (params != NULL) {
1518 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
1519 : : "framework_start_init requires no parameters");
1520 : 0 : return;
1521 : : }
1522 : :
1523 [ + - ]: 162 : spdk_rpc_server_pause(g_spdk_app.rpc_addr);
1524 : 162 : spdk_subsystem_init(rpc_framework_start_init_cpl, request);
1525 : 1 : }
1526 : 2394 : SPDK_RPC_REGISTER("framework_start_init", rpc_framework_start_init, SPDK_RPC_STARTUP)
1527 : :
1528 : : struct subsystem_init_poller_ctx {
1529 : : struct spdk_poller *init_poller;
1530 : : struct spdk_jsonrpc_request *request;
1531 : : };
1532 : :
1533 : : static int
1534 : 506835 : rpc_subsystem_init_poller_ctx(void *ctx)
1535 : : {
1536 : 506835 : struct subsystem_init_poller_ctx *poller_ctx = ctx;
1537 : :
1538 [ + + ]: 506835 : if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
1539 [ # # # # ]: 2 : spdk_jsonrpc_send_bool_response(poller_ctx->request, true);
1540 [ # # ]: 2 : spdk_poller_unregister(&poller_ctx->init_poller);
1541 : 2 : free(poller_ctx);
1542 : 0 : }
1543 : :
1544 : 506835 : return SPDK_POLLER_BUSY;
1545 : : }
1546 : :
1547 : : static void
1548 : 12 : rpc_framework_wait_init(struct spdk_jsonrpc_request *request,
1549 : : const struct spdk_json_val *params)
1550 : : {
1551 : : struct subsystem_init_poller_ctx *ctx;
1552 : :
1553 [ + + ]: 12 : if (spdk_rpc_get_state() == SPDK_RPC_RUNTIME) {
1554 : 10 : spdk_jsonrpc_send_bool_response(request, true);
1555 : 0 : } else {
1556 : 2 : ctx = malloc(sizeof(struct subsystem_init_poller_ctx));
1557 [ - + ]: 2 : if (ctx == NULL) {
1558 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
1559 : : "Unable to allocate memory for the request context\n");
1560 : 0 : return;
1561 : : }
1562 [ # # # # ]: 2 : ctx->request = request;
1563 [ # # # # ]: 2 : ctx->init_poller = SPDK_POLLER_REGISTER(rpc_subsystem_init_poller_ctx, ctx, 0);
1564 : : }
1565 : 0 : }
1566 : 2394 : SPDK_RPC_REGISTER("framework_wait_init", rpc_framework_wait_init,
1567 : : SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
1568 : :
1569 : : static void
1570 : 21 : rpc_framework_disable_cpumask_locks(struct spdk_jsonrpc_request *request,
1571 : : const struct spdk_json_val *params)
1572 : : {
1573 : 10 : char msg[128];
1574 : : int rc;
1575 : 10 : uint32_t failed_core;
1576 : :
1577 [ - + ]: 21 : if (params != NULL) {
1578 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
1579 : : "framework_disable_cpumask_locks"
1580 : : "requires no arguments");
1581 : 0 : return;
1582 : : }
1583 : :
1584 : 21 : rc = unclaim_cpu_cores(&failed_core);
1585 [ + + ]: 21 : if (rc) {
1586 [ # # ]: 0 : snprintf(msg, sizeof(msg), "Failed to unclaim CPU core: %" PRIu32, failed_core);
1587 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, msg);
1588 : 0 : return;
1589 : : }
1590 : :
1591 : 21 : spdk_jsonrpc_send_bool_response(request, true);
1592 : 1 : }
1593 : 2394 : SPDK_RPC_REGISTER("framework_disable_cpumask_locks", rpc_framework_disable_cpumask_locks,
1594 : : SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
1595 : :
1596 : : static void
1597 : 63 : rpc_framework_enable_cpumask_locks(struct spdk_jsonrpc_request *request,
1598 : : const struct spdk_json_val *params)
1599 : : {
1600 : 30 : char msg[128];
1601 : : int rc;
1602 : 30 : uint32_t failed_core;
1603 : :
1604 [ - + ]: 63 : if (params != NULL) {
1605 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
1606 : : "framework_enable_cpumask_locks"
1607 : : "requires no arguments");
1608 : 10 : return;
1609 : : }
1610 : :
1611 : 63 : rc = claim_cpu_cores(&failed_core);
1612 [ + + ]: 63 : if (rc) {
1613 [ - + ]: 21 : snprintf(msg, sizeof(msg), "Failed to claim CPU core: %" PRIu32, failed_core);
1614 : 21 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, msg);
1615 : 21 : return;
1616 : : }
1617 : :
1618 : 42 : spdk_jsonrpc_send_bool_response(request, true);
1619 : 3 : }
1620 : 2394 : SPDK_RPC_REGISTER("framework_enable_cpumask_locks", rpc_framework_enable_cpumask_locks,
1621 : : SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)
|