Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7240587imu; Tue, 22 Jan 2019 02:45:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN7P4qA/tfgD2osxVH017a9xnvR3oJkRAUFx50E2D0o9736DF4hz8bBV12pa7m+EcyurwqEL X-Received: by 2002:a63:3d49:: with SMTP id k70mr31513000pga.191.1548153948285; Tue, 22 Jan 2019 02:45:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548153948; cv=none; d=google.com; s=arc-20160816; b=KoFmIwBpICDFI1Fj313es/B6fozH1HHVWk/kAu6KPLhNOpD5tLc7oeC51HTLa5HiCN h/PEvTgTf1cWVz7mSFw2CF9MjmIB+Imh2QWc7AUVC1Gyw974Ukd6sbD5NUZ0kwXKNtcG eBklxO5/9AyzNb2e56xH7c36Lmf1c4m973dssM4mWNFCz1eXI7XVHGaTEDyBfm6ZDPp/ phWcU3i4DMcD2FYth87PLAZAxX3/Wt797cUcADJo87m9E2fIZCmDV3+cbUotvHmWUFwq whgwsY6n5eL2vs7JVn+W3r7mPp8CaAKOnUo82RRysEnPsZflko82va/1nrVNT16Xa6Q6 MvPA== 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; bh=tY2B4o2FrYPFaoZYqMNaZ5oxm92yB1bD4tTZBTKDM2M=; b=YFm1/2nKzXeyUECwx7Uw0Y4FBkUEKbN0PuAgIKVOKzvq/Nr5pAX0zGIr0cWjkmywua wvFOMcIvfUJZVepveHHzKL+YVWjLDaeEWwYLpEU1XdBTUDZvj5p8501/X77ou4JUKgWE 3YVpu4Uv+kSZNG/buJFJ3A2AUwdSX9tkjSgfmelAD+rG2YQJrxyrqEntJmdmf1Jt5Z55 f3cXdJWN+hvYRLsr0nEGuNbc/Nl+Xv8moTI9mILHRyESWuqSxiq/oc0RFLj4U+G2pIYE Jb6L59XTrmH+ZkaoXIpDgrzphJ3M9ZetRP65LdB6gsQRG267LUpjy0mJ1iAxpRaFQL7Y 5qcw== 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 f23si14005462pgv.431.2019.01.22.02.45.32; Tue, 22 Jan 2019 02:45:48 -0800 (PST) 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 S1727931AbfAVKnM (ORCPT + 99 others); Tue, 22 Jan 2019 05:43:12 -0500 Received: from foss.arm.com ([217.140.101.70]:50488 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726530AbfAVKnL (ORCPT ); Tue, 22 Jan 2019 05:43:11 -0500 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 8E0E5A78; Tue, 22 Jan 2019 02:43:10 -0800 (PST) Received: from e110439-lin (e110439-lin.cambridge.arm.com [10.1.194.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9A9AB3F6A8; Tue, 22 Jan 2019 02:43:07 -0800 (PST) Date: Tue, 22 Jan 2019 10:43:05 +0000 From: Patrick Bellasi To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v6 05/16] sched/core: uclamp: Update CPU's refcount on clamp changes Message-ID: <20190122104305.6vjx37muqsxm536t@e110439-lin> References: <20190115101513.2822-1-patrick.bellasi@arm.com> <20190115101513.2822-6-patrick.bellasi@arm.com> <20190121153308.GL27931@hirez.programming.kicks-ass.net> <20190121154412.fak2t2iquj3aixtu@e110439-lin> <20190122093704.GM27931@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190122093704.GM27931@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22-Jan 10:37, Peter Zijlstra wrote: > On Mon, Jan 21, 2019 at 03:44:12PM +0000, Patrick Bellasi wrote: > > On 21-Jan 16:33, Peter Zijlstra wrote: > > > On Tue, Jan 15, 2019 at 10:15:02AM +0000, Patrick Bellasi wrote: > > > > > > > +static inline void > > > > +uclamp_task_update_active(struct task_struct *p, unsigned int clamp_id) > > > > +{ > > > > + struct rq_flags rf; > > > > + struct rq *rq; > > > > + > > > > + /* > > > > + * Lock the task and the CPU where the task is (or was) queued. > > > > + * > > > > + * We might lock the (previous) rq of a !RUNNABLE task, but that's the > > > > + * price to pay to safely serialize util_{min,max} updates with > > > > + * enqueues, dequeues and migration operations. > > > > + * This is the same locking schema used by __set_cpus_allowed_ptr(). > > > > + */ > > > > + rq = task_rq_lock(p, &rf); > > > > + > > > > + /* > > > > + * Setting the clamp bucket is serialized by task_rq_lock(). > > > > + * If the task is not yet RUNNABLE and its task_struct is not > > > > + * affecting a valid clamp bucket, the next time it's enqueued, > > > > + * it will already see the updated clamp bucket value. > > > > + */ > > > > + if (!p->uclamp[clamp_id].active) > > > > + goto done; > > > > + > > > > + uclamp_cpu_dec_id(p, rq, clamp_id); > > > > + uclamp_cpu_inc_id(p, rq, clamp_id); > > > > + > > > > +done: > > > > + task_rq_unlock(rq, p, &rf); > > > > +} > > > > > > > @@ -1008,11 +1043,11 @@ static int __setscheduler_uclamp(struct task_struct *p, > > > > > > > > mutex_lock(&uclamp_mutex); > > > > if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MIN) { > > > > - uclamp_bucket_inc(&p->uclamp[UCLAMP_MIN], > > > > + uclamp_bucket_inc(p, &p->uclamp[UCLAMP_MIN], > > > > UCLAMP_MIN, lower_bound); > > > > } > > > > if (attr->sched_flags & SCHED_FLAG_UTIL_CLAMP_MAX) { > > > > - uclamp_bucket_inc(&p->uclamp[UCLAMP_MAX], > > > > + uclamp_bucket_inc(p, &p->uclamp[UCLAMP_MAX], > > > > UCLAMP_MAX, upper_bound); > > > > } > > > > mutex_unlock(&uclamp_mutex); > > > > > > > > > But.... __sched_setscheduler() actually does the whole dequeue + enqueue > > > thing already ?!? See where it does __setscheduler(). > > > > This is slow-path accounting, not fast path. > > Sure; but that's still no reason for duplicate or unneeded code. > > > There are two refcounting going on here: > > > > 1) mapped buckets: > > > > clamp_value <--(M1)--> bucket_id > > > > 2) RUNNABLE tasks: > > > > bucket_id <--(M2)--> RUNNABLE tasks in a bucket > > > > What we fix here is the refcounting for the buckets mapping. If a task > > does not have a task specific clamp value it does not refcount any > > bucket. The moment we assign a task specific clamp value, we need to > > refcount the task in the bucket corresponding to that clamp value. > > > > This will keep the bucket in use at least as long as the task will > > need that clamp value. > > Sure, I get that. What I don't get is why you're adding that (2) here. > Like said, __sched_setscheduler() already does a dequeue/enqueue under > rq->lock, which should already take care of that. Oh, ok... got it what you mean now. With: [PATCH v6 01/16] sched/core: Allow sched_setattr() to use the current policy <20190115101513.2822-2-patrick.bellasi@arm.com> we can call __sched_setscheduler() with: attr->sched_flags & SCHED_FLAG_KEEP_POLICY whenever we want just to change the clamp values of a task without changing its class. Thus, we can end up returning from __sched_setscheduler() without doing an actual dequeue/enqueue. This is likely the most common use-case. I'll better check if I can propagate this info and avoid M2 if we actually did a dequeue/enqueue. Cheers Patrick -- #include Patrick Bellasi