Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8043847rwl; Tue, 10 Jan 2023 08:23:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXuirZyKcYpkKOcbhvlyPwYTkTUtyjZ4kf5fPfo0y+H7UEYq0MY8ZV5eCKHFYwNsghLwhwTA X-Received: by 2002:a17:902:e74a:b0:192:8e0b:23d3 with SMTP id p10-20020a170902e74a00b001928e0b23d3mr67096293plf.23.1673367783850; Tue, 10 Jan 2023 08:23:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673367783; cv=none; d=google.com; s=arc-20160816; b=KwzUcMHtNzCy2jB9MgYRszhMiQdTiRPeOOlkb+41xfx2tM/7oKp9J6lvufqOGSJ+K3 eLKwSYE1YxwN9Brr8f4vmbZFfYUMk+13/lFEvDhpriQs1TOrt2Mo809dlZMq5taHxAzE BXqmX8fmY6SySNO8IE+kLh7mdsYGu7ZZoGrw4zd3Sp9WBGimXohaWPx/iAMDYLonef6c SwilVDuDz9WiagTy9LQ/AEXqSROOuFHBSz/58lACWYYEhfIjuv1ssj6jfbPMMJfwAMLo Uot404sa9pU9Ay09RTJudACbowl6xRvzSPjYvrG+T1Lihx1JLnfLpcCcJiJ22WK0Wxt5 G2GQ== 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:dkim-signature; bh=DQpRVT0IkRUZeKZoKEdCQYhHtCMfLxNstGXOTDIvo4s=; b=pvq3nzSIH6RKYm8SS8omUBreXOHd65Fl7/kUyF2IIeBtyRGr3bPBLJ46/6LP7gfcAR Ft+gDIVMXuMFLC+B8CcTvheP5fyWuuI15hXlJEwbM/WJBvx77U3B2HwhAvT4Jb1p7yNY jCssqx9Kiqu09X/xSbofDcJ51ldLapBbBAd3Rtx60n1RpcaMwVDOoGtPsew8lYh2VAyd 5SWfvj/rAuyN4+3k/z+mu+QsiMNYPy330cN0PnZRw701VGDFXci4xBYZM7KFdrGw6vrZ KL8A3OOKS1WG7fnRLvEXxZTAtEI4YzsAIUKbSF6s+wPqn0OLWzoXRnavcuDr6TltUS1S xq3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="SJWq2/D2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w17-20020a634751000000b004780221f08bsi11695305pgk.853.2023.01.10.08.22.57; Tue, 10 Jan 2023 08:23:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="SJWq2/D2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233423AbjAJQD4 (ORCPT + 55 others); Tue, 10 Jan 2023 11:03:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238887AbjAJQDQ (ORCPT ); Tue, 10 Jan 2023 11:03:16 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 983C14F137 for ; Tue, 10 Jan 2023 08:02:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673366550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=DQpRVT0IkRUZeKZoKEdCQYhHtCMfLxNstGXOTDIvo4s=; b=SJWq2/D2crSWJOoit5wxybjmzmRtGFqTsebfav1wea3NtVkUOBO5zPM6+pzu+G/Jrl8oLy HnkTYLjPVWUeRaDb2iBdWNqWjJGenU4qihnFl1yJ4q4AnAA1kKI0LXe/KUtWM1FFwCUo/J Z3FBDy/RLH9gObH6bCnnSJ10CYmSutg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-pxik-GieMnKb-iuD7PHckg-1; Tue, 10 Jan 2023 11:02:27 -0500 X-MC-Unique: pxik-GieMnKb-iuD7PHckg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B74D3C0D855; Tue, 10 Jan 2023 16:02:25 +0000 (UTC) Received: from ypodemsk.tlv.csb (unknown [10.39.193.200]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD7FFC16031; Tue, 10 Jan 2023 16:02:22 +0000 (UTC) From: Yair Podemsky To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, peterz@infradead.org, rafael.j.wysocki@intel.com, paulmck@kernel.org, frederic@kernel.org, linux-kernel@vger.kernel.org Cc: ypodemsk@redhat.com Subject: [PATCH] x86/aperfmperf: erase stale arch_freq_scale values when disabling frequency invariance readings Date: Tue, 10 Jan 2023 18:02:06 +0200 Message-Id: <20230110160206.75912-1-ypodemsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 Once disable_freq_invariance_work is called the scale_freq_tick function will not compute or update the arch_freq_scale values. However the scheduler will still read these values and use them. The result is that the scheduler might perform unfair decisions based on stale values. This patch adds the step of setting the arch_freq_scale values for all cpus to the default (max) value SCHED_CAPACITY_SCALE, Once all cpus have the same arch_freq_scale value the scaling is meaningless. Signed-off-by: Yair Podemsky --- arch/x86/kernel/cpu/aperfmperf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/kernel/cpu/aperfmperf.c b/arch/x86/kernel/cpu/aperfmperf.c index 1f60a2b27936..fdbb5f07448f 100644 --- a/arch/x86/kernel/cpu/aperfmperf.c +++ b/arch/x86/kernel/cpu/aperfmperf.c @@ -330,7 +330,16 @@ static void __init bp_init_freq_invariance(void) static void disable_freq_invariance_workfn(struct work_struct *work) { + int cpu; + static_branch_disable(&arch_scale_freq_key); + + /* + * Set arch_freq_scale to a default value on all cpus + * This negates the effect of scaling + */ + for_each_possible_cpu(cpu) + per_cpu(arch_freq_scale, cpu) = SCHED_CAPACITY_SCALE; } static DECLARE_WORK(disable_freq_invariance_work, -- 2.31.1