Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2774257imm; Mon, 10 Sep 2018 06:21:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaV0g0vyvvOx8a738IqBG8K9+XznMt09SgObFtpZthpKmKTVmB9hNTHU1HJddjBYTarsLFq X-Received: by 2002:a62:d94:: with SMTP id 20-v6mr23604783pfn.202.1536585710738; Mon, 10 Sep 2018 06:21:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536585710; cv=none; d=google.com; s=arc-20160816; b=z8NAyb4HxPTHABEPQXhOjPZXUjlO9aAot0swf25Vmao4B9u383xovHzklSXgoL34rR g489nxmCxAbrw+Ij/IrO4daKgHFtUY6mkqeWRxzxdQhmQXMCNqt0Vwz+4weyL/+KQQuj JiIpJW9iIdMInkTRe7sOKsBG7fgd1m4S59MEeiD3/pSjjiKJS53Op42ipWH1b2op7DHq dKORWVfI5FCYs+4nkmUqlMVpfvL+th+ocayAEXJ052m2eOznIXgLU8HYjUmmiroKyETT h/6ENsjl67vFGFrwSykEOw9NcMpcFcw38QqG+uPSzyBEgNZfpFVzVcDBKtTLaCT+JVqC nesQ== 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=F7DAh0xphuCxjjqV92upvYNi4JWumQHD23dsLvg7EfA=; b=UEWmB8JSK4uMZ00gW8Sqwj97Ltql7Di9VN3DaHHEyKk8wBUICQFxTGHA08q2W/AXqZ IitoHu2KyHDU6opET0R8bjn2DInMW1K0DSjWf/r11pWnXnew0LJy18XID22ZzULUibLr r0MaqlSUUYz48Mh9tOWZLErBu2RcF60nrZ1SEvEXaRvcPirOsYG/iTTT+WtZebqqbWcp VUezF9gN1zyT9BbUP8G7pyKVcGf/YGVXqbn+0WRg2VrCvreeac49Ssf22aOMkt2iD7c4 mKx8yvP56ZiiWIIZHTzmZQYaskQgTiW1/TkUZRYLvnS6C1xxnel/E78WUzgnQpg5QMOz mmQA== 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 3-v6si16911024plv.314.2018.09.10.06.21.05; Mon, 10 Sep 2018 06:21:50 -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 S1728747AbeIJSLE (ORCPT + 99 others); Mon, 10 Sep 2018 14:11:04 -0400 Received: from smtp20.cstnet.cn ([159.226.251.20]:51838 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728159AbeIJSLE (ORCPT ); Mon, 10 Sep 2018 14:11:04 -0400 Received: from pw-vbox.higon.com (unknown [182.150.46.145]) by APP-10 (Coremail) with SMTP id tACowABXX2O9bpZb5vuZCQ--.1440S2; Mon, 10 Sep 2018 21:16:49 +0800 (CST) From: Pu Wen To: tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, thomas.lendacky@amd.com, bp@alien8.de, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Pu Wen Subject: [PATCH v6 05/16] perf/x86: Add Hygon Dhyana support to PMU infrastructure Date: Mon, 10 Sep 2018 21:16:43 +0800 Message-Id: <1e7b20df2bb5ebca6d72339f8b4e1453325cef10.1536550550.git.puwen@hygon.cn> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-CM-TRANSID: tACowABXX2O9bpZb5v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.46.145] X-CM-SenderInfo: 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 support both legacy and extension PMC MSRs(perf counter registers and event selection registers), so add Hygon Dhyana support to get bit offset in the similar way as AMD does. Signed-off-by: Pu Wen --- 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