Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7184584imu; Tue, 22 Jan 2019 01:39:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN5i0bexuUghNzMW+nMgae0kQvBvl7rcGmIn+vhBQ5WqkPiZIV5AvZ7FPLZYcj8WcCeqSd7u X-Received: by 2002:a63:d904:: with SMTP id r4mr31402441pgg.207.1548149975840; Tue, 22 Jan 2019 01:39:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548149975; cv=none; d=google.com; s=arc-20160816; b=krZCO9fvi392A+gWd+aKka8PrlMbjrnK7QttPCIgj/ZoowhdTihCRRFkAg6CzneFWr 6QJjlR2EJv0FaJD3evI68m2GlU95hdu9sctVMEA5uOtvWLXIwSDkBWrEx68K+5JU2/Jc r2mGOUaVVsRBCt4EIOchljOzIC3PhRu0+M386ZXhDIQVcxR53fDr62EEmGZ5OKWchv+R NbOUmPuFObM4NibunId2Hjk4Cgcv0w0NTmuSCfBvDkKiedsQsoKpukMhvk4xpx+l1ZrZ BI5DsTr7njEnKBgATd7s2wjedYBxkF4hbJ/vKqAFK24/pq9k3lTE5QRKm7tGf0lLKHHT /Xpg== 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=NU4V5uCQmV84QkTw0S+I2r8MuzPTPNrPYuSs+2uS5y4=; b=Le3MIlOstb05aXPf2BR/2KuXDe1SZVv/UizMSgtBuria7yNQAHiPupNEQ8vHMpH3Tz C2I5nMRm2bfJBm4YHP7r8Mdku6pHaWtMyOdRJ/ZJSA/XjCWEOMfHLgxhQbl1KZYQfwuq z6dLLnPhy7UpDjpw6XQ5tg1y9R4BE51eBLMpwAHNv+ZP9qM9H9S46mFx9LH6ezhSzI2S fUFxL1HLNvHXfLQkANhUSp3gdlgGImYcihkv+hZgNveHQCUkgX7b4u315dovn2Q/QdHh boNOOV5w2bPNuPGrCcuqwztrgVB9rTYdwq2FgN21B/dn80ZAD/tj9jS7r9xrQK7Hs/5+ l2ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PW0gNWBL; 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 k11si15521050pgh.132.2019.01.22.01.39.20; Tue, 22 Jan 2019 01:39:35 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=PW0gNWBL; 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 S1727919AbfAVJhM (ORCPT + 99 others); Tue, 22 Jan 2019 04:37:12 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:47758 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727026AbfAVJhL (ORCPT ); Tue, 22 Jan 2019 04:37:11 -0500 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=NU4V5uCQmV84QkTw0S+I2r8MuzPTPNrPYuSs+2uS5y4=; b=PW0gNWBLoYOCSz6mnwSOOsGrA Dxn2PRND+3H1sRQoZWifWHelGjQUeRKM/R8+nBIpI3flVLfRp9ZPQvC9emuHNTXk3hXHON6X4PKI2 qxk8UpjShmuoenwoZqSR4KmsetHZlfc+GS1BefEqhA2vxUCKMFbC6t5zBlS4t1zd0iMxQv3Ckk/ub lRfYeTKuZoqUErQEpzC0UAiMPlv52D8Po64jx7lw2tBqEVupQBrrwnwksfqG8mh+9mFLSNmBtlSvD /xz4BaeLTVf5pdqwBf0Sxx+uwypVB+o0tZDqd8XFvh8knuUAgnK0cpDpRHrkF8zbkVhuo+mTaYjoD mGYGy8N0g==; 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 1glsUU-0001FV-MW; Tue, 22 Jan 2019 09:37:06 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9B6BD211A59B4; Tue, 22 Jan 2019 10:37:04 +0100 (CET) Date: Tue, 22 Jan 2019 10:37:04 +0100 From: Peter Zijlstra To: Patrick Bellasi 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: <20190122093704.GM27931@hirez.programming.kicks-ass.net> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190121154412.fak2t2iquj3aixtu@e110439-lin> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.