On 04/02/20(Tue) 08:43, Amit Kulkarni wrote:
> When a cpu is idle, and wants to steal, it should steal from worst loaded
> cpu, i.e. with the highest cost, not the least cost.
What you say might be a valid choice. However I'm not sure to
understand how does it relate to the behavior of the code?
When stealing sched_proc_to_cpu_cost() is always called with for the
same CPU, `ci' is always the same, which means `cost' is equivalent to
`p_usrpri', right?
Now the priority space is defined in sys/param.h and the higher priority
correspond to a small number. So are we sure we want to steal a thread
with the highest `cost', which would mean with the lowest priority? Or
did I miss something?
> Index: kern/kern_sched.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/kern_sched.c,v
> retrieving revision 1.64
> diff -u -p -u -p -r1.64 kern_sched.c
> --- kern/kern_sched.c 30 Jan 2020 08:51:27 -0000 1.64
> +++ kern/kern_sched.c 4 Feb 2020 14:25:59 -0000
> @@ -487,7 +487,7 @@ sched_steal_proc(struct cpu_info *self)
> struct proc *best = NULL;
> #ifdef MULTIPROCESSOR
> struct schedstate_percpu *spc;
> - int bestcost = INT_MAX;
> + int bestcost = 0;
> struct cpu_info *ci;
> struct cpuset set;
>
> @@ -515,7 +515,7 @@ sched_steal_proc(struct cpu_info *self)
>
> cost = sched_proc_to_cpu_cost(self, p);
>
> - if (best == NULL || cost < bestcost) {
> + if (cost > bestcost) {
> best = p;
> bestcost = cost;
> }
> @@ -524,7 +524,6 @@ sched_steal_proc(struct cpu_info *self)
> if (best == NULL)
> return (NULL);
>
> - spc = &best->p_cpu->ci_schedstate;
> remrunqueue(best);
> best->p_cpu = self;
>
>