From patchwork Tue Nov 5 18:49:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thara Gopinath X-Patchwork-Id: 178549 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp1151385ilf; Tue, 5 Nov 2019 10:49:58 -0800 (PST) X-Google-Smtp-Source: APXvYqxX3ABhwxnT/tPjtbYFb/FJLCXzTbOFJzbbDOdpQvkBGLkVrBvP+2S/EUTQi6v2iDVqwDJW X-Received: by 2002:aa7:d0d4:: with SMTP id u20mr16175195edo.112.1572979798554; Tue, 05 Nov 2019 10:49:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572979798; cv=none; d=google.com; s=arc-20160816; b=UxEin9xWZINkYCpEbzn4VBz+it4TbGaUkL394PuyhRVqCPmAsXiDc+YNFE+eynmi/q h1QBztl0eegUpx70D6GC6z059YMhU3WPwKiVslmG3EXR6Uoa2sIpdu240kJegO4TsE4e WIuG0RkVaRCE7HT6qTDFXc+KhC55voM7UvRcVUBO7g7xUNeykDO9zcoi6aXhYIX5imUy eLW0UpMKpBYx1np0eTXO40oZtBu4nlbSLGF3WaXIVE+U2OnJC5guL04fdvw8AFU6RDz6 gCAIoq7bN7SKdIx0DCRcOCqZYjHGb76SEe9dZofTZTzl7m8z1thtXzLVzOzQ+lmQaE2s BWkg== 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=MuKIljDj+9SX43fxK+S80WZiAzsSjNwIox+BZEd7J9Y=; b=BRDN+gDEXmR5nqyqXKj4l01QrjPIxw9wd/Bys7tp4kRNez2oUPOLEFrtAVdt4zgDId 0ob3f+QA/mz2TFXUQ87rJLDeboJdWVPRXdeYq4cvRFK9EnrxjhQN8Tafnn6ghTYTj4Hr ASB+mB4hjIIu5DKFHpfEIsCDUci66Q44XB701AaIMdq0ZeTOWMDtHlGwAU7hQrAfXJue IcDUcad/xICopxqcIrbM8Shbep8nudvxdU+buJW2dkRVv7H6i6wsF+A+QGfxN8CUwfTp HBONAhOgLeM+BExbPePXGRqaFhikhS/28RLLMDRH43fiUxk3A2uA6/tO3EFwpbmMPkyp nUJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QdXBSTW3; 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 nj2si13921473ejb.233.2019.11.05.10.49.58; Tue, 05 Nov 2019 10:49:58 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QdXBSTW3; 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 S2390807AbfKEStx (ORCPT + 26 others); Tue, 5 Nov 2019 13:49:53 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:34774 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390777AbfKEStw (ORCPT ); Tue, 5 Nov 2019 13:49:52 -0500 Received: by mail-qk1-f196.google.com with SMTP id 205so20804092qkk.1 for ; Tue, 05 Nov 2019 10:49:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MuKIljDj+9SX43fxK+S80WZiAzsSjNwIox+BZEd7J9Y=; b=QdXBSTW3Kw+04AzcbpElRt6qPXZK2jBWi9b0TUpFBvqZ0jmUJOZZHqzE+mRkRFKjAB LIgnHG3qWbcnUjh3S4Fh3Lrek+Gg/zooK+jHZpo8dThwVz2dIyrHzNA3V+aIoar16Mh7 pGBz8VLs516af0LQJLcX0y2e7OqEldy7wlSMhox6c94zO8ORMNjmlSm5Yg63kmN2m/ZC WOfuCz8LtqhCnicyW7RZf3CId1Mey1UkdOOiYLXbk/TDL0ry/+X71a1a34S+g7L10xaL Hl3dVbgvaJf19263O+gF06VVYMUvmKzK/Rr2I5IFnU0AVkSdrZerFRHPaB3AHsaI36Ed nnHA== 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=MuKIljDj+9SX43fxK+S80WZiAzsSjNwIox+BZEd7J9Y=; b=MqJ9L4K/l/EvAaFajwhxaLFPv40EKxfBrm4xzvsQaFnKTcJ4Kq1t8u24PEKnBDIT4E BwsEAbImxwHC6zs/h72lY9q9CtGfXX05vf3qD4bMZ/rlPaBKdK6cF800byON3Ok7AbY6 UnuMJ6jMpBLuxzTS/bxt3J3uABIIc+XkNUOniBjj1SFeMkzon/eaCTnkfqJ2C9ZyuD0n Y2Sltt1JDyH6SsAk+caXnX3FRmVSCr6hqBDx8UkPxw1UyVf2wctc9g8Gp2MV1ESWjgy2 u81T+Srg/Ww9ADyMpmU9LFkavCh6//xa0ziQr5i6+3ctRDzcAiCxpWAPJLDU4WW5jJnH YOkw== X-Gm-Message-State: APjAAAUhFrg3k/FsV+dYrocJ8WZCNBHDWZUQtWl6sbSJz06eUEHBixjk HV2b10RuGFO7UtFoa+YZOqmshQ== X-Received: by 2002:a37:6c47:: with SMTP id h68mr12942464qkc.30.1572979790881; Tue, 05 Nov 2019 10:49:50 -0800 (PST) Received: from Thara-Work-Ubuntu.fios-router.home (pool-71-255-246-27.washdc.fios.verizon.net. [71.255.246.27]) by smtp.googlemail.com with ESMTPSA id j7sm6832565qkd.46.2019.11.05.10.49.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Nov 2019 10:49:50 -0800 (PST) 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 v5 2/6] sched/fair: Add infrastructure to store and update instantaneous thermal pressure Date: Tue, 5 Nov 2019 13:49:42 -0500 Message-Id: <1572979786-20361-3-git-send-email-thara.gopinath@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1572979786-20361-1-git-send-email-thara.gopinath@linaro.org> References: <1572979786-20361-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 interface APIs to initialize, update/average, track, accumulate and decay thermal pressure per cpu basis. A per cpu variable thermal_pressure is introduced to keep track of instantaneous per cpu thermal pressure. Thermal pressure is the delta between maximum capacity and capped capacity due to a thermal event. API trigger_thermal_pressure_average is called for periodic accumulate and decay of the thermal pressure.This API passes on the instantaneous thermal pressure 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 maximum capacity. Considering, trigger_thermal_pressure_average reads thermal_pressure and update_thermal_pressure writes into thermal_pressure, 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 thermal_pressure value used to calculate average thermal pressure for a cpu can be stale for upto 1 tick period. Signed-off-by: Thara Gopinath --- 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. v4->v5: - As per Peter's review comments folded thermal.c into fair.c. - As per Ionela's review comments revamped update_thermal_pressure to take maximum available capacity as input instead of maximum capped frequency ration. --- include/linux/sched.h | 9 +++++++++ kernel/sched/fair.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) -- 2.1.4 diff --git a/include/linux/sched.h b/include/linux/sched.h index 263cf08..3c31084 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1993,6 +1993,15 @@ static inline void rseq_syscall(struct pt_regs *regs) #endif +#ifdef CONFIG_SMP +void update_thermal_pressure(int cpu, unsigned long capped_capacity); +#else +static inline void +update_thermal_pressure(int cpu, unsigned long capped_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/fair.c b/kernel/sched/fair.c index 682a754..2e907cc 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -86,6 +86,12 @@ static unsigned int normalized_sysctl_sched_wakeup_granularity = 1000000UL; const_debug unsigned int sysctl_sched_migration_cost = 500000UL; +/* + * Per-cpu instantaneous delta between maximum capacity + * and maximum available capacity due to thermal events. + */ +static DEFINE_PER_CPU(unsigned long, thermal_pressure); + #ifdef CONFIG_SMP /* * For asym packing, by default the lower numbered CPU has higher priority. @@ -10401,6 +10407,37 @@ static unsigned int get_rr_interval_fair(struct rq *rq, struct task_struct *task return rr_interval; } +#ifdef CONFIG_SMP +/** + * update_thermal_pressure: Update thermal pressure + * @cpu: the cpu for which thermal pressure is to be updated for + * @capped_capacity: maximum capacity of the cpu after the capping + * due to thermal event. + * + * Delta between the arch_scale_cpu_capacity and capped max capacity is + * stored in per cpu thermal_pressure variable. + */ +void update_thermal_pressure(int cpu, unsigned long capped_capacity) +{ + unsigned long delta; + + delta = arch_scale_cpu_capacity(cpu) - capped_capacity; + per_cpu(thermal_pressure, cpu) = delta; +} +#endif + +/** + * trigger_thermal_pressure_average: Trigger the thermal pressure accumulate + * and average algorithm + */ +static void trigger_thermal_pressure_average(struct rq *rq) +{ +#ifdef CONFIG_SMP + update_thermal_load_avg(rq_clock_task(rq), rq, + per_cpu(thermal_pressure, cpu_of(rq))); +#endif +} + /* * All the scheduling class methods: */