From patchwork Thu Nov 22 12:36:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 151770 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp691291ljp; Thu, 22 Nov 2018 04:37:10 -0800 (PST) X-Google-Smtp-Source: AJdET5f+fU5jb7Ei+sSxW35yDHZcTTZujLdp4CFcbH2yGapJJMO4UASdsWAbgJvWJSpAq1suC5NE X-Received: by 2002:a62:6085:: with SMTP id u127-v6mr11796567pfb.147.1542890230121; Thu, 22 Nov 2018 04:37:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542890230; cv=none; d=google.com; s=arc-20160816; b=q/d+6wjN+Nh5NwG/C/qPUeaMEfsefYe/gCdJa4nNLWPUX7tSSCXIhqcpFVcyk4Sf52 EacOvOvJlYBMt8gbvzyef84yQRLuaNkfoglhJsFUt/u/h6DDMnqCiWzo9MvmhSTXayiI hYMSAZx39Xn2EjhqkLOb9KC4tBP/jECk1p+2EvP30FNksFQdD2OU8YIv/6JBM2uHVSWW 60YEu7XGSYhwTNZ5mAQ5i1PWvCASjaDMfJ2lthWKwki2ee0lL4IOeqd3zbTxUOi2KgqW BekT2mjHtX+5jt3sy+IMT8vW3qL/2uE1l9q2wPwxoJi/nb3ekpXwbPgCwKSTONCydGSk Cnpw== 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=niIh/rHDS6XLBwNgmCyNlCdvUUAHmIubbZxX7Az/O64=; b=gnTfLDT20bUaVMGft9puMXEpNA3rikRPCOeWZHaL9BDmQ/o0/syaCHUtXDHSajVJcV Qa1kWohw2n7Ad/i6Lts9MpAwKXzpr8yt4FZ1Er55SFMweBQgGxjHz6IEw+xrq1PE4DQu 6/pVwhUnlFX/vlffqDWL1jkWef4lrfrb2wR1tqIRrIUacJsBRU3CbDLb/MEvYJUWu/9y Jv8QimiaGqsOrcz2fOuhXA7qvPqlec+kiR6upGMYFPIKxjnk5mclqyv3LdJ4qn7lRJqE g4XpPO3KKbJ/eh/MLo820J3DAMFYgPPlJs8LfX63WCoim+F+tYpxjaH9t0MYrasGtZMA TY9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WwmPuv9g; 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 a6si30172481plz.316.2018.11.22.04.37.09; Thu, 22 Nov 2018 04:37:10 -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=WwmPuv9g; 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 S2395128AbeKVXQT (ORCPT + 32 others); Thu, 22 Nov 2018 18:16:19 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51893 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729105AbeKVXQS (ORCPT ); Thu, 22 Nov 2018 18:16:18 -0500 Received: by mail-wm1-f65.google.com with SMTP id j207so1698494wmj.1 for ; Thu, 22 Nov 2018 04:37:06 -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=niIh/rHDS6XLBwNgmCyNlCdvUUAHmIubbZxX7Az/O64=; b=WwmPuv9g4PorfDCvI5jsXyuLGrtsAG27OYDQ71YU8bYQvImun65BIzFvg1H3eoZbl4 JlkKuOxq1mznxojRI/lfKgL4H6FZGGIy3v12ZwfX5/s7vgF2dLrrgAA8a2ZXVY7dMa+b TQAXwC3DmwL7CwmEfesLEDHJrUa70/CGIMdqc= 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=niIh/rHDS6XLBwNgmCyNlCdvUUAHmIubbZxX7Az/O64=; b=Hu8Afprvp/CmxRq1n0hNNu+sczb47emZNclPivvxeBti1gFmeGkUWBWbRHFXvXz2IA g22FWdLEu9YLSlB+8VixfDzDPJO1mBz0qPJH4bvPty/E/10fIc8o5fdhvQYzf2wvIX0E n9IUChJ5mMA6duEkU48W8pA+cHS33nqlCGljzjJ23wCRXyW2K9iRDBh6Y/MHPvCZKjyB d0lpxuAUHTnZiYHQJm0n78QtTtIkufOx5BOuPH0UskofErQ8xbkhP+HAPXBrdPW+2oVG ZchfSdiKYKSVl8zQhRkb59blXgGjtrm2Y/D3n9cWvEifPCfpEEb6YmV8t90b3LvWop0E dRng== X-Gm-Message-State: AGRZ1gI++Og2YUNy9l+IOQkTQwMQJZAscvTSA5Q1/d8JuOuJqunNmWG1 35af4S31byl3IrilsXvISN7NzA== X-Received: by 2002:a1c:b4c1:: with SMTP id d184-v6mr10101732wmf.143.1542890225158; Thu, 22 Nov 2018 04:37:05 -0800 (PST) Received: from localhost.localdomain (189.35.136.77.rev.sfr.net. [77.136.35.189]) by smtp.gmail.com with ESMTPSA id x8sm12376840wrd.53.2018.11.22.04.37.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Nov 2018 04:37:04 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: linux-kernel@vger.kernel.org, viresh.kumar@linaro.org, Greg Kroah-Hartman , "Rafael J. Wysocki" , "Peter Zijlstra (Intel)" , Ingo Molnar , Juri Lelli , Morten Rasmussen Subject: [PATCH V2 1/2] base/drivers/arch_topology: Replace mutex with READ_ONCE / WRITE_ONCE Date: Thu, 22 Nov 2018 13:36:44 +0100 Message-Id: <1542890209-3263-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 Acked-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 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);