Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp149522pxb; Tue, 9 Mar 2021 19:07:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJwtchLUbJ5cKDcubok35TkvEambAzCtVJt65RNwPHE+3y1tOVASuLQK8evZ8Ue7BtHO6fsE X-Received: by 2002:a17:906:4f02:: with SMTP id t2mr1180478eju.121.1615345659544; Tue, 09 Mar 2021 19:07:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615345659; cv=none; d=google.com; s=arc-20160816; b=hBX+qBkBpnNMDUFhmxEp4KJaNQLDzwyAVISqQ8YD31VncEtQyckXAibzjPu+xgkLdX QvYTC6T5dTDN5bLiFMH5Q5WBOaLPMy/fn6d4LLu13n7wQt0L0RJM1I8F0q0+JkAq1TGq vwTJ7yX4Mhqj75adaF3UlSsaRdF1jWiLUaxSK1wKj7txitW7NBFYoN8d6cV64B3NEoWL +EfpgsnQQTZVY7pAhAZVJ8o8CEppZJH2Eu3VAKj3+LTkYUEvRbKR2hOwmK7QF8LLw4HT bwt0mwiEDY0PIKAkTbStIWx2C2eocstYSLJU98aX+bek6gKF4/auWBSX1Vg8WBVP4PtI HVFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0l4UeWcZvaSK23sbyoOaV8Z+baEHEhVuF/62t9jEE88=; b=WjZ5W3gjszi4bwcYs6EbUD4bVvvrPMakhWrWs5kFFfnS233kPmEp97kuGAl2Z16WmW HH0c0MZJNCro9Dw5Ih3NR+J+UQ2SslH+cUggRxmlWjRFeAbo7Ua2QtC5z9RIk6MTIGrr WzCB/wgHGYBGSs/H/8/hxHdMA85W0eXXIZONMPt+Opk3a8QJr/3ggpu07zQtCX8Jpitw JjMg8YFU1+Kjb50zrI05ZU4lYRGP0IrqC0b6zqIDMqeRRVtknKYq9uPSQjET28boiFKB g6zgJTtkdES8DP6WFTIKsy9FJAUXi7YlHo5ivTLz9QneG/KE0GZ1fPn7E8U61XdkPJEF mWOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lIkG7aiI; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx7si10356329ejc.349.2021.03.09.19.07.16; Tue, 09 Mar 2021 19:07:39 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=lIkG7aiI; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbhCJDCz (ORCPT + 99 others); Tue, 9 Mar 2021 22:02:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232204AbhCJDCj (ORCPT ); Tue, 9 Mar 2021 22:02:39 -0500 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B77F9C06174A; Tue, 9 Mar 2021 19:02:28 -0800 (PST) Received: by mail-ot1-x335.google.com with SMTP id a17so15022032oto.5; Tue, 09 Mar 2021 19:02:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=0l4UeWcZvaSK23sbyoOaV8Z+baEHEhVuF/62t9jEE88=; b=lIkG7aiIZLhz3dw8iOQolbW+rPfg7qdkdTuiiNgMFfJctJbavYtIeapw25hQfAVzuX 8OsUQiRiY29ia5Fle8oiRKMpdnQZXWSWQfrmeuLbx86ONlZA/3ihd4UNAkKr4lVWF6fC 11xVeE2HVwjEMCuIM9oDyqgKuff7FQMVs+u+7lQ20BTY2QhLtJgQcJx8u7BNjmcDJuVJ OwNVAxjxBo6E0pAumM9IOUxAPq+vbF+ZD30gSNOKD1V9OKWJICniO4FhgE3HZQt0uWLM 3r3xLTJdxfPgiZqEYnzjRAI65zPiuzTrwaKRGhi/E3NFzxCzbBSk81JyBtM8mLl5mzuR mY6w== 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:content-transfer-encoding; bh=0l4UeWcZvaSK23sbyoOaV8Z+baEHEhVuF/62t9jEE88=; b=nRFBl0nWdDZSoU6zlum0OPU6wNsrb+YUpWg4AaTdHCmrNc1+hiWICjLShVx/eneZv4 VLwYKOZ5TubTt8ICZzPEgSOyKBuwdfgAjvp40cZI/PP0alxq2Qn7TseLfKB5SqIDDQCi kKc75GFwoKOfFT3cQfYszCCWfKorFXggEJst30fNDCAwjQoNG/FhYQVRgwGR8zMuxWjY zjN1FjXvW6uGVGvxxYVy5nMLC4qu3D99WDlEQZ49LXrYRoaxxsp4gshKeSZjKZwzvICs ADtttNJBxoWoaG5eh2fPT4RjoWnEuVV1g2/sXWSPuChlduULWwFIFIRi9b+13Spy8N+6 rkSg== X-Gm-Message-State: AOAM5311ZFJajDsjbIK/nySUTupE/83URO+2kmf/Fv5wy3w55Z8ik0CO SWfd5blGQnyPIifxUDYBSRtUCcMcyi+8OjwQCRs= X-Received: by 2002:a9d:62d1:: with SMTP id z17mr1017952otk.118.1615345348183; Tue, 09 Mar 2021 19:02:28 -0800 (PST) MIME-Version: 1.0 References: <1615294733-22761-1-git-send-email-aisheng.dong@nxp.com> <1615294733-22761-10-git-send-email-aisheng.dong@nxp.com> <4cee7ace-e6b9-fa0c-7cfe-d794ac9deabf@gmail.com> In-Reply-To: <4cee7ace-e6b9-fa0c-7cfe-d794ac9deabf@gmail.com> From: Dong Aisheng Date: Wed, 10 Mar 2021 11:02:27 +0800 Message-ID: Subject: Re: [PATCH 09/11] PM / devfreq: governor: optimize simpleondemand get_target_freq To: Chanwoo Choi Cc: Dong Aisheng , Linux PM , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , Sascha Hauer , Shawn Guo , dl-linux-imx , open list , myungjoo.ham@samsung.com, kyungmin.park@samsung.com, Chanwoo Choi , Abel Vesa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 10, 2021 at 12:09 AM Chanwoo Choi wrote: > > On 21. 3. 9. =EC=98=A4=ED=9B=84 9:58, Dong Aisheng wrote: > > devfreq_simple_ondemand_data only needs to be initialized once when > > calling devm_devfreq_add_device. It's unnecessary to put the data > > check logic in the hot path (.get_target_freq()) where it will be > > called all the time during polling. Instead, we only check and initiali= ze > > it one time during DEVFREQ_GOV_START. > > > > This also helps check data validability in advance during DEVFREQ_GOV_S= TART > > rather than checking it later when running .get_target_freq(). > > > > Signed-off-by: Dong Aisheng > > --- > > drivers/devfreq/governor_simpleondemand.c | 50 +++++++++++++++-------= - > > 1 file changed, 34 insertions(+), 16 deletions(-) > > > > diff --git a/drivers/devfreq/governor_simpleondemand.c b/drivers/devfre= q/governor_simpleondemand.c > > index ea287b57cbf3..341eb7e9dc04 100644 > > --- a/drivers/devfreq/governor_simpleondemand.c > > +++ b/drivers/devfreq/governor_simpleondemand.c > > @@ -15,15 +15,19 @@ > > /* Default constants for DevFreq-Simple-Ondemand (DFSO) */ > > #define DFSO_UPTHRESHOLD (90) > > #define DFSO_DOWNDIFFERENCTIAL (5) > > + > > +static struct devfreq_simple_ondemand_data od_default =3D { > > + .upthreshold =3D DFSO_UPTHRESHOLD, > > + .downdifferential =3D DFSO_DOWNDIFFERENCTIAL, > > +}; > > + > > static int devfreq_simple_ondemand_func(struct devfreq *df, > > unsigned long *freq) > > { > > int err; > > struct devfreq_dev_status *stat; > > unsigned long long a, b; > > - unsigned int dfso_upthreshold =3D DFSO_UPTHRESHOLD; > > - unsigned int dfso_downdifferential =3D DFSO_DOWNDIFFERENCTIAL; > > - struct devfreq_simple_ondemand_data *data =3D df->data; > > + struct devfreq_simple_ondemand_data *od =3D df->data; > > > > err =3D devfreq_update_stats(df); > > if (err) > > @@ -31,16 +35,6 @@ static int devfreq_simple_ondemand_func(struct devfr= eq *df, > > > > stat =3D &df->last_status; > > > > - if (data) { > > - if (data->upthreshold) > > - dfso_upthreshold =3D data->upthreshold; > > - if (data->downdifferential) > > - dfso_downdifferential =3D data->downdifferential; > > - } > > - if (dfso_upthreshold > 100 || > > - dfso_upthreshold < dfso_downdifferential) > > - return -EINVAL; > > - > > /* Assume MAX if it is going to be divided by zero */ > > if (stat->total_time =3D=3D 0) { > > *freq =3D DEVFREQ_MAX_FREQ; > > @@ -55,7 +49,7 @@ static int devfreq_simple_ondemand_func(struct devfre= q *df, > > > > /* Set MAX if it's busy enough */ > > if (stat->busy_time * 100 > > > - stat->total_time * dfso_upthreshold) { > > + stat->total_time * od->upthreshold) { > > *freq =3D DEVFREQ_MAX_FREQ; > > return 0; > > } > > @@ -68,7 +62,7 @@ static int devfreq_simple_ondemand_func(struct devfre= q *df, > > > > /* Keep the current frequency */ > > if (stat->busy_time * 100 > > > - stat->total_time * (dfso_upthreshold - dfso_downdifferential)= ) { > > + stat->total_time * (od->upthreshold - od->downdifferential)) = { > > *freq =3D stat->current_frequency; > > return 0; > > } > > @@ -78,17 +72,41 @@ static int devfreq_simple_ondemand_func(struct devf= req *df, > > a *=3D stat->current_frequency; > > b =3D div_u64(a, stat->total_time); > > b *=3D 100; > > - b =3D div_u64(b, (dfso_upthreshold - dfso_downdifferential / 2)); > > + b =3D div_u64(b, (od->upthreshold - od->downdifferential / 2)); > > *freq =3D (unsigned long) b; > > > > return 0; > > } > > > > +static int devfreq_simple_ondemand_check_od(struct devfreq *devfreq) > > +{ > > + struct devfreq_simple_ondemand_data *od =3D devfreq->data; > > + > > + if (od) { > > + if (!od->upthreshold) > > + od->upthreshold =3D DFSO_UPTHRESHOLD; > > + > > + if (!od->downdifferential) > > + od->downdifferential =3D DFSO_DOWNDIFFERENCTIAL; > > + > > + if (od->upthreshold > 100 || > > + od->upthreshold < od->downdifferential) > > + return -EINVAL; > > + } else { > > + od =3D &od_default; > > + } > > + > > + return 0; > > +} > > + > > static int devfreq_simple_ondemand_handler(struct devfreq *devfreq, > > unsigned int event, void *data) > > { > > switch (event) { > > case DEVFREQ_GOV_START: > > + if (devfreq_simple_ondemand_check_od(devfreq)) > > + return -EINVAL; > > + > > return devfreq_monitor_start(devfreq); > > > > case DEVFREQ_GOV_STOP: > > > > I'm editing the upthreshold and downdifferential for exposing them > via sysfs. So that after my work to expose them via sysfs, > send the patches if you think that need to do more about them. Thanks for letting me know.. I can rework after your patch merged. Regards Aisheng > > [1] > https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/linux.git/commit/= ?h=3Ddevfreq-testing&id=3Ddc9e557845c17cee173a6adcc3ae14940da03f44 > > -- > Best Regards, > Samsung Electronics > Chanwoo Choi