2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2016 Intel Corporation. All rights reserved.
|
2019-11-12 17:12:00 +00:00
|
|
|
* Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
|
2016-05-24 18:04:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-01-26 23:10:25 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Event framework public API.
|
|
|
|
*
|
|
|
|
* See @ref event_components for an overview of the SPDK event framework API.
|
|
|
|
*/
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
#ifndef SPDK_EVENT_H
|
|
|
|
#define SPDK_EVENT_H
|
|
|
|
|
2017-05-01 20:22:48 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-12-21 16:48:31 +00:00
|
|
|
#include "spdk/cpuset.h"
|
2021-03-02 19:22:03 +00:00
|
|
|
#include "spdk/init.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
#include "spdk/queue.h"
|
2017-11-03 23:16:34 +00:00
|
|
|
#include "spdk/log.h"
|
2019-03-04 20:52:59 +00:00
|
|
|
#include "spdk/thread.h"
|
2022-08-17 20:09:55 +00:00
|
|
|
#include "spdk/assert.h"
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-12-07 20:25:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-04-16 07:24:13 +00:00
|
|
|
/**
|
|
|
|
* Event handler function.
|
|
|
|
*
|
|
|
|
* \param arg1 Argument 1.
|
|
|
|
* \param arg2 Argument 2.
|
|
|
|
*/
|
2017-01-05 01:19:02 +00:00
|
|
|
typedef void (*spdk_event_fn)(void *arg1, void *arg2);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief An event is a function that is passed to and called on an lcore.
|
|
|
|
*/
|
2017-01-05 01:21:29 +00:00
|
|
|
struct spdk_event;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief A poller is a function that is repeatedly called on an lcore.
|
|
|
|
*/
|
2016-08-11 23:00:45 +00:00
|
|
|
struct spdk_poller;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-04-16 07:24:13 +00:00
|
|
|
/**
|
|
|
|
* Callback function for customized shutdown handling of application.
|
|
|
|
*/
|
2016-05-24 18:04:20 +00:00
|
|
|
typedef void (*spdk_app_shutdown_cb)(void);
|
2018-04-16 07:24:13 +00:00
|
|
|
|
|
|
|
/**
|
2021-11-25 01:40:58 +00:00
|
|
|
* Signal handler function.
|
2018-04-16 07:24:13 +00:00
|
|
|
*
|
|
|
|
* \param signal Signal number.
|
|
|
|
*/
|
|
|
|
typedef void (*spdk_sighandler_t)(int signal);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Event framework initialization options
|
|
|
|
*/
|
|
|
|
struct spdk_app_opts {
|
|
|
|
const char *name;
|
2018-08-14 16:53:07 +00:00
|
|
|
const char *json_config_file;
|
2020-02-06 12:38:46 +00:00
|
|
|
bool json_config_ignore_errors;
|
2022-08-17 22:09:09 +00:00
|
|
|
|
|
|
|
/* Hole at bytes 17-23. */
|
|
|
|
uint8_t reserved17[7];
|
|
|
|
|
2017-11-09 23:33:29 +00:00
|
|
|
const char *rpc_addr; /* Can be UNIX domain socket path or IP address + TCP port */
|
2016-05-24 18:04:20 +00:00
|
|
|
const char *reactor_mask;
|
|
|
|
const char *tpoint_group_mask;
|
|
|
|
|
2017-02-01 21:34:45 +00:00
|
|
|
int shm_id;
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2022-08-17 22:09:09 +00:00
|
|
|
/* Hole at bytes 52-55. */
|
|
|
|
uint8_t reserved52[4];
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
spdk_app_shutdown_cb shutdown_cb;
|
|
|
|
|
|
|
|
bool enable_coredump;
|
2022-08-17 22:09:09 +00:00
|
|
|
|
|
|
|
/* Hole at bytes 65-67. */
|
|
|
|
uint8_t reserved65[3];
|
|
|
|
|
2017-06-16 08:41:13 +00:00
|
|
|
int mem_channel;
|
2021-02-26 12:44:39 +00:00
|
|
|
int main_core;
|
2017-06-16 08:41:13 +00:00
|
|
|
int mem_size;
|
2017-06-14 07:31:55 +00:00
|
|
|
bool no_pci;
|
2018-02-23 08:19:09 +00:00
|
|
|
bool hugepage_single_segments;
|
2018-07-12 07:58:59 +00:00
|
|
|
bool unlink_hugepage;
|
2022-08-17 22:09:09 +00:00
|
|
|
|
|
|
|
/* Hole at bytes 83-85. */
|
|
|
|
uint8_t reserved83[5];
|
|
|
|
|
2018-11-06 06:10:11 +00:00
|
|
|
const char *hugedir;
|
2017-11-03 23:16:34 +00:00
|
|
|
enum spdk_log_level print_level;
|
2022-08-17 22:09:09 +00:00
|
|
|
|
|
|
|
/* Hole at bytes 100-103. */
|
|
|
|
uint8_t reserved100[4];
|
|
|
|
|
2018-03-30 17:39:37 +00:00
|
|
|
size_t num_pci_addr;
|
2021-02-26 12:44:39 +00:00
|
|
|
struct spdk_pci_addr *pci_blocked;
|
|
|
|
struct spdk_pci_addr *pci_allowed;
|
2020-06-16 17:26:30 +00:00
|
|
|
const char *iova_mode;
|
2016-08-16 19:51:25 +00:00
|
|
|
|
2018-05-02 04:50:39 +00:00
|
|
|
/* Wait for the associated RPC before initializing subsystems
|
|
|
|
* when this flag is enabled.
|
|
|
|
*/
|
|
|
|
bool delay_subsystem_init;
|
2018-11-13 17:23:16 +00:00
|
|
|
|
2022-08-17 22:09:09 +00:00
|
|
|
/* Hole at bytes 137-143. */
|
|
|
|
uint8_t reserved137[7];
|
|
|
|
|
2018-11-13 17:23:16 +00:00
|
|
|
/* Number of trace entries allocated for each core */
|
|
|
|
uint64_t num_entries;
|
2019-02-05 11:51:53 +00:00
|
|
|
|
|
|
|
/** Opaque context for use of the env implementation. */
|
|
|
|
void *env_context;
|
2019-05-20 22:29:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* for passing user-provided log call
|
|
|
|
*/
|
2019-09-30 08:46:37 +00:00
|
|
|
logfunc *log;
|
2019-05-20 22:29:45 +00:00
|
|
|
|
2020-06-04 16:05:53 +00:00
|
|
|
uint64_t base_virtaddr;
|
2020-11-30 11:38:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The size of spdk_app_opts according to the caller of this library is used for ABI
|
|
|
|
* compatibility. The library uses this field to know how many fields in this
|
|
|
|
* structure are valid. And the library will populate any remaining fields with default values.
|
|
|
|
* After that, new added fields should be put after opts_size.
|
|
|
|
*/
|
|
|
|
size_t opts_size;
|
2021-09-02 17:11:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disable default signal handlers.
|
|
|
|
* If set to `true`, the shutdown process is not started implicitly by
|
|
|
|
* process signals, hence the application is responsible for calling
|
|
|
|
* spdk_app_start_shutdown().
|
|
|
|
*
|
|
|
|
* Default is `false`.
|
|
|
|
*/
|
|
|
|
bool disable_signal_handlers;
|
2022-02-13 18:32:26 +00:00
|
|
|
|
2022-08-17 22:09:09 +00:00
|
|
|
/* Hole at bytes 185-191. */
|
|
|
|
uint8_t reserved185[7];
|
|
|
|
|
2022-02-13 18:32:26 +00:00
|
|
|
/**
|
|
|
|
* The allocated size for the message pool used by the threading library.
|
|
|
|
*
|
|
|
|
* Default is `SPDK_DEFAULT_MSG_MEMPOOL_SIZE`.
|
|
|
|
*/
|
|
|
|
size_t msg_mempool_size;
|
2022-11-04 17:01:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If non-NULL, a string array of allowed RPC methods.
|
|
|
|
*/
|
|
|
|
const char **rpc_allowlist;
|
2022-09-08 09:29:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to pass vf_token to vfio_pci driver through DPDK.
|
|
|
|
* The vf_token is an UUID that shared between SR-IOV PF and VF.
|
|
|
|
*/
|
|
|
|
const char *vf_token;
|
2022-08-17 22:09:09 +00:00
|
|
|
} __attribute__((packed));
|
2022-09-08 09:29:15 +00:00
|
|
|
SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 216, "Incorrect size");
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Initialize the default value of opts
|
|
|
|
*
|
|
|
|
* \param opts Data structure where SPDK will initialize the default options.
|
2020-11-30 11:38:37 +00:00
|
|
|
* \param opts_size Must be set to sizeof(struct spdk_app_opts).
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2020-11-30 11:38:37 +00:00
|
|
|
void spdk_app_opts_init(struct spdk_app_opts *opts, size_t opts_size);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Start the framework.
|
|
|
|
*
|
2019-03-04 20:52:59 +00:00
|
|
|
* Before calling this function, opts must be initialized by
|
|
|
|
* spdk_app_opts_init(). Once started, the framework will call start_fn on
|
|
|
|
* an spdk_thread running on the current system thread with the
|
2020-01-30 13:21:50 +00:00
|
|
|
* argument provided.
|
|
|
|
*
|
|
|
|
* If opts->delay_subsystem_init is set
|
|
|
|
* (e.g. through --wait-for-rpc flag in spdk_app_parse_args())
|
|
|
|
* this function will only start a limited RPC server accepting
|
|
|
|
* only a few RPC commands - mostly related to pre-initialization.
|
|
|
|
* With this option, the framework won't be started and start_fn
|
|
|
|
* won't be called until the user sends an `rpc_framework_start_init`
|
|
|
|
* RPC command, which marks the pre-initialization complete and
|
|
|
|
* allows start_fn to be finally called.
|
|
|
|
*
|
|
|
|
* This call will block until spdk_app_stop() is called. If an error
|
2021-11-25 01:40:58 +00:00
|
|
|
* condition occurs during the initialization code within spdk_app_start(),
|
2020-01-30 13:21:50 +00:00
|
|
|
* this function will immediately return before invoking start_fn.
|
2017-12-25 06:28:38 +00:00
|
|
|
*
|
2020-11-30 11:38:37 +00:00
|
|
|
* \param opts_user Initialization options used for this application. It should not be
|
|
|
|
* NULL. And the opts_size value inside the opts structure should not be zero.
|
2019-03-04 20:52:59 +00:00
|
|
|
* \param start_fn Entry point that will execute on an internally created thread
|
|
|
|
* once the framework has been started.
|
|
|
|
* \param ctx Argument passed to function start_fn.
|
2017-12-25 06:28:38 +00:00
|
|
|
*
|
2018-02-22 23:50:51 +00:00
|
|
|
* \return 0 on success or non-zero on failure.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2020-11-30 11:38:37 +00:00
|
|
|
int spdk_app_start(struct spdk_app_opts *opts_user, spdk_msg_fn start_fn,
|
2019-03-04 20:52:59 +00:00
|
|
|
void *ctx);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Perform final shutdown operations on an application using the event framework.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2017-10-05 14:15:17 +00:00
|
|
|
void spdk_app_fini(void);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2016-11-03 21:26:45 +00:00
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Start shutting down the framework.
|
|
|
|
*
|
|
|
|
* Typically this function is not called directly, and the shutdown process is
|
|
|
|
* started implicitly by a process signal. But in applications that are using
|
|
|
|
* SPDK for a subset of its process threads, this function can be called in lieu
|
|
|
|
* of a signal.
|
2016-11-03 21:26:45 +00:00
|
|
|
*/
|
|
|
|
void spdk_app_start_shutdown(void);
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Stop the framework.
|
|
|
|
*
|
|
|
|
* This does not wait for all threads to exit. Instead, it kicks off the shutdown
|
|
|
|
* process and returns. Once the shutdown process is complete, spdk_app_start()
|
|
|
|
* will return.
|
|
|
|
*
|
2018-02-22 23:50:51 +00:00
|
|
|
* \param rc The rc value specified here will be returned to caller of spdk_app_start().
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2016-05-24 18:04:20 +00:00
|
|
|
void spdk_app_stop(int rc);
|
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Return the shared memory id for this application.
|
|
|
|
*
|
|
|
|
* \return shared memory id.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2017-02-01 21:34:45 +00:00
|
|
|
int spdk_app_get_shm_id(void);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Convert a string containing a CPU core mask into a bitmask
|
|
|
|
*
|
|
|
|
* \param mask String containing a CPU core mask.
|
|
|
|
* \param cpumask Bitmask of CPU cores.
|
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
2016-05-24 18:04:20 +00:00
|
|
|
*/
|
2017-12-21 16:48:31 +00:00
|
|
|
int spdk_app_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Get the mask of the CPU cores active for this application
|
|
|
|
*
|
|
|
|
* \return the bitmask of the active CPU cores.
|
2016-05-24 18:04:20 +00:00
|
|
|
*/
|
2020-09-18 01:22:49 +00:00
|
|
|
const struct spdk_cpuset *spdk_app_get_core_mask(void);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2020-12-18 13:05:37 +00:00
|
|
|
#define SPDK_APP_GETOPT_STRING "c:de:ghi:m:n:p:r:s:uvA:B:L:RW:"
|
2017-11-09 20:20:56 +00:00
|
|
|
|
2018-02-22 23:50:51 +00:00
|
|
|
enum spdk_app_parse_args_rvals {
|
|
|
|
SPDK_APP_PARSE_ARGS_HELP = 0,
|
|
|
|
SPDK_APP_PARSE_ARGS_SUCCESS = 1,
|
|
|
|
SPDK_APP_PARSE_ARGS_FAIL = 2
|
|
|
|
};
|
|
|
|
typedef enum spdk_app_parse_args_rvals spdk_app_parse_args_rvals_t;
|
|
|
|
|
2017-11-09 20:20:56 +00:00
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Helper function for parsing arguments and printing usage messages.
|
2017-11-09 20:20:56 +00:00
|
|
|
*
|
|
|
|
* \param argc Count of arguments in argv parameter array.
|
|
|
|
* \param argv Array of command line arguments.
|
|
|
|
* \param opts Default options for the application.
|
|
|
|
* \param getopt_str String representing the app-specific command line parameters.
|
2017-12-25 06:28:38 +00:00
|
|
|
* Characters in this string must not conflict with characters in SPDK_APP_GETOPT_STRING.
|
2018-07-31 13:26:44 +00:00
|
|
|
* \param app_long_opts Array of full-name parameters. Can be NULL.
|
2017-11-09 20:20:56 +00:00
|
|
|
* \param parse Function pointer to call if an argument in getopt_str is found.
|
|
|
|
* \param usage Function pointer to print usage messages for app-specific command
|
2018-02-22 23:50:51 +00:00
|
|
|
* line parameters.
|
|
|
|
*\return SPDK_APP_PARSE_ARGS_FAIL on failure, SPDK_APP_PARSE_ARGS_SUCCESS on
|
|
|
|
* success, SPDK_APP_PARSE_ARGS_HELP if '-h' passed as an option.
|
2017-11-09 20:20:56 +00:00
|
|
|
*/
|
2018-02-22 23:50:51 +00:00
|
|
|
spdk_app_parse_args_rvals_t spdk_app_parse_args(int argc, char **argv,
|
|
|
|
struct spdk_app_opts *opts, const char *getopt_str,
|
event: pass "const struct option*" to spdk_app_parse_args()
before this change, we cannot pass a `const struct option*` to
spdk_app_parse_args() even the callee does not mutate the value pointed
by the pointer. in other words, we are not able to write something like:
static const option g_options[] = {...};
// ...
spdk_app_parse_args(argc, argv, &opts, "",
g_options, app_parse_arg, app_usage);
after this change, the requirement of the type of the `option` argument
is relaxed, so we can pass a `const struct option*` to this function
now.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
Change-Id: I8794fcf92090f538743850a28ef4a2a8c357f121
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14082
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
2022-08-17 16:41:41 +00:00
|
|
|
const struct option *app_long_opts, int (*parse)(int ch, char *arg),
|
2018-07-31 13:26:44 +00:00
|
|
|
void (*usage)(void));
|
2017-11-09 20:20:56 +00:00
|
|
|
|
2018-06-07 14:16:43 +00:00
|
|
|
/**
|
|
|
|
* Print usage strings for common SPDK command line options.
|
|
|
|
*
|
|
|
|
* May only be called after spdk_app_parse_args().
|
|
|
|
*/
|
|
|
|
void spdk_app_usage(void);
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Allocate an event to be passed to spdk_event_call().
|
|
|
|
*
|
|
|
|
* \param lcore Lcore to run this event.
|
|
|
|
* \param fn Function used to execute event.
|
|
|
|
* \param arg1 Argument passed to function fn.
|
|
|
|
* \param arg2 Argument passed to function fn.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated event.
|
2016-05-24 18:04:20 +00:00
|
|
|
*/
|
2017-01-05 01:24:18 +00:00
|
|
|
struct spdk_event *spdk_event_allocate(uint32_t lcore, spdk_event_fn fn,
|
2017-01-05 01:40:14 +00:00
|
|
|
void *arg1, void *arg2);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Pass the given event to the associated lcore and call the function.
|
|
|
|
*
|
|
|
|
* \param event Event to execute.
|
2016-05-24 18:04:20 +00:00
|
|
|
*/
|
2017-01-05 01:24:18 +00:00
|
|
|
void spdk_event_call(struct spdk_event *event);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-08-31 03:51:19 +00:00
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Enable or disable monitoring of context switches.
|
|
|
|
*
|
|
|
|
* \param enabled True to enable, false to disable.
|
2017-08-31 03:51:19 +00:00
|
|
|
*/
|
2019-12-20 00:06:44 +00:00
|
|
|
void spdk_framework_enable_context_switch_monitor(bool enabled);
|
2017-08-31 03:51:19 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-25 06:28:38 +00:00
|
|
|
* Return whether context switch monitoring is enabled.
|
|
|
|
*
|
|
|
|
* \return true if enabled or false otherwise.
|
2017-08-31 03:51:19 +00:00
|
|
|
*/
|
2019-12-20 00:06:44 +00:00
|
|
|
bool spdk_framework_context_switch_monitor_enabled(void);
|
2017-08-31 03:51:19 +00:00
|
|
|
|
2017-12-07 20:25:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
#endif
|