Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp829582ybk; Fri, 15 May 2020 15:00:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuR34TF5ZhOBPy23H3xaSDStB/KawxuEWHQrPryiKteMpalkieav5XziSgfL3ip7CpClDy X-Received: by 2002:a17:906:b2c6:: with SMTP id cf6mr3710546ejb.210.1589580006264; Fri, 15 May 2020 15:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589580006; cv=none; d=google.com; s=arc-20160816; b=KeIf+LRfUNB7a2tfC3aN1pw0tHjRNrJB63HFMBlfQZ9TfOS3YTULE7DLB6f19Qo3xD MTkC5pZ1KTP+ii//mHtbQDfRNEcUxTmKUKZyAe5HtA4Ugdggh0it96uRjTBVCwAVvtJk QbaSOGZX6KyfllT1qVxC/Fom+xl74kP0vpJEJy8VmWy8EJK76PhAVGcODN3ov5nhniSU jIU6OiTaAXo+NV8QEjTbPN5Ik9eSYeJgOMxtXa330a1KEDpMULcW06mC2Ea80Fya3Coj 2ou+/ExrfgbjUXZnHZHNNIqszyAC5WK++9GcFD8aUOF8hPItexAM3pMJ0juacV7K7EMF eX/g== 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=GTVuWwS2hblHClQm8gIFz7ihw1x99scmM3jSEY3TZaU=; b=F2DuFpA3TscGSKBdsoBRG1sop/n/WDWXYAzMEot2u7bp7sEZMnCw1hnNTBAOlNG0wP KSadry05fSwShQVUZxo8wRr4/xDtdDQIlUqPc9f9szvBMCBaUnZleZd3EH0IhsK493me ORsJk8dL+V7bsBzGR7gXVQEs1oObCGt69OZ00lt+WD9W+5b8rsN+ER3tEgBNMSed/hJN XYUFVPIfaIOY983XkcTUkQszSH70CR8dLLiGOgQzC1ER0NSB2s4LzD49Jyu5qAS36QPI 5z1yf0lVvW9AH2cTxAtNmDLxedQq5zRmGKd8+sY6GvijVzeG5oBBJ7+ly/Pyf75OxQIg 4bag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="ScF/vljj"; 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 h63si1697128edd.451.2020.05.15.14.59.43; Fri, 15 May 2020 15:00:06 -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="ScF/vljj"; 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 S1727847AbgEOV6I (ORCPT + 99 others); Fri, 15 May 2020 17:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726261AbgEOV6H (ORCPT ); Fri, 15 May 2020 17:58:07 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F617C061A0C for ; Fri, 15 May 2020 14:58:07 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id y7so4250193ybj.15 for ; Fri, 15 May 2020 14:58:07 -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=GTVuWwS2hblHClQm8gIFz7ihw1x99scmM3jSEY3TZaU=; b=ScF/vljjjOsoUAb5eKQehk5LdUROhB34RIBR84M41ZsXhMv0d/atJP7umjBss/Egu/ w7fiy1x6T9JcSbJP6FXR64pddeDbHFmDgqqeTJWQ/4N458sqSXARPxOqGl5GTyIHyhW5 ylHimsKfLfytO/ZIV4TvYSPBSCFCGUJoDLPOdbtRS3CBBNFyvuRhgLB7NFRXfxEIoH/v jABZSzkqgWzY1Pb/HpGNMu3g/QXoPYFsNlepvBSj3jjR1MnnY6jZCw3KlY5FMdgGbn3Z vohIko2feeuCPsmRq+nsMZk/8r5P+DXa2y9DHdea89nVgbzkxGBaaYCeY8szGRGOOYI9 /PrQ== 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=GTVuWwS2hblHClQm8gIFz7ihw1x99scmM3jSEY3TZaU=; b=QEqTbJmFzCtzWGeIz0rpq8O4nsb7g8Z/fjcqBWtEMyDhWXJ+XR7h7CLd+7MsWB+po5 Ik8I9k3CxuKUaPLsDeG+C5X57wp+LYUSUO6X0QXDL6AmJu9gLOUs6cZ4VGG7m+wPFzQE kX217bi+QOCIi0+d7GohP5rCi6OkKH5pjxbpduFLoN3fhvjCWigcDDxTrKz1iCbzTejM YRNWWFJKyqCO0Wi3VlN3IsWQK0z3wxhK9QFOpBstUwIHYkaoLqMYG0TK+XlNfNsEbCzB Kybf/nOPM7UP0YKmfcyr+joiBOePmsUmKmNLUszAC/LbcNdN2eIdG/itFigDGeM2wAhc OMKg== X-Gm-Message-State: AOAM531x01VJN/EQgrh+n6oGKF7WT+EgbM3LPdYCLrqn5748QQW/QmZ8 p12cb9pghaFDIoCEX38CjJ5guTdAOJIybWUIM1uPw2RPEFil9uXwQgc9GtGp1ldXsnt9QmPoUaS VpXELf2mrg+PFmYssSBf1iOpLk9Tm0GS7L01C8UHTXZlFBC9igzgxPZ8DFrkPCsfPF4HMMonK X-Received: by 2002:a25:a06:: with SMTP id 6mr8811658ybk.238.1589579886553; Fri, 15 May 2020 14:58:06 -0700 (PDT) Date: Fri, 15 May 2020 14:57:33 -0700 In-Reply-To: <20200515215733.20647-1-eranian@google.com> Message-Id: <20200515215733.20647-4-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 3/3] perf/x86/rapl: add AMD Fam17h RAPL support 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 enables AMD Fam17h RAPL support for the Package level metric. The support is as per AMD Fam17h Model31h (Zen2) and model 00-ffh (Zen1) PPR. The same output is available via the energy-pkg pseudo event: $ perf stat -a -I 1000 --per-socket -e power/energy-pkg/ Signed-off-by: Stephane Eranian --- arch/x86/events/probe.c | 4 ++++ arch/x86/events/rapl.c | 17 +++++++++++++++++ arch/x86/include/asm/msr-index.h | 3 +++ 3 files changed, 24 insertions(+) diff --git a/arch/x86/events/probe.c b/arch/x86/events/probe.c index c2ede2f3b2770..b3a9df2e48dfa 100644 --- a/arch/x86/events/probe.c +++ b/arch/x86/events/probe.c @@ -26,6 +26,10 @@ perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data) grp->is_visible = not_visible; + /* avoid unpopulated entries */ + if (!msr[bit].msr) + continue; + if (msr[bit].test && !msr[bit].test(bit, data)) continue; /* Virt sucks; you cannot tell if a R/O MSR is present :/ */ diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c index e98f627a13fa8..47ff20dfde889 100644 --- a/arch/x86/events/rapl.c +++ b/arch/x86/events/rapl.c @@ -526,6 +526,15 @@ static struct perf_msr intel_rapl_msrs[] = { [PERF_RAPL_PSYS] = { MSR_PLATFORM_ENERGY_STATUS, &rapl_events_psys_group, test_msr }, }; +static struct perf_msr amd_rapl_msrs[] = { + [PERF_RAPL_PP0] = { 0, &rapl_events_cores_group, NULL}, + [PERF_RAPL_PKG] = { MSR_AMD_PKG_ENERGY_STATUS, &rapl_events_pkg_group, test_msr }, + [PERF_RAPL_RAM] = { 0, &rapl_events_ram_group, NULL}, + [PERF_RAPL_PP1] = { 0, &rapl_events_gpu_group, NULL}, + [PERF_RAPL_PSYS] = { 0, &rapl_events_psys_group, NULL}, +}; + + static int rapl_cpu_offline(unsigned int cpu) { struct rapl_pmu *pmu = cpu_to_rapl_pmu(cpu); @@ -729,6 +738,13 @@ static struct rapl_model model_skl = { .rapl_msrs = intel_rapl_msrs, }; +static struct rapl_model model_amd_fam17h = { + .events = BIT(PERF_RAPL_PKG), + .apply_quirk = false, + .msr_power_unit = MSR_AMD_RAPL_POWER_UNIT, + .rapl_msrs = amd_rapl_msrs, +}; + static const struct x86_cpu_id rapl_model_match[] __initconst = { X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE, &model_snb), X86_MATCH_INTEL_FAM6_MODEL(SANDYBRIDGE_X, &model_snbep), @@ -757,6 +773,7 @@ static const struct x86_cpu_id rapl_model_match[] __initconst = { X86_MATCH_INTEL_FAM6_MODEL(ICELAKE, &model_skl), X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE_L, &model_skl), X86_MATCH_INTEL_FAM6_MODEL(COMETLAKE, &model_skl), + X86_MATCH_VENDOR_FAM(AMD, 0x17, &model_amd_fam17h), {}, }; MODULE_DEVICE_TABLE(x86cpu, rapl_model_match); diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h index 12c9684d59ba6..ef452b817f44f 100644 --- a/arch/x86/include/asm/msr-index.h +++ b/arch/x86/include/asm/msr-index.h @@ -301,6 +301,9 @@ #define MSR_PP1_ENERGY_STATUS 0x00000641 #define MSR_PP1_POLICY 0x00000642 +#define MSR_AMD_PKG_ENERGY_STATUS 0xc001029b +#define MSR_AMD_RAPL_POWER_UNIT 0xc0010299 + /* Config TDP MSRs */ #define MSR_CONFIG_TDP_NOMINAL 0x00000648 #define MSR_CONFIG_TDP_LEVEL_1 0x00000649 -- 2.26.2.761.g0e0b3e54be-goog