diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 100c112..3da5e29 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -485,6 +485,9 @@ main(void) /* Initialize sockets thread(s) */ soinit1(); + /* This should be before configure() for softint_establish */ + ipi_sysinit(); + /* Configure the system hardware. This will enable interrupts. */ configure(); @@ -499,7 +502,7 @@ main(void) configure2(); - ipi_sysinit(); + ipi_sysinit_ncpu(ncpu); /* Now timer is working. Enable preemption. */ kpreempt_enable(); diff --git a/sys/kern/subr_ipi.c b/sys/kern/subr_ipi.c index 4d26e92..c5dbfc9 100644 --- a/sys/kern/subr_ipi.c +++ b/sys/kern/subr_ipi.c @@ -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 @@ -120,6 +110,25 @@ ipi_sysinit(void) } /* + * Must be called after ncpu is determined. + */ +void +ipi_sysinit_ncpu(int _ncpu) +{ + 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. * * => Returns IPI ID which is greater than zero; on failure - zero.