From patchwork Tue Apr 16 19:38:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 162352 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp4615956jan; Tue, 16 Apr 2019 12:38:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqw0XzHKm34OxEN4rvdd+0bGiRbc0EfbyCL7rmK/EKGx5Oi3GUiiyWFk+D6r9g0QxRtBPR6L X-Received: by 2002:aa7:8ac8:: with SMTP id b8mr84611333pfd.234.1555443530923; Tue, 16 Apr 2019 12:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555443530; cv=none; d=google.com; s=arc-20160816; b=Ipt5iNflz2kKBRE+khd3IenTiiC7+WjYNdpwhTJ02FUCQK6nb2JA9YCOieD5FXwk37 KPOI6y1K6bCUrOwYjmgoow2uagfow0DmYDWJHCFADPvNxGDsuD2c8hCJ8yA8fSsAJ5z/ 44xxzWHFoMNZhKIApKX4x8P6I+omyhy2DsP4YrUIq0F+XzAHKcFGi4ge0kGvIG4hl/Vi nAgBfDUrY2x3N8t750LOnIDpdRoEATrHYDJjjMwGXB94lRnrCBR109vZpHrlbArdf0aC +Xat8KOFW7xfRcBMEVIBHo99ZUFtzYDqzcdyk305txxmTSshgv+3KMOm7pU6pT+phiqa Nk+A== 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=TguL0qXFpdoQPdCMMxXUN1DOZgs5y7WCqH1cN7imVPk=; b=CV3F83bBIs9fbdVJwPvmzAhMOXqQYWAx8LJahCe6wfAkU2SVOyV3/4+CvAsg44VEfg ZR9Hgi0MzbkAFCrmptn/sOpFVGGCGu5O166P3VnmOF6miLhsf4AI3cSOcBTAF32ytN74 HnYbOAMLgbNMEuP2eediGAtw/3HHHK4mMegF4lKlv1oh2ZGUg1LZWBwLkB3WxbwBvUfO GwWpAYYZ/hZwR2r/hgvkQc2G8KCzpPxBJMnOog9sB/dEZnikXdtLnNh7JiI8pdxLsjWI S6a3x7Wv+YOqSaPGVsIqxZVcW9QD/dtGFmZhChIdW8qKccwnY3oNHO6Qwbmf3rn5QgbG qBxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="RVECsf/T"; 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 1si24973666ply.311.2019.04.16.12.38.50; Tue, 16 Apr 2019 12:38:50 -0700 (PDT) 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="RVECsf/T"; 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 S1729961AbfDPTit (ORCPT + 30 others); Tue, 16 Apr 2019 15:38:49 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:43995 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbfDPTir (ORCPT ); Tue, 16 Apr 2019 15:38:47 -0400 Received: by mail-qt1-f195.google.com with SMTP id v32so24679825qtc.10 for ; Tue, 16 Apr 2019 12:38:46 -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=TguL0qXFpdoQPdCMMxXUN1DOZgs5y7WCqH1cN7imVPk=; b=RVECsf/Ty8kRUb5hdZswhPos288RtA8hIoPKCB2YLr+FY3aBAkjByxifi5roX9Gci6 mfikE3klcA9pjDh6MDF338flL+YXz+GVT6bICLYv4i/62eLeKRgI2ojnZYEiXQLCy5Vv rxvqgEC9iYCC53TBaF9mChDVaoEdKY2eoFD3ji1eIjN86cH2HgDvy0TjIPQjLlcbMyXu 1RDbMiZM37vOmwo6AgAXzG8OoNsP5HtQoH9bSjlXoqy2vO28uSwyRUb81ntEbaerY/SN E9ylW2XpfUCrGGcC0OzPHmJzKR0HepGiE4J5SGg5D81UsyK/2aHqZIqUhpybepYQiDHa bQhQ== 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=TguL0qXFpdoQPdCMMxXUN1DOZgs5y7WCqH1cN7imVPk=; b=DfuNy6Q5SL4hoIfqF4wd/824k7F9wZy4x00mBX/5rdqTwQV87GhJUqQ0AUBr8O6uQK 6BiM3RaKrTwEAAj7J73BRreqIPOClzUNMJ0LcaDEZeAhuRoUzQm4Qnx1etYwpf78k757 ojx2/btaMdv3ugsnLAPfpqO9a34vSXn5HTAlGVHXrzSgRT2KQZNlPfhZxWNlAgTyzaix Z0WEbYG8mxr/kIPGh71Ga/mEPGaDMtCEZxAr3+J7ecwSrpqf0Nzz3lkUCKXbDj2RgVvq L3LwjfRjX6AVo1Vs+XQtehEaIwhJUZ3M9OsUl/ppMKQQtqJDGRmos5bkanIh5z3y31Oz nYfA== X-Gm-Message-State: APjAAAV5W5W+f+4z3AFT1ZtJdI61rRXzvoDj/2pEqVCaAZ5xi3swKJuz engPzci2N/5jsbPM2yJMlVmi2w== X-Received: by 2002:a0c:b342:: with SMTP id a2mr64255690qvf.211.1555443525919; Tue, 16 Apr 2019 12:38:45 -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 k41sm46150797qtc.89.2019.04.16.12.38.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Apr 2019 12:38:45 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, rui.zhang@intel.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, javi.merino@kernel.org, edubezval@gmail.com, daniel.lezcano@linaro.org, vincent.guittot@linaro.org, nicolas.dechesne@linaro.org, bjorn.andersson@linaro.org, dietmar.eggemann@arm.com Subject: [PATCH V2 1/3] Calculate Thermal Pressure Date: Tue, 16 Apr 2019 15:38:39 -0400 Message-Id: <1555443521-579-2-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1555443521-579-1-git-send-email-thara.gopinath@linaro.org> References: <1555443521-579-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 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 thermal_pressure is introduced to keep track of instantaneous per cpu thermal pressure. Per cpu timers are scheduled to accumulate and decay thermal pressure periodically. Two interfaces are introduced: sched_update_thermal_pressure to be called from any entity that caps the maximum frequency of a cpu and sched_get_thermal_pressure to be called by scheduler to get the thermal pressure of the cpu. Signed-off-by: Thara Gopinath --- include/linux/sched/thermal.h | 11 +++ kernel/sched/Makefile | 2 +- kernel/sched/thermal.c | 220 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 include/linux/sched/thermal.h create mode 100644 kernel/sched/thermal.c -- 2.1.4 diff --git a/include/linux/sched/thermal.h b/include/linux/sched/thermal.h new file mode 100644 index 0000000..cda158e --- /dev/null +++ b/include/linux/sched/thermal.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_SCHED_THERMAL_H +#define _LINUX_SCHED_THERMAL_H + +void sched_update_thermal_pressure(struct cpumask *cpus, + unsigned long cap_max_freq, + unsigned long max_freq); + +unsigned long sched_get_thermal_pressure(int cpu); + +#endif /* _LINUX_SCHED_THERMAL_H */ diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile index 21fb5a5..4d3b820 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..1acee52 --- /dev/null +++ b/kernel/sched/thermal.c @@ -0,0 +1,220 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Sceduler Thermal Interactions + * + * Copyright (C) 2018 Linaro, Inc., Thara Gopinath + */ + +#include +#include +#include +#include "sched.h" + +/* Per cpu structure to keep track of Thermal Pressure */ +struct thermal_pressure { + unsigned long scale; /* scale reflecting average cpu max capacity*/ + unsigned long acc_scale; /* Accumulated scale for this time window */ + unsigned long old_scale; /* Scale value for the previous window */ + unsigned long raw_scale; /* Raw max capacity */ + unsigned long age_stamp; /* Last time old_scale was updated */ + unsigned long last_update; /* Last time acc_scale was updated */ + spinlock_t lock; /* Lock for protecting from simultaneous access*/ + /* Timer for periodic update of thermal pressure */ + struct timer_list timer; + int cpu; +}; + +DEFINE_PER_CPU(struct thermal_pressure *, thermal_pressure_cpu); + +#define THERMAL_PRESSURE_DECAY_PERIOD (NSEC_PER_SEC / 2) + +static unsigned long calculate_simple(struct thermal_pressure *cpu_thermal, + s64 delta, s64 period) +{ + unsigned long scale; + s64 decay_period = THERMAL_PRESSURE_DECAY_PERIOD; + + cpu_thermal->acc_scale += delta * cpu_thermal->raw_scale; + scale = cpu_thermal->old_scale * decay_period; + scale += cpu_thermal->acc_scale; + scale /= (decay_period + period); + cpu_thermal->last_update += delta; + + return scale; +} + +/* + * Calculate thermal pressure. + * At the crux this is an averaging algorithm. Intially a tunable + * decay period(D) is defined. Thermal pressure at the end of a decay + * period D is the average of thermal pressure of period D-1 and D. + * + * Time D-2 D-1 D + * ---------------------------------------------------------- + * Raw Thermal r1 r2 r3 + * Pressure + * + * Average Thermal r1 (r1+r2)/2 ((r1+r2)/2 + r3)/2 + * Pressure. + */ +static void calculate_thermal_pressure(struct thermal_pressure *cpu_thermal) +{ + unsigned long scale; + s64 now, delta, decay_period, period; + int cpu; + + if (!cpu_thermal) + return; + + cpu = cpu_thermal->cpu; + now = sched_clock_cpu(cpu); + period = now - cpu_thermal->age_stamp; + decay_period = THERMAL_PRESSURE_DECAY_PERIOD; + + if (period <= 0) + return; + + /* + * If period is less than decay_period, + * just accumulate thermal pressure + */ + if (period < decay_period) { + delta = now - cpu_thermal->last_update; + scale = calculate_simple(cpu_thermal, delta, period); + } else { + /* delta here is the remaining time in the last time window */ + delta = decay_period - + (cpu_thermal->last_update - cpu_thermal->age_stamp); + scale = calculate_simple(cpu_thermal, delta, decay_period); + cpu_thermal->acc_scale = 0; + cpu_thermal->age_stamp += decay_period; + /* Decay thermal pressure for every decay period remaining */ + while ((sched_clock_cpu(cpu) - cpu_thermal->age_stamp) + > decay_period) { + scale += cpu_thermal->raw_scale; + scale /= 2; + cpu_thermal->age_stamp += decay_period; + cpu_thermal->last_update += decay_period; + } + cpu_thermal->old_scale = scale; + delta = sched_clock_cpu(cpu) - cpu_thermal->age_stamp; + if (delta > 0) + scale = calculate_simple(cpu_thermal, delta, delta); + } + cpu_thermal->scale = scale; +} + +static void thermal_pressure_update(struct thermal_pressure *cpu_thermal, + unsigned long cap_max_freq, + unsigned long max_freq, bool change_scale) +{ + unsigned long flags = 0; + + calculate_thermal_pressure(cpu_thermal); + if (change_scale) + cpu_thermal->raw_scale = + (cap_max_freq << SCHED_CAPACITY_SHIFT) / max_freq; + + mod_timer(&cpu_thermal->timer, jiffies + + usecs_to_jiffies(TICK_USEC)); + + spin_unlock_irqrestore(&cpu_thermal->lock, flags); +} + +/** + * Function for the tick update of the thermal pressure. + * The thermal pressure update is aborted if already an update is + * happening. + */ +static void thermal_pressure_timeout(struct timer_list *timer) +{ + struct thermal_pressure *cpu_thermal = from_timer(cpu_thermal, timer, + timer); + unsigned long flags = 0; + + if (!cpu_thermal) + return; + + if (!spin_trylock_irqsave(&cpu_thermal->lock, flags)) + return; + + thermal_pressure_update(cpu_thermal, 0, 0, 0); +} + +/** + * Function to update thermal pressure from cooling device + * or any framework responsible for capping cpu maximum + * capacity. + */ +void sched_update_thermal_pressure(struct cpumask *cpus, + unsigned long cap_max_freq, + unsigned long max_freq) +{ + int cpu; + unsigned long flags = 0; + struct thermal_pressure *cpu_thermal; + + for_each_cpu(cpu, cpus) { + cpu_thermal = per_cpu(thermal_pressure_cpu, cpu); + if (!cpu_thermal) + return; + spin_lock_irqsave(&cpu_thermal->lock, flags); + thermal_pressure_update(cpu_thermal, cap_max_freq, max_freq, 1); + } +} + +/** + * Function to be called from scheduler to get thermal pressure + * of a cpu + */ +unsigned long sched_get_thermal_pressure(int cpu) +{ + struct thermal_pressure *cpu_thermal = per_cpu(thermal_pressure_cpu, + cpu); + + if (!cpu_thermal) + return SCHED_CAPACITY_SCALE; + else + return cpu_thermal->scale; +} + +static void __init init_thermal_pressure(void) +{ + struct thermal_pressure *cpu_thermal; + unsigned long scale; + int cpu; + + pr_debug("Init thermal pressure\n"); + for_each_possible_cpu(cpu) { + cpu_thermal = per_cpu(thermal_pressure_cpu, cpu); + if (cpu_thermal) + continue; + + cpu_thermal = kzalloc(sizeof(*cpu_thermal), GFP_KERNEL); + if (!cpu_thermal) + continue; + scale = SCHED_CAPACITY_SCALE; + cpu_thermal->scale = scale; + cpu_thermal->old_scale = scale; + cpu_thermal->raw_scale = scale; + cpu_thermal->age_stamp = sched_clock_cpu(cpu); + cpu_thermal->last_update = sched_clock_cpu(cpu); + cpu_thermal->cpu = cpu; + spin_lock_init(&cpu_thermal->lock); + timer_setup(&cpu_thermal->timer, thermal_pressure_timeout, + TIMER_DEFERRABLE); + per_cpu(thermal_pressure_cpu, cpu) = cpu_thermal; + pr_debug("cpu %d thermal scale = %ld\n", cpu, cpu_thermal->scale); + } + + for_each_possible_cpu(cpu) { + cpu_thermal = per_cpu(thermal_pressure_cpu, cpu); + if (!cpu_thermal) + continue; + cpu_thermal->timer.expires = jiffies + + usecs_to_jiffies(TICK_USEC); + add_timer(&cpu_thermal->timer); + } +} + +late_initcall(init_thermal_pressure); From patchwork Tue Apr 16 19:38:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 162353 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp4616080jan; Tue, 16 Apr 2019 12:38:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqwx6npVFVx462ivlR+w/xoas6URtRdHBAN6/TQh6zR0mBW6WJUSwwBeDeV8PAknGEZXIod2 X-Received: by 2002:a17:902:b40a:: with SMTP id x10mr84617431plr.231.1555443538863; Tue, 16 Apr 2019 12:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555443538; cv=none; d=google.com; s=arc-20160816; b=SX2GqCRBohzjQzIGkvq5u1d4pl9V8NOnUajWtfQqu2R6/JrEBaXoSZCUrN/PpUsCyh B5IO4d/Vm7NzIVBtjZUPubeAQm4BKMiZ4BKltJ2/u9oMkNVU1dbOT18YLZVsu3RDNYJL TWXULGMxUIgrN22byc1HqSdajRvuRv95bVemj41Lh6Pvmlq50Dbi+q0NjBkgZ7EBl4Xz aTMsNJz7C8DoYF6dDmQ/fALWc3nVcLuv14CKuFaBfjV/iGeJqKqSY1FIJFgacbdDy8HX 5xNLlZ6v/ErEjBz0CuM3/5jxwcxXjEFbDKURsjtg+Wc18PCG0z2iZHEW18pQHDNjJ9vC rtoA== 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=KNbekIfBRRm8uM1KdnvYGnhJo7PPeihMU4LxOw05fOc=; b=G3huIFQMHqird7GscGbsfhoKB6RAEmbdxOeH+WUckMNmQNXCXzXhnMGakGR/MBlORj JsTnop8hWCKth/EER6+ssvXzr4A7Y7qKHyXLwFbvmHfyjWaRYPk7MGyvrAFv5pMVIrLB VCgBM2Wmza7/uhkuNgif2ye8FWGlKKIUD53scFsXsxktMj+EKYTbef23O/Ye8icm1BPs K0cY771jZ2AshQUeUEXLP9cD4QzXrJY2KofseAHn/TbC9h6Mg7CF4O6gD1+7LmcOXy9s kdddDsqH2AIlaUYT3pTuWir9xIZcBwWiXB09EPzd6fgFpER4zNfbS2WO9qO2ow5eVXUo RMAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dPULVRJj; 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 a1si49035478pff.258.2019.04.16.12.38.58; Tue, 16 Apr 2019 12:38:58 -0700 (PDT) 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=dPULVRJj; 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 S1730301AbfDPTi4 (ORCPT + 30 others); Tue, 16 Apr 2019 15:38:56 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:36414 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729785AbfDPTit (ORCPT ); Tue, 16 Apr 2019 15:38:49 -0400 Received: by mail-qt1-f195.google.com with SMTP id s15so24745855qtn.3 for ; Tue, 16 Apr 2019 12:38:48 -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=KNbekIfBRRm8uM1KdnvYGnhJo7PPeihMU4LxOw05fOc=; b=dPULVRJjB3vqxeNVjKurm9q6bgO2XVeQgLiDeXQptGe8f2megTmgP6kpFst3QBJfZW W5bGXDdhGFOMqMwcD8oiGUCOofULwc5Q43oCKAfUdUZXkG2VgW8efkNuJR2fsOzJZpbX 4UR0+IMSYJFc1S6HkZIrhiQXW+6Od/uwjGdhoJFdOjvkUoakOPX8Dk9QiDnhDiqtkFzB bcFEHaYNs+swYiwsToSJh3pNQc/C9icY3uLvZpz1ozTB0TvZZ1ViMYqHLq4Uy5CoaFSg hsYUAbEIOXkWmXLPusFcxBldxHFkWLAoEuIcVT43pUvTsr07s5LmvZutt8TOW874to1S k6+Q== 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=KNbekIfBRRm8uM1KdnvYGnhJo7PPeihMU4LxOw05fOc=; b=WBdrdeCZqHi088S2x7WH3/HNf7tmr3r/GANdUcJUj5xDKUFoFOpSKxzUZWic+tEVLt +t8J8FN3Dnrkb4LYkyTIdMlCJ7hcGIUC49435Y7bRUFUYBUbz/YiTA1/OLbsNrdngek1 27qsH1BefVxTAje4HTFAp5qk5Z1+wyEzibNdDs2P8kEN21SjaymnZwWVAxB3uu/LbIZb 6NnoRM6KSCEvTnG980U5bZtD8hitIY4lFmYMHYUEFT6+AvIECwn3bQS5Jz1mACC5vzl3 /oCw0qHWUA0NbkL4PEBMciagHWE6wkjhkRGaCjDhcU4Mt+XeAqbgyNtqxbaMP3X9miyU A2Kg== X-Gm-Message-State: APjAAAUJB51+ZpPXM7Kevlw1SatEmYibNVfYnkIUg6nnWbagqf+GYep8 StsNbLSP4i2kSNTJQ8NitT6wag== X-Received: by 2002:a0c:d2f2:: with SMTP id x47mr64643661qvh.90.1555443527688; Tue, 16 Apr 2019 12:38:47 -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 k41sm46150797qtc.89.2019.04.16.12.38.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Apr 2019 12:38:47 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, rui.zhang@intel.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, javi.merino@kernel.org, edubezval@gmail.com, daniel.lezcano@linaro.org, vincent.guittot@linaro.org, nicolas.dechesne@linaro.org, bjorn.andersson@linaro.org, dietmar.eggemann@arm.com Subject: [PATCH V2 2/3] sched/fair: update cpu_capcity to reflect thermal pressure Date: Tue, 16 Apr 2019 15:38:40 -0400 Message-Id: <1555443521-579-3-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1555443521-579-1-git-send-email-thara.gopinath@linaro.org> References: <1555443521-579-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 cpu_capacity relflects the maximum available capacity of a cpu. Thermal pressure on a cpu means this maximum available capacity is reduced. This patch reduces the average thermal pressure for a cpu from its maximum available capacity so that cpu_capacity reflects the actual available capacity. Signed-off-by: Thara Gopinath --- kernel/sched/fair.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.1.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 8213ff6..c5454d3 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -23,6 +23,7 @@ #include "sched.h" #include +#include /* * Targeted preemption latency for CPU-bound tasks: @@ -7967,6 +7968,9 @@ static void update_cpu_capacity(struct sched_domain *sd, int cpu) if (!capacity) capacity = 1; + capacity *= sched_get_thermal_pressure(cpu); + capacity >>= SCHED_CAPACITY_SHIFT; + cpu_rq(cpu)->cpu_capacity = capacity; sdg->sgc->capacity = capacity; sdg->sgc->min_capacity = capacity; From patchwork Tue Apr 16 19:38:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 162354 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp4616101jan; Tue, 16 Apr 2019 12:39:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwLW+8IAxQLV202lNsKX4yZkEEoq+I/S7bnp5BrWT6JLo1OKiUbXmLGuWxRu2w24eYI46ze X-Received: by 2002:a17:902:7043:: with SMTP id h3mr85717557plt.228.1555443540040; Tue, 16 Apr 2019 12:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555443540; cv=none; d=google.com; s=arc-20160816; b=N9T9CN1r6KDpKZJw7M/d6Ek+iq6tOzLKuE2iiL8RCdPNt2sUL2Rcd4imrmMwWyeX76 dSJDOBliY9owMsUtv7qq4UJniz7s5GTBA42VdO+e2H3p8DG3dupkL1mdOAzueqnYvJ3x luw8vyeFOq74W0Rs+w+njTO3+MNX8t7jrfqudWN4wDZx5kNqttLpdRiS+hYFBLvAxlMj j7dYZJIJfL1LXt5QEaxbXJ+wojjSWp3+hGJI2NzbeaYwb0qBV2Eno+p+1RHxerZsYukY iRIFJxaubd2fUW0725A6aeKMqFy8UpdRMX8SZyAEwwxueZBq5toMcQgW3bo5YJj+mox/ jnAA== 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=DHvwucClEuE6vcfN7CuEc8eFK+qMiBspP3oOBK+KZZE=; b=kzw08srF4KT205vam/k1IsfMrwS3IcF4hyhPuMXmJ+nVgG7/hWCoA+Vi2iyfcZX5uU fNeJfROn7OONVAUC3tdkjIJbfHrldHKJOg8N9lFCmWXesxi2fzANMDw2QBwXP9CMMPrf CYIY70H2qOgORtQC/NVJ+NCEkj1H1qHFkVyP6mZ+At6V8NqhkdG6prQjko608+fvGCq9 kFcRr/hDMx8f3Y6CXPCkMF3mlhOK3J6o/IswPoq9L5DuAXFp+Jlw6Pkl907S01z7h+Vw AZQvyu5WIPEN0JMlviF6M7R9I/Pa0R3VtBn88Pt7vaUAV72jILnwY0wm1UYSg8K5fgzF 7yPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="sL/wnHvm"; 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 t185si25826136pgd.485.2019.04.16.12.38.59; Tue, 16 Apr 2019 12:39:00 -0700 (PDT) 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="sL/wnHvm"; 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 S1730263AbfDPTiw (ORCPT + 30 others); Tue, 16 Apr 2019 15:38:52 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:36418 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729925AbfDPTiu (ORCPT ); Tue, 16 Apr 2019 15:38:50 -0400 Received: by mail-qt1-f195.google.com with SMTP id s15so24745951qtn.3 for ; Tue, 16 Apr 2019 12:38:49 -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=DHvwucClEuE6vcfN7CuEc8eFK+qMiBspP3oOBK+KZZE=; b=sL/wnHvmS8sJ5Cgb3Z/Ioo4m4Apbm4Eve1PwNIh0xYbgNh9Vq/AFdwbWhtBb2XDgcH U+XlSoQjehVMSTlhE4hbEZ7fsx9HJDnkExCEXL9rTkN9QiX16Y2FvKWTLyT4HumqseVu 3ejFYFn/9cM5kSutWvOF6wi2ClYNEOBzACNvN/CDnG329cP6gI53yhlzJRTjCSIQZuo7 6qA5W4s7vHgrSoYYlAMXt7iV6XhbeOTSAR2ztxVcDNpOh4+ysiRzXhm3XgUHRVQY6hRw t7RPjuVGg3NiDSZQXMlwDW5XqbAHI28D6/FSvuHTxGdAIBe5IgdW7a3r0lBMLh8AuB0O LhSQ== 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=DHvwucClEuE6vcfN7CuEc8eFK+qMiBspP3oOBK+KZZE=; b=rgRlBDYREevXegaD5BqZaz+VbktMkH01IBSczsa3/F4G7T4wNIFuWFt54vAnRlKxt0 t55shLH/bEphhxwpsRhL2KhuKoL87LlXVRmjMTaDrh3fyah0ziek6IzZWRogImHFuQVr mgvsuhv1mXSqkK7jy2y4p+aVgOU0MNipiMb3Pj1VSKufTWtmjSr4I/eg/N9/qsT0vxpn OKKf59oduSeeC7QVHJcaBmU5gcaR5PqaadKSIF7aL43XvQAaBokb3I3JGPx30b1WvA0n Vi/4e39SKvNtA2gil2vT8INar1xa+p7ROgwtssDuJFYHub1zBMqcSDZL3NLZ946gmfRe 9n2g== X-Gm-Message-State: APjAAAWx2o8RlIcnJW80l6h6TW+JtK2+YoOm/IBZwwa1kjE2wzrN/D0h YFPs3Hnxfjy7S2Kx8A5NuWmmHg== X-Received: by 2002:aed:3f49:: with SMTP id q9mr69900551qtf.279.1555443528979; Tue, 16 Apr 2019 12:38:48 -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 k41sm46150797qtc.89.2019.04.16.12.38.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Apr 2019 12:38:48 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, rui.zhang@intel.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, viresh.kumar@linaro.org, javi.merino@kernel.org, edubezval@gmail.com, daniel.lezcano@linaro.org, vincent.guittot@linaro.org, nicolas.dechesne@linaro.org, bjorn.andersson@linaro.org, dietmar.eggemann@arm.com Subject: [PATCH V3 3/3] thermal/cpu-cooling: Update thermal pressure in case of a maximum frequency capping Date: Tue, 16 Apr 2019 15:38:41 -0400 Message-Id: <1555443521-579-4-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1555443521-579-1-git-send-email-thara.gopinath@linaro.org> References: <1555443521-579-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 Enable cpufreq cooling device to update the thermal pressure in event of a capped maximum frequency or removal of capped maximum frequency. Signed-off-by: Thara Gopinath --- drivers/thermal/cpu_cooling.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.1.4 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 6fff161..d5cc3c3 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -177,6 +178,9 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb, if (policy->max > clipped_freq) cpufreq_verify_within_limits(policy, 0, clipped_freq); + + sched_update_thermal_pressure(policy->cpus, + policy->max, policy->cpuinfo.max_freq); break; } mutex_unlock(&cooling_list_lock);