4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Event framework public API.
38 * See @ref event_components for an overview of the SPDK event framework API.
49 #include "spdk/queue.h"
51 typedef void (*spdk_event_fn
)(void *arg1
, void *arg2
);
54 * \brief An event is a function that is passed to and called on an lcore.
58 typedef void (*spdk_poller_fn
)(void *arg
);
61 * \brief A poller is a function that is repeatedly called on an lcore.
65 typedef void (*spdk_app_shutdown_cb
)(void);
66 typedef void (*spdk_sighandler_t
)(int);
69 * \brief Event framework initialization options
71 struct spdk_app_opts
{
73 const char *config_file
;
74 const char *reactor_mask
;
75 const char *log_facility
;
76 const char *tpoint_group_mask
;
80 spdk_app_shutdown_cb shutdown_cb
;
81 spdk_sighandler_t usr1_handler
;
88 /* The maximum latency allowed when passing an event
89 * from one core to another. A value of 0
90 * means all cores continually poll. This is
91 * specified in microseconds.
93 uint64_t max_delay_us
;
97 * \brief Initialize the default value of opts
99 void spdk_app_opts_init(struct spdk_app_opts
*opts
);
102 * \brief Initialize an application to use the event framework. This must be called prior to using
103 * any other functions in this library.
105 void spdk_app_init(struct spdk_app_opts
*opts
);
108 * \brief Perform final shutdown operations on an application using the event framework.
110 int spdk_app_fini(void);
113 * \brief Start the framework. Once started, the framework will call start_fn on the master
114 * core with the arguments provided. This call will block until \ref spdk_app_stop is called.
116 int spdk_app_start(spdk_event_fn start_fn
, void *arg1
, void *arg2
);
119 * \brief Start shutting down the framework. Typically this function is not called directly, and
120 * the shutdown process is started implicitly by a process signal. But in applications that are
121 * using SPDK for a subset of its process threads, this function can be called in lieu of a signal.
123 void spdk_app_start_shutdown(void);
126 * \brief Stop the framework. This does not wait for all threads to exit. Instead, it kicks off
127 * the shutdown process and returns. Once the shutdown process is complete, \ref spdk_app_start will return.
129 void spdk_app_stop(int rc
);
132 * \brief Generate a configuration file that corresponds to the current running state.
134 int spdk_app_get_running_config(char **config_str
, char *name
);
137 * \brief Return the shared memory id for this application.
139 int spdk_app_get_shm_id(void);
142 * \brief Convert a string containing a CPU core mask into a bitmask
144 int spdk_app_parse_core_mask(const char *mask
, uint64_t *cpumask
);
147 * \brief Return a mask of the CPU cores active for this application
149 uint64_t spdk_app_get_core_mask(void);
152 * \brief Return the number of CPU cores utilized by this application
154 int spdk_app_get_core_count(void) __attribute__((deprecated
));
157 * \brief Return the lcore of the current thread.
159 uint32_t spdk_app_get_current_core(void) __attribute__((deprecated
));
162 * \brief Allocate an event to be passed to \ref spdk_event_call
164 struct spdk_event
*spdk_event_allocate(uint32_t lcore
, spdk_event_fn fn
,
165 void *arg1
, void *arg2
);
168 * \brief Pass the given event to the associated lcore and call the function.
170 void spdk_event_call(struct spdk_event
*event
);
173 * \brief Register a poller on the given lcore.
175 void spdk_poller_register(struct spdk_poller
**ppoller
,
179 uint64_t period_microseconds
);
182 * \brief Unregister a poller on the given lcore.
184 void spdk_poller_unregister(struct spdk_poller
**ppoller
,
185 struct spdk_event
*complete
);