Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp899802pxb; Fri, 22 Apr 2022 13:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIiZv6gWjvQP5J52H0iY3Je6E7PL6khyt9O7EDzZYo/MNelsG5Wo8ZxStSYmZPH9rxOJyE X-Received: by 2002:a05:6a00:16c7:b0:4f7:e497:69c7 with SMTP id l7-20020a056a0016c700b004f7e49769c7mr6728572pfc.7.1650660505595; Fri, 22 Apr 2022 13:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650660505; cv=none; d=google.com; s=arc-20160816; b=QA9h8s9Cl6Yd8GuxPTm0dBacpf2JVQwt7pSFKtSLl9WV6zsm/jr0F+VaiBfgSXF0dO /VMVpzDH+l0Ef2GYRGrPV0/bH8/wHKQVGjs/SjMjZxhVToQszXeP9OrFbBZmpMhtdlDl FFaFzUddX6jYoM3eE0VlzRBB0uquNoBeQaAxmkIW/KNYjWTa44nsTEI5v/7dNII+xG3j Q1BXJZs5sKzxc2ECDyOvFlynrFKsM3YmTo+RtrF0ZjfFiCJ17mVWbzvMQpXxLpgunRhp u2KAEGm/1FuWiPcpy4N2uiAcYeHFHcien8bGTIKllA2AcAv2Fqlp+LvKrWn3Vi3J9h2z 4m5g== 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; bh=qqDfnR/pNAXrnStMMgvKfK9Y55MNdDB4d+D1vHAYIyA=; b=CeMi7cB5DJOhBUqhB6BBFbybDaZ6PVZLAQoWb+rrQMQaV0K6EPG4M4hsKbh+93FljP fByw/dCN7+VUgIbsL4KkrdnkATMWWiI703ewuabVqfvhvXqJaMwqqMwBkhazPSbO8neW 0eYjyxQtolnNUv40qEPt6bJJzAdW5g/IxY82MBOaR7Y2StMi/gZX1YEn3AX8JBdKFnnv zloAheqc7BLmQSlpFuf+gRYUxm+USwnB9PyRqLvEu0xvAUlgp+RdnyJRbNq7z7wmicTq KMiCNCchOt7rfYQ5KNkOPilWTh6ArIe4qqCasKKhgTV+rzGgFt3muMgjvcG+YxkYuG9C TXtA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id 78-20020a630251000000b003816043f13dsi9195546pgc.818.2022.04.22.13.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:48:25 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 058611FDBDB; Fri, 22 Apr 2022 12:37:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354673AbiDSQig (ORCPT + 99 others); Tue, 19 Apr 2022 12:38:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345034AbiDSQid (ORCPT ); Tue, 19 Apr 2022 12:38:33 -0400 Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5989113DF3; Tue, 19 Apr 2022 09:35:49 -0700 (PDT) Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-2ec04a2ebadso178342667b3.12; Tue, 19 Apr 2022 09:35:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qqDfnR/pNAXrnStMMgvKfK9Y55MNdDB4d+D1vHAYIyA=; b=2XruMW5wrSIfYcPoq5ggevIKVPu/mBfg0Wnp1509B7EXZ+UjuvH1YBT9mPM6yE0WZp P4JfiHx81Thw9H9OUbYUHuK8UIcrzOZclXHIzRxucgpzG2BxWBLvcrfZxAeqriQbx91k a3mPt91vpM28tZzpLv9ytty8ZV1+97JTwYa5FyUERKpXW1blYOPj9JVqgtONz8YGI8Io z2zlcdfoqTdyxSH5/xFDV5e3xLo2RcirjqETJzr86gy1+GTpP2cF5shDoRr9eKLfHmna Z8AJvqzKW3p5PH0pGVRPCpQ/qnmZeOTAdzSSY149BZFFf0oZPFZXUUNbcIxTc/DWsHyR ydkw== X-Gm-Message-State: AOAM532ECNeHC/XiwwkWYsXX5sGVv/W3Xjla8Vsw3N53fyp8sIsnBtDj e1ZX/+If6xKM2MzxugTgn/AUVWuyfOXo62Mg7bQ= X-Received: by 2002:a81:4b8e:0:b0:2ef:5240:69fc with SMTP id y136-20020a814b8e000000b002ef524069fcmr16726449ywa.19.1650386148582; Tue, 19 Apr 2022 09:35:48 -0700 (PDT) MIME-Version: 1.0 References: <20220415133356.179706384@linutronix.de> <20220415161206.875029458@linutronix.de> In-Reply-To: <20220415161206.875029458@linutronix.de> From: "Rafael J. Wysocki" Date: Tue, 19 Apr 2022 18:35:37 +0200 Message-ID: Subject: Re: [patch 09/10] x86/aperfmperf: Replace aperfmperf_get_khz() To: Thomas Gleixner Cc: LKML , "the arch/x86 maintainers" , "Rafael J. Wysocki" , Linux PM , Eric Dumazet , "Paul E. McKenney" , Eric Dumazet Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 15, 2022 at 9:20 PM Thomas Gleixner wrote: > > The frequency invariance infrastructure provides the APERF/MPERF samples > already. Utilize them for the cpu frequency display in /proc/cpuinfo. > > The sample is considered valid for 20ms. So for idle or isolated NOHZ full > CPUs the function returns 0, which is matching the previous behaviour. > > This gets rid of the mass IPIs and a delay of 20ms for stabilizing observed > by Eric when reading /proc/cpuinfo. > > Reported-by: Eric Dumazet > Signed-off-by: Thomas Gleixner All fine IMV, one minor nit below. Reviewed-by: Rafael J. Wysocki > --- > arch/x86/kernel/cpu/aperfmperf.c | 77 +++++++++++++++++---------------------- > fs/proc/cpuinfo.c | 6 --- > include/linux/cpufreq.h | 1 > 3 files changed, 35 insertions(+), 49 deletions(-) > > --- a/arch/x86/kernel/cpu/aperfmperf.c > +++ b/arch/x86/kernel/cpu/aperfmperf.c > @@ -100,49 +100,6 @@ static bool aperfmperf_snapshot_cpu(int > return time_delta <= APERFMPERF_STALE_THRESHOLD_MS; > } > > -unsigned int aperfmperf_get_khz(int cpu) > -{ > - if (!cpu_khz) > - return 0; > - > - if (!boot_cpu_has(X86_FEATURE_APERFMPERF)) > - return 0; > - > - if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) > - return 0; > - > - if (rcu_is_idle_cpu(cpu)) > - return 0; /* Idle CPUs are completely uninteresting. */ > - > - aperfmperf_snapshot_cpu(cpu, ktime_get(), true); > - return per_cpu(samples.khz, cpu); > -} > - > -void arch_freq_prepare_all(void) > -{ > - ktime_t now = ktime_get(); > - bool wait = false; > - int cpu; > - > - if (!cpu_khz) > - return; > - > - if (!boot_cpu_has(X86_FEATURE_APERFMPERF)) > - return; > - > - for_each_online_cpu(cpu) { > - if (!housekeeping_cpu(cpu, HK_TYPE_MISC)) > - continue; > - if (rcu_is_idle_cpu(cpu)) > - continue; /* Idle CPUs are completely uninteresting. */ > - if (!aperfmperf_snapshot_cpu(cpu, now, false)) > - wait = true; > - } > - > - if (wait) > - msleep(APERFMPERF_REFRESH_DELAY_MS); > -} > - > unsigned int arch_freq_get_on_cpu(int cpu) > { > struct aperfmperf_sample *s = per_cpu_ptr(&samples, cpu); > @@ -529,6 +486,40 @@ void arch_scale_freq_tick(void) > scale_freq_tick(acnt, mcnt); > } > > +/* > + * Discard samples older than the define maximum sample age of 20ms. There > + * is no point in sending IPIs in such a case. If the scheduler tick was > + * not running then the CPU is either idle or isolated. > + */ > +#define MAX_SAMPLE_AGE ((unsigned long)HZ / 50) > + > +unsigned int aperfmperf_get_khz(int cpu) > +{ > + struct aperfmperf *s = per_cpu_ptr(&cpu_samples, cpu); > + unsigned long last; > + unsigned int seq; > + u64 acnt, mcnt; > + > + if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF)) > + return 0; > + > + do { > + seq = raw_read_seqcount_begin(&s->seq); > + last = s->last_update; > + acnt = s->acnt; > + mcnt = s->mcnt; > + } while (read_seqcount_retry(&s->seq, seq)); > + > + /* > + * Bail on invalid count and when the last update was too long ago, > + * which covers idle and NOHZ full CPUs. > + */ > + if (!mcnt || (jiffies - last) > MAX_SAMPLE_AGE) The inner parens are not needed here. > + return 0; > + > + return div64_u64((cpu_khz * acnt), mcnt); > +} > + > static int __init bp_init_aperfmperf(void) > { > if (!cpu_feature_enabled(X86_FEATURE_APERFMPERF)) > --- a/fs/proc/cpuinfo.c > +++ b/fs/proc/cpuinfo.c > @@ -5,14 +5,10 @@ > #include > #include > > -__weak void arch_freq_prepare_all(void) > -{ > -} > - > extern const struct seq_operations cpuinfo_op; > + > static int cpuinfo_open(struct inode *inode, struct file *file) > { > - arch_freq_prepare_all(); > return seq_open(file, &cpuinfo_op); > } > > --- a/include/linux/cpufreq.h > +++ b/include/linux/cpufreq.h > @@ -1199,7 +1199,6 @@ static inline void sched_cpufreq_governo > struct cpufreq_governor *old_gov) { } > #endif > > -extern void arch_freq_prepare_all(void); > extern unsigned int arch_freq_get_on_cpu(int cpu); > > #ifndef arch_set_freq_scale >