2016-05-24 11:04:20 -07: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 16:10:25 -07:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Event framework public API.
|
|
|
|
*
|
|
|
|
* See @ref event_components for an overview of the SPDK event framework API.
|
|
|
|
*/
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
#ifndef SPDK_EVENT_H
|
|
|
|
#define SPDK_EVENT_H
|
|
|
|
|
2017-05-01 13:22:48 -07:00
|
|
|
#include "spdk/stdinc.h"
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
#include "spdk/queue.h"
|
2017-11-03 16:16:34 -07:00
|
|
|
#include "spdk/log.h"
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-01-04 18:19:02 -07:00
|
|
|
typedef void (*spdk_event_fn)(void *arg1, void *arg2);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief An event is a function that is passed to and called on an lcore.
|
|
|
|
*/
|
2017-01-04 18:21:29 -07:00
|
|
|
struct spdk_event;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief A poller is a function that is repeatedly called on an lcore.
|
|
|
|
*/
|
2016-08-11 16:00:45 -07:00
|
|
|
struct spdk_poller;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
typedef void (*spdk_app_shutdown_cb)(void);
|
|
|
|
typedef void (*spdk_sighandler_t)(int);
|
|
|
|
|
2017-11-09 16:33:29 -07:00
|
|
|
#define SPDK_DEFAULT_RPC_ADDR "/var/tmp/spdk.sock"
|
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
/**
|
|
|
|
* \brief Event framework initialization options
|
|
|
|
*/
|
|
|
|
struct spdk_app_opts {
|
|
|
|
const char *name;
|
|
|
|
const char *config_file;
|
2017-11-09 16:33:29 -07:00
|
|
|
const char *rpc_addr; /* Can be UNIX domain socket path or IP address + TCP port */
|
2016-05-24 11:04:20 -07:00
|
|
|
const char *reactor_mask;
|
|
|
|
const char *tpoint_group_mask;
|
|
|
|
|
2017-02-01 14:34:45 -07:00
|
|
|
int shm_id;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
spdk_app_shutdown_cb shutdown_cb;
|
|
|
|
spdk_sighandler_t usr1_handler;
|
|
|
|
|
|
|
|
bool enable_coredump;
|
2017-06-16 16:41:13 +08:00
|
|
|
int mem_channel;
|
|
|
|
int master_core;
|
|
|
|
int mem_size;
|
2017-06-14 15:31:55 +08:00
|
|
|
bool no_pci;
|
2017-11-03 16:16:34 -07:00
|
|
|
enum spdk_log_level print_level;
|
2016-08-16 12:51:25 -07:00
|
|
|
|
|
|
|
/* The maximum latency allowed when passing an event
|
|
|
|
* from one core to another. A value of 0
|
|
|
|
* means all cores continually poll. This is
|
|
|
|
* specified in microseconds.
|
|
|
|
*/
|
|
|
|
uint64_t max_delay_us;
|
2016-05-24 11:04:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Initialize the default value of opts
|
2017-04-25 10:35:22 -07:00
|
|
|
*/
|
2016-05-24 11:04:20 -07:00
|
|
|
void spdk_app_opts_init(struct spdk_app_opts *opts);
|
|
|
|
|
|
|
|
/**
|
2017-06-06 14:31:47 +08:00
|
|
|
* \brief Start the framework. Once started, the framework will call start_fn on the master
|
|
|
|
* core with the arguments provided. This call will block until \ref spdk_app_stop is called.
|
2017-04-25 10:35:22 -07:00
|
|
|
*/
|
2017-06-06 14:31:47 +08:00
|
|
|
int spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn,
|
|
|
|
void *arg1, void *arg2);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Perform final shutdown operations on an application using the event framework.
|
2017-04-25 10:35:22 -07:00
|
|
|
*/
|
2017-10-05 16:15:17 +02:00
|
|
|
void spdk_app_fini(void);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2016-11-03 14:26:45 -07:00
|
|
|
/**
|
|
|
|
* \brief 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.
|
|
|
|
*/
|
|
|
|
void spdk_app_start_shutdown(void);
|
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
/**
|
|
|
|
* \brief 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, \ref spdk_app_start will return.
|
2017-04-25 10:35:22 -07:00
|
|
|
*/
|
2016-05-24 11:04:20 -07:00
|
|
|
void spdk_app_stop(int rc);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Generate a configuration file that corresponds to the current running state.
|
2017-04-25 10:35:22 -07:00
|
|
|
*/
|
2016-05-24 11:04:20 -07:00
|
|
|
int spdk_app_get_running_config(char **config_str, char *name);
|
|
|
|
|
|
|
|
/**
|
2017-02-01 14:34:45 -07:00
|
|
|
* \brief Return the shared memory id for this application.
|
2017-04-25 10:35:22 -07:00
|
|
|
*/
|
2017-02-01 14:34:45 -07:00
|
|
|
int spdk_app_get_shm_id(void);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Convert a string containing a CPU core mask into a bitmask
|
|
|
|
*/
|
|
|
|
int spdk_app_parse_core_mask(const char *mask, uint64_t *cpumask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Return a mask of the CPU cores active for this application
|
|
|
|
*/
|
|
|
|
uint64_t spdk_app_get_core_mask(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Return the number of CPU cores utilized by this application
|
|
|
|
*/
|
2017-03-27 12:59:40 -07:00
|
|
|
int spdk_app_get_core_count(void) __attribute__((deprecated));
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2016-08-04 10:18:25 -07:00
|
|
|
/**
|
|
|
|
* \brief Return the lcore of the current thread.
|
|
|
|
*/
|
2017-03-27 12:59:40 -07:00
|
|
|
uint32_t spdk_app_get_current_core(void) __attribute__((deprecated));
|
2016-08-04 10:18:25 -07:00
|
|
|
|
2017-11-09 16:33:29 -07:00
|
|
|
#define SPDK_APP_GETOPT_STRING "c:de:hi:m:n:p:qr:s:t:"
|
2017-11-09 13:20:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Helper function for parsing arguments and printing usage messages.
|
|
|
|
*
|
|
|
|
* \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.
|
|
|
|
* Characters in this string must not conflict with characters in
|
|
|
|
* SPDK_APP_GETOPT_STRING.
|
|
|
|
* \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
|
|
|
|
* line parameters.
|
|
|
|
*/
|
|
|
|
int spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts,
|
|
|
|
const char *getopt_str, void (*parse)(int ch, char *arg),
|
|
|
|
void (*usage)(void));
|
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
/**
|
|
|
|
* \brief Allocate an event to be passed to \ref spdk_event_call
|
|
|
|
*/
|
2017-01-04 18:24:18 -07:00
|
|
|
struct spdk_event *spdk_event_allocate(uint32_t lcore, spdk_event_fn fn,
|
2017-01-04 18:40:14 -07:00
|
|
|
void *arg1, void *arg2);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Pass the given event to the associated lcore and call the function.
|
|
|
|
*/
|
2017-01-04 18:24:18 -07:00
|
|
|
void spdk_event_call(struct spdk_event *event);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-08-30 20:51:19 -07:00
|
|
|
/**
|
|
|
|
* \brief Enable or disable monitoring of context switches.
|
|
|
|
*/
|
|
|
|
void spdk_reactor_enable_context_switch_monitor(bool enabled);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Return whether context switch monitoring is enabled.
|
|
|
|
*/
|
|
|
|
bool spdk_reactor_context_switch_monitor_enabled(void);
|
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
#endif
|