From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 348B1C433DF for ; Fri, 16 Oct 2020 16:36:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2D7220874 for ; Fri, 16 Oct 2020 16:36:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="dofkqMiA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2410850AbgJPQgh (ORCPT ); Fri, 16 Oct 2020 12:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408787AbgJPQgg (ORCPT ); Fri, 16 Oct 2020 12:36:36 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A676BC061755 for ; Fri, 16 Oct 2020 09:36:37 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id w4so1655298plp.17 for ; Fri, 16 Oct 2020 09:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:cc; bh=ESK7AGq3xcY8c9Kxha7AtdakH67WdRXIQfnsDd+BhXg=; b=dofkqMiAcYaTZ/EU/5BiqncgO4c4vvmzEbKqHqFSlvIscLiIgRE/bTb1TustzDyW5+ 1d+MDxzUeGcty3tPvWgNBr8re5d1r05uCLQVUyvDWo12ygO68kqBUaC/YvvrQOBXKx6C lDzvruetF0BhW2g9fEHlRdHlShRQBxUvfcBGy8xB8BE0KZm0AhYakD993Plztl0nmxu3 7W2ffDpO0liBBnb7GDO5SbSR2mrFTmtKJxjCIoQwys77J/qZgidVxMhgN6EqoA4KNTk8 wX+qKyK6iRoT+AGjl7M1ZrIyJhBDRT/klURxjkDudaL3DgoJBj3dfx2KzoXfZyfAjs/H DAPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :cc; bh=ESK7AGq3xcY8c9Kxha7AtdakH67WdRXIQfnsDd+BhXg=; b=V+SxOz79zabXPbCkhRUEXE2VChuPoV5y/1kLdcTZnIA2DyvcCuJdEuHRzBWCVu0GjG bYcc6NUpxPfgvdzDCl4L03VkAyONgkVJMgITOXdRA6b8JOW2w4oE3VHfQaG1jVgIuWtC OcDuvOWusxGiywrLDAvrqPgJzA+ob24xcUwEPWBtdSGgxZR53jW69ZsEohCPbFbigm2R 3M+5W9MZXFsYjMit20hSkMpaM4nPpZQzmELbczYfRbY5ih5Fk99AtpQPs95vfi9DIFFq ynfjA0qcGb7DWpKLJcQSbuUslS+7/czRUcfc5Xg274KRtx3Ao+VR2+F0VyLx1HLSmYxq OCmA== X-Gm-Message-State: AOAM530HclUMsT8CUHkja6BEKFa18p8X0u1OhbLxIIy+gNv/eJfzCIEx HHg97PADjldXU4pA6en6eYwcU34= X-Google-Smtp-Source: ABdhPJzIj8wfAyuTdoCZc19cbR6Oa/+HMGW+IbJchs8PIY78j7uCCcCE0AmQhWTlP9Gx/+KxhSvLj6o= Sender: "wvw via sendgmr" X-Received: from wvw-pc.mtv.corp.google.com ([2620:15c:211:1:f693:9fff:fef4:4f9b]) (user=wvw job=sendgmr) by 2002:a17:902:402:b029:d5:ac47:c33f with SMTP id 2-20020a1709020402b02900d5ac47c33fmr4582746ple.60.1602866197061; Fri, 16 Oct 2020 09:36:37 -0700 (PDT) Date: Fri, 16 Oct 2020 09:36:33 -0700 Message-Id: <20201016163634.857573-1-wvw@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog Subject: [PATCH] sched: cpufreq_schedutil: maintain raw cache when next_f is not changed From: Wei Wang Cc: wei.vince.wang@gmail.com, viresh.kumar@linaro.org, qperret@google.com, Wei Wang , "Rafael J. Wysocki" , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, raw cache will be reset when next_f is changed after get_next_freq for correctness. However, it may introduce more cycles. This patch changes it to maintain the cached value instead of dropping it. This is adapted from https://android-review.googlesource.com/1352810/ Signed-off-by: Wei Wang --- kernel/sched/cpufreq_schedutil.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 5ae7b4e6e8d6..ae3ae7fcd027 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -31,6 +31,7 @@ struct sugov_policy { s64 freq_update_delay_ns; unsigned int next_freq; unsigned int cached_raw_freq; + unsigned int prev_cached_raw_freq; /* The next fields are only needed if fast switch cannot be used: */ struct irq_work irq_work; @@ -165,6 +166,7 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, return sg_policy->next_freq; sg_policy->need_freq_update = false; + sg_policy->prev_cached_raw_freq = sg_policy->cached_raw_freq; sg_policy->cached_raw_freq = freq; return cpufreq_driver_resolve_freq(policy, freq); } @@ -464,8 +466,8 @@ static void sugov_update_single(struct update_util_data *hook, u64 time, if (busy && next_f < sg_policy->next_freq) { next_f = sg_policy->next_freq; - /* Reset cached freq as next_freq has changed */ - sg_policy->cached_raw_freq = 0; + /* Restore cached freq as next_freq has changed */ + sg_policy->cached_raw_freq = sg_policy->prev_cached_raw_freq; } /* @@ -828,6 +830,7 @@ static int sugov_start(struct cpufreq_policy *policy) sg_policy->limits_changed = false; sg_policy->need_freq_update = false; sg_policy->cached_raw_freq = 0; + sg_policy->prev_cached_raw_freq = 0; for_each_cpu(cpu, policy->cpus) { struct sugov_cpu *sg_cpu = &per_cpu(sugov_cpu, cpu); -- 2.29.0.rc1.297.gfa9743e501-goog