From patchwork Mon Oct 29 16:23:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 149683 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4348503ljp; Mon, 29 Oct 2018 09:23:52 -0700 (PDT) X-Google-Smtp-Source: AJdET5faWWAG0PUlmtlHINLEGllsrti9Mmb8hFTGxqSVzCG+XCxBPkvgQA4X/Fsp8AmRxPTE35aF X-Received: by 2002:a63:a902:: with SMTP id u2-v6mr14534392pge.207.1540830232356; Mon, 29 Oct 2018 09:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540830232; cv=none; d=google.com; s=arc-20160816; b=TfTQ/W1ss5jTXdZFs9BLHUQBEszy8QyLHiBZU4om6SEONFuUPrdSrw8uuj3qtX9BkY ++d4ENa/NOzzCnF5RON11M7YR+HQGR1D2HnOe5zCDLvOsKJwrUBWcqMIwnr7F/E6VQ1Y CUOSRLIcLGMzEuN1G6rYSHFOl54JxPbcnH4UjCT6AjcC8D7211/5ofwXee+kL3+19ZW7 7U1EkB6t+gJyZ/RG1xuI+wqEGshjg/XArBqIekk8b8Ja1xeeG0M960gv/C+zT6Mlu3lo MN6Mc3E955RoS4WiTyxhzFKYksM/wNRQi4DD6P/kh58i7fyukH9biyA2gY2h1VbsF9y0 aMeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=xF7JxkKvdHK/anNbLW0P/RgEA6x91dDlC16uGRsXEpA=; b=ZDxZKxDfuj33f4IAp/fhmdQJHOM6xAlyfW6rJhWttkY4FlVCT5beJ6ZBnxI61UqebB B22BTd4h9Eevx1fT0E+tQ9T3uArJzXE9pVC29xuA79Xzamc5tT4RhavUYmT2/7wjchek Y1vdSHfELlxCTpa6AddOXSn4sff5ZNhaYM4AJgdOQyjcAdxVDpZXLfpUw4Zo/fEEga49 i33YCMDLrR+mvFQTFH5ahVnFRuu50d6tJeuXU23wjND+xR194fcO3OMEmCwzSBXi0Bf2 8KIke3nH4lFXQHWSd21FjqjVcv8/3NPonT9juQ8RCphT8/1xt9d39PnXNHTIMZiqYNK+ IBPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=I3oAfEOw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 63-v6si20701245pfg.178.2018.10.29.09.23.51; Mon, 29 Oct 2018 09:23:52 -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=pass header.i=@linaro.org header.s=google header.b=I3oAfEOw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728103AbeJ3BNH (ORCPT + 32 others); Mon, 29 Oct 2018 21:13:07 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38114 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727565AbeJ3BNH (ORCPT ); Mon, 29 Oct 2018 21:13:07 -0400 Received: by mail-wr1-f68.google.com with SMTP id d10-v6so9384639wrs.5 for ; Mon, 29 Oct 2018 09:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xF7JxkKvdHK/anNbLW0P/RgEA6x91dDlC16uGRsXEpA=; b=I3oAfEOwOHRbCq+1bEpOrnF5NMYcJDSEE7M8MADPyMAICoYRO2BM1rjUeHmo920khB ATeS1j1vfRprif6Ph3vekUkcxzeGVgu1w461KLQ18IcpJqjV5EJ7SirEMuEja8/oAWd0 55TMbF5vQdelAR5s+HcQTn9Yp3TyFiJocWQTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xF7JxkKvdHK/anNbLW0P/RgEA6x91dDlC16uGRsXEpA=; b=ArEHtBXUpcECHX3AayC+g/k2L6wSylSRJX2Ic2+lOkxjX/x9ame5lB2RDJtE2y+BCJ zXCdl/qF1B3gxxGCx7md655Kidr3WohxPjv9PawU0U2K3z71UpgGqxzgdiaq7z/kVoT6 91qVi7aSY6DTxJePRCMLAv0sm90wam1vJ62lh7oK0g3/MSnpDXJo6ZXcJwdxedHYSCsz 1XzS2VgUNH5/a/f0Pa3y79mM/NWEgZ1uzLJn/9XECXYfvwXofCqBEhbKCgO3/gltdtI2 2vAreYZ0ast6AWZdzwelMRnOI6PGVj8IcTTcRUUcHms8g4N0YxL4HBJS9QpwuuU11Bpu q/7g== X-Gm-Message-State: AGRZ1gL/k1k6+SMXHw4MXv1vVGgnfntuQC1aurH4rVMjMOYY8k6rMupl Q+tBLYSDDrGRy+i032+THUNBQw== X-Received: by 2002:adf:8281:: with SMTP id 1-v6mr15560623wrc.252.1540830228052; Mon, 29 Oct 2018 09:23:48 -0700 (PDT) Received: from localhost.localdomain (137.55.88.92.rev.sfr.net. [92.88.55.137]) by smtp.gmail.com with ESMTPSA id y19-v6sm28150499wra.60.2018.10.29.09.23.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Oct 2018 09:23:47 -0700 (PDT) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: vincent.guittot@linaro.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , Kate Stewart , Juri Lelli , Thomas Gleixner , "Peter Zijlstra (Intel)" Subject: [PATCH 2/4] base/drivers/arch_topology: Replace mutex with READ_ONCE / WRITE_ONCE Date: Mon, 29 Oct 2018 17:23:18 +0100 Message-Id: <1540830201-2947-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1540830201-2947-1-git-send-email-daniel.lezcano@linaro.org> References: <1540830201-2947-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mutex protects a per_cpu variable access. The potential race can happen only when the cpufreq governor module is loaded and at the same time the cpu capacity is changed in the sysfs. There is no real interest of using a mutex to protect a variable assignation when there is no situation where a task can take the lock and block. Replace the mutex by READ_ONCE / WRITE_ONCE. Signed-off-by: Daniel Lezcano --- drivers/base/arch_topology.c | 7 +------ include/linux/arch_topology.h | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) -- 2.7.4 Reviewed-by: Viresh Kumar diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 204ed10..b19d6d4 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -30,12 +30,11 @@ void arch_set_freq_scale(struct cpumask *cpus, unsigned long cur_freq, per_cpu(freq_scale, i) = scale; } -static DEFINE_MUTEX(cpu_scale_mutex); DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE; void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity) { - per_cpu(cpu_scale, cpu) = capacity; + WRITE_ONCE(per_cpu(cpu_scale, cpu), capacity); } static ssize_t cpu_capacity_show(struct device *dev, @@ -67,10 +66,8 @@ static ssize_t cpu_capacity_store(struct device *dev, if (new_capacity > SCHED_CAPACITY_SCALE) return -EINVAL; - mutex_lock(&cpu_scale_mutex); for_each_cpu(i, &cpu_topology[this_cpu].core_sibling) topology_set_cpu_scale(i, new_capacity); - mutex_unlock(&cpu_scale_mutex); return count; } @@ -116,7 +113,6 @@ void topology_normalize_cpu_scale(void) return; pr_debug("cpu_capacity: capacity_scale=%u\n", capacity_scale); - mutex_lock(&cpu_scale_mutex); for_each_possible_cpu(cpu) { pr_debug("cpu_capacity: cpu=%d raw_capacity=%u\n", cpu, raw_capacity[cpu]); @@ -126,7 +122,6 @@ void topology_normalize_cpu_scale(void) pr_debug("cpu_capacity: CPU%d cpu_capacity=%lu\n", cpu, topology_get_cpu_scale(NULL, cpu)); } - mutex_unlock(&cpu_scale_mutex); } bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index 2b70941..7c0aaa9 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -19,7 +19,7 @@ struct sched_domain; static inline unsigned long topology_get_cpu_scale(struct sched_domain *sd, int cpu) { - return per_cpu(cpu_scale, cpu); + return READ_ONCE(per_cpu(cpu_scale, cpu)); } void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);