Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp932028ybz; Wed, 15 Apr 2020 22:49:32 -0700 (PDT) X-Google-Smtp-Source: APiQypIitmBN4brY6I9KreqsGzjFB2LSEZeYcCR8b0t4E8gJSegNIt0RRWQw9/aT/zz/AWFtUT3+ X-Received: by 2002:a50:cf8e:: with SMTP id h14mr28923951edk.369.1587016171907; Wed, 15 Apr 2020 22:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587016171; cv=none; d=google.com; s=arc-20160816; b=AUw5ly1YUC/nem+w0vtT9bcgRHGiUI3qs5HGxxSStkZc8e1EXFzG+J192dRlEdvuYR UZfhtWJCC5UpHUwFY+RRwM6Ei3aqFtZKvAM103rxJfRt3nPGlRptONiciArcYI6aO3wm rkSUUd72RNn+tXv4KafBL5dmk/BtA2Xsbq3mzCljsybDTnkgPz4EaTG9K7SO+EyijCnX iecbZ0e73nOtex+11IqcwZepneyVungql5BcQ+a5ohNTRwvF0aAX9Ksg3dsmPWIQGNd6 qwgga2mAlzxGGBQnrLzZNQcoUIti0MNKCad6Cab4axKnixug4+8JqIq7lLIIGL0JDb80 UrxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=OmjgVM+dpqLr+Cpgm6g4QT2lZk7V7JTDUtu0opW49qQ=; b=UnsStJ9YAjzC8jomRxBYld8O7YtDXnUFrmoTKAGpqkPMR9aKFy+z9wmZotqTyyu/3f Bpwd8l2xtLQHlMoTCeIMz6U/C97LayjRj+S0wWQoIkjgWt12K7y8DbN4QlgdJs/673n9 NW6mKYgl93eCBIcXdzF9rybSe1i2aLtTMJfs7go8bUbKD5ekw6jrMhp7MTdeWK75dsSp drRN87RToVuRPgLCFc2+VBMRsaAKa8FyuOuR2i9VpssjizA4NeOqFgDA6Ao1oU7Emya6 RUX+1tw1HeP72xbulBOauRJGbvs1vao02W7opPYaNE3JPjzETPOIRTPagazJsb3iokwZ mMkA== 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 k6si11686958ejv.507.2020.04.15.22.49.07; Wed, 15 Apr 2020 22:49:31 -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 S2407074AbgDPFsO (ORCPT + 99 others); Thu, 16 Apr 2020 01:48:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:38452 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406805AbgDPFsM (ORCPT ); Thu, 16 Apr 2020 01:48:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8B068AD7C; Thu, 16 Apr 2020 05:48:09 +0000 (UTC) From: Giovanni Gherdovich To: Srinivas Pandruvada , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Borislav Petkov , Len Brown , "Rafael J . Wysocki" Cc: x86@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Mel Gorman , Doug Smythies , Like Xu , Neil Rickert , Chris Wilson , Giovanni Gherdovich Subject: [PATCH 3/4] x86, sched: Don't enable static key when starting secondary CPUs Date: Thu, 16 Apr 2020 07:47:44 +0200 Message-Id: <20200416054745.740-4-ggherdovich@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20200416054745.740-1-ggherdovich@suse.cz> References: <20200416054745.740-1-ggherdovich@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Peter Zijlstra (Intel)" 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] Reported-by: Chris Wilson Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Giovanni Gherdovich Fixes: 1567c3e3467c ("x86, sched: Add support for frequency invariance") --- 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 5d346b70844b..dd8e15f648bc 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 @@ static bool intel_set_max_freq_ratio(void) 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"); -- 2.16.4