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); From patchwork Thu Nov 22 12:36:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 151771 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp691323ljp; Thu, 22 Nov 2018 04:37:12 -0800 (PST) X-Google-Smtp-Source: AJdET5dFgwTm7jNrZ0tAKaNLkYx9jZQvPoZSsyVvJVjltRKM1jotQA10cUmtXkEJlaeo4f+kWBMz X-Received: by 2002:a62:2b17:: with SMTP id r23-v6mr11522531pfr.251.1542890232187; Thu, 22 Nov 2018 04:37:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542890232; cv=none; d=google.com; s=arc-20160816; b=zy0mAQh9PEw5e4QXhGfvaS4jNpVZz7yiaEqBCJIBSdstBfT95xxkziLXvuTVz5sLUf smOSGr9FBXg8ixMXCsuH7+LjjBu4Esr8VKZvE2VCqLyzsAzSLq7SIxdLE91roypxOP1X tk5L9hhKcoDcPEiVCr7FTFsfTAMLINA1twJMVKQXdYTSU1jHLEJClSrZ1h7T7cEUHCTF viIWXc29AQxdidGngBnHJt4HcHweaAaxJZlkcN6CXTJTlSOLMVUXCM5sHLH/gTytTSl4 NSNtNV3kzjIcreddOGH2TVs7+MQIltfilrRUXJCwfzqlR2HUb1PooJrCrOEIYLGjhC1I BPkQ== 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=SiwgRx6Q1l7iY5NUc0wCGobyhCRyGF6V12d2REUS55w=; b=aaa1Yi5o5XiRR951uh91P9/rbXvFtSIHNKfGfQY6qLlOq8BCiWCwb7Ac4CUjl8tjAF b8iK/9EMSy8IS+8W+QEgbsBTWfnRhTtGo/unAZ1WMYbFW5s8NFHT2UCMSUOSL/T6wGBA mTwXBHBsshd4/ufwpEViXqNF+8LXUM0lwADDheyMOQh3HQcWzeChbuph9VJ0dyiBLJL4 zyhvt2V1e7X891uxGqrQeUwMVfThjAKDdHWMWAxQaU8avUIEm8SR1IFWnkmplr9NVf/q ya+xKQ2sexmFqcq1sNMJdDN2q33O+yGJzwUssP6k3PBsiEQtobEFWRFj3MWho3tH/RP3 odgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eid0aJWg; 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.11; Thu, 22 Nov 2018 04:37:12 -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=eid0aJWg; 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 S2395140AbeKVXQV (ORCPT + 32 others); Thu, 22 Nov 2018 18:16:21 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51897 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395115AbeKVXQU (ORCPT ); Thu, 22 Nov 2018 18:16:20 -0500 Received: by mail-wm1-f67.google.com with SMTP id j207so1698579wmj.1 for ; Thu, 22 Nov 2018 04:37: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:in-reply-to:references; bh=SiwgRx6Q1l7iY5NUc0wCGobyhCRyGF6V12d2REUS55w=; b=eid0aJWgdiiKu+mHiHVKRO5pYSXoC8+yApiLupucnzxSJVSj/V2eRvWZteaSRN3WFi su5YJILv0uIfp88a2KO3ghMUy3mRPRkm8Q85jumZmvqeqEhEjAGsF4xnIFK0PNRHA10p hsO3p+QuipDW55RVQQXycgVBsrKX4MyeW5kso= 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=SiwgRx6Q1l7iY5NUc0wCGobyhCRyGF6V12d2REUS55w=; b=YsiYJWEOI2AsU6sRs9cMYrlXw5mQCqM1gz6kVKz/zjk/rOcdmqijTAsqdfhWHoEoEg WC8JoX8ajRq/s7oh0NfJd4hvqW4HgiZ5lNvEu11k0rpVWxxzsLPW46GyTFJTZ7dl//Sx IxwBSMHXbbvxM/OL5GbTvclW3u6ggzXqEcZijxc8oGo6DbAeNd+NVqWgYg2sv9ZVpU9Z S/RTt0RBNQlHcYBya42ZmXbG/S9LnYBKPMKUrItd1L05hKG85/2fwNK0Rlt7W/T1mZde wnBR01i+bBlMxRW1tDllO8LkQebnWR8Zv8kBiqXyBL/ASTo+xC9KdPW2w4IwmVcoNGwT f1Eg== X-Gm-Message-State: AGRZ1gKvcZqS4oQv0qnxZp8rZXVRlM4ay6l6OJ+7c7l/iqP+kODsvxJW PL6vLUh6+NqgT5tYP1eP0s2GYA== X-Received: by 2002:a1c:f916:: with SMTP id x22mr9933302wmh.87.1542890227066; Thu, 22 Nov 2018 04:37:07 -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.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Nov 2018 04:37:06 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: linux-kernel@vger.kernel.org, viresh.kumar@linaro.org, Chris Redpath , Quentin Perret , Amit Kucheria , Nicolas Dechesne , Niklas Cassel , Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH V2 2/2] base/drivers/arch_topology: Default dmips-mhz if they are not set in DT Date: Thu, 22 Nov 2018 13:36:45 +0100 Message-Id: <1542890209-3263-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542890209-3263-1-git-send-email-daniel.lezcano@linaro.org> References: <1542890209-3263-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 In the case of asymmetric SoC with the same micro-architecture, we have a group of CPUs with smaller OPPs than the other group. One example is the 96boards dragonboard 820c. There is no dmips/MHz difference between both groups, so no need to specify the values in the DT. Unfortunately, without these defined, there is no scaling capacity computation triggered, so we need to write 'capacity-dmips-mhz' for each CPU with the same value in order to force the scaled capacity computation. Fix this by setting a default capacity to SCHED_CAPACITY_SCALE, if no 'capacity-dmips-mhz' is defined in the DT. This was tested on db820c: - specified values in the DT (correct results) - partial values defined in the DT (error + fallback to defaults) - no specified values in the DT (correct results) correct results are: cat /sys/devices/system/cpu/cpu*/cpu_capacity 758 758 1024 1024 ... respectively for CPU0, CPU1, CPU2 and CPU3. That reflects the capacity for the max frequencies 1593600 and 2150400. Cc: Chris Redpath Cc: Quentin Perret Cc: Viresh Kumar Cc: Amit Kucheria Cc: Nicolas Dechesne Cc: Niklas Cassel Signed-off-by: Daniel Lezcano --- drivers/base/arch_topology.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index fd5325b..e0c5b60 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -243,9 +243,20 @@ static int __init register_cpufreq_notifier(void) * until we have the necessary code to parse the cpu capacity, so * skip registering cpufreq notifier. */ - if (!acpi_disabled || !raw_capacity) + if (!acpi_disabled) return -EINVAL; + if (!raw_capacity) { + + pr_info("cpu_capacity: No capacity defined in DT, set default " + "values to %ld\n", SCHED_CAPACITY_SCALE); + + raw_capacity = kmalloc_array(num_possible_cpus(), + sizeof(*raw_capacity), GFP_KERNEL); + if (!raw_capacity) + return -ENOMEM; + } + if (!alloc_cpumask_var(&cpus_to_visit, GFP_KERNEL)) { pr_err("cpu_capacity: failed to allocate memory for cpus_to_visit\n"); return -ENOMEM;