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