SCHED_ULE and function sched_shouldpreempt

Daniel Janzon janzon at gmail.com
Mon Nov 25 23:05:42 UTC 2013


On Mon, Nov 25, 2013 at 11:25 PM, Ivan Klymenko <fidaj at ukr.net> wrote:

> Hello all.
>
> sched_shouldpreempt function can return only 2 values: 0 or 1
>
> there is a set of specific conditions under which the function returns
> 1 if the remaining conditions - it will return 0.
> why use a kung fu which is currently in use?
> not be simpler to use that variant?:
>
> --- sched_ule.c.orig    2013-11-18 17:41:52.000000000 +0200
> +++ sched_ule.c 2013-11-18 17:48:21.000000000 +0200
> @@ -419,32 +419,7 @@
>  static inline int
>  sched_shouldpreempt(int pri, int cpri, int remote)
>  {
> -       /*
> -        * If the new priority is not better than the current priority
> there is
> -        * nothing to do.
> -        */
> -       if (pri >= cpri)
> -               return (0);
> -       /*
> -        * Always preempt idle.
> -        */
> -       if (cpri >= PRI_MIN_IDLE)
> -               return (1);
> -       /*
> -        * If preemption is disabled don't preempt others.
> -        */
> -       if (preempt_thresh == 0)
> -               return (0);
> -       /*
> -        * Preempt if we exceed the threshold.
> -        */
> -       if (pri <= preempt_thresh)
> -               return (1);
> -       /*
> -        * If we're interactive or better and there is non-interactive
> -        * or worse running preempt only remote processors.
> -        */
> -       if (remote && pri <= PRI_MAX_INTERACT && cpri > PRI_MAX_INTERACT)
> +       if ((remote && pri <= PRI_MAX_INTERACT && cpri >
> PRI_MAX_INTERACT)||(pri <= preempt_thresh)||(cpri >= PRI_MIN_IDLE))
>                 return (1);
>         return (0);
>  }
>
> or indeed there is some uneven distribution fulfillment of certain
> conditions under which the execution time of that function will be much
> more?
>
> or to use the original variant there is any other reasons?
>


The compiler can generate efficient code in both cases. So the code should
be quick to understand,
not quick to type. Also notice that all the comments are deleted in your
patch.

Suppose you enter the function with pri=3, cpri=2 and remote = 0. What is
returned? In the deleted
portion of the patch, you have the answer loud and clear in the first if
case.

Cheers,
Daniel


More information about the freebsd-questions mailing list