From patchwork Mon Nov 26 12:20:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 152036 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5604886ljp; Mon, 26 Nov 2018 04:21:20 -0800 (PST) X-Google-Smtp-Source: AFSGD/UnuVU2/N1m92835yDHJnYk9eZeHJW46pNy1uBMkAjirEPjK5edG8ce1WSZmJxT661HgmyV X-Received: by 2002:a17:902:ba89:: with SMTP id k9mr27850322pls.189.1543234880024; Mon, 26 Nov 2018 04:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543234880; cv=none; d=google.com; s=arc-20160816; b=KpkJdzyjoKbQVj18d9g70O1r6GLjlD+dBCrEaahm3RG/ptlUUJCDhyHssigDp9xNN9 uXpwwnNjEAoqYPE9oVsz9zAQcsi8VS1rr7PIk0ghtfrYvbIdJLxNiUIh9Cf4qs+ZDXW4 1QB1Vrf47D+oE2GueIcDyd78zl16ZgWthq3aq/DvgS3omRqAJyh9LoCb1nPBwdW9pbga CN2ALV/OEu4wregA6ybZWnj95bI2aHJAyz2o2QmvMekZZiHjPAqbERI9R/dFnPk+395/ b7LuAeXT/YjVzISUa6KkIgF8iT03dzwknRWZG95nxTHUz0xuYIgGjCEgX1ZFo3Zd9C4s WgTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=He3pqGo+A5MVuYP3nfDqw4JkRlqG2IIP4aWgZQSIRFM=; b=hETIwBf+RWn8ns6MEG8AQZcaU0a5oHZq6OpsB0mTSP5J7yTh2RxaSRf1kUR7tH3cre eOGo68g6sY1mmbHpn2GTb2vfaEIu6LGmwlTWPs271Q87ODVxDsRjGxWYnji/x2vW+3KE YGpV3m/whUPknGrCQr4yQoj+yiNBsaBvPmlfJhyKsQLrV8kxNs9PL3YfwpX/7f63KFY+ X15vWm84IgxKMDKDEGHBlx8vOKhO0JLT+xsPTaO0ISl1g4juLj8StWM5THGWEsCcyi5Z z6W6JaNnz3VUbxHYst51gOJHLVygHmhFb/tULMJAyy1UxuYQGLVyAo/KkRs+q6P8IHkO KuwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=f4T87ttq; 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 14si136744pgo.511.2018.11.26.04.21.10; Mon, 26 Nov 2018 04:21:20 -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; dkim=pass header.i=@linaro.org header.s=google header.b=f4T87ttq; 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 S1726316AbeKZXPG (ORCPT + 32 others); Mon, 26 Nov 2018 18:15:06 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:39744 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbeKZXPF (ORCPT ); Mon, 26 Nov 2018 18:15:05 -0500 Received: by mail-wr1-f66.google.com with SMTP id t27so10708111wra.6 for ; Mon, 26 Nov 2018 04:21:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=He3pqGo+A5MVuYP3nfDqw4JkRlqG2IIP4aWgZQSIRFM=; b=f4T87ttqxfXMkxkMFjaaUtNeegOzIVywlwwfgBmZLktSBk4/SWb2FgNu9PxITbbEZj VseJ+Px7bxQIMYv0ErYIq+YoOnWyfc4D2aSds04k9A40m66EAI1gwai0HhEMkRG8NgeB KPv40xgyxLZzB7TXnoulxCuDl12gFDRBxM4vI= 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; bh=He3pqGo+A5MVuYP3nfDqw4JkRlqG2IIP4aWgZQSIRFM=; b=CDvPTR/AghNNhi3XvVXwv0q7BU+WgzIhHSKRwkpZOdYdTfbv/Ji8iYQ4rbME1zYQ/V S4CusAOBGuwy21d0qVQQtE0SugT/b6O3JHCSfQ1zzytzBvlywieCBsnoQKPGXQpP/1SF fkWRwBgp/dwkH8jxlIDrEsLBYoLj6vBuZz5eH6v1hKASxs/4SkuekHOhMx3f6uMj1ZCc ZnHhxIPA1fU0/44f2XL4RHyHhkQyj7Mxh7Rxsb1VDqT7McjhxzeSX2TbnaVuXdNUsc71 D3LBqS6CBy63QwGBeOHZ10ftqeAFKcvv3oVWvZ4NcAkinKz03YvFofPTOaMNg4vb485a zD5A== X-Gm-Message-State: AA+aEWYaJtU67kKRfdgYtMTLzr37Ef1LgQ9pFjilxasHfWjM2nXSo8tA nKXlDGnBJWM28K9wnVpNqW5nhw== X-Received: by 2002:adf:d089:: with SMTP id y9mr23701218wrh.22.1543234866308; Mon, 26 Nov 2018 04:21:06 -0800 (PST) Received: from localhost.localdomain (72.224.136.77.rev.sfr.net. [77.136.224.72]) by smtp.gmail.com with ESMTPSA id r76-v6sm797816wmb.21.2018.11.26.04.21.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Nov 2018 04:21:05 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: linux-kernel@vger.kernel.org, viresh.kumar@linaro.org, Sudeep Holla , Greg Kroah-Hartman , "Rafael J. Wysocki" , "Peter Zijlstra (Intel)" , Ingo Molnar , Juri Lelli , Morten Rasmussen Subject: [PATCH V4 1/2] base/drivers/arch_topology: Replace mutex with READ_ONCE / WRITE_ONCE Date: Mon, 26 Nov 2018 13:20:42 +0100 Message-Id: <1543234847-21611-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 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 Cc: Sudeep Holla Reviewed-by: Viresh Kumar --- drivers/base/arch_topology.c | 7 +------ include/linux/arch_topology.h | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) -- 2.7.4 Acked-by: Rob Herring diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index edfcf8d..fd5325b 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -31,12 +31,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, @@ -71,10 +70,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); schedule_work(&update_topology_flags_work); @@ -141,7 +138,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]); @@ -151,7 +147,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 d9bdc1a..12c439f 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -20,7 +20,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);