2009-04-19 18:11:36 +04:00
|
|
|
/* $NetBSD: kern_cpu.c,v 1.42 2009/04/19 14:11:37 ad Exp $ */
|
2007-08-04 15:02:56 +04:00
|
|
|
|
|
|
|
/*-
|
2009-04-19 18:11:36 +04:00
|
|
|
* Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
|
2007-08-04 15:02:56 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Andrew Doran.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
2007-05-17 18:51:11 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c)2007 YAMAMOTO Takashi,
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2009-04-19 18:11:36 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.42 2009/04/19 14:11:37 ad Exp $");
|
2007-05-17 18:51:11 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/idle.h>
|
|
|
|
#include <sys/sched.h>
|
2007-10-08 19:51:02 +04:00
|
|
|
#include <sys/intr.h>
|
2007-08-04 15:02:56 +04:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/cpuio.h>
|
|
|
|
#include <sys/proc.h>
|
2008-01-14 15:40:02 +03:00
|
|
|
#include <sys/percpu.h>
|
2007-08-04 15:02:56 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/kauth.h>
|
2007-10-08 19:12:05 +04:00
|
|
|
#include <sys/xcall.h>
|
|
|
|
#include <sys/pool.h>
|
2008-02-14 17:26:57 +03:00
|
|
|
#include <sys/kmem.h>
|
2008-03-22 21:04:42 +03:00
|
|
|
#include <sys/select.h>
|
2008-04-11 19:25:24 +04:00
|
|
|
#include <sys/namei.h>
|
2008-04-22 15:45:28 +04:00
|
|
|
#include <sys/callout.h>
|
2007-08-04 15:02:56 +04:00
|
|
|
|
2007-08-18 04:21:10 +04:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
2007-08-04 15:02:56 +04:00
|
|
|
void cpuctlattach(int);
|
2007-05-17 18:51:11 +04:00
|
|
|
|
2007-11-04 14:43:07 +03:00
|
|
|
static void cpu_xc_online(struct cpu_info *);
|
|
|
|
static void cpu_xc_offline(struct cpu_info *);
|
2007-10-08 19:12:05 +04:00
|
|
|
|
2007-08-04 15:02:56 +04:00
|
|
|
dev_type_ioctl(cpuctl_ioctl);
|
|
|
|
|
|
|
|
const struct cdevsw cpuctl_cdevsw = {
|
|
|
|
nullopen, nullclose, nullread, nullwrite, cpuctl_ioctl,
|
|
|
|
nullstop, notty, nopoll, nommap, nokqfilter,
|
|
|
|
D_OTHER | D_MPSAFE
|
|
|
|
};
|
2007-11-04 14:43:07 +03:00
|
|
|
|
2007-08-04 15:02:56 +04:00
|
|
|
kmutex_t cpu_lock;
|
2007-10-15 18:12:54 +04:00
|
|
|
int ncpu;
|
|
|
|
int ncpuonline;
|
2008-01-14 15:40:02 +03:00
|
|
|
bool mp_online;
|
2008-04-11 19:31:34 +04:00
|
|
|
struct cpuqueue cpu_queue = CIRCLEQ_HEAD_INITIALIZER(cpu_queue);
|
2007-05-17 18:51:11 +04:00
|
|
|
|
2007-12-22 06:26:34 +03:00
|
|
|
static struct cpu_info *cpu_infos[MAXCPUS];
|
|
|
|
|
2007-05-17 18:51:11 +04:00
|
|
|
int
|
|
|
|
mi_cpu_attach(struct cpu_info *ci)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2007-08-05 05:19:17 +04:00
|
|
|
ci->ci_index = ncpu;
|
2008-04-11 19:31:34 +04:00
|
|
|
cpu_infos[cpu_index(ci)] = ci;
|
|
|
|
CIRCLEQ_INSERT_TAIL(&cpu_queue, ci, ci_data.cpu_qchain);
|
2008-05-06 22:40:57 +04:00
|
|
|
TAILQ_INIT(&ci->ci_data.cpu_ld_locks);
|
|
|
|
__cpu_simple_lock_init(&ci->ci_data.cpu_ld_lock);
|
2007-08-05 05:19:17 +04:00
|
|
|
|
2007-05-17 18:51:11 +04:00
|
|
|
sched_cpuattach(ci);
|
|
|
|
|
|
|
|
error = create_idle_lwp(ci);
|
|
|
|
if (error != 0) {
|
|
|
|
/* XXX revert sched_cpuattach */
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-11-06 03:42:39 +03:00
|
|
|
if (ci == curcpu())
|
|
|
|
ci->ci_data.cpu_onproc = curlwp;
|
|
|
|
else
|
|
|
|
ci->ci_data.cpu_onproc = ci->ci_data.cpu_idlelwp;
|
|
|
|
|
2008-01-14 15:40:02 +03:00
|
|
|
percpu_init_cpu(ci);
|
2007-10-08 19:51:02 +04:00
|
|
|
softint_init(ci);
|
2008-04-22 15:45:28 +04:00
|
|
|
callout_init_cpu(ci);
|
2007-10-08 19:12:05 +04:00
|
|
|
xc_init_cpu(ci);
|
2007-11-07 03:23:13 +03:00
|
|
|
pool_cache_cpu_init(ci);
|
2008-03-22 21:04:42 +03:00
|
|
|
selsysinit(ci);
|
2008-04-11 19:25:24 +04:00
|
|
|
cache_cpu_init(ci);
|
2007-10-08 19:12:05 +04:00
|
|
|
TAILQ_INIT(&ci->ci_data.cpu_biodone);
|
2007-05-17 18:51:11 +04:00
|
|
|
ncpu++;
|
2007-10-15 18:12:54 +04:00
|
|
|
ncpuonline++;
|
2007-05-17 18:51:11 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-08-04 15:02:56 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
cpuctlattach(int dummy)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpuctl_ioctl(dev_t dev, u_long cmd, void *data, int flag, lwp_t *l)
|
|
|
|
{
|
|
|
|
CPU_INFO_ITERATOR cii;
|
|
|
|
cpustate_t *cs;
|
|
|
|
struct cpu_info *ci;
|
|
|
|
int error, i;
|
|
|
|
u_int id;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
mutex_enter(&cpu_lock);
|
|
|
|
switch (cmd) {
|
|
|
|
case IOC_CPU_SETSTATE:
|
2009-01-19 20:39:02 +03:00
|
|
|
if (error == 0)
|
|
|
|
cs = data;
|
2008-02-01 23:01:06 +03:00
|
|
|
error = kauth_authorize_system(l->l_cred,
|
|
|
|
KAUTH_SYSTEM_CPU, KAUTH_REQ_SYSTEM_CPU_SETSTATE, cs, NULL,
|
|
|
|
NULL);
|
2007-08-04 15:02:56 +04:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
2008-10-15 12:13:17 +04:00
|
|
|
if (cs->cs_id >= __arraycount(cpu_infos) ||
|
|
|
|
(ci = cpu_lookup(cs->cs_id)) == NULL) {
|
2007-08-04 15:02:56 +04:00
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
2009-04-19 18:11:36 +04:00
|
|
|
error = cpu_setintr(ci, cs->cs_intr);
|
2008-10-31 03:36:22 +03:00
|
|
|
error = cpu_setstate(ci, cs->cs_online);
|
2007-08-04 15:02:56 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IOC_CPU_GETSTATE:
|
2009-01-19 20:39:02 +03:00
|
|
|
if (error == 0)
|
|
|
|
cs = data;
|
2007-08-04 15:02:56 +04:00
|
|
|
id = cs->cs_id;
|
2007-10-17 21:50:07 +04:00
|
|
|
memset(cs, 0, sizeof(*cs));
|
2007-08-04 15:02:56 +04:00
|
|
|
cs->cs_id = id;
|
2008-10-15 12:13:17 +04:00
|
|
|
if (cs->cs_id >= __arraycount(cpu_infos) ||
|
|
|
|
(ci = cpu_lookup(id)) == NULL) {
|
2007-08-04 15:02:56 +04:00
|
|
|
error = ESRCH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((ci->ci_schedstate.spc_flags & SPCF_OFFLINE) != 0)
|
|
|
|
cs->cs_online = false;
|
|
|
|
else
|
|
|
|
cs->cs_online = true;
|
2009-04-19 18:11:36 +04:00
|
|
|
if ((ci->ci_schedstate.spc_flags & SPCF_NOINTR) != 0)
|
|
|
|
cs->cs_intr = false;
|
|
|
|
else
|
|
|
|
cs->cs_intr = true;
|
|
|
|
cs->cs_lastmod = (int32_t)ci->ci_schedstate.spc_lastmod;
|
|
|
|
cs->cs_lastmodhi = (int32_t)
|
|
|
|
(ci->ci_schedstate.spc_lastmod >> 32);
|
|
|
|
cs->cs_intrcnt = cpu_intr_count(ci) + 1;
|
2007-08-04 15:02:56 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IOC_CPU_MAPID:
|
|
|
|
i = 0;
|
|
|
|
for (CPU_INFO_FOREACH(cii, ci)) {
|
|
|
|
if (i++ == *(int *)data)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ci == NULL)
|
|
|
|
error = ESRCH;
|
|
|
|
else
|
2008-11-06 19:48:51 +03:00
|
|
|
*(int *)data = cpu_index(ci);
|
2007-08-04 15:02:56 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IOC_CPU_GETCOUNT:
|
|
|
|
*(int *)data = ncpu;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_exit(&cpu_lock);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cpu_info *
|
2008-10-15 12:13:17 +04:00
|
|
|
cpu_lookup(u_int idx)
|
2007-12-22 06:26:34 +03:00
|
|
|
{
|
|
|
|
struct cpu_info *ci = cpu_infos[idx];
|
|
|
|
|
2008-10-15 12:13:17 +04:00
|
|
|
KASSERT(idx < __arraycount(cpu_infos));
|
2007-12-22 06:26:34 +03:00
|
|
|
KASSERT(ci == NULL || cpu_index(ci) == idx);
|
|
|
|
|
|
|
|
return ci;
|
|
|
|
}
|
|
|
|
|
2007-10-08 19:12:05 +04:00
|
|
|
static void
|
2007-11-04 14:43:07 +03:00
|
|
|
cpu_xc_offline(struct cpu_info *ci)
|
2007-10-08 19:12:05 +04:00
|
|
|
{
|
2007-11-04 14:43:07 +03:00
|
|
|
struct schedstate_percpu *spc, *mspc = NULL;
|
2008-10-31 03:36:22 +03:00
|
|
|
struct cpu_info *target_ci;
|
2007-11-04 14:43:07 +03:00
|
|
|
struct lwp *l;
|
|
|
|
CPU_INFO_ITERATOR cii;
|
2007-10-08 19:12:05 +04:00
|
|
|
int s;
|
|
|
|
|
2008-10-31 03:36:22 +03:00
|
|
|
/*
|
2009-04-19 18:11:36 +04:00
|
|
|
* Thread that made the cross call (separate context) holds
|
|
|
|
* cpu_lock on our behalf.
|
2008-10-31 03:36:22 +03:00
|
|
|
*/
|
2007-11-04 14:43:07 +03:00
|
|
|
spc = &ci->ci_schedstate;
|
2007-10-08 19:12:05 +04:00
|
|
|
s = splsched();
|
|
|
|
spc->spc_flags |= SPCF_OFFLINE;
|
|
|
|
splx(s);
|
2007-11-04 14:43:07 +03:00
|
|
|
|
2009-04-19 18:11:36 +04:00
|
|
|
/* Take the first available CPU for the migration. */
|
2008-10-31 03:36:22 +03:00
|
|
|
for (CPU_INFO_FOREACH(cii, target_ci)) {
|
|
|
|
mspc = &target_ci->ci_schedstate;
|
2007-11-04 14:43:07 +03:00
|
|
|
if ((mspc->spc_flags & SPCF_OFFLINE) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2008-10-31 03:36:22 +03:00
|
|
|
KASSERT(target_ci != NULL);
|
2007-11-04 14:43:07 +03:00
|
|
|
|
|
|
|
/*
|
2008-10-31 03:36:22 +03:00
|
|
|
* Migrate all non-bound threads to the other CPU. Note that this
|
|
|
|
* runs from the xcall thread, thus handling of LSONPROC is not needed.
|
2007-11-04 14:43:07 +03:00
|
|
|
*/
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_enter(proc_lock);
|
2007-11-04 14:43:07 +03:00
|
|
|
LIST_FOREACH(l, &alllwp, l_list) {
|
2008-10-31 03:36:22 +03:00
|
|
|
struct cpu_info *mci;
|
|
|
|
|
2008-08-28 10:18:26 +04:00
|
|
|
lwp_lock(l);
|
2008-10-31 03:36:22 +03:00
|
|
|
if (l->l_cpu != ci || (l->l_pflag & (LP_BOUND | LP_INTR))) {
|
2008-08-28 10:18:26 +04:00
|
|
|
lwp_unlock(l);
|
2008-10-31 03:36:22 +03:00
|
|
|
continue;
|
2007-11-04 14:43:07 +03:00
|
|
|
}
|
2008-10-31 03:36:22 +03:00
|
|
|
/* Normal case - no affinity */
|
|
|
|
if ((l->l_flag & LW_AFFINITY) == 0) {
|
|
|
|
lwp_migrate(l, target_ci);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Affinity is set, find an online CPU in the set */
|
|
|
|
KASSERT(l->l_affinity != NULL);
|
|
|
|
for (CPU_INFO_FOREACH(cii, mci)) {
|
|
|
|
mspc = &mci->ci_schedstate;
|
|
|
|
if ((mspc->spc_flags & SPCF_OFFLINE) == 0 &&
|
|
|
|
kcpuset_isset(cpu_index(mci), l->l_affinity))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mci == NULL) {
|
|
|
|
lwp_unlock(l);
|
|
|
|
mutex_exit(proc_lock);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
lwp_migrate(l, mci);
|
2007-11-04 14:43:07 +03:00
|
|
|
}
|
2008-04-24 19:35:27 +04:00
|
|
|
mutex_exit(proc_lock);
|
2008-01-15 17:50:07 +03:00
|
|
|
|
|
|
|
#ifdef __HAVE_MD_CPU_OFFLINE
|
|
|
|
cpu_offline_md();
|
|
|
|
#endif
|
2008-10-31 03:36:22 +03:00
|
|
|
return;
|
|
|
|
fail:
|
|
|
|
/* Just unset the SPCF_OFFLINE flag, caller will check */
|
|
|
|
s = splsched();
|
|
|
|
spc->spc_flags &= ~SPCF_OFFLINE;
|
|
|
|
splx(s);
|
2007-10-08 19:12:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2007-11-04 14:43:07 +03:00
|
|
|
cpu_xc_online(struct cpu_info *ci)
|
2007-10-08 19:12:05 +04:00
|
|
|
{
|
2007-11-04 14:43:07 +03:00
|
|
|
struct schedstate_percpu *spc;
|
2007-10-08 19:12:05 +04:00
|
|
|
int s;
|
|
|
|
|
2007-11-04 14:43:07 +03:00
|
|
|
spc = &ci->ci_schedstate;
|
2007-10-08 19:12:05 +04:00
|
|
|
s = splsched();
|
|
|
|
spc->spc_flags &= ~SPCF_OFFLINE;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
2007-08-04 15:02:56 +04:00
|
|
|
int
|
2008-10-31 03:36:22 +03:00
|
|
|
cpu_setstate(struct cpu_info *ci, bool online)
|
2007-08-04 15:02:56 +04:00
|
|
|
{
|
|
|
|
struct schedstate_percpu *spc;
|
|
|
|
CPU_INFO_ITERATOR cii;
|
|
|
|
struct cpu_info *ci2;
|
2007-10-08 19:12:05 +04:00
|
|
|
uint64_t where;
|
|
|
|
xcfunc_t func;
|
2007-08-04 15:02:56 +04:00
|
|
|
int nonline;
|
|
|
|
|
|
|
|
spc = &ci->ci_schedstate;
|
|
|
|
|
|
|
|
KASSERT(mutex_owned(&cpu_lock));
|
|
|
|
|
|
|
|
if (online) {
|
|
|
|
if ((spc->spc_flags & SPCF_OFFLINE) == 0)
|
|
|
|
return 0;
|
2007-10-08 19:12:05 +04:00
|
|
|
func = (xcfunc_t)cpu_xc_online;
|
2007-10-15 18:12:54 +04:00
|
|
|
ncpuonline++;
|
2007-08-04 15:02:56 +04:00
|
|
|
} else {
|
|
|
|
if ((spc->spc_flags & SPCF_OFFLINE) != 0)
|
|
|
|
return 0;
|
|
|
|
nonline = 0;
|
2008-06-22 17:59:06 +04:00
|
|
|
/*
|
|
|
|
* Ensure that at least one CPU within the processor set
|
|
|
|
* stays online. Revisit this later.
|
|
|
|
*/
|
2007-08-04 15:02:56 +04:00
|
|
|
for (CPU_INFO_FOREACH(cii, ci2)) {
|
2008-06-22 17:59:06 +04:00
|
|
|
if ((ci2->ci_schedstate.spc_flags & SPCF_OFFLINE) != 0)
|
|
|
|
continue;
|
|
|
|
if (ci2->ci_schedstate.spc_psid != spc->spc_psid)
|
|
|
|
continue;
|
|
|
|
nonline++;
|
2007-08-04 15:02:56 +04:00
|
|
|
}
|
|
|
|
if (nonline == 1)
|
|
|
|
return EBUSY;
|
2007-10-08 19:12:05 +04:00
|
|
|
func = (xcfunc_t)cpu_xc_offline;
|
2007-10-15 18:12:54 +04:00
|
|
|
ncpuonline--;
|
2007-08-04 15:02:56 +04:00
|
|
|
}
|
|
|
|
|
2007-11-04 14:43:07 +03:00
|
|
|
where = xc_unicast(0, func, ci, NULL, ci);
|
2007-10-08 19:12:05 +04:00
|
|
|
xc_wait(where);
|
2007-11-04 14:43:07 +03:00
|
|
|
if (online) {
|
|
|
|
KASSERT((spc->spc_flags & SPCF_OFFLINE) == 0);
|
2008-10-31 03:36:22 +03:00
|
|
|
} else if ((spc->spc_flags & SPCF_OFFLINE) == 0) {
|
|
|
|
/* If was not set offline, then it is busy */
|
|
|
|
return EBUSY;
|
2007-11-04 14:43:07 +03:00
|
|
|
}
|
2007-10-08 19:12:05 +04:00
|
|
|
|
2008-10-31 03:36:22 +03:00
|
|
|
spc->spc_lastmod = time_second;
|
2007-08-04 15:02:56 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2008-12-07 14:40:53 +03:00
|
|
|
|
2009-04-19 18:11:36 +04:00
|
|
|
#ifdef __HAVE_INTR_CONTROL
|
|
|
|
static void
|
|
|
|
cpu_xc_intr(struct cpu_info *ci)
|
|
|
|
{
|
|
|
|
struct schedstate_percpu *spc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
spc = &ci->ci_schedstate;
|
|
|
|
s = splsched();
|
|
|
|
spc->spc_flags &= ~SPCF_NOINTR;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cpu_xc_nointr(struct cpu_info *ci)
|
|
|
|
{
|
|
|
|
struct schedstate_percpu *spc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
spc = &ci->ci_schedstate;
|
|
|
|
s = splsched();
|
|
|
|
spc->spc_flags |= SPCF_NOINTR;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cpu_setintr(struct cpu_info *ci, bool intr)
|
|
|
|
{
|
|
|
|
struct schedstate_percpu *spc;
|
|
|
|
CPU_INFO_ITERATOR cii;
|
|
|
|
struct cpu_info *ci2;
|
|
|
|
uint64_t where;
|
|
|
|
xcfunc_t func;
|
|
|
|
int nintr;
|
|
|
|
|
|
|
|
spc = &ci->ci_schedstate;
|
|
|
|
|
|
|
|
KASSERT(mutex_owned(&cpu_lock));
|
|
|
|
|
|
|
|
if (intr) {
|
|
|
|
if ((spc->spc_flags & SPCF_NOINTR) == 0)
|
|
|
|
return 0;
|
|
|
|
func = (xcfunc_t)cpu_xc_intr;
|
|
|
|
} else {
|
|
|
|
if ((spc->spc_flags & SPCF_NOINTR) != 0)
|
|
|
|
return 0;
|
|
|
|
/*
|
|
|
|
* Ensure that at least one CPU within the system
|
|
|
|
* is handing device interrupts.
|
|
|
|
*/
|
|
|
|
nintr = 0;
|
|
|
|
for (CPU_INFO_FOREACH(cii, ci2)) {
|
|
|
|
if ((ci2->ci_schedstate.spc_flags & SPCF_NOINTR) != 0)
|
|
|
|
continue;
|
|
|
|
if (ci2 == ci)
|
|
|
|
continue;
|
|
|
|
nintr++;
|
|
|
|
}
|
|
|
|
if (nintr == 0)
|
|
|
|
return EBUSY;
|
|
|
|
func = (xcfunc_t)cpu_xc_nointr;
|
|
|
|
}
|
|
|
|
|
|
|
|
where = xc_unicast(0, func, ci, NULL, ci);
|
|
|
|
xc_wait(where);
|
|
|
|
if (intr) {
|
|
|
|
KASSERT((spc->spc_flags & SPCF_NOINTR) == 0);
|
|
|
|
} else if ((spc->spc_flags & SPCF_NOINTR) == 0) {
|
|
|
|
/* If was not set offline, then it is busy */
|
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Direct interrupts away from the CPU and record the change. */
|
|
|
|
cpu_intr_redistribute();
|
|
|
|
spc->spc_lastmod = time_second;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else /* __HAVE_INTR_CONTROL */
|
|
|
|
int
|
|
|
|
cpu_setintr(struct cpu_info *ci, bool intr)
|
|
|
|
{
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
|
|
|
cpu_intr_count(struct cpu_info *ci)
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0; /* 0 == "don't know" */
|
|
|
|
}
|
|
|
|
#endif /* __HAVE_INTR_CONTROL */
|
|
|
|
|
2008-12-07 14:40:53 +03:00
|
|
|
bool
|
|
|
|
cpu_softintr_p(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (curlwp->l_pflag & LP_INTR) != 0;
|
|
|
|
}
|