Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2034052imc; Tue, 12 Mar 2019 05:55:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeffjBN6ZeuiDSC0y/oJyT08LU01IG9YQresNzq9hjuQvv0Waf1FiXZRL/SqULH6ao3YH7 X-Received: by 2002:a62:ea08:: with SMTP id t8mr38183385pfh.60.1552395302480; Tue, 12 Mar 2019 05:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552395302; cv=none; d=google.com; s=arc-20160816; b=WRSwdK5w1OU20jyevVIz80uPa2iwjvX/e/HAQtFbT3OkbhKHxz/+TiQmO1wvq1OzFQ aA2BoFJC8YmofOQCND7c/xQjqEnfObsRyDeqt45hkwIhquEodEXD7vfRm6ycNdCJ6FmR KnQkuWac7bHI6IyA+IjTuXLTsylfX8tgz8xEj5T/jny2h+SjSLSwCnTMGTGq+KSjWdOA 1kwZdYc4WJ9MkTSCwB/ahDUzL5+W4VIu7UshiAJP+GFMt/XwufFmOkrYXlU0SvUzfexJ f4okjfcXKjAXqZE2sruN/oN5GWFg8SmQk2V9YEuNSUVxWTQSvRadB2cJlC0GP6vFUTfj Q6sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=nf8jqDt5OgP1FDX4WMzof/MLgMaDY2u1vpyepjZrZlY=; b=N6n22iEaOb0U28V1CtKu2djXdnKu2M8M9/8+2dNzPLbDtgamw8LjZmj9jPm/xqKXTd BLg1EfxusRlq+byQkJRTsMGE78EHuPNhrayHe98Ey5uHErY9A2z9L5TwRTa1Nvl+7Wo5 H7sGct5Qh7cOjXY0GZc6aBr9wTOGGlKS2VJfic+wyZmgbLdbxxxEJEmjeM7rh3Hggk4E cz13bXox4iRj1gx+wIpTTvYCy4FBnvygtJ5KTBd3kgienmVobyVKXxO6NCEN64CUiotG LSNR8XEmvVxoBSGD1MqIqT4azS5YipB4w7BxdCFeLEd9H1m0FDCqXPaKnnWQkpfrLXYG mC7Q== ARC-Authentication-Results: i=1; mx.google.com; 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 j7si8419987plb.349.2019.03.12.05.54.45; Tue, 12 Mar 2019 05:55:02 -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; 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 S1726395AbfCLMwz (ORCPT + 99 others); Tue, 12 Mar 2019 08:52:55 -0400 Received: from foss.arm.com ([217.140.101.70]:41918 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbfCLMwz (ORCPT ); Tue, 12 Mar 2019 08:52:55 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8EC7E165C; Tue, 12 Mar 2019 05:52:54 -0700 (PDT) Received: from [0.0.0.0] (e107985-lin.cambridge.arm.com [10.1.194.38]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F2EBC3F614; Tue, 12 Mar 2019 05:52:50 -0700 (PDT) Subject: Re: [PATCH v7 01/15] sched/core: uclamp: Add CPU's clamp buckets refcounting To: Patrick Bellasi , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan References: <20190208100554.32196-1-patrick.bellasi@arm.com> <20190208100554.32196-2-patrick.bellasi@arm.com> From: Dietmar Eggemann Message-ID: <21171fa0-7fd5-ebbf-dd48-d6668ed563af@arm.com> Date: Tue, 12 Mar 2019 13:52:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190208100554.32196-2-patrick.bellasi@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/8/19 11:05 AM, Patrick Bellasi wrote: [...] > +config UCLAMP_BUCKETS_COUNT > + int "Number of supported utilization clamp buckets" > + range 5 20 > + default 5 > + depends on UCLAMP_TASK > + help > + Defines the number of clamp buckets to use. The range of each bucket > + will be SCHED_CAPACITY_SCALE/UCLAMP_BUCKETS_COUNT. The higher the > + number of clamp buckets the finer their granularity and the higher > + the precision of clamping aggregation and tracking at run-time. > + > + For example, with the default configuration we will have 5 clamp > + buckets tracking 20% utilization each. A 25% boosted tasks will be > + refcounted in the [20..39]% bucket and will set the bucket clamp > + effective value to 25%. > + If a second 30% boosted task should be co-scheduled on the same CPU, > + that task will be refcounted in the same bucket of the first task and > + it will boost the bucket clamp effective value to 30%. > + The clamp effective value of a bucket is reset to its nominal value > + (20% in the example above) when there are anymore tasks refcounted in this sounds weird. [...] > +static inline unsigned int uclamp_bucket_value(unsigned int clamp_value) > +{ > + return UCLAMP_BUCKET_DELTA * uclamp_bucket_id(clamp_value); > +} Soemthing like uclamp_bucket_nominal_value() should be clearer. > +static inline void uclamp_rq_update(struct rq *rq, unsigned int clamp_id) > +{ > + struct uclamp_bucket *bucket = rq->uclamp[clamp_id].bucket; > + unsigned int max_value = uclamp_none(clamp_id); > + unsigned int bucket_id; unsigned int bucket_id = UCLAMP_BUCKETS; > + > + /* > + * Both min and max clamps are MAX aggregated, thus the topmost > + * bucket with some tasks defines the rq's clamp value. > + */ > + bucket_id = UCLAMP_BUCKETS; to get rid of this line? > + do { > + --bucket_id; > + if (!rq->uclamp[clamp_id].bucket[bucket_id].tasks) if (!bucket[bucket_id].tasks) [...] > +/* > + * When a task is enqueued on a rq, the clamp bucket currently defined by the > + * task's uclamp::bucket_id is reference counted on that rq. This also > + * immediately updates the rq's clamp value if required. > + * > + * Since tasks know their specific value requested from user-space, we track > + * within each bucket the maximum value for tasks refcounted in that bucket. > + * This provide a further aggregation (local clamping) which allows to track s/This provide/This provides > + * within each bucket the exact "requested" clamp value whenever all tasks > + * RUNNABLE in that bucket require the same clamp. > + */ > +static inline void uclamp_rq_inc_id(struct task_struct *p, struct rq *rq, > + unsigned int clamp_id) > +{ > + unsigned int bucket_id = p->uclamp[clamp_id].bucket_id; > + unsigned int rq_clamp, bkt_clamp, tsk_clamp; Wouldn't it be easier to have a pointer to the task's and rq's uclamp structure as well to the bucket? - unsigned int bucket_id = p->uclamp[clamp_id].bucket_id; + struct uclamp_se *uc_se = &p->uclamp[clamp_id]; + struct uclamp_rq *uc_rq = &rq->uclamp[clamp_id]; + struct uclamp_bucket *bucket = &uc_rq->bucket[uc_se->bucket_id]; The code in uclamp_rq_inc_id() and uclamp_rq_dec_id() for example becomes much more readable. [...] > struct sched_class { > const struct sched_class *next; > > +#ifdef CONFIG_UCLAMP_TASK > + int uclamp_enabled; > +#endif > + > void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags); > void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags); > - void (*yield_task) (struct rq *rq); > - bool (*yield_to_task)(struct rq *rq, struct task_struct *p, bool preempt); > > void (*check_preempt_curr)(struct rq *rq, struct task_struct *p, int flags); > > @@ -1685,7 +1734,6 @@ struct sched_class { > void (*set_curr_task)(struct rq *rq); > void (*task_tick)(struct rq *rq, struct task_struct *p, int queued); > void (*task_fork)(struct task_struct *p); > - void (*task_dead)(struct task_struct *p); > > /* > * The switched_from() call is allowed to drop rq->lock, therefore we > @@ -1702,12 +1750,17 @@ struct sched_class { > > void (*update_curr)(struct rq *rq); > > + void (*yield_task) (struct rq *rq); > + bool (*yield_to_task)(struct rq *rq, struct task_struct *p, bool preempt); > + > #define TASK_SET_GROUP 0 > #define TASK_MOVE_GROUP 1 > > #ifdef CONFIG_FAIR_GROUP_SCHED > void (*task_change_group)(struct task_struct *p, int type); > #endif > + > + void (*task_dead)(struct task_struct *p); Why do you move yield_task, yield_to_task and task_dead here? [...]