Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp303366ybx; Wed, 6 Nov 2019 00:31:11 -0800 (PST) X-Google-Smtp-Source: APXvYqwHrcnEFu7MmtsIz7AnLup5I3BNLiQ09CHdAemkqMzOtCVQuF0aOAl2WqSIukBG4o/zVt+s X-Received: by 2002:a05:6402:78b:: with SMTP id d11mr1286452edy.92.1573029071243; Wed, 06 Nov 2019 00:31:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573029071; cv=none; d=google.com; s=arc-20160816; b=qZGVGa9kf7L+NpzBJTwyi5v1kkLCNKdGyVupY3pJs4m4ftvPkdtk9d1AgDvOEmJVN/ 35MXQ0QJh0g7iy8GZSMBb4629Yqy4TsdSI0UvL/Puf3wlGtCP3yvpQgK77SxigVETl/8 +I+31LKae4uxr70O35rNlA26+YcG1cyq+Kgb4nA0aWgb6q+CzxNSonU5J4MeFRj1EOc6 tnvd+9g7Q06kVzNCsiNva/2/7UcBkbrtDByeQa+2KRu4v1kAx8lZd65ewW9ZFQqvMjyE 6qHiK0WuIHmjCidsbx+9X55cQZLNadx5gGURz5i+0adYpnbCILlX3YCITS7VuzpXRtp9 Lo6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=wU786Awcjz+6BSkvh6Je1o6qXR7QFvkpKoodPXBut84=; b=KWN/QeBkdlXfLvcejD+r7YMhLFS2DfiRQXF27YkXDjKy8Pw5bWgWIW6giDtxk0lmTq 1ZDpbF1dNyNUhHvPPfTJNTY1DUCrExtp+I2wDzXZ04HYlfYjSu+2RMnMNwVoDMRJEnOC dTYm6rPJqly6cZ06AodcCaMexd7Lvq9lGA6GanKgg6MLGRvdN5gRJ86dyAqdQ8hkl6zk eqQFZciZqHduyI1/vGidBrXoPAVvZARRKZx2L9JD8sWu4AX/t3Hn6GWpVDZ5IZX2t6Ix XSIRg4PDKEssheVfK89B5nbpnrbHapp8UDiuoecRxKMIi98hH/w+BC+RdjVYFsLS0YdE 9bbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s9GNFshb; 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 h13si6515766ejq.54.2019.11.06.00.30.47; Wed, 06 Nov 2019 00:31:11 -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=s9GNFshb; 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 S1730293AbfKFI1j (ORCPT + 99 others); Wed, 6 Nov 2019 03:27:39 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:41920 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729951AbfKFI1j (ORCPT ); Wed, 6 Nov 2019 03:27:39 -0500 Received: by mail-lf1-f68.google.com with SMTP id j14so17322238lfb.8 for ; Wed, 06 Nov 2019 00:27:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wU786Awcjz+6BSkvh6Je1o6qXR7QFvkpKoodPXBut84=; b=s9GNFshb9nAwn/bv6cCM8g+T5gn5Rc+IG0iKjtgg3S1cYLkuCkx5GavWDIHU0uZJ3K 8yrpWzfq7qEJIFyDL/3n4m9Rup++Ji2eLKTAX8UHqBmV3jSDara7Kpg3oHnlPvcZS/Rk eT57j2ZQ0VApzIDT+eosMzV02inMXeLyP5blWfsfeu3XoeQZ9TueE9opm4dVOD8lxCf4 5vKI2V41SKH5JnBI9uBcW2W5JhaXuuKPTbJy9CSumBCnjSCMT/L+c3yFxRRG+VQOfaYe 5g/nAFHuQ4/QlZD0z6qYqzm2AtyDC2OlUce5kAdD0DkoFf6kcH/g4drayoNxAnb38WBj UskQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wU786Awcjz+6BSkvh6Je1o6qXR7QFvkpKoodPXBut84=; b=qnsqTX8Pzn+yghy3sQb0KFKg79pig7g3oG8rAyLQWirgpxytx5fwma0SK5B0kh127z v6no8UeKo9nFp92A9JVjpmFIUAteXu8sjwV4v/XgjEq/+n1V8c6GxUOGMQEo/7vMmfdZ ZHWS/ZE/KZ/cRYuKryavGKATJwDdDavR+x7hTwNHLrkVAb6sK8F7f2630zg36I1hpuEe aO4uRXZv0wFzKNWHx/2BS0jb5+EKiGNTC5AWAFKsHIDjmK7lT4TYxtWp8VVvwYrKaA04 SPcQRxAWDr6KLBP0jcHdsxUZSiDJlmwHScut/FRSxPp1U2NGyzdtRmFnSCwNRHNaW6bm TmUA== X-Gm-Message-State: APjAAAVD8atkSrsHW5NQsgP9kPnCifAIT20+aRkNXEI4p0jSR1xH22q/ sODGw8CEHZtvCWnivNkEmHLN+CtPguhmDyraiI6/Eg== X-Received: by 2002:ac2:4650:: with SMTP id s16mr24761323lfo.32.1573028854869; Wed, 06 Nov 2019 00:27:34 -0800 (PST) MIME-Version: 1.0 References: <1572979786-20361-1-git-send-email-thara.gopinath@linaro.org> <1572979786-20361-3-git-send-email-thara.gopinath@linaro.org> In-Reply-To: <1572979786-20361-3-git-send-email-thara.gopinath@linaro.org> From: Vincent Guittot Date: Wed, 6 Nov 2019 09:27:23 +0100 Message-ID: Subject: Re: [Patch v5 2/6] sched/fair: Add infrastructure to store and update instantaneous thermal pressure To: Thara Gopinath Cc: Ingo Molnar , Peter Zijlstra , Ionela Voinescu , Zhang Rui , Eduardo Valentin , Quentin Perret , linux-kernel , Amit Kachhap , Javi Merino , Daniel Lezcano Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Thara, On Tue, 5 Nov 2019 at 19:49, Thara Gopinath wrote: > > 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(+) > > 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; use WRITE_ONCE > +} > +#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: > */ > -- > 2.1.4 >