Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp514006imm; Wed, 29 Aug 2018 05:46:24 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaQ9T8pJoIEJsTLRkSoybZ/hmF22ZaCCooOCK2PFcpzuULwc6ogXZpUBZVG0oWAwUNPzVDy X-Received: by 2002:a62:8704:: with SMTP id i4-v6mr5816385pfe.62.1535546784553; Wed, 29 Aug 2018 05:46:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535546784; cv=none; d=google.com; s=arc-20160816; b=WoaQ+aZMiM73WFGTj+rKg5l/+9zF+rOSsBZT9uX2E3zVlTf3AaE/xp1RWwrAFh6URH aQwASjqR027ah0NyTaskTPtGX6FigyrQi7v3ZtEbPiwgGu6ozpzlj/psuu3GKQuDdyHn H1fCMder6kr5yhmB4MJhceSNj7UXHVTnfMBGLINKOa27rn4RD+RvCoaZhc/P3id29fjn EjMKBeCJ7aMZMHfl8TDsklIPR1KZFGVfPCRVC3VxTU45WqMVxiaWMm0y6Ep06tVyGcp1 K+rThCjBeFmVMAN0wa1An0dwQM8Jy04HUI3eBprdirgJgAf0NpYwHAzgk3OTHmcaorQA 9CuA== 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:arc-authentication-results; bh=1nsDwQ1s5Bpz4h8S616AEby/1Hrta4qC1KTtQMyuE1Q=; b=aPk0YgUJEID1fPR9drCVu2jQVnNgfkAUbODs37rvb49XtemNAq3wYf05hd2cD4hVqs lOaRebpEB7FU/Ea+MieoxCnB/pmum2e+iLQPVeoGVwr3t/YVfgaW1ijZzuDIBAh3Ugsk 2n4wtnB0bIrndBlklDrKdv18c5uYi0xl/dKytHzcjG1u7UQ1Zvt7RcNe8XeqxBQdL9Om JH3O3+0JAlwy4ETMM6lzjdwQ+tAO9vEn07ech2kz5g5ZPRBQmmZFFND7DazIMdqah4ce MX7JXvwTyQdPBjKfH40T+q1ArdDHpkCt759bLJHSxVIQ0W3mSz0BYMIpopkkINDeWFTs w5bA== 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 o20-v6si3751109pgk.120.2018.08.29.05.46.09; Wed, 29 Aug 2018 05:46:24 -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 S1728582AbeH2Qk5 (ORCPT + 99 others); Wed, 29 Aug 2018 12:40:57 -0400 Received: from smtp17.cstnet.cn ([159.226.251.17]:48127 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727590AbeH2Qk5 (ORCPT ); Wed, 29 Aug 2018 12:40:57 -0400 Received: from pw-vbox.higon.com (unknown [182.150.46.145]) by APP-09 (Coremail) with SMTP id swCowAAXHpILlYZbBov_BA--.10S2; Wed, 29 Aug 2018 20:44:00 +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 v5 05/16] x86/pmu: enable Hygon support to PMU infrastructure Date: Wed, 29 Aug 2018 20:43:54 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-CM-TRANSID: swCowAAXHpILlYZbBov_BA--.10S2 X-Coremail-Antispam: 1UD129KBjvJXoWxWr48XFy5GF18Jr45GFyxGrg_yoWrGryxpr ZrArs5tr97uasrX3s8trWkXrWUZFykKayFgw45K34xAF15Z3s8Xr4Ikw1rtay5Wr95CFyr tw18uw48X3ykAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvF14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1I6r4UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26r1j6r4UM28EF7xvwVC2z280aVCY1x0267AKxVW8JV W8Jr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE14v26r4UJVWxJr1lOx8S6xCaFVCjc4AY6r 1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02 628vn2kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_ GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVW8JVW3JwCI42IY6I8E87Iv67AK xVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvj fUo9NVDUUUU X-Originating-IP: [182.150.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 Hygon PMU arch is similar to AMD Family 17h. To support Hygon PMU, the initialization flow for it just call amd_pmu_init() and change PMU name to "HYGON". To share AMD's flow, add code check for Hygon family ID 18h to run the code path of AMD family 17h in core/uncore functions. Also it returns the bit offset of the performance counter register and event selection register for Hygon CPU in the similar way as AMD does. Signed-off-by: Pu Wen --- arch/x86/events/amd/core.c | 6 ++++++ arch/x86/events/amd/uncore.c | 15 ++++++++++----- arch/x86/events/core.c | 4 ++++ arch/x86/kernel/cpu/perfctr-watchdog.c | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index c84584b..6c13c9d 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -669,6 +669,12 @@ static int __init amd_core_pmu_init(void) * We fallback to using default amd_get_event_constraints. */ break; + case 0x18: + if (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON) { + 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..9f2eb43 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -507,17 +507,22 @@ 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_vendor == X86_VENDOR_AMD && + boot_cpu_data.x86 == 0x17) || + (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON && + 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 AMD F17h or Hygon F18h, the Northbridge counters are + * repurposed as DataFabric 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; diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 5f4829f..93e026b 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