Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp907577ybl; Tue, 28 Jan 2020 14:38:20 -0800 (PST) X-Google-Smtp-Source: APXvYqwV1FAaa2nYIaDXPTHUAD+4SxCOIRYWCYPAa1PeXaeZiFXnA0yvmFlsE6r5o1yaPr9lk5Mg X-Received: by 2002:a05:6808:315:: with SMTP id i21mr4300400oie.139.1580251100216; Tue, 28 Jan 2020 14:38:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580251100; cv=none; d=google.com; s=arc-20160816; b=rnpj2SOZVkLeJ8NK6ybLBiGpSIEgEp9s8UIVpEHOUZfuoJp+G2am2WI5yIaf3svx4c dmMcG5vJgRNEXEanIMdipRMbx1nxFQn6hPvxH57Bix+LkcJaW/5iBzTCIOuVjwUTxHGN iJVMJRT63WGIOd2dU59pdN8+9o+TgqE8kpaq2s5ldmPsA2jJA0o0zSJKQCTwHQPLA2oM gUnhf6Gj1aPSS7rpAG1LpZDv/OC+g5D/zTs3a9xLwnIZh2Prq3ZeJOKrGWYIRWsCo2Do NtCAX+Ju71IlIuBAkU/snhhvV9EA4hxaB3F3WIusxZKhdBChKZZZeh0ve9gZ/z8+pr55 K3vg== 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=u9mCgdnpZfGRVNnvDxmPL1ZG+dTFUtvF99vlLoJ4Ggg=; b=xXVy8jOQathsQ+ePzwqLSdwINEaHJCTyfDlzDoizpfyq7TJEKtMhcw2nOhGWY0joxW NWO8ZIe/VxImzMggW0Lb377G1QBEc89q8/MzRi8aLJe/O+jONETXqOLeptD7DVmMsMqP yx4uephEYmDuaPgEVW15a96sbNOsAnkwmexbmbB2G9NK+h1ziP8hBH46WHoCulOeeFCh dJWXbwBoglH4s6tnyouj5+5gvcSzwC0sYJrhtYl2bh1Wy2ttlhEZpxe312NwpX9PWH1z cjNuY4vEisicSBzX/1eALeqKDn6E0QeNxbQN5JW/yan4xFqhmJpN9ggC3WLGrlZD9EF5 f2Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="IClkZ/hL"; 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 106si50400oti.106.2020.01.28.14.38.08; Tue, 28 Jan 2020 14:38: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="IClkZ/hL"; 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 S1726672AbgA1Wgj (ORCPT + 99 others); Tue, 28 Jan 2020 17:36:39 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:39206 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726257AbgA1WgQ (ORCPT ); Tue, 28 Jan 2020 17:36:16 -0500 Received: by mail-qt1-f196.google.com with SMTP id c5so2144527qtj.6 for ; Tue, 28 Jan 2020 14:36:15 -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=u9mCgdnpZfGRVNnvDxmPL1ZG+dTFUtvF99vlLoJ4Ggg=; b=IClkZ/hLgC7SwCLqpIoPYAz9jFaEt/IIv+1LuiDVhB0FGq5ZuoEcygORFfustFkDIO pBZRpvB2TChsx2uh8L1vspFgUj3CRfXqzZJUKHEfSZMXPwJynuXBwUabZVOzevuH3oI6 I/je+Ysq4mSQq1nGJjh0HgDyJUGXxDRuN/GEiPLSDSFXb4pNB3sTjPN71ylXKvyP1pGq XJJWNHAJLgf2SJP8rJcWzYfQn16/xpy0ueVLVDUhqTCNAlPwdqFylQRNNCvITMJu3kmT hQtJLwQcmnJ1x6XPyL6GAldPmRee8fh90IUUxv/bZacKmiMaJtyMi/whygezkTol5jY1 qMuA== 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=u9mCgdnpZfGRVNnvDxmPL1ZG+dTFUtvF99vlLoJ4Ggg=; b=Lml6Gqv2ksgtGPp0q5K4SW7Q2QWrNfsvDfDtNVMM+IbYgYZP16wsb6lhC0VTBkI+4W JrfmYDZdIlDXORnWxvH/i6N3pKBmM8olGKjJaSOHZRElH5yrxvo0lzQUM8HZG4wLiGMi w0+n6idGM38sxsxOTvJFjMqsNAUGiTDeH+mNshfcWTbCOCWewgHXjYA+BsPBz686cyh2 l+rV3f1pIsNjw0rDJEscTUQuDMgfq7SlO7E9mAAWZsr9iPmLYogbxpEbbMaTLiJXGlvt rMU9VSbXnrkEcD3E/+R3C2bZT4z7jtJD4LZhDxQH9eZq2jG6umLhMVqPWMuC9MXcJU1p lRoQ== X-Gm-Message-State: APjAAAWu3wSq2c8q62koJYTO9xmqYwrKM+wPOgMlssoDnwH+6ax9Vs5C 3/tVIbwRBdh1VxUDRT0VM5kwcg== X-Received: by 2002:ac8:74cb:: with SMTP id j11mr10080790qtr.304.1580250974910; Tue, 28 Jan 2020 14:36:14 -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 124sm13014259qko.11.2020.01.28.14.36.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Jan 2020 14:36:14 -0800 (PST) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rui.zhang@intel.com, qperret@google.com, daniel.lezcano@linaro.org, viresh.kumar@linaro.org, rostedt@goodmis.org, will@kernel.org, catalin.marinas@arm.com, sudeep.holla@arm.com, juri.lelli@redhat.com, corbet@lwn.net Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, amit.kucheria@verdurent.com Subject: [Patch v9 3/8] arm,arm64,drivers:Add infrastructure to store and update instantaneous thermal pressure Date: Tue, 28 Jan 2020 17:36:02 -0500 Message-Id: <1580250967-4386-4-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1580250967-4386-1-git-send-email-thara.gopinath@linaro.org> References: <1580250967-4386-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. topology_get_thermal_pressure can be hooked into the scheduler specified arch_cpu_thermal_capacity to retrieve instantaneous thermal pressure of a cpu. arch_set_thermal_pressure can be used to update the thermal pressure. 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 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 --- v6->v7: - Changed the input argument in arch_set_thermal_pressure from capped capacity to delta capacity(thermal pressure) as per Ionela's review comments. arch/arm/include/asm/topology.h | 3 +++ arch/arm64/include/asm/topology.h | 3 +++ drivers/base/arch_topology.c | 11 +++++++++++ include/linux/arch_topology.h | 10 ++++++++++ 4 files changed, 27 insertions(+) diff --git a/arch/arm/include/asm/topology.h b/arch/arm/include/asm/topology.h index 8a0fae9..3a50a19 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 default thermal pressure retrieve API */ +#define arch_cpu_thermal_pressure 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..a70896f 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 default thermal pressure retrieve API */ +#define arch_cpu_thermal_pressure 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 6119e11..68dfa49 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -42,6 +42,17 @@ 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 th_pressure) +{ + int cpu; + + for_each_cpu(cpu, cpus) + WRITE_ONCE(per_cpu(thermal_pressure, cpu), th_pressure); +} + 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..88a115e 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -33,6 +33,16 @@ 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 th_pressure); + struct cpu_topology { int thread_id; int core_id; -- 2.1.4