From patchwork Tue Oct 22 20:34:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 177231 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp5372665ill; Tue, 22 Oct 2019 13:34:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPtJ52Z1P61hPuGodkK+ST0tsYo2Lf602sFhiEslVDgsmvJKbn8Q3a/WYYTgaaKXnT5pJH X-Received: by 2002:a17:906:5e07:: with SMTP id n7mr29302897eju.271.1571776474928; Tue, 22 Oct 2019 13:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571776474; cv=none; d=google.com; s=arc-20160816; b=lPjXqKCisMNr7frZqi1QaY1LwNeS5klQxOqZuc3VdOAoExxg8LspJyWDKlNTSxtUof htpdQHrDj+z2mTLOX+9L2bu61Qihc7Og8YLgDknnCX9kfHzCtPipjbL1IynR+sgslvfB 6prDfEoVrSYs47pFFdjozn7GwwGezFrcSjFaKxMzLaPzNVQHyn8rM0UHwffl0XqRxPZM XwOtVa+VV9URdJ9Orzz9ftP+AY0s1uuRvuuzzX3eFQgmyUBYRX+iNkiqfvkZQCNV40Ya mSH+Psg1nhapvBufZFLXQGR9dxCi2J5iCAmHETBHRux21mLVgYUZVwKa8XtwoyIRlu3u OLuw== 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=3iXJDm64yU5kPpIovC1LUxJgR4cu+K7/3XhEF8ojNLc=; b=0zWDEYFriKzjrRAOpNPi2+CpsXTMmmOz8XQiWFl1B4zng33IXz493D9KFtd9gOoI1c omKADU3OekG8O9DOcpoxSGHQ+U1jAf7WSVI6v26z13KJgXuWb5rTkcqAVpO6Lsa7KhZf 0mweaB9E6jmKCFOFcJuaF1Jvl/Z8JTTjszl0EirxnlTyBctI75qTquz6h22upsQTWQgD v/3FH4Me2y486LzSNNdmS6LXLfwwERc5hVGAb9Z/9QkxtUOzo6RRkkfFIE32dPeV+06Z 5Yzmu3XqsTh7lRabe/wjunUjWEqQL2llol6s4Dp8zus75Hpwukydf7+hTJlwynkzAeMb 1Kqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aH+I9Mrz; 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 k6si11690991ejs.354.2019.10.22.13.34.34; Tue, 22 Oct 2019 13:34:34 -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=aH+I9Mrz; 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 S2389376AbfJVUea (ORCPT + 26 others); Tue, 22 Oct 2019 16:34:30 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:34339 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389153AbfJVUea (ORCPT ); Tue, 22 Oct 2019 16:34:30 -0400 Received: by mail-qt1-f194.google.com with SMTP id e14so9093382qto.1 for ; Tue, 22 Oct 2019 13:34:29 -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=3iXJDm64yU5kPpIovC1LUxJgR4cu+K7/3XhEF8ojNLc=; b=aH+I9MrzgLa6oPfEAQB10D3S98FO/VBm9pwwROVFp920m35baZz1f5Hf+WH2033EnT 3rgTmpl/aeitOy6UGm1KCCbhrkpZkzMWjFr9utusfa7rWS26TZUhJwrfezuAkR/ekk5V yD7nKdwuFmgM8c7eJTLtfUMT8/qwInrjuxstvExOqFCNQuJY6CoEe1ElI1aOQ2nta9zz 1yZ7W68BgH+Eh9aTFsQV0AEknM3ufkenjZ0ac0dY6INUrjNqalZVnX3BHyX92XA3362N uWJzfJa1OmAD638xyJ+v/dxURzQjMBcFez8gyCTRINAAaGm9eFRW11h0HrqrEuwJOtdf HYGQ== 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=3iXJDm64yU5kPpIovC1LUxJgR4cu+K7/3XhEF8ojNLc=; b=Z8/F0DUPXOuTjlQcBqd+Z8OFP2IWplu/A4nJ3dtaX8i1AOwQIG8WDH5SDkPh1QfNnx PRjRlaVKk3/3awF9swWWNOiCYcvqO5ZVkZdbHPoY/CF0T1Dh23ZJF3jhg50i+VExJ0oG 2fS0Zp6e+8v0skiY9IYxMvOxOgZoaAHLBPoMkeaOhMHivukhi/peCNBZB94/y6VpZSej R6W102gmssl3QdxtOQ987+zDTVTB/ZLNk7d+KQJP1s+6D2BBhSG2d90M3FHWAq1lxJTo 6Ckp0GSLGK3xaf97ubPi9gBiHHk5JUQVcTPExS0k+udJzCMcFmhlVkaRaT1j6CL0aIq2 cceQ== X-Gm-Message-State: APjAAAVw7PWxarp9GKCw26o/hCugty5XWybgcO9oNq1FTr039nrZsmvZ qjdHOeJkmuwE/2offrHaaNqOsMh+uh4= X-Received: by 2002:ac8:3849:: with SMTP id r9mr5365347qtb.370.1571776469099; Tue, 22 Oct 2019 13:34:29 -0700 (PDT) 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 r126sm8895038qke.98.2019.10.22.13.34.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Oct 2019 13:34:28 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, edubezval@gmail.com, qperret@google.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, daniel.lezcano@linaro.org Subject: [Patch v4 1/6] sched/pelt.c: Add support to track thermal pressure Date: Tue, 22 Oct 2019 16:34:20 -0400 Message-Id: <1571776465-29763-2-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1571776465-29763-1-git-send-email-thara.gopinath@linaro.org> References: <1571776465-29763-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 Extrapolating on the exisiting framework to track rt/dl utilization using pelt signals, add a similar mechanism to track thermal pressure. 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. This is because thermal pressure signal is weighted "delta" capacity and is not binary(util_avg is binary). "delta capacity" here means delta between the actual capacity of a cpu and the decreased capacity a cpu due to a thermal event. 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 --- v3->v4: - Renamed update_thermal_avg to update_thermal_load_avg. - Fixed typos as per review comments on mailing list - Reordered the code as per review comments kernel/sched/pelt.c | 13 +++++++++++++ kernel/sched/pelt.h | 7 +++++++ kernel/sched/sched.h | 1 + 3 files changed, 21 insertions(+) -- 2.1.4 diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c index a96db50..3821069 100644 --- a/kernel/sched/pelt.c +++ b/kernel/sched/pelt.c @@ -353,6 +353,19 @@ int update_dl_rq_load_avg(u64 now, struct rq *rq, int running) return 0; } +int update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity) +{ + if (___update_load_sum(now, &rq->avg_thermal, + capacity, + capacity, + capacity)) { + ___update_load_avg(&rq->avg_thermal, 1, 1); + return 1; + } + + return 0; +} + #ifdef CONFIG_HAVE_SCHED_AVG_IRQ /* * irq: diff --git a/kernel/sched/pelt.h b/kernel/sched/pelt.h index afff644..c74226d 100644 --- a/kernel/sched/pelt.h +++ b/kernel/sched/pelt.h @@ -6,6 +6,7 @@ int __update_load_avg_se(u64 now, struct cfs_rq *cfs_rq, struct sched_entity *se int __update_load_avg_cfs_rq(u64 now, 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_load_avg(u64 now, struct rq *rq, u64 capacity); #ifdef CONFIG_HAVE_SCHED_AVG_IRQ int update_irq_load_avg(struct rq *rq, u64 running); @@ -159,6 +160,12 @@ update_dl_rq_load_avg(u64 now, struct rq *rq, int running) } static inline int +update_thermal_load_avg(u64 now, struct rq *rq, u64 capacity) +{ + return 0; +} + +static inline int update_irq_load_avg(struct rq *rq, u64 running) { return 0; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 0db2c1b..d5d82c8 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -944,6 +944,7 @@ struct rq { #ifdef CONFIG_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 22 20:34:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 177232 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp5372673ill; Tue, 22 Oct 2019 13:34:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIONSkAHHPTr6QF0hRbGqSuW5T7DgtVJQjzS+lB6zrkoETJFcdI5l6xahJ+x8LoORGnPb3 X-Received: by 2002:a17:906:4448:: with SMTP id i8mr28415686ejp.298.1571776475346; Tue, 22 Oct 2019 13:34:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571776475; cv=none; d=google.com; s=arc-20160816; b=iLuAuhYAT6K9wXneZGJwOn+O+bYpbCBhn0Uj85VCGevo68C3nMQPYtVv5ce2t0Km4r p17FEEaZxmgoWxok5bVJ5EVS/F1BtqYxfZtUHBCYmAveNWoEY78NJZaxTYfnMUNILxyW Tx0sCOx9nAWYLN8GRss29VEr0BybGknwEXmwIQnRLoAqDGUjqRDdLNoGv0xf+wca9hgo MBuczXk9G86bDy4LsxtOVHq/Q7XatOfq2N8C1dMCzx8zxAR+mdrMDrNnl05re2WLyRSz keu86y9A9PVSzu8luctA5VnHYUYagnvS/dAVuH6jENysOeX57qoaWF90m45WxSWCZd1W tNpQ== 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=vJ9FZ+tbutK9H8P0UifHj9bRmxWrH0GAs5h60TIQ7uw=; b=bb9LsQY8+l6g4LegKlFmtAJJrc9RWU8xDYD5gtHTTIkeiugQbSKBS7tnl53mNwIqmF uB/pgeFqcTuTxkFvGYthC2be3EkdMSDQ/jRw3GHD8fHR6fhjaqf69fppce715Yqh2SB1 P3Ar72BZr/czttVPYjYbVcxNIjBCntnQJXpDEADKip19eWZ01T5w2RnwTIa41WvseG1K L0MF7o1TIhzNluk453UzfaZCeVDTywtc/SW61flyi2R1nltn7VbHZ2iq+zMXLf4Crmn0 voeBQ+4kWMiZePGpzoe71+A7oGCGw1WlTWDCbnd1J76HOYOa2Y5uhDc+dvmyBj/cvFdU NFtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oo5sa5N9; 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 k6si11690991ejs.354.2019.10.22.13.34.35; Tue, 22 Oct 2019 13:34:35 -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=oo5sa5N9; 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 S2389412AbfJVUed (ORCPT + 26 others); Tue, 22 Oct 2019 16:34:33 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:39876 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389153AbfJVUec (ORCPT ); Tue, 22 Oct 2019 16:34:32 -0400 Received: by mail-qk1-f196.google.com with SMTP id 4so17625126qki.6 for ; Tue, 22 Oct 2019 13:34:31 -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=vJ9FZ+tbutK9H8P0UifHj9bRmxWrH0GAs5h60TIQ7uw=; b=oo5sa5N9CFOG7T1MGV0uPi7I5GlqjQpyKB/7oTUGTiOH0MrVZ8drYGpCpG3ObxxquP rJ2/AHUUK8ryiEGIbMmJ2UtExbT046g+n+99VqVGXNZOBnCKk5Rm7XedybmItpvQE5zC h2O/ZfmQropsP0xpw2qZj+ZZaWu3y1Q2mYGRgKWV/7u1yTWWVlG86bWgk+r6LUNH0rPM FrLzeeH1ELrLsR5xXEwluTSbHJ5ndB5IpP7tllyZUJfoknab8MOPoB2oWu0RWXWtDRYb 5rLuf0SP90WynjqrOkkiN5VDwhnoHnBoii5DLv4F4J9qERcjZn4S5OreXO3cwkDgcRN1 AoOw== 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=vJ9FZ+tbutK9H8P0UifHj9bRmxWrH0GAs5h60TIQ7uw=; b=DEP5lAEzxOkmC1UA2eC/1VEWHarB9AnUNMlACe8JC0Fobm5ynaScWi+MQjJ4ISGRnh lBjZRgnQBmEVrQxpF5B3oPa+KTkSVR1mlR6522mqMh7oSUsQWPL+nTMSjZ2CzE+SOHOM 8UM+PBlJuKoxzvYDB8sEK6En5D2KSUklDqqVl5DNIRiQvJsX9Mw2LB5k0HMg4U+NlM2b iQQ6R+ez/pUVfRVIhFkv9b6EOeHxnYr54/FAyHxjKVZEqC9oRUySYSSicNPmIfxGbHNt 80vIimgDyZ2ZLk6GD3+dzhDc/FOl7aHgM+RgsBQQOmBlWO/Cj0MSuYgzjbysRdwToEcz QgWQ== X-Gm-Message-State: APjAAAXHsiqzgmL2EdLBPJXCsOoVEheZkNLh9EccXRoONuX4v3topMhS Y7ymUb8tloY2iCslRDyyRru6Kw== X-Received: by 2002:ae9:f012:: with SMTP id l18mr4803736qkg.291.1571776470728; Tue, 22 Oct 2019 13:34:30 -0700 (PDT) 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 r126sm8895038qke.98.2019.10.22.13.34.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Oct 2019 13:34:30 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, edubezval@gmail.com, qperret@google.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, daniel.lezcano@linaro.org Subject: [Patch v4 2/6] sched: Add infrastructure to store and update instantaneous thermal pressure Date: Tue, 22 Oct 2019 16:34:21 -0400 Message-Id: <1571776465-29763-3-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1571776465-29763-1-git-send-email-thara.gopinath@linaro.org> References: <1571776465-29763-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 variable delta_capacity 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. API trigger_thermal_pressure_average is called for periodic accumulate and decay of the thermal pressure. It is to to be called from a periodic tick function. This API passes on the instantaneous delta capacity of a cpu to update_thermal_load_avg to do the necessary accumulate, decay and average. API update_thermal_pressure is for the system to update the thermal pressure by providing a capped frequency ratio. Considering, trigger_thermal_pressure_average reads delta_capacity and update_thermal_pressure writes into delta_capacity, one can argue for some sort of locking mechanism to avoid a stale value. But considering trigger_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 delta_capacity 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. include/linux/sched.h | 8 ++++++++ kernel/sched/Makefile | 2 +- kernel/sched/thermal.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ kernel/sched/thermal.h | 13 +++++++++++++ 4 files changed, 67 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 2c2e56b..d7ef543 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1983,6 +1983,14 @@ static inline void rseq_syscall(struct pt_regs *regs) #endif +#ifdef CONFIG_SMP +void update_thermal_pressure(int cpu, u64 capacity); +#else +static inline void update_thermal_pressure(int cpu, u64 capacity) +{ +} +#endif + const struct sched_avg *sched_trace_cfs_rq_avg(struct cfs_rq *cfs_rq); char *sched_trace_cfs_rq_path(struct cfs_rq *cfs_rq, char *str, int len); int sched_trace_cfs_rq_cpu(struct cfs_rq *cfs_rq); 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..0c84960 --- /dev/null +++ b/kernel/sched/thermal.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Scheduler Thermal Interactions + * + * Copyright (C) 2018 Linaro, Inc., Thara Gopinath + */ + +#include +#include "sched.h" +#include "pelt.h" +#include "thermal.h" + +static DEFINE_PER_CPU(unsigned long, delta_capacity); + +/** + * update_thermal_pressure: Update thermal pressure + * @cpu: the cpu for which thermal pressure is to be updated for + * @capped_freq_ratio: capped max frequency << SCHED_CAPACITY_SHIFT / max freq + * + * capped_freq_ratio is normalized into capped capacity and the delta between + * the arch_scale_cpu_capacity and capped capacity is stored in per cpu + * delta_capacity. + */ +void update_thermal_pressure(int cpu, u64 capped_freq_ratio) +{ + unsigned long __capacity, delta; + + /* Normalize the capped freq ratio */ + __capacity = (capped_freq_ratio * arch_scale_cpu_capacity(cpu)) >> + SCHED_CAPACITY_SHIFT; + delta = arch_scale_cpu_capacity(cpu) - __capacity; + pr_debug("updating cpu%d thermal pressure to %lu\n", cpu, delta); + + per_cpu(delta_capacity, cpu) = delta; +} + +/** + * trigger_thermal_pressure_average: Trigger the thermal pressure accumulate + * and average algorithm + */ +void trigger_thermal_pressure_average(struct rq *rq) +{ + update_thermal_load_avg(rq_clock_task(rq), rq, + per_cpu(delta_capacity, cpu_of(rq))); +} diff --git a/kernel/sched/thermal.h b/kernel/sched/thermal.h new file mode 100644 index 0000000..26e5b07 --- /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 trigger_thermal_pressure_average(struct rq *rq); + +#else +static inline void trigger_thermal_pressure_average(struct rq *rq) +{ +} +#endif From patchwork Tue Oct 22 20:34:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 177233 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp5372753ill; Tue, 22 Oct 2019 13:34:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqyS+XzQVsg7OElVqMD/cax9Bk5F2HaGyqIuzUGl5s1+jODdnWDdfLgdbSs6x/Ot4q71oh7N X-Received: by 2002:a05:6402:1507:: with SMTP id f7mr33662848edw.68.1571776480471; Tue, 22 Oct 2019 13:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571776480; cv=none; d=google.com; s=arc-20160816; b=zNXydYLep7HaFpB2EvPm9yJDLUTBk4AV+PcaXO0WhYMnRicXV6aN8+1po6t26tn4uc qVfrLlaWX0b/ue4yXZmXGNqwlWoclTek9+wDDg3Nqf2BKPSiccb4ASfXP4frTLJF3jqJ cuKNu7VtbnMHY7zMFRB6sbK6NCKjuYLrF2HDG4S5MLC1NtNAVEdaGBbfpVxb1KSkmEFc TRMEEb0EQhggjK3M3hzinB0gWn6xEDcOzzQX+SYdPtQMmXvryUHZMnHYfdF70rST0sNh DMHsDpWWwSG1IXxZVV9eBzrPu0PMAsTAEP20jrPGUtjciRuWfqJZV07Kb0c2k/QYDQGX Vysw== 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=+62b01duIzwhl+lWRPPBbONvvknzw7BTtBn7ok/CsvU=; b=bkAz9iVvuCAPP2jEa4iQ7wGepppputDCBuxgbCaohszDeQ/1dBM5AAQLd6g7At9z7C YtQc2sUnEjOklW3jlO9iJwXFKSL0jiS+0jmbHYy3zIjBb1X0Bw0DS6Dp6sy1R30ULAQa tRRlH6HV6925FzWBMZ8vR6dTq3HU6rCA1FRhrMt0fvGTsiH9kiSKqmb8htISCEQtScnP e1Mgci5yNGJvKgcWMStT4qIgffgc6KxX+NwteE4MXy5JI796pdj+tN2qS3j2STxZ0uld IoCo1ZArWtIJa23H+UkPYRIzowqL4FYksPjp0ryA1hgBJPakAJLIPsutrl46oj5qhPFp kWGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=afhY9KI9; 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 g17si6131618edh.379.2019.10.22.13.34.40; Tue, 22 Oct 2019 13:34:40 -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=afhY9KI9; 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 S2389431AbfJVUef (ORCPT + 26 others); Tue, 22 Oct 2019 16:34:35 -0400 Received: from mail-qk1-f194.google.com ([209.85.222.194]:42761 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389407AbfJVUed (ORCPT ); Tue, 22 Oct 2019 16:34:33 -0400 Received: by mail-qk1-f194.google.com with SMTP id m4so689128qke.9 for ; Tue, 22 Oct 2019 13:34:32 -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=+62b01duIzwhl+lWRPPBbONvvknzw7BTtBn7ok/CsvU=; b=afhY9KI98X7oFg8SEiw6QnjzPR5O+aClzT0lPCL6RRLwqRm4KHhE/dJea/JM6sIhDW 87pXYEQdEdxSuoZ5XetxEQuUvpk53W2X31ARCH0Zhjai2qr7guaEL5Q3pxxn1Ac+ysks xc4GjWgjvF3FKJB+E2sRVXN3TY66jGGEOd9Erz2eAX/5uYgA4Ke04oc1ozzSSMdT624f Kx8oriWjnOkyc+fkgSW3J+C9W24kfVgKxiI6ff6CsLfiOCzRVXnSzixSrZcytlvzHvjx J5DYJ7R3NSUAm7hSwIBp6mMK+3p2omGMCwV1Vsa2ZGPMJqznnTznWwMRk+rC6I1gjloF kh9g== 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=+62b01duIzwhl+lWRPPBbONvvknzw7BTtBn7ok/CsvU=; b=qKxMXsz7jQ6gbFtf1Ez9NlrDWQXlNZvIc9tkvUlel5ZhLjzQmDCsdtSgRJYFYQD7RN I3zW537CNLeXlmEP/cEfyXwsgYxihOJOM79gR8TkxW9+aq1nzsUPBALum+Qyh5qlNS07 MKxZGUbJx1t5E9QvCug2PseT2ZWqQgfjM/K6pByh5XvcQbCfuuDFLP6+SNT8oQ+y37k2 p8OAvmM2+tLZpV5AayW411XLtLBNIu41J12MzRBe5KgopJZDVXb1xrFrNlO7uxNDWJ99 4nVqcjHLMeouZzfe/zCQjN9J5hRDZHFlcFORxl+hmPccSFjG9xJToulX1Arf3H0hnLHT KkHA== X-Gm-Message-State: APjAAAXhXFlcIscZ34DwjtRn/uPSySVkMpIDy2e3QaZ5EvYUL0v4m7Zh Nnmlu2DIpxILST44lFQW6kZR+A== X-Received: by 2002:a37:6e85:: with SMTP id j127mr4993065qkc.392.1571776472427; Tue, 22 Oct 2019 13:34:32 -0700 (PDT) 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 r126sm8895038qke.98.2019.10.22.13.34.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Oct 2019 13:34:31 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, edubezval@gmail.com, qperret@google.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, daniel.lezcano@linaro.org Subject: [Patch v4 3/6] sched/fair: Enable CFS periodic tick to update thermal pressure Date: Tue, 22 Oct 2019 16:34:22 -0400 Message-Id: <1571776465-29763-4-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1571776465-29763-1-git-send-email-thara.gopinath@linaro.org> References: <1571776465-29763-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 Introduce support in CFS periodic tick to trigger the process of computing average thermal pressure for a cpu. Signed-off-by: Thara Gopinath --- kernel/sched/fair.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.1.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 682a754..4f9c2cb 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -21,6 +21,7 @@ * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra */ #include "sched.h" +#include "thermal.h" #include @@ -7574,6 +7575,8 @@ static void update_blocked_averages(int cpu) done = false; update_blocked_load_status(rq, !done); + + trigger_thermal_pressure_average(rq); rq_unlock_irqrestore(rq, &rf); } @@ -9933,6 +9936,8 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) update_misfit_status(curr, rq); update_overutilized_status(task_rq(curr)); + + trigger_thermal_pressure_average(rq); } /* From patchwork Tue Oct 22 20:34:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 177234 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp5372765ill; Tue, 22 Oct 2019 13:34:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9EtIj0YbQIy/pXLz45S3RhgZl9FSS6ZHCJQyAZ44dinhGidRwVwrVoHOSlwQReWKpjvBZ X-Received: by 2002:a05:6402:290:: with SMTP id l16mr5450360edv.190.1571776481024; Tue, 22 Oct 2019 13:34:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571776481; cv=none; d=google.com; s=arc-20160816; b=TG8LB24HWsNkMoYHvYPb36eNXSbmfAJfdXDqYQlXpUyCNtIQbAyJEvdy2wrx+wesmY Q/tzzgFTOQkbJnG6iDMqDvomTxqMxznfwyOmGcNVhKJoptvJai8fmgX1p5ZPzT8G5mHc SWLuMpnAv/bvaKx4IjZRXo6lkEGn89R1z4MdEEFwPTw/6FcofCAdEGUL1esHQsgvRNm+ 6btgfohPOC2PcrbeBuaIdLM9vtFR10t+AjGWyPz3aRD79P4tTIvWIfoUnFTLcSsyENFm w4pU6IMzvJnirkuX/HqsdZxXpzDZnP/NV5XCVZt9Q0bW9MnAe4YrZ1/9Lnj8IfxLPhcV Ld6Q== 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=701bwJkgXICGE6R4e0XJPVYqMBI43tK0euoxsDFO4As=; b=XaUf00AYgnCOrc3w9wgrBk287Z4yq0V6B8iuRBEZ1kBvRyK9gD7u8Xd1C8Z0/CCA+n 5UyAnE6mf+xRaXyibMU4p0PYIYKOzbtrFEckbnKo1fSFKoNEs4OfQr+weysGMqRPAsCC yMftTwAPKbLTNKI5dkPRGyW5nR9QzVQA9WHF+QGVsyLGnu5o6iRpNJ1AFM1BLpMAObvl fKO9fg0Fa2+CVNr48Jc5eU6OrUmuqWpf+TELT2rcxJp8eMP9oRyyEPb5pYwf2fwicXCY FPtWkOyAmvKX73u4aMtPy0QCF12cehn94ya87+KWvC7K6nyYWbHlRsB0XdcykTK4rysl NXPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LOTbe5dQ; 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 g17si6131618edh.379.2019.10.22.13.34.40; Tue, 22 Oct 2019 13:34:41 -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=LOTbe5dQ; 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 S2389456AbfJVUej (ORCPT + 26 others); Tue, 22 Oct 2019 16:34:39 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:36324 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389421AbfJVUef (ORCPT ); Tue, 22 Oct 2019 16:34:35 -0400 Received: by mail-qt1-f194.google.com with SMTP id d17so14263884qto.3 for ; Tue, 22 Oct 2019 13:34:34 -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=701bwJkgXICGE6R4e0XJPVYqMBI43tK0euoxsDFO4As=; b=LOTbe5dQz9HElq6SSgUYDkeqOyhYlUEiZ3yK9hgo3Hg7ydcyVa1JFpNTOmE5UWnMM/ 98edzR1GiBVZGxYZEWj5XIcdz6Oz2zipi3YWH95sZZcJFoBcomKv74qT8P7vTiLnt4uU oTiGKRusAka7VAY2NosSr1SKyC6rmtpEHAEBlDLNSd47Q5laK7aJXxg1M/l3jm51Aw4b RcvajLgnaHQqN76OJWTuIL+DUP7arPj1p3BZJpUOSUBWJVvEC/4YoFo5OYcJFn8UbJVm rNOdg0CV8CjuI5PRvNg6jUcQXcWPHOvpjXUT+i12cKTzKbkLMQ/S6dDXPDGURzU6zzk0 snnA== 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=701bwJkgXICGE6R4e0XJPVYqMBI43tK0euoxsDFO4As=; b=Q6yxIpWViLTEsXB36nGFGGuFVs+DVc9aNlYzGelN4GT8jM5G8YV4JxoM542VmWwM9s 9p3FthBdQvXWBXPh+FV3A6izUJF19fy3Z+fIsxKpPOK8zShSrLiqZF5YAQDpBfVCtehy 60D6NHZ2FRoICOmalk7aPAS5PuN+aSwG15l/6xwqHxItjXJbcn7H57glkM97rwhhdQ6a s3wrjaVkbpHfAlu4391a9EwkLxCfhQKLgmTU3/1IEvyj3U+z/6HK8cpPdNsxPCrQM/XP dqudXI4Is/qmpqCpq1+QLNmRKqq0GBgXsz8Td8liUQ1dWDiXXPMML975YKgoOmE/Dhkp KYJQ== X-Gm-Message-State: APjAAAXcrn5yAVFTAM+qMpQw4hjZj1GqxxDXRzjwzkCMnNqRAzoolBH+ nUGXLgIG6UkhJQkQV2V0ssQ7dw== X-Received: by 2002:a0c:e6e5:: with SMTP id m5mr5091013qvn.170.1571776474076; Tue, 22 Oct 2019 13:34:34 -0700 (PDT) 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 r126sm8895038qke.98.2019.10.22.13.34.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Oct 2019 13:34:33 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, edubezval@gmail.com, qperret@google.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, daniel.lezcano@linaro.org Subject: [Patch v4 4/6] sched/fair: update cpu_capcity to reflect thermal pressure Date: Tue, 22 Oct 2019 16:34:23 -0400 Message-Id: <1571776465-29763-5-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1571776465-29763-1-git-send-email-thara.gopinath@linaro.org> References: <1571776465-29763-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 | 1 + 1 file changed, 1 insertion(+) -- 2.1.4 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 4f9c2cb..be3e802 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7727,6 +7727,7 @@ static unsigned long scale_rt_capacity(struct sched_domain *sd, int cpu) used = READ_ONCE(rq->avg_rt.util_avg); used += READ_ONCE(rq->avg_dl.util_avg); + used += READ_ONCE(rq->avg_thermal.load_avg); if (unlikely(used >= max)) return 1; From patchwork Tue Oct 22 20:34:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 177236 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp5372905ill; Tue, 22 Oct 2019 13:34:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQMgy9itoFvOY/V/NiOMNfcojVho+cEMvD9LNGbsgtV6Id94FcMYH3rSZBRd59K1CTNV4c X-Received: by 2002:a05:6402:1514:: with SMTP id f20mr33898562edw.35.1571776489758; Tue, 22 Oct 2019 13:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571776489; cv=none; d=google.com; s=arc-20160816; b=uZ1LDx773OUkLxzFIlgrxgbOFhgRHBVcBEOf0w95iO5BPKmHNY1Xl5RdUQ3ILQuhyD 5ehilD3UJod0RG2CBI0O/tB1XqFKGG+bw14kfVKHvRj459v9GC+UG3FCSvv/AdZb3XlD IbcM8yftD9qJyiqcmMt8C3jJrDnCsClE1qeTQJxWYvDl9eu9kDO1Pks/EoIL5IOUrMYp yAquNnGqMFGFuHhPnwQgT1JtU00TRhQ0U8vapV/4qIz6xq5uoZBfG8pDaHE2j3K7Psry Ermb9omrPzNULkmUKH5KmZqOqlTFbLyKHLjPsRJZam1h7tzQpCIyp0+i70NhSaE+cM1G LV7w== 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=UTw/C9YOFOt2girMz7/HTweAfnMneRk1SahAwoeEi/8=; b=FyG2xUwRGuT+vmRJjhA3G043uzRWSnE7u8u0WYxDNUnp0Cq0K1AOdBQJBO6cpguVpT 0zv+kPdtFGo5CWgHXxq7Nv1XQNFofxLTABsqB/sy5Iqd/BnhbVzwTgpIrGYAdlCI7v8p FJ8Kfa5sE3rhZvbLE050J4tiVLjDkJLtV/TkVrCFpx/pfguOt3kFR4GX10/kjkGvANmr M7aAKnSMkdGHNy678dlxui5fmFNIdp3B1ny+A6wXr5UuKzpIh6nr8tNne4AvV6s+SvQU RR/84BNQoQfp9FLAZRCAFTYzGcHNHf7fJyWeTdJ2OvpT+vMfhEnHppb1wL7O+lqI/tLu s/AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aGkYnf6z; 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 g53si5881961edb.313.2019.10.22.13.34.49; Tue, 22 Oct 2019 13:34:49 -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=aGkYnf6z; 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 S2389497AbfJVUeo (ORCPT + 26 others); Tue, 22 Oct 2019 16:34:44 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:36329 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389407AbfJVUeh (ORCPT ); Tue, 22 Oct 2019 16:34:37 -0400 Received: by mail-qt1-f195.google.com with SMTP id d17so14264028qto.3 for ; Tue, 22 Oct 2019 13:34:36 -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=UTw/C9YOFOt2girMz7/HTweAfnMneRk1SahAwoeEi/8=; b=aGkYnf6z5uRBHSkiivv6AM3qIXlIT5VCPXugOf2w1ms7hIEg+Uz/p4OQDtJ/C/avl2 N40dP786qDXUTRM6eF2Xn6o0OQJjAV250vcfoAxxYLL2TS5k18TvLX5TdK8jxS0FoetW h11byvDgqKOwyVDvqkjFFxG3KQUpYzs0UcIwzD83t1lbOWMR8mGPRvTdfmeKHBsY9hsk ChyXQif9WtkMentpyNrEb4QJj2wHAYaOdzrkP550Kqr0182q+oc3tr08V8n/bm9HdKLs NGkdP7VtXme67OU/N6Qun1+Os1vvj0gu4bgzySU8Fnq9h0q9XiBR5sKLDAT0/C6/Ewm3 W+ig== 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=UTw/C9YOFOt2girMz7/HTweAfnMneRk1SahAwoeEi/8=; b=GKQC82juiz8IgpW4Xx6YSuL40x+PBvt6F2aANj+XSGN9Qm4qQaZ8mon7mhgYoMBlfy dThomJ/8HDftETHIy7kD74cxSMAbDIP4okpbhlBpex/ipmdwlRIYKjLZ3ctJSv613N5D uCZhazyMFSlpMy7qFocwy3lSdDTehF3n/2dV7Mgb6bdiQtpuROHFrD5QmZnrG2HMIXoX gbT4H90J1RoiWrEiewCV/mjIuFqpxqPjyg/67zwnX4BM5SJbEQJSasouAZFhmt9QJJPZ OBQDDE1RJIL+3x4KRxmiqkfrhJB2nCu2AelajvJ86b6o3t/nArZjahVTz06G7fhp0xq/ y1TQ== X-Gm-Message-State: APjAAAUQOUAEMLogIBkU1VAJx5VKcY2A6M3G8VgNczeTxVSfcHTGgw9e FUVVDvefCTZCRP21f0IYh39gXA== X-Received: by 2002:a0c:efcd:: with SMTP id a13mr5135070qvt.94.1571776475947; Tue, 22 Oct 2019 13:34:35 -0700 (PDT) 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 r126sm8895038qke.98.2019.10.22.13.34.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Oct 2019 13:34:34 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, edubezval@gmail.com, qperret@google.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, daniel.lezcano@linaro.org Subject: [Patch v4 5/6] thermal/cpu-cooling: Update thermal pressure in case of a maximum frequency capping Date: Tue, 22 Oct 2019 16:34:24 -0400 Message-Id: <1571776465-29763-6-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1571776465-29763-1-git-send-email-thara.gopinath@linaro.org> References: <1571776465-29763-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 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 | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) -- 2.1.4 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c index 391f397..2e6a979 100644 --- a/drivers/thermal/cpu_cooling.c +++ b/drivers/thermal/cpu_cooling.c @@ -218,6 +218,23 @@ static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_cdev, } /** + * update_sched_max_capacity - update scheduler about change in cpu + * max frequency. + * @policy - cpufreq policy whose max frequency is capped. + */ +static void update_sched_max_capacity(struct cpumask *cpus, + unsigned int cur_max_freq, + unsigned int max_freq) +{ + int cpu; + unsigned long capacity = (cur_max_freq << SCHED_CAPACITY_SHIFT) / + max_freq; + + for_each_cpu(cpu, cpus) + update_thermal_pressure(cpu, capacity); +} + +/** * get_load() - get load for a cpu since last updated * @cpufreq_cdev: &struct cpufreq_cooling_device for this cpu * @cpu: cpu number @@ -320,6 +337,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) { struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata; + int ret; /* Request state should be less than max_level */ if (WARN_ON(state > cpufreq_cdev->max_level)) @@ -331,8 +349,17 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, cpufreq_cdev->cpufreq_state = state; - return dev_pm_qos_update_request(&cpufreq_cdev->qos_req, - cpufreq_cdev->freq_table[state].frequency); + ret = dev_pm_qos_update_request + (&cpufreq_cdev->qos_req, + cpufreq_cdev->freq_table[state].frequency); + + if (ret > 0) + update_sched_max_capacity + (cpufreq_cdev->policy->cpus, + cpufreq_cdev->freq_table[state].frequency, + cpufreq_cdev->policy->cpuinfo.max_freq); + + return ret; } /** From patchwork Tue Oct 22 20:34:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 177235 Delivered-To: patch@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp5372889ill; Tue, 22 Oct 2019 13:34:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxduVoxUvr5sHhkxX9sUwAgOt3OzaWAIz0i4HmIAY5OCDTluPbJpZPrc6UHCb3VaelqGK5 X-Received: by 2002:a17:906:298f:: with SMTP id x15mr29140703eje.50.1571776489121; Tue, 22 Oct 2019 13:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571776489; cv=none; d=google.com; s=arc-20160816; b=rtTymK8QTgpSVjl9cCMJr6R0zQcfQq1UUMCbnBkKO8SWldKyvF0ueDxJLMITWIdKOE g80mMl1j3DqwNU+1TMH/FWSWn2NYxlMStJBKQIgPEULiw1P67t2/7QZXhCsCTfZLKcp7 7crZOFORmWcSEqwFrheYnIGRyPpQbxs+TG6nGAu06Mm3dltRDabsJuBag2VtO/tGr8Qq 0V0j3YXLDAtNflwJC3ox21NPKWxDaH/u4hzdACmgbz8MEhKoEq8DLkrSespYQ5BiGdXK iGOjHs5030aCp8iK3/y412fQor03Am8g8fAu1Dr5EdXzrd0sqOTjxATAlGqPWrZS20Pk zNEQ== 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=Cu2iRByuQkBOdiS3ftuWg2x1Invt9O2eimcBFeYIbQQ=; b=W1pD3AOprCXmTGigEbyuth97Z7YFml12UBlaIo0RQzZ3wpEJb3bYxZnF6tHiMDPG/L Sp5mb+WyKzYqcZufOaAZlrf7pZPUn2WcF1X2l6shmKq2NQx7GKzbj2rKK9yooSdghkhO hG1fSW71Mv+jXbYGTQ3qCqij7E2aAxgFXcKew6bdURk/3fMFPm3q9p+SBbpHdC50s5sc mX42FDqnTO0MrdOUpOG5OszSwcqI3nFu/0sovNlkdWyUZiXLJ9AMVr/FGKdL7WrHLt2c omm+CmrfwK22KK0RFxdpDO4m34rYXcxA9z18R8WUrk6TL4H8H6c7HFg6Wo7Ggwce2bM1 zNjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C7KBtZnl; 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 g53si5881961edb.313.2019.10.22.13.34.48; Tue, 22 Oct 2019 13:34:49 -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=C7KBtZnl; 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 S2389479AbfJVUem (ORCPT + 26 others); Tue, 22 Oct 2019 16:34:42 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:41268 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389449AbfJVUei (ORCPT ); Tue, 22 Oct 2019 16:34:38 -0400 Received: by mail-qt1-f193.google.com with SMTP id c17so25868137qtn.8 for ; Tue, 22 Oct 2019 13:34:38 -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=Cu2iRByuQkBOdiS3ftuWg2x1Invt9O2eimcBFeYIbQQ=; b=C7KBtZnlB3OLT3U/IskLPfrl3eYN7TUJSCVxUyZTTHjT39Q8gfZqWYNG/+7MnuzkzU jlvkgRS5cMhKcRFdBesSUcwLQMK7SQDxdOefzxZVbTboj9zhfgFvIEQGAQu9ClpOaaGJ usZxOmUcITG5BSz18Q3N9ySOJpP+vQo8F08cjsseG+y/jW4ldXvgNhzfbtnOP/8KGFLX Jkck8I97wwtNbLpAzlnaczz4Xu1WxWvaFf+4mEpu6LY9P+UX3qA63Ohvey0Q/eniq3+s piVm6NiLzEekGjtl6K4snX2hLIxfFKiHNpBeuBI7gaKboqZoueX3HbJNV0cTv5JRs/uX fGgw== 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=Cu2iRByuQkBOdiS3ftuWg2x1Invt9O2eimcBFeYIbQQ=; b=HdcCv8pJV/BxolGYJ0/OAWwSB8xEcVCMm9riPhuT5ydoM2YPBGeVEcz2V1fincrHGl iPNFOehjeCLbQHib31w3IFY5yafOzd8me8lK6jwJQxtkMh2+09JHVhWApSUwH/C3kAuI 5e13jMFjCS0bBszx0SDhb2vkB4wlmbnC3m0ZFhZiP4ccOlXqtXaINHmmN4PaiB7lcDTP QG7JeYd2HAFqe0px7T8Nm+TbJURpPfcCug4pzJwsXMS9idSPjekfYQzlG7X1XrORzhbH EBlxRTp+kh0DeikMDCMCOHF7M0voEdhWX9t+E4V0DhtKPRljb8igWMXWbCONYp/Hyd2g il8g== X-Gm-Message-State: APjAAAWRZpcOKHUEru873e1IBef0s0V1eTrGMVdSJhiXV3k/vN4sbJHd crHHzIeUcmEAf1A+crYU9mLaJw== X-Received: by 2002:aed:35e7:: with SMTP id d36mr5404833qte.59.1571776477484; Tue, 22 Oct 2019 13:34:37 -0700 (PDT) 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 r126sm8895038qke.98.2019.10.22.13.34.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Oct 2019 13:34:36 -0700 (PDT) From: Thara Gopinath To: mingo@redhat.com, peterz@infradead.org, ionela.voinescu@arm.com, vincent.guittot@linaro.org, rui.zhang@intel.com, edubezval@gmail.com, qperret@google.com Cc: linux-kernel@vger.kernel.org, amit.kachhap@gmail.com, javi.merino@kernel.org, daniel.lezcano@linaro.org Subject: [Patch v4 6/6] sched: thermal: Enable tuning of decay period Date: Tue, 22 Oct 2019 16:34:25 -0400 Message-Id: <1571776465-29763-7-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1571776465-29763-1-git-send-email-thara.gopinath@linaro.org> References: <1571776465-29763-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 Thermal pressure follows pelt signas which means the decay period for thermal pressure is the default pelt decay period. Depending on soc charecteristics and thermal activity, it might be beneficial to decay thermal pressure slower, but still in-tune with the pelt signals. One way to achieve this is to provide a command line parameter to set the decay coefficient to an integer between 0 and 10. Signed-off-by: Thara Gopinath --- v3->v4: - Removed the sysctl setting to tune decay period and instead introduced a command line parameter to control it. The rationale here being changing decay period of a PELT signal runtime can result in a skewed average value for atleast some cycles. Documentation/admin-guide/kernel-parameters.txt | 5 +++++ kernel/sched/thermal.c | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) -- 2.1.4 diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a84a83f..61d7baa 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4273,6 +4273,11 @@ incurs a small amount of overhead in the scheduler but is useful for debugging and performance tuning. + sched_thermal_decay_coeff= + [KNL, SMP] Set decay coefficient for thermal pressure signal. + Format: integer betweer 0 and 10 + Default is 0. + skew_tick= [KNL] Offset the periodic timer tick per cpu to mitigate xtime_lock contention on larger systems, and/or RCU lock contention on all systems with CONFIG_MAXSMP set. diff --git a/kernel/sched/thermal.c b/kernel/sched/thermal.c index 0c84960..0da31e1 100644 --- a/kernel/sched/thermal.c +++ b/kernel/sched/thermal.c @@ -10,6 +10,28 @@ #include "pelt.h" #include "thermal.h" +/** + * By default the decay is the default pelt decay period. + * The decay coefficient can change is decay period in + * multiples of 32. + * Decay coefficient Decay period(ms) + * 0 32 + * 1 64 + * 2 128 + * 3 256 + * 4 512 + */ +static int sched_thermal_decay_coeff; + +static int __init setup_sched_thermal_decay_coeff(char *str) +{ + if (kstrtoint(str, 0, &sched_thermal_decay_coeff)) + pr_warn("Unable to set scheduler thermal pressure decay coefficient\n"); + + return 1; +} +__setup("sched_thermal_decay_coeff=", setup_sched_thermal_decay_coeff); + static DEFINE_PER_CPU(unsigned long, delta_capacity); /** @@ -40,6 +62,7 @@ void update_thermal_pressure(int cpu, u64 capped_freq_ratio) */ void trigger_thermal_pressure_average(struct rq *rq) { - update_thermal_load_avg(rq_clock_task(rq), rq, + update_thermal_load_avg(rq_clock_task(rq) >> + sched_thermal_decay_coeff, rq, per_cpu(delta_capacity, cpu_of(rq))); }