Date: Tue, 26 Nov 2013 00:05:41 +0100 From: Daniel Janzon <janzon@gmail.com> To: Ivan Klymenko <fidaj@ukr.net> Cc: freebsd-hackers@freebsd.org, freebsd-questions@freebsd.org Subject: Re: SCHED_ULE and function sched_shouldpreempt Message-ID: <CAAGHsvAP6kpQRy3Xed8807tJ_0uy95xzgZdSVDpZ0j8Y7aNf_Q@mail.gmail.com> In-Reply-To: <20131126002557.6820c60e@nonamehost.local> References: <20131126002557.6820c60e@nonamehost.local>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Nov 25, 2013 at 11:25 PM, Ivan Klymenko <fidaj@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAAGHsvAP6kpQRy3Xed8807tJ_0uy95xzgZdSVDpZ0j8Y7aNf_Q>