Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5492344imm; Wed, 12 Sep 2018 06:50:43 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZtCAp/lrjPZH/FrsMLxVf91WIHS4WdyauXoCUUOMrdrgyO+vWGX6wE3UFDHbckYohssczW X-Received: by 2002:a62:1192:: with SMTP id 18-v6mr2533404pfr.54.1536760243494; Wed, 12 Sep 2018 06:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536760243; cv=none; d=google.com; s=arc-20160816; b=n+1pNJRenWLYeBhTqP4fNtbmVfSlx2wOdRsV3wU7bF6LvRp0osTbWD1MvANVBXeHIP EjrzbYHDIGVLHrzHuAvekyOWA011WI+2Y6q2hsFhNR1DOYxOSRqdJuzc0Fup4mxrpW6v LvN4Gw7JR8Sfh/K8P3669RdIO+f9WsrrwYi8iC8iBuGXil/46CHARR2Dl1z7j3vOICD4 zr+OZi3vfyz1mpxvpA/ZLaH9ZYE15q7LZD8o3W2Xjt9V6l+T6A7LXWKku1gh9K7XuDpR DQ0Dcs+Ez5NbyGcsK+zJWrU8/I4tDGsqa0GvR9cl/drusoYtwjUojQKS2n4QgNyhZ4Bi LqWQ== 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=Mp0YXKFlQIq/FJvz2sWZBGc7Ylr8qJapgT2GhAH03n0=; b=BPzMn/2SR7flBhjHomFujAjzqNm6Cn0tfLPVyMkIKbrWDcYbwQnFZPEMD3pLogNWxh QNl1TVJGps/OTx2I5AMAd2+EfFmKrjhZqtaUueXx4d0D6GA7rrNK6Ye5eYBRQ3UgdldJ 4VSKKY5Z4M1q1HUidllf0NBubbS4HtKvvR+D2CPLWcVZuwyktw3NSHF4nv4TimCh5HUk 7VMLdzINPMMTeMTT/pbw40L8rhR0SnF+CO9qA/0vdPHpLJa9aFgxspnM0R3R7kxdFrCa O8ino6qxuFEViQQ+gJeWh0em2eBXOFdJ7+EA3y4YgSLVsmJFv2YgCRvQaRq0FhSpYvc4 sIdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=e8Riz9nI; 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 184-v6si1053508pgj.421.2018.09.12.06.50.28; Wed, 12 Sep 2018 06:50: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=merlin.20170209 header.b=e8Riz9nI; 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 S1727051AbeILSyh (ORCPT + 99 others); Wed, 12 Sep 2018 14:54:37 -0400 Received: from merlin.infradead.org ([205.233.59.134]:44262 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726792AbeILSyh (ORCPT ); Wed, 12 Sep 2018 14:54:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=Mp0YXKFlQIq/FJvz2sWZBGc7Ylr8qJapgT2GhAH03n0=; b=e8Riz9nIdRlcnmcZeDxZZtlFG dsW8wq3BZ3nBmSYq/Tx4N2YddtRuDl52OpFmjJecIsEoZ6g8EiSozj27gDXwtS6LgF1NptP7EqRGi PAFbqliXsASaXkkgeSgK7MDwGwaJOZQ2DKBkFuh9k3e8YZ8lJj31QbYUr548FoVNhFaLdNcoZo7vQ 1mGIK4odUChdlcFzt0d4CMhNSwhKYgLvQkrSwKycTzb4gihPiiviUEVxfRLnZTcKH5xTGJSQxkKZv Pw/N9xSHbrDK05fsoXd3x1P6leGRB/bqQWm3KqeBPCpy0aS1LQLP8EvPjQsF1Zhp50xT4uJhcyUZn NFW344z1g==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g05Wd-000367-NR; Wed, 12 Sep 2018 13:49:48 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 211D7202C1A2E; Wed, 12 Sep 2018 15:49:45 +0200 (CEST) Date: Wed, 12 Sep 2018 15:49:45 +0200 From: Peter Zijlstra To: Patrick Bellasi Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v4 02/16] sched/core: uclamp: map TASK's clamp values into CPU's clamp groups Message-ID: <20180912134945.GZ24106@hirez.programming.kicks-ass.net> References: <20180828135324.21976-1-patrick.bellasi@arm.com> <20180828135324.21976-3-patrick.bellasi@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180828135324.21976-3-patrick.bellasi@arm.com> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 28, 2018 at 02:53:10PM +0100, Patrick Bellasi wrote: > +/** > + * Utilization's clamp group > + * > + * A utilization clamp group maps a "clamp value" (value), i.e. > + * util_{min,max}, to a "clamp group index" (group_id). > + */ > +struct uclamp_se { > + unsigned int value; > + unsigned int group_id; > +}; > +/** > + * uclamp_map: reference counts a utilization "clamp value" > + * @value: the utilization "clamp value" required > + * @se_count: the number of scheduling entities requiring the "clamp value" > + * @se_lock: serialize reference count updates by protecting se_count Why do you have a spinlock to serialize a single value? Don't we have atomics for that? > + */ > +struct uclamp_map { > + int value; > + int se_count; > + raw_spinlock_t se_lock; > +}; > + > +/** > + * uclamp_maps: maps each SEs "clamp value" into a CPUs "clamp group" > + * > + * Since only a limited number of different "clamp values" are supported, we > + * need to map each different clamp value into a "clamp group" (group_id) to > + * be used by the per-CPU accounting in the fast-path, when tasks are > + * enqueued and dequeued. > + * We also support different kind of utilization clamping, min and max > + * utilization for example, each representing what we call a "clamp index" > + * (clamp_id). > + * > + * A matrix is thus required to map "clamp values" to "clamp groups" > + * (group_id), for each "clamp index" (clamp_id), where: > + * - rows are indexed by clamp_id and they collect the clamp groups for a > + * given clamp index > + * - columns are indexed by group_id and they collect the clamp values which > + * maps to that clamp group > + * > + * Thus, the column index of a given (clamp_id, value) pair represents the > + * clamp group (group_id) used by the fast-path's per-CPU accounting. > + * > + * NOTE: first clamp group (group_id=0) is reserved for tracking of non > + * clamped tasks. Thus we allocate one more slot than the value of > + * CONFIG_UCLAMP_GROUPS_COUNT. > + * > + * Here is the map layout and, right below, how entries are accessed by the > + * following code. > + * > + * uclamp_maps is a matrix of > + * +------- UCLAMP_CNT by CONFIG_UCLAMP_GROUPS_COUNT+1 entries > + * | | > + * | /---------------+---------------\ > + * | +------------+ +------------+ > + * | / UCLAMP_MIN | value | | value | > + * | | | se_count |...... | se_count | > + * | | +------------+ +------------+ > + * +--+ +------------+ +------------+ > + * | | value | | value | > + * \ UCLAMP_MAX | se_count |...... | se_count | > + * +-----^------+ +----^-------+ > + * | | > + * uc_map = + | > + * &uclamp_maps[clamp_id][0] + > + * clamp_value = > + * uc_map[group_id].value > + */ > +static struct uclamp_map uclamp_maps[UCLAMP_CNT] > + [CONFIG_UCLAMP_GROUPS_COUNT + 1] > + ____cacheline_aligned_in_smp; > + I'm still completely confused by all this. sizeof(uclamp_map) = 12 that array is 2*6=12 of those, so the whole thing is 144 bytes. which is more than 2 (64 byte) cachelines. What's the purpose of that cacheline align statement? Note that without that apparently superfluous lock, it would be 8*12 = 96 bytes, which is 1.5 lines and would indeed suggest you default to GROUP_COUNT=7 by default to fill 2 lines. Why are the min and max things torn up like that? I'm fairly sure I asked some of that last time; but the above comments only try to explain what, not why.