From owner-freebsd-questions@FreeBSD.ORG Mon Nov 25 23:05:42 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6C49623E; Mon, 25 Nov 2013 23:05:42 +0000 (UTC) Received: from mail-ve0-x236.google.com (mail-ve0-x236.google.com [IPv6:2607:f8b0:400c:c01::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1D2D820B0; Mon, 25 Nov 2013 23:05:42 +0000 (UTC) Received: by mail-ve0-f182.google.com with SMTP id jy13so3360399veb.41 for ; Mon, 25 Nov 2013 15:05:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=KoZ4BvqbCGwBU6iBqgnJfnx7g7AnbJuE6vfmrBIEBzY=; b=D8eXzeYO6ns4qb9JVjzJPCdYTCGuudUFx65HEcQYwf5sq5EvwD9P8iKFKjEt6hlVWO DSsvhQi1RqiXROF1+XQDvCP7sMQ0tHcUGqMKEoOfHmPXcVeNAzUIYsYEKVM6IshWY5iu N6bCilL9bmV4/ShjxkZAMKpKdSqgwwpggR5IgaZByqj3IYtlrWL5EKXM/mlAGJcGyZTI wnzaN6kofpWhMc3mMeTB67R86ZAIc6JzuUl4coM/qlf5wgRUw4ywV63UbcDuVx9Nmrja EihIf2jjaVUJop1QPA1L+eCfbKFcvb7QOJyY1rIwYHFeG5FZSK7DFkWAx+yGTw/9zDVB EEpA== MIME-Version: 1.0 X-Received: by 10.58.210.66 with SMTP id ms2mr28816214vec.10.1385420741237; Mon, 25 Nov 2013 15:05:41 -0800 (PST) Received: by 10.220.145.143 with HTTP; Mon, 25 Nov 2013 15:05:41 -0800 (PST) In-Reply-To: <20131126002557.6820c60e@nonamehost.local> References: <20131126002557.6820c60e@nonamehost.local> Date: Tue, 26 Nov 2013 00:05:41 +0100 Message-ID: Subject: Re: SCHED_ULE and function sched_shouldpreempt From: Daniel Janzon To: Ivan Klymenko Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.16 Cc: freebsd-hackers@freebsd.org, freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Nov 2013 23:05:42 -0000 On Mon, Nov 25, 2013 at 11:25 PM, Ivan Klymenko 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