Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1091341imm; Thu, 13 Sep 2018 12:31:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaIKYbqWNTtVfUzaR08+tTrz4DdHJ6WlHJfssaZx0BWK2ZHtvaqeY6QQVEuMI14LI3FGwu+ X-Received: by 2002:a63:6b86:: with SMTP id g128-v6mr8335670pgc.344.1536867093394; Thu, 13 Sep 2018 12:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536867093; cv=none; d=google.com; s=arc-20160816; b=pi64YK0JXJm7qLqvyk3/G/5+IL38lH6PG64ZR86EvEQ85TUR62IOpavPA8jkn457Z1 5q5Lxb+f9XOUlW3fks657ufoaALzHtytxPhV1aLkjn6qX5/HcL0FjJa1QWWlVLIOicwi 2kBF7XzncVvQfW/ws0YxuXLYQUuF3w38MNED/cdSBCAq/QcpxzxVq7bNp89WiTIWsMTn FN7JAmsnxAZtAFjM6KB4G6rFhh3mxXqHV0xbhhbKGC37vYmBvefQELLK52N/7Nl00G0B QDFM3wh9zJ80lKClPEzLicXFraJfSo9ysp66Q5Ljwq8WQ606Q+rnSSoneRwetM0xqj6W T1lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SU/gQ9iepIa3fr6MAHl89j7sRUzM9LC+Sd8puxLGIr8=; b=t/ORSAaDyUPp21zhwc0518bsFl4OHY/fpDJiigy1OJzclkWBYQHUGCYIaBz4ItJLiQ 8MY+J+9+xed3W+8TjpwyZc/HgtgF9hmQtXHaVdxzQIoSFhzcgiI0OExEbk8z6ehlz6kk K1gQWBeHtKgzeUtppUGv1/PimeQz7ncEIHzZUOHxzi4vPX195S5xoJCjM28RF3RNUbZp w8u2P64cxfqc4sscL4NgbQtWw0IRSxITwvCKrXuV1ziornckhp0NaMAzIBwgOK02OycK iF4CnAF0uEpwNUlqG47NG3pPspvs3qOhB4MMRPZW9REudX/kmQF7h+yIEMix9nWISiPF 0rww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=VOdsvY8E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c2-v6si4798243pge.124.2018.09.13.12.31.05; Thu, 13 Sep 2018 12:31:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=VOdsvY8E; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728256AbeINAbd (ORCPT + 99 others); Thu, 13 Sep 2018 20:31:33 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:39024 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727730AbeINAbd (ORCPT ); Thu, 13 Sep 2018 20:31:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SU/gQ9iepIa3fr6MAHl89j7sRUzM9LC+Sd8puxLGIr8=; b=VOdsvY8EZ78mGVSo+j9Xev5Gx 3dOJw01aklC5Z6hasQk3r4CAEqNLzkxdc0KcN3Oyh4P4zX03emMywm0n5lzhIgHVKNIIpGtICkKN1 IrzG2jm2VsTrjnWQ//+EFEEqLvkOtSe1MwSGhYB2WVlBMe0sKPOy1YXHUu0lQx3dI5oZsfM4G7ZnA Gg4Ai8GaZCcWtyXbQAk3yhUUGW2A3J3O9E4YRzer1v2rAGCkIfaaA2/T/Z+hI7CCBCqm7RBm+aWPS IHt9v4BmR2LTABWhyj72KUkN2ZQN8u4OvE25aeo3aSBsG7WRFKi751lTBbSDtkWZXQycWapTR6bmU ElXY93ITg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g0XAK-0003Zv-9z; Thu, 13 Sep 2018 19:20:36 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A6D21202C1A34; Thu, 13 Sep 2018 21:20:34 +0200 (CEST) Date: Thu, 13 Sep 2018 21:20:34 +0200 From: Peter Zijlstra To: Patrick Bellasi Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v4 02/16] sched/core: uclamp: map TASK's clamp values into CPU's clamp groups Message-ID: <20180913192034.GA24082@hirez.programming.kicks-ass.net> References: <20180828135324.21976-1-patrick.bellasi@arm.com> <20180828135324.21976-3-patrick.bellasi@arm.com> <20180912162427.GA24106@hirez.programming.kicks-ass.net> <20180912174209.GI1413@e110439-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180912174209.GI1413@e110439-lin> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 12, 2018 at 06:42:09PM +0100, Patrick Bellasi wrote: > On 12-Sep 18:24, Peter Zijlstra wrote: > > On Tue, Aug 28, 2018 at 02:53:10PM +0100, Patrick Bellasi wrote: > > > { > > > + int group_id[UCLAMP_CNT] = { UCLAMP_NOT_VALID }; > > > + int lower_bound, upper_bound; > > > + struct uclamp_se *uc_se; > > > + int result = 0; > > > > I think the thing would become much more readable if you set > > lower/upper_bound right here. > Actually it could also make sense to have them before the mutex ;) Indeed. + upper_bound = (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) + ? attr->sched_util_max + : p->uclamp[UCLAMP_MAX].value; + + if (upper_bound == UCLAMP_NOT_VALID) + upper_bound = SCHED_CAPACITY_SCALE; + if (attr->sched_util_min > upper_bound) { + result = -EINVAL; + goto done; + } + + result = uclamp_group_find(UCLAMP_MIN, attr->sched_util_min); + if (result == -ENOSPC) { + pr_err(UCLAMP_ENOSPC_FMT, "MIN"); + goto done; + } + group_id[UCLAMP_MIN] = result; + } + if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) { + lower_bound = (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) + ? attr->sched_util_min + : p->uclamp[UCLAMP_MIN].value; + + if (lower_bound == UCLAMP_NOT_VALID) + lower_bound = 0; + if (attr->sched_util_max < lower_bound || + attr->sched_util_max > SCHED_CAPACITY_SCALE) { + result = -EINVAL; + goto done; + } That would end up soething like: unsigned int lower_bound = p->uclamp[UCLAMP_MIN].value; unsigned int upper_bound = p->uclamp[UCLAMP_MAX].value; if (sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) lower_bound = attr->sched_util_min; if (sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) upper_bound = attr->sched_util_max; if (lower_bound > upper_bound || upper_bound > SCHED_CAPACITY_MAX) return -EINVAL; mutex_lock(...);