Previous refactoring exposed that resched_proc() is call for every
thread of a process when its nice(3) value change.  Is it needed?

First resched_proc() looks at `p_cpu' of a given thread without
considering if it is currently on a runqueue.  If the thread is
sleeping it might not even correspond to the CPU it will be running
next...  But more importantly if the thread is already in a runqueue
calling setpriority() doesn't place it in a higher runqueue.  So even
if a different thread is running on `p_cpu' forcing a context-change
won't result in the newly niced thread to be selected.

So I'm suggesting getting rid of this.  On top of the previous
arguments, setpriority(2) call happen very infrequently during the
lifetime of a process, so the priority change doesn't need to be
immediate.

Getting rid of this resched_proc() here will help simplify the scheduler
code further.  It is, in the end, related to which runqueue threads are
currently sitting in.

Ok?

Index: kern/kern_resource.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_resource.c,v
retrieving revision 1.67
diff -u -p -r1.67 kern_resource.c
--- kern/kern_resource.c        8 Jul 2019 18:53:18 -0000       1.67
+++ kern/kern_resource.c        12 Jul 2019 17:03:29 -0000
@@ -214,7 +214,6 @@ donice(struct proc *curp, struct process
        SCHED_LOCK(s);
        TAILQ_FOREACH(p, &chgpr->ps_threads, p_thr_link) {
                setpriority(p, p->p_estcpu, n);
-               resched_proc(p, p->p_usrpri);
        }
        SCHED_UNLOCK(s);
        return (0);
Index: kern/sched_bsd.c
===================================================================
RCS file: /cvs/src/sys/kern/sched_bsd.c,v
retrieving revision 1.54
diff -u -p -r1.54 sched_bsd.c
--- kern/sched_bsd.c    8 Jul 2019 18:53:18 -0000       1.54
+++ kern/sched_bsd.c    12 Jul 2019 17:16:42 -0000
@@ -61,8 +61,9 @@ int   rrticks_init;           /* # of hardclock tic
 struct __mp_lock sched_lock;
 #endif
 
-void    schedcpu(void *);
-uint32_t decay_aftersleep(uint32_t, uint32_t);
+void                   schedcpu(void *);
+uint32_t               decay_aftersleep(uint32_t, uint32_t);
+static inline void     resched_proc(struct proc *, u_char);
 
 void
 scheduler_start(void)
@@ -442,7 +443,7 @@ mi_switch(void)
 #endif
 }
 
-void
+static inline void
 resched_proc(struct proc *p, u_char pri)
 {
        struct cpu_info *ci;
Index: sys/sched.h
===================================================================
RCS file: /cvs/src/sys/sys/sched.h,v
retrieving revision 1.53
diff -u -p -r1.53 sched.h
--- sys/sched.h 8 Jul 2019 18:53:18 -0000       1.53
+++ sys/sched.h 12 Jul 2019 17:03:41 -0000
@@ -164,7 +164,6 @@ void cpu_idle_cycle(void);
 void cpu_idle_leave(void);
 void sched_peg_curproc(struct cpu_info *ci);
 void sched_barrier(struct cpu_info *ci);
-void resched_proc(struct proc *, u_char);
 
 int sysctl_hwsetperf(void *, size_t *, void *, size_t);
 int sysctl_hwperfpolicy(void *, size_t *, void *, size_t);

Reply via email to