From patchwork Tue Oct 9 16:24:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 148516 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp5110310lji; Tue, 9 Oct 2018 09:25:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV61REO7NSpKNwwLZ3uI1W5ZyZ/grwBWjzivj3EGdyQfPvOPrd/aBGODCZskAmZHDceu3oVBO X-Received: by 2002:a63:6111:: with SMTP id v17-v6mr25909962pgb.226.1539102348467; Tue, 09 Oct 2018 09:25:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539102348; cv=none; d=google.com; s=arc-20160816; b=0H1SuFvHuctgQiqeM8pdnPqO86BAvYuksZK9gJs8vlG+xLK4RDlWz4K80sdPVw6g7p QxP+aLwv5Fjeln27b+xOInN7wCcOu5x51P85JQOSWcRJxc48d219XJh8FTooOii+np30 bD82EobCzQiRaBTEeQ7eTdFR9att4n9xNMnOlG+gnPZPa7OxyiQxXFXwO0DRzAwsRm+R QRXxFKZBocLV+2/swrhpgTRixT2V02MP5fDuEdFuKxsb3QYFV7YPWR9AXMbiXHROlWn8 DMbl2LqHss0E1SGEdYnserBSHHW2V6zTBLwewXLwzJICKn3xoqC3IPhBfa3zFaRUtZE4 D0Ig== 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=qbCXCRSOePNWlZULbLaHD5z+rbdqCdhX0BsGRnKqI98=; b=BLp8Znb5peWE+jbZ7p222LoEHImz4j8tpkGxW1bC316NWXJNPRvZSA5C77VWKriIFd Q0UwM2gYOaSyaPbuLyOBIzxz36a3Ou6eqAEBWU6SOpdZz8sOCQJv9nhC2qnUWy7Kxchc ldt5cGy2kQ+H7S6J3M/sXFdpUn35YZ/XTqjegAZpBSMeZap3RLYzugu/TSWRVtc84/qW NxmUZkPpiAtaawhTe66a9QeyIPpxNz32mYwonYinp3SjGaRdyePRbXAVcOWPxzsXKjnk xIAHpX24L9aCVKSm0d/Z6L2OBXS5u0kUCu4lAMQKq0Y26ImsXN5gx77JzrJ7BzWYbewI tQsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Wf0ys7uZ; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 23-v6si19747716pge.453.2018.10.09.09.25.48; Tue, 09 Oct 2018 09:25:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=Wf0ys7uZ; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1726548AbeJIXmy (ORCPT + 10 others); Tue, 9 Oct 2018 19:42:54 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:44753 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727028AbeJIXmw (ORCPT ); Tue, 9 Oct 2018 19:42:52 -0400 Received: by mail-qt1-f193.google.com with SMTP id c56-v6so2270917qtd.11 for ; Tue, 09 Oct 2018 09:25:09 -0700 (PDT) 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=qbCXCRSOePNWlZULbLaHD5z+rbdqCdhX0BsGRnKqI98=; b=Wf0ys7uZUptTZHdHTnhf5tZpd1u4BVhNoa1dMrTUTehXQMI5widEclWXpmET2J/UUi ARuy7IAJwYHViB65i4fUg3atGzJCISXwL41NA69Ez8RJSEKWYZ2J4+dM0jo1Qve39upJ MpuyjDSN/TOVTQQ6IUmaj/c2KXnifFczKDCCs= 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=qbCXCRSOePNWlZULbLaHD5z+rbdqCdhX0BsGRnKqI98=; b=bzXD7Tqdyi/Vav2aY7HbP0tPm2krp7pTKDWLbOytZyRXHgPzxQQ//2JNZZm3rjdElD 6n4Waqk9mxMMIFjS7hEu1iTIb7pWqject7WjX8kHpa2y7BkDQ7atOMVOR8cmBCzldZXW qBzb4Ax5mFyhsQdK21/AqGOt2AaKC6zugXXp695Fte3qFxTQ41YYci3nBiCNPlC05y3f B2Y2SOcCwq59BE81cD1B5qG1s0L33THubTFA1VI0Cv5Sz75Ks0WtDS5zy0ZtXUeFFXHx xEULL7Y0BPJb0ohlF6OOHp16BnWsuA01d6vwgktA5YUjtXgYdyH/wvoJ2p/dXULdAvZL MgzQ== X-Gm-Message-State: ABuFfojdB0HbrMOZ2UG1IgvA6u3xJlEu0ZxHWHmUbTojSmPPzKiPE7xo o5dlku8ohKeuLAEE4AeYPrsS6A== X-Received: by 2002:a0c:d285:: with SMTP id q5mr6920778qvh.46.1539102308545; Tue, 09 Oct 2018 09:25:08 -0700 (PDT) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-245-97.washdc.fios.verizon.net. [71.255.245.97]) by smtp.googlemail.com with ESMTPSA id o7-v6sm10441169qkc.67.2018.10.09.09.25.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 09:25:07 -0700 (PDT) From: Thara Gopinath To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, rui.zhang@intel.com Cc: gregkh@linuxfoundation.org, rafael@kernel.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, javi.merino@kernel.org, edubezval@gmail.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, quentin.perret@arm.com, ionela.voinescu@arm.com, vincent.guittot@linaro.org Subject: [RFC PATCH 2/7] sched/pelt.c: Add support to track thermal pressure Date: Tue, 9 Oct 2018 12:24:57 -0400 Message-Id: <1539102302-9057-3-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> References: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Extrapolating on the exisitng framework to track rt/dl utilization using pelt signals, add a similar mechanism to track thermal pressue. The difference here from rt/dl utilization tracking is that, instead of tracking time spent by a cpu running a rt/dl task through util_avg, the average thermal pressure is tracked through load_avg. In order to track average thermal pressure, a new sched_avg variable avg_thermal is introduced. Function update_thermal_avg can be called to do the periodic bookeeping (accumulate, decay and average) of the thermal pressure. Signed-off-by: Thara Gopinath --- kernel/sched/pelt.c | 14 ++++++++++++++ kernel/sched/pelt.h | 7 +++++++ kernel/sched/sched.h | 1 + 3 files changed, 22 insertions(+) -- 2.1.4 diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c index 05b8798..7034ede 100644 --- a/kernel/sched/pelt.c +++ b/kernel/sched/pelt.c @@ -362,6 +362,20 @@ int update_dl_rq_load_avg(u64 now, struct rq *rq, int running) return 0; } +int update_thermal_avg(u64 now, struct rq *rq, u64 capacity) +{ + if (___update_load_sum(now, rq->cpu, &rq->avg_thermal, + capacity, + capacity, + capacity, 0)) { + + ___update_load_avg(&rq->avg_thermal, 1, 1); + return 1; + } + + return 0; +} + #if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) /* * irq: diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h index d2894db..cc5a3ad 100644 --- a/kernel/sched/pelt.h +++ b/kernel/sched/pelt.h @@ -5,6 +5,7 @@ int __update_load_avg_se(u64 now, int cpu, struct cfs_rq *cfs_rq, struct sched_e int __update_load_avg_cfs_rq(u64 now, int cpu, struct cfs_rq *cfs_rq); int update_rt_rq_load_avg(u64 now, struct rq *rq, int running); int update_dl_rq_load_avg(u64 now, struct rq *rq, int running); +int update_thermal_avg(u64 now, struct rq *rq, u64 capacity); #if defined(CONFIG_IRQ_TIME_ACCOUNTING) || defined(CONFIG_PARAVIRT_TIME_ACCOUNTING) int update_irq_load_avg(struct rq *rq, u64 running); @@ -67,6 +68,12 @@ update_irq_load_avg(struct rq *rq, u64 running) { return 0; } + +static inline int +update_thermal_avg(u64 now, struct rq *rq, u64 capacity) +{ + return 0; +} #endif diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 4a2e8ca..30b40a5 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -859,6 +859,7 @@ struct rq { #define HAVE_SCHED_AVG_IRQ struct sched_avg avg_irq; #endif + struct sched_avg avg_thermal; u64 idle_stamp; u64 avg_idle; From patchwork Tue Oct 9 16:24:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 148511 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp5109641lji; Tue, 9 Oct 2018 09:25:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV62sP3fQWK9rFZ5wgpkHNzrEgIybJjJBVxKU37FCE6FcPO4FrG5GEBzSW5knyudFj3sDKNU3 X-Received: by 2002:a62:b286:: with SMTP id z6-v6mr31272929pfl.79.1539102314107; Tue, 09 Oct 2018 09:25:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539102314; cv=none; d=google.com; s=arc-20160816; b=vhgM9tFzNoUXcTuc4x3790G8W+bryk/7y0fbAtQs8BZvXcoK2/CC3HgmXsVl3EgRjd usldQgdcD2vZiXvdgfbGKUcxA/DjdAMlVVzkCiIWtEJWbp5qPq0ndJuO26rX//zkfyYl 9nhtLMYDAp0L1ksPQmLYlDLdSRsrcKaZrZ3dhWy4mz7X76Uw8PqO1hvXt3BVOr2dIEhd bWNIEFMGvQb+tKFOD+CoHFpKyfPdY27EMZ/PBCQ01cf0wIj8Qsz5JNu5V+opcuItYR5+ 1D63+Z0Vs0qlegjgRPUhT0BG43p4kHud+z9KxzOsL+20NoJowSoBrZesGyaFZZbWoOob kuDA== 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=GTTrzFlD4e7MPFOzmpkTKpYtaYABvBsIdVkj6rIH/N0=; b=lt3OuvXpAITRDKB4WU7XyFSbZZFYU+jkWABzO/uzcV72IPJu+FSuNuJET/A4LbCxnL KJOTesGxrPDqlaUWHWbckMqOO1ZZyaLZrkkUzPhAsfC6xLyoKiJJOUoCq+1u3MijIXk/ G56mKdEgelmgdpEUFH0NQUsCpjkRyRdceBkciHrUkPbiD7ZQB0QQjYijUCQmRrcd9UpQ gBzd6qB/mV7Y9irVM0Xo7lR2B37Sj+r7TRFquA306RJ5l9EozHIhqryPqvDCAFWOy6lF Co33bGJSZMQXQV8vzwetyvwl6YcDi0+HVRM0aue5RZDhyihYJaFZ8ZiduOCnHNsKCfuE apwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CrBrX09d; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 w24-v6si21742804pll.346.2018.10.09.09.25.13; Tue, 09 Oct 2018 09:25:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=CrBrX09d; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1726896AbeJIXmz (ORCPT + 10 others); Tue, 9 Oct 2018 19:42:55 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:33172 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbeJIXmy (ORCPT ); Tue, 9 Oct 2018 19:42:54 -0400 Received: by mail-qt1-f194.google.com with SMTP id q40-v6so2316571qte.0 for ; Tue, 09 Oct 2018 09:25:10 -0700 (PDT) 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=GTTrzFlD4e7MPFOzmpkTKpYtaYABvBsIdVkj6rIH/N0=; b=CrBrX09d4RQMnev9V72y7Y8ckuVLxIQQRvmb32iIlBd9euLYoPsc6uXhRPdKBk4x0C ExY4Z+FdNTvTHFUMi1UIqc9ganifwNfL799HHdzTmgxEvXOR9Ly4C3in0znoocJHGJ6F 0+CoOOFFPvu2Fl6OEK642/Vl4vp1AjF1eLmuk= 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=GTTrzFlD4e7MPFOzmpkTKpYtaYABvBsIdVkj6rIH/N0=; b=tiE/eZrjr4ujd5eJ124J5VgFkjN5sFqa8RV8IK2VgQwysJpwkDCaSdtZTT+WPLQ5s1 aT114RrFgcHEXGNEAKtUhYaQFhjkbGGaOkLKgJ6COZCQaYD6dLq+YJaIGvTWXCQFP5Yx YZvZMn+nYE/6ihuLVhnNygUBqDiSXEe5nF0ATyKOBu+AznikmS3foiPhPMwRKaNXkoVc 5PG0ktaiZHIAT8zkhGSNAj7AdppB9XucKeqXEhJ6F6/OCLrmA5zpVpqjDpqOHhY8alGk 7GPVi1KblS+tunGeutyI6QE2OHP/EXNLpw0JmGatxrlwor6uy3iAqVWBcdsgFCuzEYXJ fvHA== X-Gm-Message-State: ABuFfojfIaT0VQusI4Q91FKPss7+7vVeJmBy+fws4PMCfiCYmKd+bwmp Jc++uXcbjEoOMTriS86LCv2Xug== X-Received: by 2002:a0c:9466:: with SMTP id i35mr2311932qvi.231.1539102310308; Tue, 09 Oct 2018 09:25:10 -0700 (PDT) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-245-97.washdc.fios.verizon.net. [71.255.245.97]) by smtp.googlemail.com with ESMTPSA id o7-v6sm10441169qkc.67.2018.10.09.09.25.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 09:25:09 -0700 (PDT) From: Thara Gopinath To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, rui.zhang@intel.com Cc: gregkh@linuxfoundation.org, rafael@kernel.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, javi.merino@kernel.org, edubezval@gmail.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, quentin.perret@arm.com, ionela.voinescu@arm.com, vincent.guittot@linaro.org Subject: [RFC PATCH 3/7] sched: Add infrastructure to store and update instantaneous thermal pressure Date: Tue, 9 Oct 2018 12:24:58 -0400 Message-Id: <1539102302-9057-4-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> References: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add thermal.c and thermal.h files that provides interface APIs to initialize, update/average, track, accumulate and decay thermal pressure per cpu basis. A per cpu structure max_capacity_info is introduced to keep track of instantaneous per cpu thermal pressure. Thermal pressure the delta between max_capacity and cap_capacity. API update_periodic_maxcap is called for periodic accumulate and decay of the thermal pressure. It is to to be called from a periodic tick function. The API calculates the delta between max_capacity and cap_capacity and passes on the delta to update_thermal_avg to do the necessary accumulate, decay and average. update_maxcap_capacity is for the system to update the thermal pressure by updating cap_capacity. Considering, update_periodic_maxcap reads cap_capacity and update_maxcap_capacity writes into cap_capacity, one can argue for some sort of locking mechanism to avoid a stale value. But considering update_periodic_maxcap can be called from a system critical path like scheduler tick function, a locking mechanism is not ideal. This means that possibly for 1 tick period the value used to calculate average thermal pressure for a cpu can be stale. Signed-off-by: Thara Gopinath --- include/linux/sched.h | 14 +++++++++++ kernel/sched/Makefile | 2 +- kernel/sched/thermal.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/thermal.h | 13 ++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 kernel/sched/thermal.c create mode 100644 kernel/sched/thermal.h -- 2.1.4 diff --git a/include/linux/sched.h b/include/linux/sched.h index 977cb57..931b76d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1891,3 +1891,17 @@ static inline void rseq_syscall(struct pt_regs *regs) #endif #endif + +#ifdef CONFIG_SMP +void update_maxcap_capacity(int cpu, u64 capacity); + +void populate_max_capacity_info(void); +#else +static inline void update_maxcap_capacity(int cpu, u64 capacity) +{ +} + +static inline void populate_max_capacity_info(void) +{ +} +#endif diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile index 7fe1834..232a0cf 100644 --- a/kernel/sched/Makefile +++ b/kernel/sched/Makefile @@ -20,7 +20,7 @@ obj-y += core.o loadavg.o clock.o cputime.o obj-y += idle.o fair.o rt.o deadline.o obj-y += wait.o wait_bit.o swait.o completion.o -obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o topology.o stop_task.o pelt.o +obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o topology.o stop_task.o pelt.o thermal.o obj-$(CONFIG_SCHED_AUTOGROUP) += autogroup.o obj-$(CONFIG_SCHEDSTATS) += stats.o obj-$(CONFIG_SCHED_DEBUG) += debug.o diff --git a/kernel/sched/thermal.c b/kernel/sched/thermal.c new file mode 100644 index 0000000..dd8300d --- /dev/null +++ b/kernel/sched/thermal.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sceduler Thermal Interactions + * + * Copyright (C) 2018 Linaro, Inc., Thara Gopinath + */ + +#include +#include "sched.h" +#include "pelt.h" +#include "thermal.h" + +struct max_capacity_info { + unsigned long max_capacity; + unsigned long cap_capacity; +}; + +static DEFINE_PER_CPU(struct max_capacity_info, max_cap); + +void update_maxcap_capacity(int cpu, u64 capacity) +{ + struct max_capacity_info *__max_cap; + u64 __capacity; + + __max_cap = (&per_cpu(max_cap, cpu)); + if (!__max_cap) { + pr_err("no max_capacity_info structure for cpu %d\n", cpu); + return; + } + + /* Normalize the capacity */ + __capacity = (capacity * arch_scale_cpu_capacity(NULL, cpu)) >> + SCHED_CAPACITY_SHIFT; + pr_debug("updating cpu%d capped capacity from %ld to %ld\n", cpu, __max_cap->cap_capacity, __capacity); + + __max_cap->cap_capacity = __capacity; +} + +void populate_max_capacity_info(void) +{ + struct max_capacity_info *__max_cap; + u64 capacity; + int cpu; + + + for_each_possible_cpu(cpu) { + __max_cap = (&per_cpu(max_cap, cpu)); + if (!__max_cap) + continue; + capacity = arch_scale_cpu_capacity(NULL, cpu); + __max_cap->max_capacity = __max_cap->cap_capacity = capacity; + pr_debug("cpu %d max capacity set to %ld\n", cpu, __max_cap->max_capacity); + } +} + +void update_periodic_maxcap(struct rq *rq) +{ + struct max_capacity_info *__max_cap = (&per_cpu(max_cap, cpu_of(rq))); + unsigned long delta; + + if (!__max_cap) + return; + + delta = __max_cap->max_capacity - __max_cap->cap_capacity; + update_thermal_avg(rq_clock_task(rq), rq, delta); +} diff --git a/kernel/sched/thermal.h b/kernel/sched/thermal.h new file mode 100644 index 0000000..20a0270 --- /dev/null +++ b/kernel/sched/thermal.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Scheduler thermal interaction internal methods. + */ + +#ifdef CONFIG_SMP +void update_periodic_maxcap(struct rq *rq); + +#else +static inline void update_periodic_maxcap(struct rq *rq) +{ +} +#endif From patchwork Tue Oct 9 16:24:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 148515 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp5110158lji; Tue, 9 Oct 2018 09:25:39 -0700 (PDT) X-Google-Smtp-Source: ACcGV63i5oDUezqbcFNqB7BtwxL89D+u8aSA4HhsL3sNuUmBYcyi+2bqx8NgQq2RbgzFCKIaj0NL X-Received: by 2002:a62:c957:: with SMTP id k84-v6mr31669125pfg.205.1539102339855; Tue, 09 Oct 2018 09:25:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539102339; cv=none; d=google.com; s=arc-20160816; b=I6D8fNvDX3QASpvzz1Zh86eRv1AmbY/+jh4UYNENj2MyJLKgF1tw5e0/O0+U5Lw+n+ eF4RjdNLkkvFuCcjcELX/+oa3fc3YdlEavzOtHopZ52uYmxOG8m72pxu+c2Bi+hwMlFY Ks5Am0zz3pPhVGFJ3u1Uw3fYQXV6kWTVaE6MueuhNeDpF/MlO3SSulZ423PcJ7qGlQY4 jyiKLNe6PV//CztWWQAZD0cRDC3I+d8csYkjNVFjJOZi2fG8C/UfW/hdcahSNXMyv7Q6 ZVkwTANdxBNrQdYeWBGMryTGnHt+vlNnYxmI6FUChUGXlDKm1n/thmbfSdKCbubyKhPH cONg== 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=rGWgMI1+Sov2UL2W3G/z4V3AYRc3F2jCrmMhsGLsaSc=; b=ZLHDSuyQ6LYqj8+iDRiyaj8N02sKnglEcpVDv4vUoVGkL9HZvRPVZ058Do8af3Akub LrcAXvrwRGn6tIEZlVMANdLILLNZjKQIQqv05YoVCkUcjMbVFAfcAV75+UXZDr+pUDbA B0L/W6n6qnuJ3m0QvDdesEZeEiJqtm4TPkvnEKsy+9QOWMi6MCPdESzkj0u7is81m2cL 21Y+9yaSe0xv0wB0nnhGkd54jU0Hu1TAF7NOALvMyliQMpsq9M4OzFtvaqFMc/DQV5KZ RT11i6yNik+CuXRXSFeUB1m5Gadk3cXFOSznMRvN06G8DxRA5dSZPvVCmEKAMJRU4jaH iQMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kFjTPb7G; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 d4-v6si11737235pgl.524.2018.10.09.09.25.39; Tue, 09 Oct 2018 09:25:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=kFjTPb7G; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1726925AbeJIXm4 (ORCPT + 10 others); Tue, 9 Oct 2018 19:42:56 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:35394 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726810AbeJIXm4 (ORCPT ); Tue, 9 Oct 2018 19:42:56 -0400 Received: by mail-qk1-f193.google.com with SMTP id v68-v6so1321627qka.2 for ; Tue, 09 Oct 2018 09:25:13 -0700 (PDT) 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=rGWgMI1+Sov2UL2W3G/z4V3AYRc3F2jCrmMhsGLsaSc=; b=kFjTPb7GvlvcqqUl63mme8PN5mlZcwqjW+ATtvnaJEl0XoFJMZ8Ay1WAVuHps+VgBx svfB27nf95qf95qR0svOwo2QaQGuIHYeV61E9ryxHuKhYiNtk9JwfuH+E/lPn6jUjiY8 6ZdgxI8FTxReaKCHOyf6fDISPoGJVymJosJYo= 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=rGWgMI1+Sov2UL2W3G/z4V3AYRc3F2jCrmMhsGLsaSc=; b=LOUFsPeKk4r8DkNwuZPHg7h8wFGA/wVV9dmRf+Dx9HXs3VqQVcyGz4q+kHfTgMvK6Y 1W+BjbN41bFjht8L7+AhtwvIBvrRj9/bpCDRtapWHytlPVuMOGHFCwKPoh1kPPqp3Efs 2AY/S5dsuZiX26PRN+Ow9D0jXC3CU01NuM34rnJ7V5UVuLeS6tNUj8S9GL6qQKWz920w FlXzmU4Rl87tO3Uql03CjHpGF6EzELLLdAJJgeCWEORIrwmctZxxk54hRXkksY+K/jv9 LrBBsharWdrPjnDSFF51cJPWr8YV6/c1Gdz6e9bb4oCD9Flin3KXjAKMhef11qS3gOqr mktA== X-Gm-Message-State: ABuFfoheGEwdihF0xRf0s/8117y9s3sx04Hfv9RnVaylIhdSBD5Nwzbv PAx4NLaW3q89D3Nrf/RxXNvFzg== X-Received: by 2002:a37:10a7:: with SMTP id 39-v6mr22580045qkq.131.1539102312277; Tue, 09 Oct 2018 09:25:12 -0700 (PDT) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-245-97.washdc.fios.verizon.net. [71.255.245.97]) by smtp.googlemail.com with ESMTPSA id o7-v6sm10441169qkc.67.2018.10.09.09.25.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 09:25:11 -0700 (PDT) From: Thara Gopinath To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, rui.zhang@intel.com Cc: gregkh@linuxfoundation.org, rafael@kernel.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, javi.merino@kernel.org, edubezval@gmail.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, quentin.perret@arm.com, ionela.voinescu@arm.com, vincent.guittot@linaro.org Subject: [RFC PATCH 4/7] sched: Initialize per cpu thermal pressure structure Date: Tue, 9 Oct 2018 12:24:59 -0400 Message-Id: <1539102302-9057-5-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> References: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Initialize per cpu max_capacity_info during scheduler init. Signed-off-by: Thara Gopinath --- drivers/base/arch_topology.c | 1 + kernel/sched/core.c | 2 ++ 2 files changed, 3 insertions(+) -- 2.1.4 diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index e7cb0c6..542745f 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -126,6 +126,7 @@ void topology_normalize_cpu_scale(void) pr_debug("cpu_capacity: CPU%d cpu_capacity=%lu\n", cpu, topology_get_cpu_scale(NULL, cpu)); } + populate_max_capacity_info(); mutex_unlock(&cpu_scale_mutex); } diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 625bc98..f0eed1a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5868,6 +5868,8 @@ void __init sched_init_smp(void) init_sched_rt_class(); init_sched_dl_class(); + populate_max_capacity_info(); + sched_smp_initialized = true; } From patchwork Tue Oct 9 16:25:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 148514 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp5109791lji; Tue, 9 Oct 2018 09:25:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV62nrhSKZcSJBRT/L4G4nSDjFRX59Eo50kfj0ueFeBk89iMIgSqjsjJxUITzMVUmjpmdW9/A X-Received: by 2002:a63:2807:: with SMTP id o7-v6mr26087700pgo.155.1539102321284; Tue, 09 Oct 2018 09:25:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539102321; cv=none; d=google.com; s=arc-20160816; b=h0YfODnHWaRobjudrjblrWIL7sStHPRrxCVtyePqUlbjSF8FPgaWcBzsJ1Xo0VxWEZ dNkKWcG0yCddnDpKClbdp5VaVgHxLMxl58ANO2ywG4tXDTWajWIGKIa1efokQx9Gdncj GwTXzw4CaDxlVr2N0KRlC7hEEbm9NXSohEmS9NQKh7gNt+S5KK/+xDL4PN/FGsfdH/IX nQMBx8/5eGAcU4xLQCQ0kl9Xgbg3rGNVmNLVVmsQxdwjbtHDrkephG1gdzibvakcj5NN /nn/7428XPi8q2ZXUuh8nFDSRTc4fQUqyr2sZC2DniHwoLAGiX6NabyB9NefiRHFmgsg XosA== 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=GRe242656I2kSmkisEDP4QURqPrSR1lR6wXda3PHx2M=; b=UIFc3U9b1yatdLWujpefxy7t6MQaAgHr+I2D1im9/HuJYIm0sMHFYA4gDWKabCkLWG z9awvlXvlKJrqR86WFD9ofZSY+1QWoScn257QTZcrYbrThYG4t779znrvnR2w0/jmP67 H9J1kVdJXfACBY1adSh2FQKy1dj3iCGrbtzIrhVyPIkeZPJfnNcbiVlu1rd7frXWrtJf Cp3WzGv6Ero0O0YVi+EqvE9VnjpWYyU8GsAZWNjpxCYuh4gKKV1I4MvgOCPiIUTGgN5K wWXtp+niA1tVwBvU4wg6j7HaB+Rk9W/rrbJ1nnr40BCzBzZJdi+EEMIbSOqbThd3wprB 3guw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ER4xWmIG; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 g6-v6si19960506pgb.408.2018.10.09.09.25.21; Tue, 09 Oct 2018 09:25:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=ER4xWmIG; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1727370AbeJIXnC (ORCPT + 10 others); Tue, 9 Oct 2018 19:43:02 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:38644 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727344AbeJIXnB (ORCPT ); Tue, 9 Oct 2018 19:43:01 -0400 Received: by mail-qt1-f193.google.com with SMTP id l9-v6so2301561qtf.5 for ; Tue, 09 Oct 2018 09:25:18 -0700 (PDT) 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=GRe242656I2kSmkisEDP4QURqPrSR1lR6wXda3PHx2M=; b=ER4xWmIGGf0H2vl9y2Fj4owD1BLyf9jZ95fW+MYRK+nMMVlkbQWwdinhRQcjqR5zxn PykedBVvjECgPpObatTrDWTvAFhWZwEnfot/r1pOdP7ivf04iIYooC4YU3fO2I0jg7eT F1bCoLNJysWM98qBP8HpCLP3hZcnodWcJAFb4= 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=GRe242656I2kSmkisEDP4QURqPrSR1lR6wXda3PHx2M=; b=UjFW8WyzIvmu75UUqKEpPth7e+hCQQcu7PcPeRawyTY5w8m2ScQyFhQABGpQAup7YW gbHaLqD9QdOy4V11nRe33CLxhB3BtBaXeGqaYuL6NX7sL2gZwVIFyziICx7HVq4laadW YIZwVjgnmeP6R+lxPmLLy0cuFnqXKJiHFQmFrZJD4C/NFduggqVlUldMX1JN6f9DUX6Q sn1Kxa/wXQPq36VvWb2unhSEdO01OesoPvKFNtXpRxVnySgdipRUxrvhwVMKXezLU/Np yBYpoM5iMvuA/2d/O5Pg6Ud5oYBBQxeKRcVFBxbNmy+VUDs76MdmH0fkJaTb/C1XeH7h EBOA== X-Gm-Message-State: ABuFfoiYc+8xw+sn2NWUcBUTXvJssRgBh2nsok5HBr7ie4Ybvl37AP83 Uy9ArMXz8MCHf/rVF1BQFolVOw== X-Received: by 2002:ac8:b0d:: with SMTP id e13-v6mr742910qti.375.1539102317526; Tue, 09 Oct 2018 09:25:17 -0700 (PDT) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-245-97.washdc.fios.verizon.net. [71.255.245.97]) by smtp.googlemail.com with ESMTPSA id o7-v6sm10441169qkc.67.2018.10.09.09.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Oct 2018 09:25:16 -0700 (PDT) From: Thara Gopinath To: linux-kernel@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, rui.zhang@intel.com Cc: gregkh@linuxfoundation.org, rafael@kernel.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, javi.merino@kernel.org, edubezval@gmail.com, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, quentin.perret@arm.com, ionela.voinescu@arm.com, vincent.guittot@linaro.org Subject: [RFC PATCH 7/7] thermal/cpu-cooling: Update thermal pressure in case of a maximum frequency capping Date: Tue, 9 Oct 2018 12:25:02 -0400 Message-Id: <1539102302-9057-8-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> References: <1539102302-9057-1-git-send-email-thara.gopinath@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Thermal governors can request for a cpu's maximum supported frequency to be capped in case of an overheat event. This in turn means that the maximum capacity available for tasks to run on the particular cpu is reduced. Delta between the original maximum capacity and capped maximum capacity is known as thermal pressure. Enable cpufreq cooling device to update the thermal pressure in event of a capped maximum frequency. Signed-off-by: Thara Gopinath --- drivers/thermal/cpu_cooling.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) -- 2.1.4 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index dfd2324..da8de66 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -132,6 +133,21 @@ static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_cdev, } /** + * cpufreq_update_sched_max_capacity - update scheduler about change in cpu + * max frequency. + * @policy - cpufreq policy whose max frequency is capped. + */ +static void cpufreq_update_sched_max_capacity(struct cpufreq_policy *policy) +{ + int cpu; + unsigned long capacity = (policy->max << SCHED_CAPACITY_SHIFT) / + policy->cpuinfo.max_freq; + + for_each_cpu(cpu, policy->cpus) + update_maxcap_capacity(cpu, capacity); +} + +/** * cpufreq_thermal_notifier - notifier callback for cpufreq policy change. * @nb: struct notifier_block * with callback info. * @event: value showing cpufreq event for which this function invoked. @@ -175,8 +191,10 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, */ clipped_freq = cpufreq_cdev->clipped_freq; - if (policy->max > clipped_freq) + if (policy->max > clipped_freq) { cpufreq_verify_within_limits(policy, 0, clipped_freq); + cpufreq_update_sched_max_capacity(policy); + } break; } mutex_unlock(&cooling_list_lock);