ipi: Split up initialization into two parts.

First part runs early so ipi_register can be used in module
initialization, e.g. via pktqueue_create; second part runs after CPUs
have been detected.
This commit is contained in:
riastradh 2020-09-08 16:00:35 +00:00
parent b4ab0863f3
commit da697e67ba
3 changed files with 27 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: init_main.c,v 1.530 2020/09/07 03:50:41 thorpej Exp $ */
/* $NetBSD: init_main.c,v 1.531 2020/09/08 16:00:35 riastradh Exp $ */
/*-
* Copyright (c) 2008, 2009, 2019 The NetBSD Foundation, Inc.
@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.530 2020/09/07 03:50:41 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.531 2020/09/08 16:00:35 riastradh Exp $");
#include "opt_cnmagic.h"
#include "opt_ddb.h"
@ -362,6 +362,9 @@ main(void)
*/
bpf_setops();
/* Initialize what we can in ipi(9) before CPUs are detected. */
ipi_sysinit();
/* Start module system. */
module_init();
module_hook_init();
@ -546,7 +549,8 @@ main(void)
configure2();
ipi_sysinit();
/* Initialize the rest of ipi(9) after CPUs have been detected. */
ipi_percpu_init();
futex_sys_init();

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_ipi.c,v 1.7 2019/10/16 18:29:49 christos Exp $ */
/* $NetBSD: subr_ipi.c,v 1.8 2020/09/08 16:00:35 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_ipi.c,v 1.7 2019/10/16 18:29:49 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_ipi.c,v 1.8 2020/09/08 16:00:35 riastradh Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -93,20 +93,10 @@ static void ipi_msg_cpu_handler(void *);
void
ipi_sysinit(void)
{
const size_t len = ncpu * sizeof(ipi_mbox_t);
/* Initialise the per-CPU bit fields. */
for (u_int i = 0; i < ncpu; i++) {
struct cpu_info *ci = cpu_lookup(i);
memset(&ci->ci_ipipend, 0, sizeof(ci->ci_ipipend));
}
mutex_init(&ipi_mngmt_lock, MUTEX_DEFAULT, IPL_NONE);
memset(ipi_intrs, 0, sizeof(ipi_intrs));
/* Allocate per-CPU IPI mailboxes. */
ipi_mboxes = kmem_zalloc(len, KM_SLEEP);
KASSERT(ipi_mboxes != NULL);
/*
* Register the handler for synchronous IPIs. This mechanism
* is built on top of the asynchronous interface. Slot zero is
@ -119,6 +109,22 @@ ipi_sysinit(void)
"ipi", "full");
}
void
ipi_percpu_init(void)
{
const size_t len = ncpu * sizeof(ipi_mbox_t);
/* Initialise the per-CPU bit fields. */
for (u_int i = 0; i < ncpu; i++) {
struct cpu_info *ci = cpu_lookup(i);
memset(&ci->ci_ipipend, 0, sizeof(ci->ci_ipipend));
}
/* Allocate per-CPU IPI mailboxes. */
ipi_mboxes = kmem_zalloc(len, KM_SLEEP);
KASSERT(ipi_mboxes != NULL);
}
/*
* ipi_register: register an asynchronous IPI handler.
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipi.h,v 1.4 2019/04/06 02:59:05 thorpej Exp $ */
/* $NetBSD: ipi.h,v 1.5 2020/09/08 16:00:35 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@ -60,6 +60,7 @@ typedef struct {
#define IPI_BITWORDS (IPI_MAXREG >> IPI_BITW_SHIFT)
void ipi_sysinit(void);
void ipi_percpu_init(void);
void ipi_cpu_handler(void);
void cpu_ipi(struct cpu_info *);