Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6419909imu; Mon, 21 Jan 2019 08:35:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN54JGZSXPVyuvbxJHZHaiKYZT+KnK7I6JGdK86/6gNY5uGWRFfe8DW5Eh572Z32fgAp8CJl X-Received: by 2002:a17:902:b282:: with SMTP id u2mr31180537plr.89.1548088519449; Mon, 21 Jan 2019 08:35:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548088519; cv=none; d=google.com; s=arc-20160816; b=Eqei/fFZlac51Q2ZXKsW83/oho8bm9E4JrIodSPwlnE1VoXr1i7kMGCccJnATI0gBg jPAsrCB9ORxYkvGlqfde1vOUj8xxaHjRb/HzLnXwhoEbV+/rBjNSVt8SYz+yB2mFTl1+ paOBkysIHPnbDM2xFUlWJ0vX5t6GkkmbOvuoIHRL64VitiUDkaZJYErWyL2I4zZhDkDf eZxObI87wfalabFKMtaiIdnUr0mXYPD4qZcW8MUHN/PpIJoI+3p1u6ekhq9NEyJgDn1m kWTdyd20u7Ri3U+7oSDuQQEiXkIyza+pJk4VUO98w2aSadXyVb8pwC2H0NWpfxxRImpY 3nXg== 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=LW2dpqtODRoO4mViPjieF7PIlaSRi8jKyGg3atjwFRU=; b=iJH6016DmjYCff7aG6XJrrRXvy2ckOOQcNnvlz41jEVTGTkompfM9301QDTcMC6WIC K20+Rk52eBKrFWjQ6fLP9LH+L0B67FALzAYcmsSEqaYD2V2I5/GMpZmYtheBo2DLQmbL TfI60MF7d6nnrDebBJjVRWj4koGYgBeohKYgwIMI0g8lnXOtj0arqoIsjeaEndWAPkxT MCsxiwqDdRgt/PDt1mobKtyh/rKfoWIZ3AlluiK5F0M4iIQZFEMtJnmK+Acqc64fE7hY m6rntISb4J9qCZSDk9HubhzKia4EmoncKn/rGxsOkiGoIP6tGNwA4dlHJsO/2F3HSRjq v90g== 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 c13si5980052pgi.531.2019.01.21.08.34.57; Mon, 21 Jan 2019 08:35:19 -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 S1730412AbfAUQdo (ORCPT + 99 others); Mon, 21 Jan 2019 11:33:44 -0500 Received: from foss.arm.com ([217.140.101.70]:38574 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729870AbfAUQdo (ORCPT ); Mon, 21 Jan 2019 11:33:44 -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 7321015AB; Mon, 21 Jan 2019 08:33:43 -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 7EAC73F614; Mon, 21 Jan 2019 08:33:40 -0800 (PST) Date: Mon, 21 Jan 2019 16:33:38 +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 04/16] sched/core: uclamp: Add CPU's clamp buckets refcounting Message-ID: <20190121163337.6l7hkggicndtpzjs@e110439-lin> References: <20190115101513.2822-1-patrick.bellasi@arm.com> <20190115101513.2822-5-patrick.bellasi@arm.com> <20190121145929.GI27931@hirez.programming.kicks-ass.net> <20190121152311.7u7bwbjopuptnzcy@e110439-lin> <20190121161237.GB13777@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190121161237.GB13777@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 21-Jan 17:12, Peter Zijlstra wrote: > On Mon, Jan 21, 2019 at 03:23:11PM +0000, Patrick Bellasi wrote: > > On 21-Jan 15:59, Peter Zijlstra wrote: > > > On Tue, Jan 15, 2019 at 10:15:01AM +0000, Patrick Bellasi wrote: > > > > @@ -835,6 +954,28 @@ static void uclamp_bucket_inc(struct uclamp_se *uc_se, unsigned int clamp_id, > > > > } while (!atomic_long_try_cmpxchg(&uc_maps[bucket_id].adata, > > > > &uc_map_old.data, uc_map_new.data)); > > > > > > > > + /* > > > > + * Ensure each CPU tracks the correct value for this clamp bucket. > > > > + * This initialization of per-CPU variables is required only when a > > > > + * clamp value is requested for the first time from a slow-path. > > > > + */ > > > > > > I'm confused; why is this needed? > > > > That's a lazy initialization of the per-CPU uclamp data for a given > > bucket, i.e. the clamp value assigned to a bucket, which happens only > > when new clamp values are requested... usually only at system > > boot/configuration time. > > > > For example, let say we have these buckets mapped to given clamp > > values: > > > > bucket_#0: clamp value: 10% (mapped) > > bucket_#1: clamp value: 20% (mapped) > > bucket_#2: clamp value: 30% (mapped) > > > > and then let's assume all the users of bucket_#1 are "destroyed", i.e. > > there are no more tasks, system defaults or cgroups asking for a > > 20% clamp value. The corresponding bucket will become free: > > > > bucket_#0: clamp value: 10% (mapped) > > bucket_#1: clamp value: 20% (free) > > bucket_#2: clamp value: 30% (mapped) > > > > If, in the future, we ask for a new clamp value, let say a task ask > > for a 40% clamp value, then we need to map that value into a bucket. > > Since bucket_#1 is free we can use it to fill up the hold and keep all > > the buckets in use at the beginning of a cache line. > > > > However, since now bucket_#1 tracks a different clamp value (40 > > instead of 20) we need to walk all the CPUs and updated the cached > > value: > > > > bucket_#0: clamp value: 10% (mapped) > > bucket_#1: clamp value: 40% (mapped) > > bucket_#2: clamp value: 30% (mapped) > > > > Is that more clear ? > > Yes, and I realized this a little while after sending this; but I'm not > sure I have an answer to why though. > > That is; why isn't the whole thing hard coded to have: > > bucket_n: clamp value: n*UCLAMP_BUCKET_DELTA > > We already do that division anyway (clamp_value / UCLAMP_BUCKET_DELTA), > and from that we instantly have the right bucket index. And that allows > us to initialize all this beforehand. > > > and keep all > > the buckets in use at the beginning of a cache line. > > That; is that the rationale for all this? Note that per the defaults > everything is in a single line already. Yes, that's because of the loop in: dequeue_task() uclamp_cpu_dec() uclamp_cpu_dec_id() uclamp_cpu_update() where buckets needs sometimes to be scanned to find a new max. Consider also that, with mapping, we can more easily increase the buckets count to 20 in order to have a finer clamping granularity if needed without warring too much about performance impact especially when we use anyway few different clamp values. So, I agree that mapping adds (code) complexity but it can also save few cycles in the fast path... do you think it's not worth the added complexity? TBH I never did a proper profiling w/-w/o mapping... I'm just worried in principle for a loop on 20 entries spanning 4 cache lines. :/ NOTE: the loop is currently going through all the entries anyway, but we can add later a guard to bail out once we covered the number of active entries. -- #include Patrick Bellasi