Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1257717imm; Tue, 2 Oct 2018 05:32:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV63ayvty+LImgGC0JNVIOjO+ruoKIrFkt25XzxgTjaETm61jcyBxkS1QrlIpZk/g7/tstdLU X-Received: by 2002:a17:902:720b:: with SMTP id ba11-v6mr16362249plb.199.1538483556146; Tue, 02 Oct 2018 05:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538483556; cv=none; d=google.com; s=arc-20160816; b=lX7yJvuJiO2kmGzBDikHNVa8jGAGyLJ1aTArN4KeiST0aSp9g7S+I7Ylyvedr7NyYn EZNUDu38bsbiBivSeIaJKVgECODXsaBSuu9epUub8+I63+w0G5wPiamSR1k6LTWpPaj4 vm3GJKecTcSi1nlJdbHB05LaET9KgTY3CqYjWjqKqx3Z/mPQniVN6WC8dOGS58y/wBe4 93ClRmlVavwScVTnWGPB+Ic65DojW5whOBjuZqUoHJy7Cm3Zv6q8+eDWCyOlOnq73mwp nxFL1855wMoCwTzhnfdGVyDoXc0IH600XTMQCWUGId9FMfiv/cLgnMgPgEcX3U7yOiVs Gfww== 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=HSr3FhwV9XplMIOZboEhtSsPPSBy1VziUnZk167T0vI=; b=h044hFeySoJitmM0uhd7qH1mv7+Ch5/Jm0qb9EZ/UfLx80YbIuDatbLSubBSj2skEo JJsyx4f8ukxJGWwl/UUJcoXCVUINZLySpoi6S3/fFcm5PQ4cgrXYNbTDi4GC30q7J42+ kunn4DpA5Hb4GpL5G9hAZ66dzY49vjyH0hZ2mMTFtNpypsaCCZasxaXEMEtgSV8nuNDt v6254SXPA2F4kbn+r2pIKX28nupkXxZWhKDqlJUvN3kLnCVsKjFPn8sLuVEYcyGyuS9D 1PJPfdgpdMTXhnWddwcH+V9a++HeBSVncioH9NWb9DCXEDoliOjIxPVDt4sTHPRmWcgJ AUyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Q7GzRv3W; 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 w15-v6si14904091pgc.366.2018.10.02.05.32.21; Tue, 02 Oct 2018 05:32:36 -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=bombadil.20170209 header.b=Q7GzRv3W; 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 S1727830AbeJBTNq (ORCPT + 99 others); Tue, 2 Oct 2018 15:13:46 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:53944 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727562AbeJBTNq (ORCPT ); Tue, 2 Oct 2018 15:13:46 -0400 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=HSr3FhwV9XplMIOZboEhtSsPPSBy1VziUnZk167T0vI=; b=Q7GzRv3WrRNOvBMPSnSV7gfO6 aWHDcHAPG9SRuUL1sRopj8TKdd4wjcyzoQ+xi7HsqwYKruJWnLL8RLp7xqqCFwONKMJExjm+lhFzl iuKTQZUKKWpg7E1COyULRoeQQcBywcNrCUAAbQ68+mVqeVt9AWvceVB36IKWvaE766TZh2jWmFbGN oYXioNdoACdMnbltvXGNaVf5ALCfNCfkncZaxsQNYoXifXeASWI4Wz/0SBThN5ndYHPAZiWLVIwrt Wv18/kazWmMPstIX44qCvoYy7AMBc9/LiRsPJapkvT2q8OGauXE7wVpVj3R2cb4Si+bloM9VqEQFw +LZoTCmjA==; 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 1g7Jov-0005dg-R3; Tue, 02 Oct 2018 12:30:34 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id A4DAD2025A349; Tue, 2 Oct 2018 14:30:31 +0200 (CEST) Date: Tue, 2 Oct 2018 14:30:31 +0200 From: Peter Zijlstra To: Quentin Perret Cc: rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, gregkh@linuxfoundation.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, joel@joelfernandes.org, smuckle@google.com, adharmap@codeaurora.org, skannan@codeaurora.org, pkondeti@codeaurora.org, juri.lelli@redhat.com, edubezval@gmail.com, srinivas.pandruvada@linux.intel.com, currojerez@riseup.net, javi.merino@kernel.org Subject: Re: [PATCH v7 03/14] PM: Introduce an Energy Model management framework Message-ID: <20181002123031.GZ3439@hirez.programming.kicks-ass.net> References: <20180912091309.7551-1-quentin.perret@arm.com> <20180912091309.7551-4-quentin.perret@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180912091309.7551-4-quentin.perret@arm.com> 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 Wed, Sep 12, 2018 at 10:12:58AM +0100, Quentin Perret wrote: > +/** > + * em_register_perf_domain() - Register the Energy Model of a performance domain > + * @span : Mask of CPUs in the performance domain > + * @nr_states : Number of capacity states to register > + * @cb : Callback functions providing the data of the Energy Model > + * > + * Create Energy Model tables for a performance domain using the callbacks > + * defined in cb. > + * > + * If multiple clients register the same performance domain, all but the first > + * registration will be ignored. > + * > + * Return 0 on success > + */ > +int em_register_perf_domain(cpumask_t *span, unsigned int nr_states, > + struct em_data_callback *cb) > +{ > + unsigned long cap, prev_cap = 0; > + struct em_perf_domain *pd; > + int cpu, ret = 0; > + > + if (!span || !nr_states || !cb) > + return -EINVAL; > + > + /* > + * Use a mutex to serialize the registration of performance domains and > + * let the driver-defined callback functions sleep. > + */ > + mutex_lock(&em_pd_mutex); > + > + for_each_cpu(cpu, span) { > + /* Make sure we don't register again an existing domain. */ > + if (READ_ONCE(per_cpu(em_data, cpu))) { > + ret = -EEXIST; > + goto unlock; > + } > + > + /* > + * All CPUs of a domain must have the same micro-architecture > + * since they all share the same table. > + */ > + cap = arch_scale_cpu_capacity(NULL, cpu); > + if (prev_cap && prev_cap != cap) { > + pr_err("CPUs of %*pbl must have the same capacity\n", > + cpumask_pr_args(span)); > + ret = -EINVAL; > + goto unlock; > + } > + prev_cap = cap; > + } > + > + /* Create the performance domain and add it to the Energy Model. */ > + pd = em_create_pd(span, nr_states, cb); > + if (!pd) { > + ret = -EINVAL; > + goto unlock; > + } > + > + for_each_cpu(cpu, span) > + WRITE_ONCE(per_cpu(em_data, cpu), pd); It's not immediately obvious to me why this doesn't need to be smp_store_release(). The moment you publish that pointer, it can be read, right? Even if you never again change the pointer value, you want to ensure the content of pd is stable before pd itself is observable, right? > + > + pr_debug("Created perf domain %*pbl\n", cpumask_pr_args(span)); > +unlock: > + mutex_unlock(&em_pd_mutex); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(em_register_perf_domain); > -- > 2.18.0 >