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-05-02 11:18:25 -07:00
|
|
|
#include "spdk/stdinc.h"
|
2018-02-22 18:50:51 -05:00
|
|
|
#include "spdk/likely.h"
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-05-02 11:18:25 -07:00
|
|
|
#include "spdk_internal/event.h"
|
2017-08-17 09:59:06 +08:00
|
|
|
#include "spdk_internal/log.h"
|
2018-09-17 16:18:53 -07:00
|
|
|
#include "spdk_internal/thread.h"
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
#include "spdk/log.h"
|
2018-06-11 13:32:15 -07:00
|
|
|
#include "spdk/thread.h"
|
2016-08-18 12:52:48 -07:00
|
|
|
#include "spdk/env.h"
|
2018-04-25 08:58:50 +02:00
|
|
|
#include "spdk/util.h"
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2016-11-02 13:31:33 -07:00
|
|
|
#define SPDK_EVENT_BATCH_SIZE 8
|
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
enum spdk_reactor_state {
|
|
|
|
SPDK_REACTOR_STATE_INVALID = 0,
|
|
|
|
SPDK_REACTOR_STATE_INITIALIZED = 1,
|
|
|
|
SPDK_REACTOR_STATE_RUNNING = 2,
|
|
|
|
SPDK_REACTOR_STATE_EXITING = 3,
|
|
|
|
SPDK_REACTOR_STATE_SHUTDOWN = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct spdk_reactor {
|
|
|
|
/* Logical core number for this reactor. */
|
2016-07-26 12:56:07 -07:00
|
|
|
uint32_t lcore;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-08-17 09:59:06 +08:00
|
|
|
/* Poller for get the rusage for the reactor. */
|
|
|
|
struct spdk_poller *rusage_poller;
|
2017-01-20 10:41:21 -07:00
|
|
|
|
2017-08-17 09:59:06 +08:00
|
|
|
/* The last known rusage values */
|
2018-03-02 12:49:36 -07:00
|
|
|
struct rusage rusage;
|
2017-08-30 20:51:19 -07:00
|
|
|
|
2017-05-09 10:48:16 -07:00
|
|
|
struct spdk_ring *events;
|
2017-01-05 14:23:20 -07:00
|
|
|
} __attribute__((aligned(64)));
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-12-25 08:57:50 +09:00
|
|
|
static struct spdk_reactor *g_reactors;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
static enum spdk_reactor_state g_reactor_state = SPDK_REACTOR_STATE_INVALID;
|
|
|
|
|
2017-08-30 20:51:19 -07:00
|
|
|
static bool g_context_switch_monitor_enabled = true;
|
|
|
|
|
2019-02-13 09:56:13 -07:00
|
|
|
static void spdk_reactor_construct(struct spdk_reactor *w, uint32_t lcore);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2018-11-15 09:51:02 -07:00
|
|
|
static struct spdk_mempool *g_spdk_event_mempool = NULL;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-12-21 17:48:31 +01:00
|
|
|
static struct spdk_cpuset *g_spdk_app_core_mask;
|
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
static struct spdk_reactor *
|
|
|
|
spdk_reactor_get(uint32_t lcore)
|
|
|
|
{
|
|
|
|
struct spdk_reactor *reactor;
|
2018-02-22 18:50:51 -05:00
|
|
|
reactor = spdk_likely(g_reactors) ? &g_reactors[lcore] : NULL;
|
2016-05-24 11:04:20 -07:00
|
|
|
return reactor;
|
|
|
|
}
|
|
|
|
|
2017-01-04 18:24:18 -07:00
|
|
|
struct spdk_event *
|
2017-01-04 18:40:14 -07:00
|
|
|
spdk_event_allocate(uint32_t lcore, spdk_event_fn fn, void *arg1, void *arg2)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
|
|
|
struct spdk_event *event = NULL;
|
2017-01-20 11:09:43 -07:00
|
|
|
struct spdk_reactor *reactor = spdk_reactor_get(lcore);
|
2016-11-02 13:31:33 -07:00
|
|
|
|
2018-04-18 15:44:53 -07:00
|
|
|
if (!reactor) {
|
|
|
|
assert(false);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:51:02 -07:00
|
|
|
event = spdk_mempool_get(g_spdk_event_mempool);
|
2016-09-30 14:14:18 -07:00
|
|
|
if (event == NULL) {
|
2016-08-18 09:45:50 -07:00
|
|
|
assert(false);
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
event->lcore = lcore;
|
|
|
|
event->fn = fn;
|
|
|
|
event->arg1 = arg1;
|
|
|
|
event->arg2 = arg2;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-04 18:24:18 -07:00
|
|
|
spdk_event_call(struct spdk_event *event)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct spdk_reactor *reactor;
|
|
|
|
|
|
|
|
reactor = spdk_reactor_get(event->lcore);
|
|
|
|
|
2016-08-18 09:45:50 -07:00
|
|
|
assert(reactor->events != NULL);
|
2017-05-09 10:48:16 -07:00
|
|
|
rc = spdk_ring_enqueue(reactor->events, (void **)&event, 1);
|
|
|
|
if (rc != 1) {
|
2016-08-18 09:45:50 -07:00
|
|
|
assert(false);
|
|
|
|
}
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2017-01-20 10:41:21 -07:00
|
|
|
static inline uint32_t
|
2018-09-17 16:18:53 -07:00
|
|
|
_spdk_event_queue_run_batch(struct spdk_reactor *reactor, struct spdk_thread *thread)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
2016-11-02 13:31:33 -07:00
|
|
|
unsigned count, i;
|
|
|
|
void *events[SPDK_EVENT_BATCH_SIZE];
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-01-20 10:41:21 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
2017-05-09 10:48:16 -07:00
|
|
|
* spdk_ring_dequeue() fills events and returns how many entries it wrote,
|
2017-01-20 10:41:21 -07:00
|
|
|
* so we will never actually read uninitialized data from events, but just to be sure
|
|
|
|
* (and to silence a static analyzer false positive), initialize the array to NULL pointers.
|
|
|
|
*/
|
|
|
|
memset(events, 0, sizeof(events));
|
|
|
|
#endif
|
2017-05-09 10:48:16 -07:00
|
|
|
|
|
|
|
count = spdk_ring_dequeue(reactor->events, events, SPDK_EVENT_BATCH_SIZE);
|
2016-11-02 13:31:33 -07:00
|
|
|
if (count == 0) {
|
|
|
|
return 0;
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 16:18:53 -07:00
|
|
|
spdk_set_thread(thread);
|
|
|
|
|
2016-11-02 13:31:33 -07:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
struct spdk_event *event = events[i];
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-01-20 10:41:21 -07:00
|
|
|
assert(event != NULL);
|
2017-01-04 18:19:02 -07:00
|
|
|
event->fn(event->arg1, event->arg2);
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2018-09-17 16:18:53 -07:00
|
|
|
spdk_set_thread(NULL);
|
|
|
|
|
2018-11-15 09:51:02 -07:00
|
|
|
spdk_mempool_put_bulk(g_spdk_event_mempool, events, count);
|
2016-08-16 12:51:25 -07:00
|
|
|
|
|
|
|
return count;
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2018-03-12 17:16:47 -07:00
|
|
|
static int
|
2017-08-17 09:59:06 +08:00
|
|
|
get_rusage(void *arg)
|
|
|
|
{
|
|
|
|
struct spdk_reactor *reactor = arg;
|
|
|
|
struct rusage rusage;
|
|
|
|
|
|
|
|
if (getrusage(RUSAGE_THREAD, &rusage) != 0) {
|
2018-03-12 17:16:47 -07:00
|
|
|
return -1;
|
2017-08-17 09:59:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rusage.ru_nvcsw != reactor->rusage.ru_nvcsw || rusage.ru_nivcsw != reactor->rusage.ru_nivcsw) {
|
2017-08-30 11:06:33 -07:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_REACTOR,
|
2017-08-30 20:51:19 -07:00
|
|
|
"Reactor %d: %ld voluntary context switches and %ld involuntary context switches in the last second.\n",
|
|
|
|
reactor->lcore, rusage.ru_nvcsw - reactor->rusage.ru_nvcsw,
|
|
|
|
rusage.ru_nivcsw - reactor->rusage.ru_nivcsw);
|
2017-08-17 09:59:06 +08:00
|
|
|
}
|
|
|
|
reactor->rusage = rusage;
|
2018-03-12 17:16:47 -07:00
|
|
|
|
|
|
|
return -1;
|
2017-08-17 09:59:06 +08:00
|
|
|
}
|
2017-08-30 20:51:19 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_reactor_context_switch_monitor_start(void *arg1, void *arg2)
|
|
|
|
{
|
|
|
|
struct spdk_reactor *reactor = arg1;
|
|
|
|
|
|
|
|
if (reactor->rusage_poller == NULL) {
|
|
|
|
getrusage(RUSAGE_THREAD, &reactor->rusage);
|
2017-11-14 13:42:17 -07:00
|
|
|
reactor->rusage_poller = spdk_poller_register(get_rusage, reactor, 1000000);
|
2017-08-30 20:51:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_reactor_context_switch_monitor_stop(void *arg1, void *arg2)
|
|
|
|
{
|
|
|
|
struct spdk_reactor *reactor = arg1;
|
|
|
|
|
|
|
|
if (reactor->rusage_poller != NULL) {
|
2017-11-15 15:09:40 -07:00
|
|
|
spdk_poller_unregister(&reactor->rusage_poller);
|
2017-08-30 20:51:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_reactor_enable_context_switch_monitor(bool enable)
|
|
|
|
{
|
|
|
|
struct spdk_reactor *reactor;
|
|
|
|
spdk_event_fn fn;
|
|
|
|
uint32_t core;
|
|
|
|
|
|
|
|
if (enable != g_context_switch_monitor_enabled) {
|
|
|
|
g_context_switch_monitor_enabled = enable;
|
|
|
|
if (enable) {
|
|
|
|
fn = _spdk_reactor_context_switch_monitor_start;
|
|
|
|
} else {
|
|
|
|
fn = _spdk_reactor_context_switch_monitor_stop;
|
|
|
|
}
|
|
|
|
SPDK_ENV_FOREACH_CORE(core) {
|
|
|
|
reactor = spdk_reactor_get(core);
|
|
|
|
spdk_event_call(spdk_event_allocate(core, fn, reactor, NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
spdk_reactor_context_switch_monitor_enabled(void)
|
|
|
|
{
|
|
|
|
return g_context_switch_monitor_enabled;
|
|
|
|
}
|
2017-08-17 09:59:06 +08:00
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
static int
|
|
|
|
_spdk_reactor_run(void *arg)
|
|
|
|
{
|
|
|
|
struct spdk_reactor *reactor = arg;
|
2018-07-03 10:21:36 -07:00
|
|
|
struct spdk_thread *thread;
|
2017-08-22 13:06:57 -07:00
|
|
|
char thread_name[32];
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-08-22 13:06:57 -07:00
|
|
|
snprintf(thread_name, sizeof(thread_name), "reactor_%u", reactor->lcore);
|
2019-01-15 13:51:09 -07:00
|
|
|
thread = spdk_thread_create(thread_name);
|
2018-07-03 10:21:36 -07:00
|
|
|
if (!thread) {
|
2017-10-03 06:23:56 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2018-11-15 09:51:02 -07:00
|
|
|
SPDK_NOTICELOG("Reactor started on core %u\n", reactor->lcore);
|
2016-08-16 12:51:25 -07:00
|
|
|
|
2017-08-30 20:51:19 -07:00
|
|
|
if (g_context_switch_monitor_enabled) {
|
2018-09-17 16:18:53 -07:00
|
|
|
spdk_set_thread(thread);
|
2017-08-30 20:51:19 -07:00
|
|
|
_spdk_reactor_context_switch_monitor_start(reactor, NULL);
|
2018-09-17 16:18:53 -07:00
|
|
|
spdk_set_thread(NULL);
|
2017-08-30 20:51:19 -07:00
|
|
|
}
|
2018-05-28 16:14:36 -07:00
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
while (1) {
|
2019-01-30 15:30:48 -07:00
|
|
|
_spdk_event_queue_run_batch(reactor, thread);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2019-02-13 09:56:13 -07:00
|
|
|
spdk_thread_poll(thread, 0, 0);
|
2016-08-16 12:51:25 -07:00
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
if (g_reactor_state != SPDK_REACTOR_STATE_RUNNING) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 16:18:53 -07:00
|
|
|
spdk_set_thread(thread);
|
2017-08-30 20:51:19 -07:00
|
|
|
_spdk_reactor_context_switch_monitor_stop(reactor, NULL);
|
2019-01-15 13:54:51 -07:00
|
|
|
spdk_thread_exit(thread);
|
2016-05-24 11:04:20 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-13 09:56:13 -07:00
|
|
|
spdk_reactor_construct(struct spdk_reactor *reactor, uint32_t lcore)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
|
|
|
reactor->lcore = lcore;
|
|
|
|
|
2018-11-15 09:51:02 -07:00
|
|
|
reactor->events = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY);
|
2016-08-18 09:45:50 -07:00
|
|
|
assert(reactor->events != NULL);
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-12-21 17:48:31 +01:00
|
|
|
spdk_app_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
2017-12-21 17:48:31 +01:00
|
|
|
int ret;
|
|
|
|
struct spdk_cpuset *validmask;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-12-21 17:48:31 +01:00
|
|
|
ret = spdk_cpuset_parse(cpumask, mask);
|
|
|
|
if (ret < 0) {
|
|
|
|
return ret;
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:48:31 +01:00
|
|
|
validmask = spdk_app_get_core_mask();
|
|
|
|
spdk_cpuset_and(cpumask, validmask);
|
2017-06-02 11:00:35 -07:00
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-21 17:48:31 +01:00
|
|
|
struct spdk_cpuset *
|
2017-04-03 15:59:41 -07:00
|
|
|
spdk_app_get_core_mask(void)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
2017-12-21 17:48:31 +01:00
|
|
|
return g_spdk_app_core_mask;
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-06-06 14:23:42 +08:00
|
|
|
spdk_reactors_start(void)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
|
|
|
struct spdk_reactor *reactor;
|
2017-04-03 15:02:49 -07:00
|
|
|
uint32_t i, current_core;
|
2017-06-02 11:40:40 -07:00
|
|
|
int rc;
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
g_reactor_state = SPDK_REACTOR_STATE_RUNNING;
|
2017-12-21 17:48:31 +01:00
|
|
|
g_spdk_app_core_mask = spdk_cpuset_alloc();
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-04-03 15:02:49 -07:00
|
|
|
current_core = spdk_env_get_current_core();
|
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
|
|
|
if (i != current_core) {
|
|
|
|
reactor = spdk_reactor_get(i);
|
2017-06-02 11:40:40 -07:00
|
|
|
rc = spdk_env_thread_launch_pinned(reactor->lcore, _spdk_reactor_run, reactor);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to start reactor thread on core %u\n", reactor->lcore);
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
}
|
2017-04-03 15:02:49 -07:00
|
|
|
}
|
2017-12-21 17:48:31 +01:00
|
|
|
spdk_cpuset_set_cpu(g_spdk_app_core_mask, i, true);
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Start the master reactor */
|
2017-04-03 15:02:49 -07:00
|
|
|
reactor = spdk_reactor_get(current_core);
|
2017-06-02 11:40:40 -07:00
|
|
|
_spdk_reactor_run(reactor);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2017-06-02 11:40:40 -07:00
|
|
|
spdk_env_thread_wait_all();
|
2016-05-24 11:04:20 -07:00
|
|
|
|
|
|
|
g_reactor_state = SPDK_REACTOR_STATE_SHUTDOWN;
|
2017-12-21 17:48:31 +01:00
|
|
|
spdk_cpuset_free(g_spdk_app_core_mask);
|
|
|
|
g_spdk_app_core_mask = NULL;
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2017-10-25 15:58:02 +02:00
|
|
|
void
|
|
|
|
spdk_reactors_stop(void *arg1, void *arg2)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
|
|
|
g_reactor_state = SPDK_REACTOR_STATE_EXITING;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2019-02-13 09:56:13 -07:00
|
|
|
spdk_reactors_init(void)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
2017-12-25 08:57:50 +09:00
|
|
|
int rc;
|
2018-11-15 09:51:02 -07:00
|
|
|
uint32_t i, last_core;
|
2016-05-24 11:04:20 -07:00
|
|
|
struct spdk_reactor *reactor;
|
2016-06-27 23:24:36 -04:00
|
|
|
char mempool_name[32];
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2018-11-15 09:51:02 -07:00
|
|
|
snprintf(mempool_name, sizeof(mempool_name), "evtpool_%d", getpid());
|
|
|
|
g_spdk_event_mempool = spdk_mempool_create(mempool_name,
|
|
|
|
262144 - 1, /* Power of 2 minus 1 is optimal for memory consumption */
|
|
|
|
sizeof(struct spdk_event),
|
|
|
|
SPDK_MEMPOOL_DEFAULT_CACHE_SIZE,
|
|
|
|
SPDK_ENV_SOCKET_ID_ANY);
|
2016-05-24 11:04:20 -07:00
|
|
|
|
2018-11-15 09:51:02 -07:00
|
|
|
if (g_spdk_event_mempool == NULL) {
|
|
|
|
SPDK_ERRLOG("spdk_event_mempool creation failed\n");
|
2017-03-23 15:52:18 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2016-06-27 23:24:36 -04:00
|
|
|
|
2017-12-25 08:57:50 +09:00
|
|
|
/* struct spdk_reactor must be aligned on 64 byte boundary */
|
|
|
|
last_core = spdk_env_get_last_core();
|
|
|
|
rc = posix_memalign((void **)&g_reactors, 64,
|
|
|
|
(last_core + 1) * sizeof(struct spdk_reactor));
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Could not allocate array size=%u for g_reactors\n",
|
|
|
|
last_core + 1);
|
2018-11-15 09:51:02 -07:00
|
|
|
spdk_mempool_free(g_spdk_event_mempool);
|
2017-12-25 08:57:50 +09:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(g_reactors, 0, (last_core + 1) * sizeof(struct spdk_reactor));
|
|
|
|
|
2019-01-15 13:57:14 -07:00
|
|
|
spdk_thread_lib_init(NULL);
|
|
|
|
|
2017-04-03 15:02:49 -07:00
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
2017-04-03 15:59:41 -07:00
|
|
|
reactor = spdk_reactor_get(i);
|
2019-02-13 09:56:13 -07:00
|
|
|
spdk_reactor_construct(reactor, i);
|
2017-01-20 10:41:21 -07:00
|
|
|
}
|
|
|
|
|
2016-05-24 11:04:20 -07:00
|
|
|
g_reactor_state = SPDK_REACTOR_STATE_INITIALIZED;
|
|
|
|
|
2017-04-03 15:59:41 -07:00
|
|
|
return 0;
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2017-10-05 16:15:17 +02:00
|
|
|
void
|
2016-06-06 14:23:42 +08:00
|
|
|
spdk_reactors_fini(void)
|
2016-05-24 11:04:20 -07:00
|
|
|
{
|
2017-02-24 16:27:42 -07:00
|
|
|
uint32_t i;
|
|
|
|
struct spdk_reactor *reactor;
|
|
|
|
|
2019-01-15 13:57:14 -07:00
|
|
|
spdk_thread_lib_fini();
|
|
|
|
|
2017-04-03 15:02:49 -07:00
|
|
|
SPDK_ENV_FOREACH_CORE(i) {
|
2017-04-03 15:59:41 -07:00
|
|
|
reactor = spdk_reactor_get(i);
|
2018-02-22 18:50:51 -05:00
|
|
|
if (spdk_likely(reactor != NULL) && reactor->events != NULL) {
|
2017-05-09 10:48:16 -07:00
|
|
|
spdk_ring_free(reactor->events);
|
2017-02-24 16:27:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:51:02 -07:00
|
|
|
spdk_mempool_free(g_spdk_event_mempool);
|
2017-12-25 08:57:50 +09:00
|
|
|
|
|
|
|
free(g_reactors);
|
2018-02-22 18:50:51 -05:00
|
|
|
g_reactors = NULL;
|
2016-05-24 11:04:20 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 11:06:33 -07:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT("reactor", SPDK_LOG_REACTOR)
|