Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1370068imm; Sun, 23 Sep 2018 02:36:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV60FemoLywyiTF1iupVUIGgUMSxfBYBx13UD8tC3FyiWikL9fvIclM3akWTVaPIrGKhneVGx X-Received: by 2002:a63:610:: with SMTP id 16-v6mr5085046pgg.96.1537695415871; Sun, 23 Sep 2018 02:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537695415; cv=none; d=google.com; s=arc-20160816; b=pTeDvPtj3ZNLT+VIBXBEoNzmwqHc98qTtDAut9Dvtxo0K/wm3mRJLteLS7H6hd1gkN f/PSSx4UYO5HUe+/lRTVLVxgZIr32i7VZ67nDdkykRwW1JwBdNXdm7Feu0j3kA+3ua9Y bzMzIj3CX/vuDETFCRwdEhmkUSt4flrFSREz5NOGHttRAXfTUj5RtSXyjJG2wo+jqAJT 6uJPNF5Mfu7yGVigxL/H946t+Ca0Fj0xbztQ26zZ+e/g2z7oQ7CeEMZpQn5M9VaOlpfj VxZq4CyduYue3c1TlmPjbjmdBJDJMKzJPL6SqtjugTQpiDA6+J4rLbtF7SAbH6vmOGfz ayWQ== 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=LMeosLRiY19eGAhbOi79TO5Hl6OTkAeYNNZk8glhRNs=; b=OpLXwUuByvnCrw0Q57CwKkRT9OHLpkW0+Cp8KgIgquvt7HCNOP0QJ+53kByHXWkmm2 cHeVDGhZpMbsuvLyWxrLqHlv6b1guiJaHGoeaBeQGGX1o3HGaN4RELeV78lTKjneti6B ha4SwZWIeTPwKlywpVaTt+TjEVgEnhuZcPTSpabdyGSu2AqwbxJSL3A0BJeFxmAyOVnF crRKa1UFrkxU15Q5GrUtMTlaQAbdC3W1fIwmdNEuxCKgqD/yQX8xIQvUFJamER+vNlLT k+xsb6ZodHbzc/QhrtkfWabWTlavUqUHuI6MflvnFfIg7T424LuQOWhkhb+1TtN/v0Z6 Jtqw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ca7-v6si936874plb.480.2018.09.23.02.36.41; Sun, 23 Sep 2018 02:36:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726222AbeIWPbx (ORCPT + 99 others); Sun, 23 Sep 2018 11:31:53 -0400 Received: from smtp21.cstnet.cn ([159.226.251.21]:47803 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726035AbeIWPbx (ORCPT ); Sun, 23 Sep 2018 11:31:53 -0400 Received: from pw-vbox.higon.com (unknown [182.150.46.145]) by APP-01 (Coremail) with SMTP id qwCowAA3Pb06Xqdb7z6zDA--.53S2; Sun, 23 Sep 2018 17:34:54 +0800 (CST) From: Pu Wen To: bp@alien8.de, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, thomas.lendacky@amd.com Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Pu Wen Subject: [PATCH v8 05/16] perf/x86: Add Hygon Dhyana support to PMU infrastructure Date: Sun, 23 Sep 2018 17:34:47 +0800 Message-Id: <9d93ed54a975f33ef7247e0967960f4ce5d3d990.1537533369.git.puwen@hygon.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-CM-TRANSID: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fo: psxzv046klw03qof0z/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The PMU architecture for Hygon Dhyana CPU is similar to the AMD Family 17h one. To support Hygon Dhyana PMU, call amd_pmu_init() to share AMD PMU initialization flow, and change the PMU name to "HYGON". The Hygon Dhyana CPU supports both legacy and extension PMC MSRs(perf counter registers and event selection registers), so add Hygon Dhyana support in the similar way as AMD does. Signed-off-by: Pu Wen Reviewed-by: Borislav Petkov --- arch/x86/events/amd/core.c | 4 ++++ arch/x86/events/amd/uncore.c | 20 +++++++++++++------- arch/x86/events/core.c | 4 ++++ arch/x86/kernel/cpu/perfctr-watchdog.c | 2 ++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index c84584b..7d2d7c8 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -669,6 +669,10 @@ static int __init amd_core_pmu_init(void) * We fallback to using default amd_get_event_constraints. */ break; + case 0x18: + pr_cont("Fam18h "); + /* Using default amd_get_event_constraints. */ + break; default: pr_err("core perfctr but no constraints; unknown hardware!\n"); return -ENODEV; diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index 981ba5e..c7d745b 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -507,17 +507,19 @@ static int __init amd_uncore_init(void) { int ret = -ENODEV; - if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) + if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD && + boot_cpu_data.x86_vendor != X86_VENDOR_HYGON) return -ENODEV; if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) return -ENODEV; - if (boot_cpu_data.x86 == 0x17) { + if (boot_cpu_data.x86 == 0x17 || boot_cpu_data.x86 == 0x18) { /* - * For F17h, the Northbridge counters are repurposed as Data - * Fabric counters. Also, L3 counters are supported too. The PMUs - * are exported based on family as either L2 or L3 and NB or DF. + * For F17h or F18h, the Northbridge counters are + * repurposed as Data Fabric counters. Also, L3 + * counters are supported too. The PMUs are exported + * based on family as either L2 or L3 and NB or DF. */ num_counters_nb = NUM_COUNTERS_NB; num_counters_llc = NUM_COUNTERS_L3; @@ -547,7 +549,9 @@ static int __init amd_uncore_init(void) if (ret) goto fail_nb; - pr_info("AMD NB counters detected\n"); + pr_info("%s NB counters detected\n", + boot_cpu_data.x86_vendor == X86_VENDOR_HYGON ? + "HYGON" : "AMD"); ret = 0; } @@ -561,7 +565,9 @@ static int __init amd_uncore_init(void) if (ret) goto fail_llc; - pr_info("AMD LLC counters detected\n"); + pr_info("%s LLC counters detected\n", + boot_cpu_data.x86_vendor == X86_VENDOR_HYGON ? + "HYGON" : "AMD"); ret = 0; } diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index dfb2f7c..9c562f5 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -1776,6 +1776,10 @@ static int __init init_hw_perf_events(void) case X86_VENDOR_AMD: err = amd_pmu_init(); break; + case X86_VENDOR_HYGON: + err = amd_pmu_init(); + x86_pmu.name = "HYGON"; + break; default: err = -ENOTSUPP; } diff --git a/arch/x86/kernel/cpu/perfctr-watchdog.c b/arch/x86/kernel/cpu/perfctr-watchdog.c index d389083..9556930 100644 --- a/arch/x86/kernel/cpu/perfctr-watchdog.c +++ b/arch/x86/kernel/cpu/perfctr-watchdog.c @@ -46,6 +46,7 @@ static inline unsigned int nmi_perfctr_msr_to_bit(unsigned int msr) { /* returns the bit offset of the performance counter register */ switch (boot_cpu_data.x86_vendor) { + case X86_VENDOR_HYGON: case X86_VENDOR_AMD: if (msr >= MSR_F15H_PERF_CTR) return (msr - MSR_F15H_PERF_CTR) >> 1; @@ -74,6 +75,7 @@ static inline unsigned int nmi_evntsel_msr_to_bit(unsigned int msr) { /* returns the bit offset of the event selection register */ switch (boot_cpu_data.x86_vendor) { + case X86_VENDOR_HYGON: case X86_VENDOR_AMD: if (msr >= MSR_F15H_PERF_CTL) return (msr - MSR_F15H_PERF_CTL) >> 1; -- 2.7.4