Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3043428imc;
        Wed, 13 Mar 2019 07:33:43 -0700 (PDT)
X-Google-Smtp-Source: APXvYqwJ7f1S9NHT1Q/yBcf4q2i3L3lb0KE3pej0zssvFH+7fcNaT6+HeIxAMQpAzTdsimvfRGYX
X-Received: by 2002:a17:902:e85:: with SMTP id 5mr46330610plx.13.1552487623593;
        Wed, 13 Mar 2019 07:33:43 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1552487623; cv=none;
        d=google.com; s=arc-20160816;
        b=OSvYWOYXhhI3gcGnbCE5JKjA9t1/pyrIQxYWyZknYZ+xTBv6GuFD8bQb2EYnHF+DWE
         RQLiLTD6MHhrMikJjnGAEdGoYBURouJFn1Q37seZfjpj9IBjhQLQxicAPJqcB5MXIAi2
         aFTq8MiT+jKrwCGsFntLNOqCA7g3EgTDQ9de7eZAbwG5hiQga4S/fJ1JoayhXnn9MWYr
         1iqWlXQxMNyC/T8gfNuTfSVOae17Abuw55BRzCz9gBa2vt25mECJXQ+JxZmIIUN62a3Q
         DzH1RPey9vuztNX5bs07itzOP5zzlVFkBf/8Mx5OXajM0c7TrlhIa41OCchfU2jNot98
         wsjQ==
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=l4y3uyx9OFx08MnbvVoBjf1QMWF43hx5TE5qEzJ65l8=;
        b=fKP8umIJXy5JAbMAdn7OfnBmZAONyRxXY0eehSU7KMtR1unBE0LNokngett+IXAFAn
         kiG2Aax2xFuvOrDYi7k7Bl6ON0pDBFSbkRDWkk5XSDjz1+d3GM2dVZZkoCN2ySeH8AZF
         e5XEVp6KI4lGf3pHq6vxjar+bMzTpqnPMxi3w4A9kEQQKsd17cM35xLG6pbH3yN339JT
         l6qzWpQJKrx+DLEkc12AH5x2k9UfgFwD398akJWBpT4oHxughD84s4Dx4fldaERzABzS
         rKHNvx2iMYFjHYboxGWvOUkK6MuTNibZZB/Gf1iFXefoOKBexjH6m5DP26uqHn1LR+Pv
         n5Hg==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=EhgUOilA;
       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: <linux-kernel-owner@vger.kernel.org>
Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67])
        by mx.google.com with ESMTP id j5si9918548pfi.227.2019.03.13.07.33.26;
        Wed, 13 Mar 2019 07:33:43 -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=EhgUOilA;
       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 S1726686AbfCMOcr (ORCPT <rfc822;michael.k.kehoe@gmail.com>
        + 99 others); Wed, 13 Mar 2019 10:32:47 -0400
Received: from bombadil.infradead.org ([198.137.202.133]:44716 "EHLO
        bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
        with ESMTP id S1726033AbfCMOcr (ORCPT
        <rfc822;linux-kernel@vger.kernel.org>);
        Wed, 13 Mar 2019 10:32:47 -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=l4y3uyx9OFx08MnbvVoBjf1QMWF43hx5TE5qEzJ65l8=; b=EhgUOilAsh89BK/UGoRir5+2L
        JWBLCMbScO9AA/REYxTunmHkol0X/caW8qpAJ9MAFUIWApVNhHDhfHgtFYpPj9CqwZk0frVwNhVhX
        Ah8UUpsUpSKGXCUD4/tx/pJHUNnVlwWJzyCCKttGH/t6coPy0ZcorVaknhr9zdOrK4wjl5zcIbWfM
        TGPOb5ud+BP2RnmbDhvEINC9qVw3/+8QYLBRpSli7Ru1Wbqs3Oz9l9b7j9BP8deK/QhEsWzSFXZHT
        6Kt42pz88yBhSbwX7+clqyJfy/e0Y6fVAltoWPl0yAVA2AW8WM1A5OMLHMLb8osYz8d5CLRSmDa9f
        J/cH65usw==;
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 1h44vx-0004j2-Q2; Wed, 13 Mar 2019 14:32:41 +0000
Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000)
        id 4B247202989D2; Wed, 13 Mar 2019 15:32:40 +0100 (CET)
Date:   Wed, 13 Mar 2019 15:32:40 +0100
From:   Peter Zijlstra <peterz@infradead.org>
To:     Patrick Bellasi <patrick.bellasi@arm.com>
Cc:     linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
        linux-api@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
        Tejun Heo <tj@kernel.org>,
        "Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
        Vincent Guittot <vincent.guittot@linaro.org>,
        Viresh Kumar <viresh.kumar@linaro.org>,
        Paul Turner <pjt@google.com>,
        Quentin Perret <quentin.perret@arm.com>,
        Dietmar Eggemann <dietmar.eggemann@arm.com>,
        Morten Rasmussen <morten.rasmussen@arm.com>,
        Juri Lelli <juri.lelli@redhat.com>,
        Todd Kjos <tkjos@google.com>,
        Joel Fernandes <joelaf@google.com>,
        Steve Muckle <smuckle@google.com>,
        Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH v7 03/15] sched/core: uclamp: Add system default clamps
Message-ID: <20190313143240.GH5922@hirez.programming.kicks-ass.net>
References: <20190208100554.32196-1-patrick.bellasi@arm.com>
 <20190208100554.32196-4-patrick.bellasi@arm.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20190208100554.32196-4-patrick.bellasi@arm.com>
User-Agent: Mutt/1.10.1 (2018-07-13)
Sender: linux-kernel-owner@vger.kernel.org
Precedence: bulk
List-ID: <linux-kernel.vger.kernel.org>
X-Mailing-List: linux-kernel@vger.kernel.org

On Fri, Feb 08, 2019 at 10:05:42AM +0000, Patrick Bellasi wrote:

> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 45460e7a3eee..447261cd23ba 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -584,14 +584,32 @@ struct sched_dl_entity {
>   * Utilization clamp for a scheduling entity
>   * @value:		clamp value "requested" by a se
>   * @bucket_id:		clamp bucket corresponding to the "requested" value
> + * @effective:		clamp value and bucket actually "assigned" to the se
> + * @active:		the se is currently refcounted in a rq's bucket
>   *
> + * Both bucket_id and effective::bucket_id are the index of the clamp bucket
> + * matching the corresponding clamp value which are pre-computed and stored to
> + * avoid expensive integer divisions from the fast path.
> + *
> + * The active bit is set whenever a task has got an effective::value assigned,
> + * which can be different from the user requested clamp value. This allows to
> + * know a task is actually refcounting the rq's effective::bucket_id bucket.
>   */
>  struct uclamp_se {
> +	/* Clamp value "requested" by a scheduling entity */
>  	unsigned int value		: bits_per(SCHED_CAPACITY_SCALE);
>  	unsigned int bucket_id		: bits_per(UCLAMP_BUCKETS);
> +	unsigned int active		: 1;
> +	/*
> +	 * Clamp value "obtained" by a scheduling entity.
> +	 *
> +	 * This cache the actual clamp value, possibly enforced by system
> +	 * default clamps, a task is subject to while enqueued in a rq.
> +	 */
> +	struct {
> +		unsigned int value	: bits_per(SCHED_CAPACITY_SCALE);
> +		unsigned int bucket_id	: bits_per(UCLAMP_BUCKETS);
> +	} effective;

I still think that this effective thing is backwards.

The existing code already used @value and @bucket_id as 'effective' and
you're now changing all that again. This really doesn't make sense to
me.

Also; if you don't add it inside struct uclamp_se, but add a second
instance,

>  };
>  #endif /* CONFIG_UCLAMP_TASK */
>  


> @@ -803,6 +811,70 @@ static inline void uclamp_rq_update(struct rq *rq, unsigned int clamp_id,
>  	WRITE_ONCE(rq->uclamp[clamp_id].value, max_value);
>  }
>  
> +/*
> + * The effective clamp bucket index of a task depends on, by increasing
> + * priority:
> + * - the task specific clamp value, when explicitly requested from userspace
> + * - the system default clamp value, defined by the sysadmin
> + *
> + * As a side effect, update the task's effective value:
> + *    task_struct::uclamp::effective::value
> + * to represent the clamp value of the task effective bucket index.
> + */
> +static inline void
> +uclamp_effective_get(struct task_struct *p, unsigned int clamp_id,
> +		     unsigned int *clamp_value, unsigned int *bucket_id)
> +{
> +	/* Task specific clamp value */
> +	*bucket_id = p->uclamp[clamp_id].bucket_id;
> +	*clamp_value = p->uclamp[clamp_id].value;
> +
> +	/* Always apply system default restrictions */
> +	if (unlikely(*clamp_value > uclamp_default[clamp_id].value)) {
> +		*clamp_value = uclamp_default[clamp_id].value;
> +		*bucket_id = uclamp_default[clamp_id].bucket_id;
> +	}
> +}

you can avoid horrors like this and simply return a struct uclamp_se by
value.