event: Move spdk_reactors_init up in file
Begin organizing file so setup operations appear at the top. Change-Id: I7411b4bf20480c8aeb40bc21b521e5d359f8da1f Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/465991 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
This commit is contained in:
parent
9d14641dd5
commit
2139bfa91f
@ -88,6 +88,18 @@ static bool g_context_switch_monitor_enabled = true;
|
||||
|
||||
static struct spdk_mempool *g_spdk_event_mempool = NULL;
|
||||
|
||||
static void
|
||||
spdk_reactor_construct(struct spdk_reactor *reactor, uint32_t lcore)
|
||||
{
|
||||
reactor->lcore = lcore;
|
||||
reactor->is_valid = true;
|
||||
|
||||
TAILQ_INIT(&reactor->threads);
|
||||
|
||||
reactor->events = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY);
|
||||
assert(reactor->events != NULL);
|
||||
}
|
||||
|
||||
static struct spdk_reactor *
|
||||
spdk_reactor_get(uint32_t lcore)
|
||||
{
|
||||
@ -107,6 +119,51 @@ spdk_reactor_get(uint32_t lcore)
|
||||
return reactor;
|
||||
}
|
||||
|
||||
static int spdk_reactor_schedule_thread(struct spdk_thread *thread);
|
||||
|
||||
int
|
||||
spdk_reactors_init(void)
|
||||
{
|
||||
int rc;
|
||||
uint32_t i, last_core;
|
||||
char mempool_name[32];
|
||||
|
||||
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);
|
||||
|
||||
if (g_spdk_event_mempool == NULL) {
|
||||
SPDK_ERRLOG("spdk_event_mempool creation failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
spdk_mempool_free(g_spdk_event_mempool);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(g_reactors, 0, (last_core + 1) * sizeof(struct spdk_reactor));
|
||||
|
||||
spdk_thread_lib_init(spdk_reactor_schedule_thread, sizeof(struct spdk_lw_thread));
|
||||
|
||||
SPDK_ENV_FOREACH_CORE(i) {
|
||||
spdk_reactor_construct(&g_reactors[i], i);
|
||||
}
|
||||
|
||||
g_reactor_state = SPDK_REACTOR_STATE_INITIALIZED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct spdk_event *
|
||||
spdk_event_allocate(uint32_t lcore, spdk_event_fn fn, void *arg1, void *arg2)
|
||||
{
|
||||
@ -307,18 +364,6 @@ _spdk_reactor_run(void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
spdk_reactor_construct(struct spdk_reactor *reactor, uint32_t lcore)
|
||||
{
|
||||
reactor->lcore = lcore;
|
||||
reactor->is_valid = true;
|
||||
|
||||
TAILQ_INIT(&reactor->threads);
|
||||
|
||||
reactor->events = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY);
|
||||
assert(reactor->events != NULL);
|
||||
}
|
||||
|
||||
int
|
||||
spdk_app_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
|
||||
{
|
||||
@ -463,49 +508,6 @@ spdk_reactor_schedule_thread(struct spdk_thread *thread)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_reactors_init(void)
|
||||
{
|
||||
int rc;
|
||||
uint32_t i, last_core;
|
||||
char mempool_name[32];
|
||||
|
||||
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);
|
||||
|
||||
if (g_spdk_event_mempool == NULL) {
|
||||
SPDK_ERRLOG("spdk_event_mempool creation failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
spdk_mempool_free(g_spdk_event_mempool);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(g_reactors, 0, (last_core + 1) * sizeof(struct spdk_reactor));
|
||||
|
||||
spdk_thread_lib_init(spdk_reactor_schedule_thread, sizeof(struct spdk_lw_thread));
|
||||
|
||||
SPDK_ENV_FOREACH_CORE(i) {
|
||||
spdk_reactor_construct(&g_reactors[i], i);
|
||||
}
|
||||
|
||||
g_reactor_state = SPDK_REACTOR_STATE_INITIALIZED;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_reactors_fini(void)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user