Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp829520ybk; Fri, 15 May 2020 14:59:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxipi53ahgPA8CfaSq9EV0cYtveoq/DzTGAtlC2Kv7xI39AYdSj5G2FLlg66VFR5KwR9Xo7 X-Received: by 2002:a17:906:51b:: with SMTP id j27mr4682396eja.246.1589579997793; Fri, 15 May 2020 14:59:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589579997; cv=none; d=google.com; s=arc-20160816; b=o3x/7D7eZ1qkdxjFVwRV/cobg2wmk4Ol9kkg3j/sjPfwDGPZkLwn8YNCfO+i1TkN3f 3G2Y0piqpVJBN1I3qk5n06s6MqCLP4CfVX1U9zMWjvIjvjkcwk0ZRacMvimOEDCabQRt YZX7V6n5LRumS9eGbC113yRQv2wW+kVw/U8IJYlJBNx4QfmLCJm88073cwdeTbB9V83H V1qtFBCXgllHyxMBYGYumGEeJCWzN022fMCrTM+jfV4Oe2ScW3vMzq+0nMc6k8xAAPbU sluVzg912yGLDwGP2X/LXwJ4ycZ9oH9QVnap1txzrg8YDytrDamFeHoaG3mvovzUWkZI p7Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=Hva6k/6TTq+q0N05SG0Vffd+jU34Hf/9UQ5ci8XyaCk=; b=a3SoN0gMFjtBqHZcmdhLSwJruibN5bQB/7KhfIvNkU3RtciDuQCdg8wvR15d7DvF0A rrFRHUA+c2qrVR0y6q9KCQcR7GXzehRO/u0P93gYlUnRrvC0L30ceuqPVvWIX9yq5IiR kMM/1xqnsypOrz+6cRWkIzWu//cmYowSyZ8sIqW2Y+7Ao8uSJED4QLBFsu3QC+qAyklT LH/eRxenaaYV50cqDLrWq0xuIWlLO3d/aGnX7DS4z4NCw6UQiLmCVCf23GG5eigfjBxQ dRpUw1saWegACRsMglHSIQrENTgISN/Js3aw1DUGEYS+IjwDzBiocAyrFnkdGDd70z3J Ylyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=K3NbLYkG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z70si1957485ede.463.2020.05.15.14.59.33; Fri, 15 May 2020 14:59:57 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=K3NbLYkG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727817AbgEOV6G (ORCPT + 99 others); Fri, 15 May 2020 17:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726261AbgEOV6F (ORCPT ); Fri, 15 May 2020 17:58:05 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77156C061A0C for ; Fri, 15 May 2020 14:58:05 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id t57so4022831qte.7 for ; Fri, 15 May 2020 14:58:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Hva6k/6TTq+q0N05SG0Vffd+jU34Hf/9UQ5ci8XyaCk=; b=K3NbLYkGQqInbFDQg4wMLCm8zkpXEm1pb14TmLQBG0foOFozUS9bzBnYl9W/nK8tvm /+KcIresLOO23AOlP9y84BNnZFVZGeOp+7FxqvMaMf+nZVN1izXFANUEJbIYo8ALWc2V C2Vpn15gMocmwVDZsLw/ADh3ROXEryOsOPlBqNo3fE3fiEsCiOe719HudYeEWnb+VlWS ZCnnZlzuxJu0cw3kxoArRCxBJRP+/291YSxPRWDw85mwhdf7vgfM/ptEx85cXov+amnc vVAiVo4pqdqbIEPg13rh8KUpRTIDka5RXZ/ztuLgU6d2aUWyeK+EemCogNwq3FM18Lcv f4bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Hva6k/6TTq+q0N05SG0Vffd+jU34Hf/9UQ5ci8XyaCk=; b=d+BDgqoS+JcnT5phpkDMD7HuOpqGesjdrLoDZmrYUsrAk/SFQFYJcpsmIZEYbeNwEy howh6m2/Obb+Xk529dxVyrVrJuxZ04ReSpzOa8XIZ6ogUcvO+92Lo0sBaCTxBobfd0M4 2CdK+s1K1FgfY0nyA7q/RFFlNml8Snl8HAC1GL7Rczqm4t/9xRlmtkXI1f7MSn+iekRJ NblvaU6N1p5IHxbi/0Qnp3T/zSxOERKqrmB7Jg0E3oMiJCbliJAX00i8tHyov7eTdVa5 IuWIEvEIxEd+sA/WcbXgadc09DGI4M9tttLDOjboJHmEleUTQqbEWHP45mrByzizUNA0 p0Ew== X-Gm-Message-State: AOAM533gZk3g+mp9UGz6m03i4hFkGBvuGKZsIrakJxBEcyc4HoJiHIFb LbC1HrpVeRUe/12GllJcEhrzltMHBnK8Ez7+wnEc9lliAvP5Q8FuR7V4XxOccfXpQCSXsNs01qT tbqsKCwWEDOsr1uma2DDsrCc4ap1JLzc7YdPNiGjlG5I+ZijB7v09vE/Io/YkDrRgzQxg0Vpj X-Received: by 2002:a0c:90e7:: with SMTP id p94mr5803823qvp.219.1589579884577; Fri, 15 May 2020 14:58:04 -0700 (PDT) Date: Fri, 15 May 2020 14:57:32 -0700 In-Reply-To: <20200515215733.20647-1-eranian@google.com> Message-Id: <20200515215733.20647-3-eranian@google.com> Mime-Version: 1.0 References: <20200515215733.20647-1-eranian@google.com> X-Mailer: git-send-email 2.26.2.761.g0e0b3e54be-goog Subject: [PATCH 2/3] perf/x86/rapl: refactor code for Intel/AMD sharing From: Stephane Eranian To: linux-kernel@vger.kernel.org Cc: peterz@infradead.org, mingo@elte.hu, irogers@google.com, kim.phillips@amd.com, jolsa@redhat.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch modifies the rapl_model struct to include architecture specific knowledge to Intel specific structure, and in particular the MSR for POWER_UNIT and the rapl_msrs array. No functional changes. Signed-off-by: Stephane Eranian --- arch/x86/events/rapl.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index ece043fb7b494..e98f627a13fa8 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -131,7 +131,9 @@ struct rapl_pmus { }; struct rapl_model { + struct perf_msr *rapl_msrs; unsigned long events; + int msr_power_unit; bool apply_quirk; }; @@ -141,7 +143,7 @@ static struct rapl_pmus *rapl_pmus; static cpumask_t rapl_cpu_mask; static unsigned int rapl_cntr_mask; static u64 rapl_timer_ms; -static struct perf_msr rapl_msrs[]; +static struct perf_msr *rapl_msrs; static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu) { @@ -516,7 +518,7 @@ static bool test_msr(int idx, void *data) return test_bit(idx, (unsigned long *) data); } -static struct perf_msr rapl_msrs[] = { +static struct perf_msr intel_rapl_msrs[] = { [PERF_RAPL_PP0] = { MSR_PP0_ENERGY_STATUS, &rapl_events_cores_group, test_msr }, [PERF_RAPL_PKG] = { MSR_PKG_ENERGY_STATUS, &rapl_events_pkg_group, test_msr }, [PERF_RAPL_RAM] = { MSR_DRAM_ENERGY_STATUS, &rapl_events_ram_group, test_msr }, @@ -578,13 +580,13 @@ static int rapl_cpu_online(unsigned int cpu) return 0; } -static int rapl_check_hw_unit(bool apply_quirk) +static int rapl_check_hw_unit(struct rapl_model *rm) { u64 msr_rapl_power_unit_bits; int i; /* protect rdmsrl() to handle virtualization */ - if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &msr_rapl_power_unit_bits)) + if (rdmsrl_safe(rm->msr_power_unit, &msr_rapl_power_unit_bits)) return -1; for (i = 0; i < NR_RAPL_DOMAINS; i++) rapl_hw_unit[i] = (msr_rapl_power_unit_bits >> 8) & 0x1FULL; @@ -595,7 +597,7 @@ static int rapl_check_hw_unit(bool apply_quirk) * "Intel Xeon Processor E5-1600 and E5-2600 v3 Product Families, V2 * of 2. Datasheet, September 2014, Reference Number: 330784-001 " */ - if (apply_quirk) + if (rm->apply_quirk) rapl_hw_unit[PERF_RAPL_RAM] = 16; /* @@ -676,6 +678,8 @@ static struct rapl_model model_snb = { BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_PP1), .apply_quirk = false, + .msr_power_unit = MSR_RAPL_POWER_UNIT, + .rapl_msrs = intel_rapl_msrs, }; static struct rapl_model model_snbep = { @@ -683,6 +687,8 @@ static struct rapl_model model_snbep = { BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM), .apply_quirk = false, + .msr_power_unit = MSR_RAPL_POWER_UNIT, + .rapl_msrs = intel_rapl_msrs, }; static struct rapl_model model_hsw = { @@ -691,6 +697,8 @@ static struct rapl_model model_hsw = { BIT(PERF_RAPL_RAM) | BIT(PERF_RAPL_PP1), .apply_quirk = false, + .msr_power_unit = MSR_RAPL_POWER_UNIT, + .rapl_msrs = intel_rapl_msrs, }; static struct rapl_model model_hsx = { @@ -698,12 +706,16 @@ static struct rapl_model model_hsx = { BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM), .apply_quirk = true, + .msr_power_unit = MSR_RAPL_POWER_UNIT, + .rapl_msrs = intel_rapl_msrs, }; static struct rapl_model model_knl = { .events = BIT(PERF_RAPL_PKG) | BIT(PERF_RAPL_RAM), .apply_quirk = true, + .msr_power_unit = MSR_RAPL_POWER_UNIT, + .rapl_msrs = intel_rapl_msrs, }; static struct rapl_model model_skl = { @@ -713,6 +725,8 @@ static struct rapl_model model_skl = { BIT(PERF_RAPL_PP1) | BIT(PERF_RAPL_PSYS), .apply_quirk = false, + .msr_power_unit = MSR_RAPL_POWER_UNIT, + .rapl_msrs = intel_rapl_msrs, }; static const struct x86_cpu_id rapl_model_match[] __initconst = { @@ -758,10 +772,13 @@ static int __init rapl_pmu_init(void) return -ENODEV; rm = (struct rapl_model *) id->driver_data; + + rapl_msrs = rm->rapl_msrs; + rapl_cntr_mask = perf_msr_probe(rapl_msrs, PERF_RAPL_MAX, false, (void *) &rm->events); - ret = rapl_check_hw_unit(rm->apply_quirk); + ret = rapl_check_hw_unit(rm); if (ret) return ret; -- 2.26.2.761.g0e0b3e54be-goog