Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp799214pxj; Wed, 16 Jun 2021 13:58:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYTQs+0Vm7hV7vzlTLKdgBrpVa3itMGtEQ1ku+H29wcg5xJeyF49AwFkpVZu9xRRVwzBoq X-Received: by 2002:a6b:e306:: with SMTP id u6mr998228ioc.132.1623877104941; Wed, 16 Jun 2021 13:58:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623877104; cv=none; d=google.com; s=arc-20160816; b=gtijIati4bBR8gSQMfUkjgJ0iBPdkt3akS9+/ANX48soFYcYxrYNn8NhLzlNN6yMt3 vUdH3RbuwIeX/20X9jPnJokzUGpl87aCqtiuFPdKlqXT3/sFFTpPVanDUuSx0KwzH4CI 4DeubBIwX119qtCI9BQTElW4Y4xaM0u1OgCEThkKmXiJwjrbofNJZm9gWZsrn+P/iZ+n khUR29fKKE4DAC1oBg3Ml4SSIsVFdEfdSzHuyjP6IlBw+Yi5GlTeKrq1M07wsC7dwmjx PRf85IC4Elds3ptuY+NZcD+SiVs40hEf7/GK6l7Ttoi/KTZySFxM8RBU7JgANmO3l/74 KR1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=1ukyOAmpzQWdmpmUsMzfBm79YkK27laiGKotM430XzI=; b=u+FXVTsYiS0XULOZc0cgh0sYlEyLgtIQjJVjqnvG72Y6LJvVgiuhRlqHPXgh5kIuMK nBJuBaLpDRq7cVg6Z6Ejw2blXzDPydiHc44M+x7QU7/En2zo0Qsm0MfgXp26uqcxTs8N 1XVae/2p67CAbz8MGuNY5AOdw/mCvtTXJg9JvtIs4Jmygkk2I7JQUwI3uz4HKctMrLeg cgqzrsMvAuWhpndjFPvEZCBxKaEcs1EEHhuEREAsBINBDrH9upTslY92OQqBwAjtdB8I XIrkXQD/afde4pcE6xOtG1AyjpkKyPtvQpoxZodsIumfANa1r4x2i1B57BIyx0a5jwJR YY4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="EkMIOR/P"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id v6si3668100ilu.109.2021.06.16.13.58.12; Wed, 16 Jun 2021 13:58:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="EkMIOR/P"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234561AbhFPPYi (ORCPT + 99 others); Wed, 16 Jun 2021 11:24:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234002AbhFPPYh (ORCPT ); Wed, 16 Jun 2021 11:24:37 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 742AAC06175F for ; Wed, 16 Jun 2021 08:22:31 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id r16so4370395ljk.9 for ; Wed, 16 Jun 2021 08:22:31 -0700 (PDT) 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=1ukyOAmpzQWdmpmUsMzfBm79YkK27laiGKotM430XzI=; b=EkMIOR/PiXLp54WcwHksaJA9STCAGH6XFItpd/u6uetS/tFJbAkSo5TUW9dDdAPUwm qdw4wP6RH//rcPEqpzsG5At1Yc6a3AltYSGYhmB0Z9Vl2omGzB1LAIrBhr4nf6c1xJnZ UEusPQ7BHmCzGvMnCnEINXLmBfjz+GQ2ARt0A1lCXjEdeHbhsOsEr1mhRxWioafCDueu FL383FSjLuSaeIkB6XLtV1ZzbVV04pzn7s7RzzYm4+C513U0UdqtT6GjHULiLkjL8pYd 9nhz0KFPqD6MMMnIyrcCDAVMudnWicQT16jHrcXc0NKX00dJ+AR03w+/i8Q1L/pF8bj6 x8XA== 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=1ukyOAmpzQWdmpmUsMzfBm79YkK27laiGKotM430XzI=; b=WzWtKYB6F59MB9Cj2pqsnKWmNz53AIdtElja+6MS8Sp+Bq7pUJm68t2/MrlVNP39A5 AqcGMwxZIpAXaiY4EQYeHub3GeYzaZwd1BaILP43L6PPvTSBb/AuLzN/4vbUOk3hrH+Z Nhw+xvIgvlfyMZk/LyWhNIOZuLmnx4kq4JFCgGWOiTPg6mn432sMaIXa9J7pIvoNMlTR 9gU8Z06U9HzEPwg/LULeWc1auILFFl6opAAZ01x3rIh61ExO0Z23bW64f8ET/tSA7PtD weuB8EBzngWqY7UGHc/np5rMNmDmthl28LygVz6oCtwjx1vAOM9sQri0F0HhjNGpP2rh BIUg== X-Gm-Message-State: AOAM530x9jDftmfvcLShkVUHuiCr9rqm6JYUf6eQJ54pi1dpW6Tsa+uV oj7UNFLUqvrZ4gI2Nxe3l7t0ntEvIrVJLbtRMw0PRQ== X-Received: by 2002:a2e:9b07:: with SMTP id u7mr307435lji.209.1623856949636; Wed, 16 Jun 2021 08:22:29 -0700 (PDT) MIME-Version: 1.0 References: <1623855954-6970-1-git-send-email-yt.chang@mediatek.com> In-Reply-To: <1623855954-6970-1-git-send-email-yt.chang@mediatek.com> From: Vincent Guittot Date: Wed, 16 Jun 2021 17:22:18 +0200 Message-ID: Subject: Re: [PATCH 1/1] sched: Add tunable capacity margin for fis_capacity To: YT Chang Cc: "Rafael J. Wysocki" , Viresh Kumar , Luis Chamberlain , Kees Cook , Iurii Zaikin , Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Matthias Brugger , Paul Turner , Qais Yousef , Greg Kroah-Hartman , "open list:THERMAL" , linux-kernel , linux-fs , LAK , linux-mediatek@lists.infradead.org, wsd_upstream@mediatek.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 16 Jun 2021 at 17:06, YT Chang wrote: > > Currently, the margin of cpu frequency raising and cpu overutilized are > hard-coded as 25% (1280/1024). Make the margin tunable cpu_overutilized is 20% not 25%. Even if they light looks similar these 2 margins are differents > to control the aggressive for placement and frequency control. Such as > for power tuning framework could adjust smaller margin to slow down > frequency raising speed and let task stay in smaller cpu. > > For light loading scenarios, like beach buggy blitz and messaging apps, > the app threads are moved big core with 25% margin and causing > unnecessary power. > With 0% capacity margin (1024/1024), the app threads could be kept in > little core and deliver better power results without any fps drop. > > capacity margin 0% 10% 20% 30% > current current current current > Fps (mA) Fps (mA) Fps (mA) Fps (mA) > Beach buggy blitz 60 198.164 60 203.211 60 209.984 60 213.374 > Yahoo browser 60 232.301 59.97 237.52 59.95 248.213 60 262.809 Would be good to know the impact of each part: Changing the +25% in cpufreq governor Changing the 20% margin to detect overloaded CPU Also, IIUC your description, the current values are ok with some UCs but not with others like the 2 aboves. Have you evaluated whether it was not your power model that was not accurate ? > > Change-Id: Iba48c556ed1b73c9a2699e9e809bc7d9333dc004 > Signed-off-by: YT Chang > --- > include/linux/sched/cpufreq.h | 19 +++++++++++++++++++ > include/linux/sched/sysctl.h | 1 + > include/linux/sysctl.h | 1 + > kernel/sched/fair.c | 4 +++- > kernel/sysctl.c | 15 +++++++++++++++ > 5 files changed, 39 insertions(+), 1 deletion(-) > > diff --git a/include/linux/sched/cpufreq.h b/include/linux/sched/cpufreq.h > index 6205578..8a6c23a1 100644 > --- a/include/linux/sched/cpufreq.h > +++ b/include/linux/sched/cpufreq.h > @@ -23,6 +23,23 @@ void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, > void cpufreq_remove_update_util_hook(int cpu); > bool cpufreq_this_cpu_can_update(struct cpufreq_policy *policy); > > +#ifdef CONFIG_SMP > +extern unsigned int sysctl_sched_capacity_margin; > + > +static inline unsigned long map_util_freq(unsigned long util, > + unsigned long freq, unsigned long cap) > +{ > + freq = freq * util / cap; > + freq = freq * sysctl_sched_capacity_margin / SCHED_CAPACITY_SCALE; > + > + return freq; > +} > + > +static inline unsigned long map_util_perf(unsigned long util) > +{ > + return util * sysctl_sched_capacity_margin / SCHED_CAPACITY_SCALE; > +} > +#else > static inline unsigned long map_util_freq(unsigned long util, > unsigned long freq, unsigned long cap) > { > @@ -33,6 +50,8 @@ static inline unsigned long map_util_perf(unsigned long util) > { > return util + (util >> 2); > } > +#endif > + > #endif /* CONFIG_CPU_FREQ */ > > #endif /* _LINUX_SCHED_CPUFREQ_H */ > diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h > index db2c0f3..5dee024 100644 > --- a/include/linux/sched/sysctl.h > +++ b/include/linux/sched/sysctl.h > @@ -10,6 +10,7 @@ > > #ifdef CONFIG_SMP > extern unsigned int sysctl_hung_task_all_cpu_backtrace; > +extern unsigned int sysctl_sched_capacity_margin; > #else > #define sysctl_hung_task_all_cpu_backtrace 0 > #endif /* CONFIG_SMP */ > diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h > index d99ca99..af6d70f 100644 > --- a/include/linux/sysctl.h > +++ b/include/linux/sysctl.h > @@ -41,6 +41,7 @@ > #define SYSCTL_ZERO ((void *)&sysctl_vals[0]) > #define SYSCTL_ONE ((void *)&sysctl_vals[1]) > #define SYSCTL_INT_MAX ((void *)&sysctl_vals[2]) > +#define SCHED_CAPACITY_MARGIN_MIN 1024 > > extern const int sysctl_vals[]; > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 20aa234..609b431 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -111,7 +111,9 @@ int __weak arch_asym_cpu_priority(int cpu) > * > * (default: ~20%) > */ > -#define fits_capacity(cap, max) ((cap) * 1280 < (max) * 1024) > +unsigned int sysctl_sched_capacity_margin = 1280; > +EXPORT_SYMBOL_GPL(sysctl_sched_capacity_margin); > +#define fits_capacity(cap, max) ((cap) * sysctl_sched_capacity_margin < (max) * 1024) > > /* > * The margin used when comparing CPU capacities. > diff --git a/kernel/sysctl.c b/kernel/sysctl.c > index 14edf84..d6d2b84 100644 > --- a/kernel/sysctl.c > +++ b/kernel/sysctl.c > @@ -127,6 +127,11 @@ > static int six_hundred_forty_kb = 640 * 1024; > #endif > > +/* this is needed for the proc of sysctl_sched_capacity_margin */ > +#ifdef CONFIG_SMP > +static int min_sched_capacity_margin = 1024; > +#endif /* CONFIG_SMP */ > + > /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */ > static unsigned long dirty_bytes_min = 2 * PAGE_SIZE; > > @@ -1716,6 +1721,16 @@ int proc_do_static_key(struct ctl_table *table, int write, > .mode = 0644, > .proc_handler = proc_dointvec, > }, > +#ifdef CONFIG_SMP > + { > + .procname = "sched_capcity_margin", > + .data = &sysctl_sched_capacity_margin, > + .maxlen = sizeof(unsigned int), > + .mode = 0644, > + .proc_handler = proc_dointvec_minmax, > + .extra1 = &min_sched_capacity_margin, > + }, > +#endif > #ifdef CONFIG_SCHEDSTATS > { > .procname = "sched_schedstats", > -- > 1.9.1 >