2016-05-24 18:04:20 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
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"
|
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"
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal handler fucntion.
|
|
|
|
*
|
|
|
|
* \param signal Signal number.
|
|
|
|
*/
|
|
|
|
typedef void (*spdk_sighandler_t)(int signal);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2017-11-09 23:33:29 +00:00
|
|
|
#define SPDK_DEFAULT_RPC_ADDR "/var/tmp/spdk.sock"
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
/**
|
|
|
|
* \brief Event framework initialization options
|
|
|
|
*/
|
|
|
|
struct spdk_app_opts {
|
|
|
|
const char *name;
|
|
|
|
const char *config_file;
|
2018-08-14 16:53:07 +00:00
|
|
|
const char *json_config_file;
|
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
|
|
|
|
|
|
|
spdk_app_shutdown_cb shutdown_cb;
|
|
|
|
spdk_sighandler_t usr1_handler;
|
|
|
|
|
|
|
|
bool enable_coredump;
|
2017-06-16 08:41:13 +00:00
|
|
|
int mem_channel;
|
2018-03-02 19:49:36 +00:00
|
|
|
int master_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;
|
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;
|
2018-03-30 17:39:37 +00:00
|
|
|
size_t num_pci_addr;
|
|
|
|
struct spdk_pci_addr *pci_blacklist;
|
|
|
|
struct spdk_pci_addr *pci_whitelist;
|
2016-08-16 19:51:25 +00:00
|
|
|
|
2019-02-13 16:56:13 +00:00
|
|
|
/* DEPRECATED. No longer has any effect.
|
|
|
|
*
|
|
|
|
* The maximum latency allowed when passing an event
|
2016-08-16 19:51:25 +00:00
|
|
|
* from one core to another. A value of 0
|
|
|
|
* means all cores continually poll. This is
|
|
|
|
* specified in microseconds.
|
|
|
|
*/
|
|
|
|
uint64_t max_delay_us;
|
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
|
|
|
|
|
|
|
/* 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;
|
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.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2016-05-24 18:04:20 +00:00
|
|
|
void spdk_app_opts_init(struct spdk_app_opts *opts);
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
* argument provided. This call will block until spdk_app_stop()
|
|
|
|
* is called. If an error condition occurs during the intialization
|
|
|
|
* code within spdk_app_start(), this function will immediately return
|
|
|
|
* before invoking start_fn.
|
2017-12-25 06:28:38 +00:00
|
|
|
*
|
|
|
|
* \param opts Initialization options used for this application.
|
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
|
|
|
*/
|
2019-03-04 20:52:59 +00:00
|
|
|
int spdk_app_start(struct spdk_app_opts *opts, spdk_msg_fn start_fn,
|
|
|
|
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
|
|
|
* Generate a configuration file that corresponds to the current running state.
|
|
|
|
*
|
|
|
|
* \param config_str Values obtained from the generated configuration file.
|
|
|
|
* \param name Prefix for name of temporary configuration file to save the current config.
|
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2016-05-24 18:04:20 +00:00
|
|
|
int spdk_app_get_running_config(char **config_str, char *name);
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2017-12-21 16:48:31 +00:00
|
|
|
struct spdk_cpuset *spdk_app_get_core_mask(void);
|
2016-05-24 18:04:20 +00:00
|
|
|
|
2018-08-20 21:57:50 +00:00
|
|
|
#define SPDK_APP_GETOPT_STRING "c:de:ghi:m:n:p:r:s:uB: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,
|
2019-01-08 19:40:06 +00:00
|
|
|
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
|
|
|
*/
|
|
|
|
void spdk_reactor_enable_context_switch_monitor(bool enabled);
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
|
|
|
bool spdk_reactor_context_switch_monitor_enabled(void);
|
|
|
|
|
2017-12-07 20:25:19 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-24 18:04:20 +00:00
|
|
|
#endif
|