From patchwork Thu Dec 12 04:11:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 181435 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp394129ile; Wed, 11 Dec 2019 20:12:24 -0800 (PST) X-Google-Smtp-Source: APXvYqxlmMbjt2zc1+3QvS0SjWVE5JpxBsaI4h80FG/ajbgnuBmKnqBsVsHWNcOvllp8WtY87obA X-Received: by 2002:a9d:6f82:: with SMTP id h2mr5829405otq.69.1576123943878; Wed, 11 Dec 2019 20:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576123943; cv=none; d=google.com; s=arc-20160816; b=IIfdxrd90eu+rReVXpSN2Xt5eI8wLxZgHLxKFJy3TriIqPpwPreMLxmZFl6Qi3rhPD Yi7j4ttXQwlOElwbCbLd6swUfoaTnwMWbMfTo/BfTybkf6rakVqV/Mp1pVn2XipnCnOh GW+M5u+G4TTvDHbqtkATVYp8Cw8ABA76H3coGz1RZF6E+xy/zz9xOMvjdFUf7WZcFGXH zYySorDGdfsiomR8BYZvCoxuZJFQ/Ikx+XhaPkad+QVM8O7GJBqYRONKZyhhZdf2buob CV0lpTcIA+j0YVu9wdYZzNZZF+q5OJRNrgzLcmOarMWEh4lCKyNQ5xNxNgR/oMGLzlgg G+7Q== 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=7l5JKLqHdHgruudTWmIyB43cagXE9G3mjJRNavUYrx4=; b=oj/Px6bBVMY52MAXFjl7wczyjZ+HItgQsGSsH4L8dm0NlRtrSruJdip4Ob7lURtVho giQqInOjlWUPaJmN28Fb+NUY+XkmbhWb5C6o75344que6ifJJqvoLQYs/NL2ivzbqFa+ pfjnwKOYjOer+lm3SR2a6iaf489rlKEfOfq5h7lSiJfsLcqAIW2ZM4UKhdnR6xx8U5ZH 5d0QHwrYtpdTR7WCKw6kpjD6MoJApV1N5E5FvzwMT6KfaJXzr9Uk0NGylvZ2zb9pcR1l PmbWqJtJJX/HqlqBUVYnS8iGffBCQDBJns3fLfkzrplz1VBZpAZVei16hdS576FmVlgq xa2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e3SCyNmm; 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 a128si2463747oib.142.2019.12.11.20.12.23; Wed, 11 Dec 2019 20:12:23 -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=e3SCyNmm; 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 S1728009AbfLLEMW (ORCPT + 27 others); Wed, 11 Dec 2019 23:12:22 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:36372 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727900AbfLLELz (ORCPT ); Wed, 11 Dec 2019 23:11:55 -0500 Received: by mail-qk1-f194.google.com with SMTP id a203so539599qkc.3 for ; Wed, 11 Dec 2019 20:11:54 -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=7l5JKLqHdHgruudTWmIyB43cagXE9G3mjJRNavUYrx4=; b=e3SCyNmm8WdEkCQ7f3y2JoLiUnEkvMrrU/TuSfpi+kkupGJr28+LC5r5TA0lQcSeIR vvBy19qWpacP2+4UZTKfaFcgRe8r7P1Wfcq3xidv9Hf43Mq3Cvt8TvxmiTXfn3N/Xsvh Apr44+/tMBHFY6K27rPCm9SiRomjBs/sNiM3GDLBtohddXnL6BcV0q4+mMU+HkXsnzAC /EdpT3yUbUdm/3Ib5DgDGRuiIV2g1jbbDKPN6TtSstSp4SVzX0aydgoGdgd+INdWmFB9 3dIjeKF+X+Ig3QzTtNaP7/pEhOU80TuR1vsNrqwGQiNR5uaY+iYmySn639nxva/hL8CW RiWg== 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=7l5JKLqHdHgruudTWmIyB43cagXE9G3mjJRNavUYrx4=; b=PNaDAP8eoHgZnk9rFbVNJfUsuC0oNe5KWSIBSpOIdroWWxVdCSBhqo3zwoy2lxwGqr a+podJzhTt4uF5QIgdNK5khbXnkOGPh670iRdvWy+R733fjbj9Y+Fis3oT2OSaMYILpk ZCoFUQpeigE41onca2WcDKyEdR2mRvTylfNXdP08Mb6eTScIPlP6wSHPQjYiQO82R/HH nJ0e3UckOV8QwrlfNgcn/UjiBbiMsE3CyUMONuWAcnlUwRHVNiTAFzgo/Tjp9Vx/KqbA 51xg4CXWMitV6JbjSxs9syb5SSLj4p7BUVaOqKAFV1HVAOxC86qk8DZBOdxWcHe9bkBA Rt/Q== X-Gm-Message-State: APjAAAUYiCgji/1zAN5TcN3SbOEJpdofxchREApRAK+taiZh1FpSK2tL n4MafJEpFIUhYe/hmNlzUzAP/Q== X-Received: by 2002:a37:b601:: with SMTP id g1mr6388350qkf.114.1576123914207; Wed, 11 Dec 2019 20:11:54 -0800 (PST) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-246-27.washdc.fios.verizon.net. [71.255.246.27]) by smtp.googlemail.com with ESMTPSA id s11sm1364126qkg.99.2019.12.11.20.11.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Dec 2019 20:11:53 -0800 (PST) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, qperret@google.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, amit.kucheria@verdurent.com Subject: [Patch v6 3/7] Add infrastructure to store and update instantaneous thermal pressure Date: Wed, 11 Dec 2019 23:11:44 -0500 Message-Id: <1576123908-12105-4-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1576123908-12105-1-git-send-email-thara.gopinath@linaro.org> References: <1576123908-12105-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add architecture specific APIs to update and track thermal pressure on a per cpu basis. A per cpu variable thermal_pressure is introduced to keep track of instantaneous per cpu thermal pressure. Thermal pressure is the delta between maximum capacity and capped capacity due to a thermal event. capacity and capped capacity due to a thermal event. topology_get_thermal_pressure can be hooked into the scheduler specified arch_scale_thermal_capacity to retrieve instantaneius thermal pressure of a cpu. arch_set_thermal_presure can be used to update the thermal pressure by providing a capped maximum capacity. Considering topology_get_thermal_pressure reads thermal_pressure and arch_set_thermal_pressure writes into thermal_pressure, one can argue for some sort of locking mechanism to avoid a stale value. But considering topology_get_thermal_pressure_average can be called from a system critical path like scheduler tick function, a locking mechanism is not ideal. This means that it is possible the thermal_pressure value used to calculate average thermal pressure for a cpu can be stale for upto 1 tick period. Signed-off-by: Thara Gopinath --- v3->v4: - Dropped per cpu max_capacity_info struct and instead added a per delta_capacity variable to store the delta between maximum capacity and capped capacity. The delta is now calculated when thermal pressure is updated and not every tick. - Dropped populate_max_capacity_info api as only per cpu delta capacity is stored. - Renamed update_periodic_maxcap to trigger_thermal_pressure_average and update_maxcap_capacity to update_thermal_pressure. v4->v5: - As per Peter's review comments folded thermal.c into fair.c. - As per Ionela's review comments revamped update_thermal_pressure to take maximum available capacity as input instead of maximum capped frequency ration. v5->v6: - As per review comments moved all the infrastructure to track and retrieve instantaneous thermal pressure out of scheduler to topology files. arch/arm/include/asm/topology.h | 3 +++ arch/arm64/include/asm/topology.h | 3 +++ drivers/base/arch_topology.c | 13 +++++++++++++ include/linux/arch_topology.h | 11 +++++++++++ 4 files changed, 30 insertions(+) -- 2.1.4 diff --git a/arch/arm/include/asm/topology.h b/arch/arm/include/asm/topology.h index 8a0fae9..90b18c3 100644 --- a/arch/arm/include/asm/topology.h +++ b/arch/arm/include/asm/topology.h @@ -16,6 +16,9 @@ /* Enable topology flag updates */ #define arch_update_cpu_topology topology_update_cpu_topology +/* Replace task scheduler's defalut thermal pressure retrieve API */ +#define arch_scale_thermal_capacity topology_get_thermal_pressure + #else static inline void init_cpu_topology(void) { } diff --git a/arch/arm64/include/asm/topology.h b/arch/arm64/include/asm/topology.h index a4d945d..ccb277b 100644 --- a/arch/arm64/include/asm/topology.h +++ b/arch/arm64/include/asm/topology.h @@ -25,6 +25,9 @@ int pcibus_to_node(struct pci_bus *bus); /* Enable topology flag updates */ #define arch_update_cpu_topology topology_update_cpu_topology +/* Replace task scheduler's defalut thermal pressure retrieve API */ +#define arch_scale_thermal_capacity topology_get_thermal_pressure + #include #endif /* _ASM_ARM_TOPOLOGY_H */ diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 1eb81f11..3a91379 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -42,6 +42,19 @@ void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity) per_cpu(cpu_scale, cpu) = capacity; } +DEFINE_PER_CPU(unsigned long, thermal_pressure); + +void arch_set_thermal_pressure(struct cpumask *cpus, + unsigned long capped_capacity) +{ + int cpu; + unsigned long delta = arch_scale_cpu_capacity(cpumask_first(cpus)) - + capped_capacity; + + for_each_cpu(cpu, cpus) + WRITE_ONCE(per_cpu(thermal_pressure, cpu), delta); +} + static ssize_t cpu_capacity_show(struct device *dev, struct device_attribute *attr, char *buf) diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index 3015ecb..7a04364 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -33,6 +33,17 @@ unsigned long topology_get_freq_scale(int cpu) return per_cpu(freq_scale, cpu); } +DECLARE_PER_CPU(unsigned long, thermal_pressure); + +static inline +unsigned long topology_get_thermal_pressure(int cpu) +{ + return per_cpu(thermal_pressure, cpu); +} + +void arch_set_thermal_pressure(struct cpumask *cpus, + unsigned long capped_capacity); + struct cpu_topology { int thread_id; int core_id;