Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5195568imm; Tue, 19 Jun 2018 06:41:17 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL6Ow2tZA7gxjPte/MTnDoIJLm1a3r2IyqlvcsB3muR3MVqCc4Aij3hrrV3KhpVHYQaGbqW X-Received: by 2002:a17:902:8206:: with SMTP id x6-v6mr18636769pln.220.1529415677268; Tue, 19 Jun 2018 06:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529415677; cv=none; d=google.com; s=arc-20160816; b=m+20UvhSGcX4asVL4oIi5HiIVCp+fyavTNL/uBzTMlAfzI3kfzE+9b7+rs/SCp7s/V keEqfDBstri1SwfiKxfPHyVvn2gR+oiMzVnrnNBschBEljZZP9u5twbXN6hAPmgeSrTe napwADHTXFoAL4BOR/wwgBWWoltbUY2XrPfxWeGV1XlzXACT0sLmGpKzo0wJEpUf0GI6 fGx1U/oV9FrKF5tBg1DCB+7/KCYm8UQ6C8oBXWWwUFqbfcq3j73v2cxrE9RmNFRYQ9DM FrluIYJp3xCwwny8pKNtgIgeqN1Hva/Svw2mEaQ67T2k7AIR66RT7gLkAEcpHBB1Y3Dg h7tg== 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:arc-authentication-results; bh=Tn05rQG7QGKclw4A7d1Y0HSxOq1NEuiJU+nMozhmZ9c=; b=WhHAwRzG6CqaTA1cnlP1VWXqSHXN9QVvbQvxUszndAQjrenULRokUkZPvJO7mgansF dTrPBWs+iXfuEla88eoLHpAnHh82j3WN5rjq4MreXP/AhMB/ZFqx7hk8oB4G78/0sS0P 9eHT/AIxwaBQmvEUV8OiCZs1ZDeU1QDMeNaZ1R7JJnkqsGcimDzGoOy7Ka+sWirGvrOG ee/Kiq5+Pn/7OJxTYTuFa3cLclKbXvYwT/tanI63jI+Co7QP+lsbNethVmVAIObT2Woj F9YQ+mI1emBGf8VcsNmPFFgu2wT4h1FZFKr2MfzeD/Ac3iPABDoM04+CT7e+j7lvWSsa gu8g== 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 c7-v6si16747129plo.47.2018.06.19.06.41.03; Tue, 19 Jun 2018 06:41:17 -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 S966078AbeFSNix (ORCPT + 99 others); Tue, 19 Jun 2018 09:38:53 -0400 Received: from foss.arm.com ([217.140.101.70]:50492 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965829AbeFSNiv (ORCPT ); Tue, 19 Jun 2018 09:38:51 -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 A752080D; Tue, 19 Jun 2018 06:38:50 -0700 (PDT) Received: from e108498-lin.cambridge.arm.com (e108498-lin.cambridge.arm.com [10.1.211.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B2CDE3F246; Tue, 19 Jun 2018 06:38:46 -0700 (PDT) Date: Tue, 19 Jun 2018 14:38:45 +0100 From: Quentin Perret To: Peter Zijlstra Cc: rjw@rjwysocki.net, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, mingo@redhat.com, dietmar.eggemann@arm.com, morten.rasmussen@arm.com, chris.redpath@arm.com, patrick.bellasi@arm.com, valentin.schneider@arm.com, vincent.guittot@linaro.org, thara.gopinath@linaro.org, viresh.kumar@linaro.org, tkjos@google.com, joelaf@google.com, smuckle@google.com, adharmap@quicinc.com, skannan@quicinc.com, pkondeti@codeaurora.org, juri.lelli@redhat.com, edubezval@gmail.com, srinivas.pandruvada@linux.intel.com, currojerez@riseup.net, javi.merino@kernel.org Subject: Re: [RFC PATCH v3 03/10] PM: Introduce an Energy Model management framework Message-ID: <20180619133844.GB17720@e108498-lin.cambridge.arm.com> References: <20180521142505.6522-1-quentin.perret@arm.com> <20180521142505.6522-4-quentin.perret@arm.com> <20180619113408.GQ2458@hirez.programming.kicks-ass.net> <20180619125857.GY17720@e108498-lin.cambridge.arm.com> <20180619132338.GF2476@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180619132338.GF2476@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.8.3 (2017-05-23) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tuesday 19 Jun 2018 at 15:23:38 (+0200), Peter Zijlstra wrote: > On Tue, Jun 19, 2018 at 01:58:58PM +0100, Quentin Perret wrote: > > On Tuesday 19 Jun 2018 at 13:34:08 (+0200), Peter Zijlstra wrote: > > > On Mon, May 21, 2018 at 03:24:58PM +0100, Quentin Perret wrote: > > > > +struct em_freq_domain *em_cpu_get(int cpu) > > > > +{ > > > > + struct em_freq_domain *fd; > > > > + unsigned long flags; > > > > + > > > > + read_lock_irqsave(&em_data_lock, flags); > > > > + fd = per_cpu(em_data, cpu); > > > > + read_unlock_irqrestore(&em_data_lock, flags); > > > > > > Why can't this use RCU? This is the exact thing read_locks are terrible > > > at and RCU excells at. > > > > So the idea was that clients (the scheduler for ex) can get a reference > > to a frequency domain object once, and they're guaranteed it always > > exists without asking for it again. > > > > For example, my proposal was to have the scheduler (patch 05) build its > > own private list of frequency domains on which it can iterate efficiently > > in the wake-up path. If we protect this per_cpu variable with RCU, then > > this isn't possible any-more. The scheduler will have to re-ask > > em_cpu_get() at every wake-up, and that makes iterating over frequency > > domains a whole lot more complex. > > > > Does that make any sense ? > > None what so ever... The lock doesn't guarantee stability any more than > RCU does. > > If you hand out the pointer and then drop the read-lock, the write-lock > can proceed and change the pointer right after you. > > The very easiest solution is to never change the data, as I think was > suggested elsewhere in the thread. Construct the thing once and then > never mutate. This is what is done actually. We will never write twice in the per_cpu array itself. One of the fields (the table) in the structure pointed from the per_cpu array can change, but not the pointer on the structure itself. The only reason this lock is here is to ensure the atomicity of the write happening in em_register_freq_domain. But that write can happen only once, the first time the frequency domain is registered. But maybe I could use something simpler than a lock in this case ? Would WRITE_ONCE/READ_ONCE be enough to ensure that atomicity for example ? Thanks, Quentin