Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1138811ybz; Wed, 22 Apr 2020 14:22:16 -0700 (PDT) X-Google-Smtp-Source: APiQypJc9GF6YPkNJ74InpTNWQ6FTnNw9HHCvAboz1O9hg0V+6Uyo5DPsqqdnv88e8xQCZJIurqL X-Received: by 2002:a50:f095:: with SMTP id v21mr474752edl.103.1587590536754; Wed, 22 Apr 2020 14:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587590536; cv=none; d=google.com; s=arc-20160816; b=Y/8HA7yWSzFdqFiK5YiHA7YZtVMmegdlVIhI3WrhhXamMzIIOOIr3J5Fbm+pY+JJ5l zr6LwG7GnOOEm5ui1Kqs5Bn/emmr2GPNtLgeQu+veG3gRcEsYz4mA7WbeaM2YEViGwam by1ckcRkdVJNzQusaVJYa6T7oxJwSg8E7QVb9f9yPT2wfQgJ8159yyA34cBuCprwu2gk VyaU6aCrCCKIcbAPGCZ1bCvKDHEt06qXP2w2t+8osihiyLg14zrPqFLZ3PnRW+/LjFHk qAyIhII/Wt8pfLzZvIBWZMQ7vh8tC0rFa+KwVTgjR1nLe+wKB29ldKr6sidVM6rx9Xtp J9jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=D2nTOxyZ+7MXzx4HFsx7wuUqyWHEuLSQgkwqlNLVQ7k=; b=qUdWULqI7DXscwkeiImFZDtHvENIAgQLN59UyaOSko50XnIR30TlnsKsdrH1nJVaLz P729nsR/pjPwUvemjl6uI6P0OHvaihRSGQeTrAv3mUc2WJaQuxx1qF8izK5r9QgneUBs Ij1eCSGpWw67ElIrKZZaRGU7k8OpjsT7VzTeaKVGvlviy3BA9T8L1oH9bTKBnALF+meq AYAWSciAqahZUx0BF1A6dPKU5iMGrVY9L+/q6aOteeIQ1j1Hc8BmxwGO3qnRfN29GM+s KMmUQjLz2TqdlP3tcgtkYKx15rRBorzYcxLAvj9HP7uw0JojmAZTc+KLmVKmgd+2+DvP zhQw== 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 c3si198261ejr.452.2020.04.22.14.21.53; Wed, 22 Apr 2020 14:22:16 -0700 (PDT) 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 S1726584AbgDVVU6 (ORCPT + 99 others); Wed, 22 Apr 2020 17:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbgDVVU5 (ORCPT ); Wed, 22 Apr 2020 17:20:57 -0400 Received: from Galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 456FBC03C1A9; Wed, 22 Apr 2020 14:20:57 -0700 (PDT) Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jRMnZ-0000O6-0s; Wed, 22 Apr 2020 23:20:49 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 8CD4F1C0450; Wed, 22 Apr 2020 23:20:48 +0200 (CEST) Date: Wed, 22 Apr 2020 21:20:48 -0000 From: "tip-bot2 for Peter Zijlstra (Intel)" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/urgent] x86, sched: Don't enable static key when starting secondary CPUs Cc: Chris Wilson , "Peter Zijlstra (Intel)" , Giovanni Gherdovich , "Rafael J. Wysocki" , x86 , LKML In-Reply-To: <20200416054745.740-4-ggherdovich@suse.cz> References: <20200416054745.740-4-ggherdovich@suse.cz> MIME-Version: 1.0 Message-ID: <158759044814.28353.10087364439077051099.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/urgent branch of tip: Commit-ID: b56e7d45e80796ca963ac10902245b244d823caf Gitweb: https://git.kernel.org/tip/b56e7d45e80796ca963ac10902245b244d823caf Author: Peter Zijlstra (Intel) AuthorDate: Thu, 16 Apr 2020 07:47:44 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 22 Apr 2020 23:10:13 +02:00 x86, sched: Don't enable static key when starting secondary CPUs The static key arch_scale_freq_key only needs to be enabled once (at boot). This change fixes a bug by which the key was enabled every time cpu0 is started, even as a secondary CPU during cpu hotplug. Secondary CPUs are started from the idle thread: setting a static key from there means acquiring a lock and may result in sleeping in the idle task, causing CPU lockup. Another consequence of this change is that init_counter_refs() is now called on each CPU correctly; previously the function on_each_cpu() was used, but it was called at boot when the only online cpu is cpu0. [ggherdovich@suse.cz: Tested and wrote changelog] Fixes: 1567c3e3467c ("x86, sched: Add support for frequency invariance") Reported-by: Chris Wilson Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Giovanni Gherdovich Signed-off-by: Peter Zijlstra (Intel) Acked-by: Rafael J. Wysocki Link: https://lkml.kernel.org/r/20200416054745.740-4-ggherdovich@suse.cz --- arch/x86/kernel/smpboot.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 5d346b7..dd8e15f 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -147,7 +147,7 @@ static inline void smpboot_restore_warm_reset_vector(void) *((volatile u32 *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) = 0; } -static void init_freq_invariance(void); +static void init_freq_invariance(bool secondary); /* * Report back to the Boot Processor during boot time or to the caller processor @@ -185,7 +185,7 @@ static void smp_callin(void) */ set_cpu_sibling_map(raw_smp_processor_id()); - init_freq_invariance(); + init_freq_invariance(true); /* * Get our bogomips. @@ -1341,7 +1341,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus) set_sched_topology(x86_topology); set_cpu_sibling_map(0); - init_freq_invariance(); + init_freq_invariance(false); smp_sanity_check(); switch (apic_intr_mode) { @@ -2005,7 +2005,7 @@ out: return true; } -static void init_counter_refs(void *arg) +static void init_counter_refs(void) { u64 aperf, mperf; @@ -2016,18 +2016,25 @@ static void init_counter_refs(void *arg) this_cpu_write(arch_prev_mperf, mperf); } -static void init_freq_invariance(void) +static void init_freq_invariance(bool secondary) { bool ret = false; - if (smp_processor_id() != 0 || !boot_cpu_has(X86_FEATURE_APERFMPERF)) + if (!boot_cpu_has(X86_FEATURE_APERFMPERF)) return; + if (secondary) { + if (static_branch_likely(&arch_scale_freq_key)) { + init_counter_refs(); + } + return; + } + if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) ret = intel_set_max_freq_ratio(); if (ret) { - on_each_cpu(init_counter_refs, NULL, 1); + init_counter_refs(); static_branch_enable(&arch_scale_freq_key); } else { pr_debug("Couldn't determine max cpu frequency, necessary for scale-invariant accounting.\n");