From e4df77f03a368ba0deaac527960a8bab6cef77c1 Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Fri, 3 Apr 2009 09:29:16 +0000 Subject: sched_peg_curproc_to_cpu() - function to force a proc to stay on a cpu forever. --- sys/kern/kern_sched.c | 28 +++++++++++++++++++++++++++- sys/sys/proc.h | 3 ++- sys/sys/sched.h | 3 ++- 3 files changed, 31 insertions(+), 3 deletions(-) (limited to 'sys') diff --git a/sys/kern/kern_sched.c b/sys/kern/kern_sched.c index 1b921159985..29dd5793efe 100644 --- a/sys/kern/kern_sched.c +++ b/sys/kern/kern_sched.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sched.c,v 1.9 2009/03/23 13:25:11 art Exp $ */ +/* $OpenBSD: kern_sched.c,v 1.10 2009/04/03 09:29:15 art Exp $ */ /* * Copyright (c) 2007, 2008 Artur Grabowski * @@ -291,6 +291,12 @@ sched_choosecpu(struct proc *p) struct cpu_info *ci; struct cpuset set; + /* + * If pegged to a cpu, don't allow it to move. + */ + if (p->p_flag & P_CPUPEG) + return; + sched_choose++; /* @@ -481,6 +487,26 @@ sched_proc_to_cpu_cost(struct cpu_info *ci, struct proc *p) return (cost); } +/* + * Peg a proc to a cpu. + */ +void +sched_peg_curproc(struct cpu_info *ci) +{ + struct proc *p = curproc; + int s; + + SCHED_LOCK(s); + p->p_priority = p->p_usrpri; + p->p_stat = SRUN; + p->p_cpu = ci; + atomic_setbits_int(&p->p_flag, P_CPUPEG); + setrunqueue(p); + p->p_stats->p_ru.ru_nvcsw++; + mi_switch(); + SCHED_UNLOCK(s); +} + /* * Functions to manipulate cpu sets. */ diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 2031c6f1870..2bfc6e308e5 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.114 2009/03/26 17:24:33 oga Exp $ */ +/* $OpenBSD: proc.h,v 1.115 2009/04/03 09:29:15 art Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -305,6 +305,7 @@ struct proc { #define P_IGNEXITRV 0x8000000 /* For thread kills */ #define P_SOFTDEP 0x10000000 /* Stuck processing softdep worklist */ #define P_STOPPED 0x20000000 /* Just stopped. */ +#define P_CPUPEG 0x40000000 /* Do not move to another cpu. */ #define P_BITS \ ("\20\01ADVLOCK\02CTTY\04NOCLDSTOP\05PPWAIT\06PROFIL\07SELECT" \ diff --git a/sys/sys/sched.h b/sys/sys/sched.h index 151adc9af37..7766f4da093 100644 --- a/sys/sys/sched.h +++ b/sys/sys/sched.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sched.h,v 1.20 2009/03/23 13:25:11 art Exp $ */ +/* $OpenBSD: sched.h,v 1.21 2009/04/03 09:29:15 art Exp $ */ /* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */ /*- @@ -144,6 +144,7 @@ void sched_choosecpu(struct proc *); void cpu_idle_enter(void); void cpu_idle_cycle(void); void cpu_idle_leave(void); +void sched_peg_curproc(struct cpu_info *ci); #define curcpu_is_idle() (curcpu()->ci_schedstate.spc_whichqs == 0) -- cgit v1.2.3