Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp498040pxb; Fri, 8 Jan 2021 10:09:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxDpy55jILWkBSIJ2N9ooVuK64tLgmZ6iuZrkAFpZHnM3VSAJz2HDISyZQR8OzZoG56P8M7 X-Received: by 2002:a17:906:118c:: with SMTP id n12mr3498180eja.167.1610129394929; Fri, 08 Jan 2021 10:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610129394; cv=none; d=google.com; s=arc-20160816; b=mjlH+vrcavNH3pAoVDIVOElOGURhBTnYZheOhS8lZLcKtEv9fg0P/C4zZGPrJJ1av8 Sja0mNgEwjDWuSWLK+UV3x7Ay5gCBZ3i3oYzM0rFNflMNDYxxFBdbw/q8VPfxLSy9z2Z 5WbaCgTDiA0nsIfZaIcvdisA+YOV4+pWVSP69h0KhzzMu4MTTveB6biZLf+0Gh/JgzDN +z3o1q/qnrCaRoTphGnJe4cCQpL3YU9cE2T/onw/gU66Dm5X+9SDiTgOW+Khr3h7oXS1 lMMcuXlI30MwJz+52WfIQIERlwDxa59nt41KUR6qiN1GQ3PZ83zN2Lj8e2drDLtYm9vM vpZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=5L90vqqse1eHD6JOPX8TRzAuGOdYZIl/qkDII7nv3rA=; b=on11Xj1WfRQ5r7IJcGORPQ9+tSjfg2j+/i3ESC6njGFFD0XPEHJxZxYBF9Wo0UNoud jDdI+Y8hx26XQKAh7rt9RrK7pjMBL7cq/479aYwkqcZYLl/IfUa5lkzacSmig/ejJAug LzomTat3dqTIYkhWUK9lnS9fpadIA4NI+4VoODsgxlgadVlR424m08LYeDJWLpO5Bye8 zfkhaozSUZ3cqASWddcXDPlX4IxOG/aE5bD2RTNJ38arXcPk7lnJTdVGRWyjlMmaHjN6 wyxmWOgPegq5ioC1rO1NvQPp+HraRlVkwkESITvv/gySQ1Wd11FB3lRfUpd4cxdTLXQC qy5Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c20si3826436edw.222.2021.01.08.10.09.30; Fri, 08 Jan 2021 10:09:54 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728707AbhAHSGo (ORCPT + 99 others); Fri, 8 Jan 2021 13:06:44 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:43634 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728442AbhAHSGn (ORCPT ); Fri, 8 Jan 2021 13:06:43 -0500 Received: from 89-64-81-105.dynamic.chello.pl (89.64.81.105) (HELO kreacher.localnet) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.83.537) id f8e5a3c0ad700087; Fri, 8 Jan 2021 19:06:01 +0100 From: "Rafael J. Wysocki" To: Peter Zijlstra Cc: Linux PM , LKML , x86 Maintainers , Srinivas Pandruvada , Giovanni Gherdovich , Giovanni Gherdovich Subject: [PATCH] x86: PM: Register syscore_ops for scale invariance Date: Fri, 08 Jan 2021 19:05:59 +0100 Message-ID: <1803209.Mvru99baaF@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki On x86 scale invariace tends to be disabled during resume from suspend-to-RAM, because the MPERF or APERF MSR values are not as expected then due to updates taking place after the platform firmware has been invoked to complete the suspend transition. That, of course, is not desirable, especially if the schedutil scaling governor is in use, because the lack of scale invariance causes it to be less reliable. To counter that effect, modify init_freq_invariance() to register a syscore_ops object for scale invariance with the ->resume callback pointing to init_counter_refs() which will run on the CPU starting the resume transition (the other CPUs will be taken care of the "online" operations taking place later). Fixes: e2b0d619b400 ("x86, sched: check for counters overflow in frequency invariant accounting") Signed-off-by: Rafael J. Wysocki --- arch/x86/kernel/smpboot.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) Index: linux-pm/arch/x86/kernel/smpboot.c =================================================================== --- linux-pm.orig/arch/x86/kernel/smpboot.c +++ linux-pm/arch/x86/kernel/smpboot.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include @@ -2083,6 +2084,23 @@ static void init_counter_refs(void) this_cpu_write(arch_prev_mperf, mperf); } +#ifdef CONFIG_PM_SLEEP +static struct syscore_ops freq_invariance_syscore_ops = { + .resume = init_counter_refs, +}; + +static void register_freq_invariance_syscore_ops(void) +{ + /* Bail out if registered already. */ + if (freq_invariance_syscore_ops.node.prev) + return; + + register_syscore_ops(&freq_invariance_syscore_ops); +} +#else +static inline void register_freq_invariance_syscore_ops(void) {} +#endif + static void init_freq_invariance(bool secondary, bool cppc_ready) { bool ret = false; @@ -2109,6 +2127,7 @@ static void init_freq_invariance(bool se if (ret) { init_counter_refs(); static_branch_enable(&arch_scale_freq_key); + register_freq_invariance_syscore_ops(); pr_info("Estimated ratio of average max frequency by base frequency (times 1024): %llu\n", arch_max_freq_ratio); } else { pr_debug("Couldn't determine max cpu frequency, necessary for scale-invariant accounting.\n");