Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1019117pxf; Thu, 18 Mar 2021 18:12:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGR0EraWfy0mON78Yc/MkEFC+t+8cgM1tE11JeQ3aBXDGnVZeOyuNwLQ6sFWEfGPv06Lk6 X-Received: by 2002:a17:906:4a19:: with SMTP id w25mr1549557eju.180.1616116339044; Thu, 18 Mar 2021 18:12:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616116339; cv=none; d=google.com; s=arc-20160816; b=GCbA/cyfuy40oK+mNZNmdo5Qkxok207jAEMrojbzN9eAA5MrY9lpnljgnLaSUHtPL+ K78Lz/C7+M3c7JB+DAk2b2KFmcVIpTYzFSz/Vl7Gu+OPfb7k4wS96/ygNo/cQKE9TDXM 2EdI4qhiqLiIvZ65svLPUPFXdasKM+MNQ8QPVpI1cqxNT+wEWy1zCrIatueQXEQi/OvR j5wxegRGfWm/CaXLFJ2d7at/wEeJ2Zpzk8c16+w90gDDsagYvweIvQVBWRbCXjEgEt8T upjbb7NoeBE5umpk5Tm3CJJ8S0gCaCupKBHljag5vJFMdjD4RjXhwQ07IpTpH/Z4FsdE dBfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=0X4AR0FUqslo6/bd0K7Ngd+/gfgIYgdxYKc2e/VmGsw=; b=M31GNRKTpF/M9xI9R6xcTKdDljRY+4/1n7c8WCDlhMOhCAvJZClACROuT2RBUEBlLV KD7SRNMoFkxUz2Z2i384jPTwCJbZ7J+CSR355XmBhqQohwD8fFFb4LTG2e8J8eW5urPw ihn/VWQH0LYW6UKJ0HhF4wNdb5agRBDbh/NlIdxDgGSZuZGBn67N6KWp5Tm9pBQuwdtA i2fbIDWHl6ZP4WmAbFGVJFoQ6xIbkNQz/MZWd+dgf5Hy+MRJFprIZJiPd6jKhT1SrL9a RrR1QURT21LiHi7x8fjly8Rs/p61/z+hPEvMkjUcDtIwTO+z2WM2KkCOHz/2bCHn/Jbx A7Tg== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si3010619ejf.292.2021.03.18.18.11.56; Thu, 18 Mar 2021 18:12:19 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231558AbhCSBKw (ORCPT + 99 others); Thu, 18 Mar 2021 21:10:52 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:36558 "EHLO mail-lf1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230507AbhCSBKl (ORCPT ); Thu, 18 Mar 2021 21:10:41 -0400 Received: by mail-lf1-f42.google.com with SMTP id n138so7486112lfa.3 for ; Thu, 18 Mar 2021 18:10:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0X4AR0FUqslo6/bd0K7Ngd+/gfgIYgdxYKc2e/VmGsw=; b=NFBZmb0SQiLCi4UJX4pXcrchoawSC+oOcDeOEfsM6DN/Jx3Sy2DOSXmmcKzaHuIdjg 4iCMTIDl2g36O4GyC+kpCvLh8WMasMB1PjE0tDyxmOB1X69WeMIcisEX2Bku54Oxg+XK S+FBwIDCM7JH0+jXEQpqS4DPvlqTgxJG9KxSdNqGfs1rfbMiimyaOVRgghoC+JYUgzSZ JBfc3ts6eepIlM616H8AS+CHTkTf/8L0iPbXrhkpPKzpo4G37Z1IjgA87/7LymPhPuyz oyqkmLq+VAVKUNiqWsp3FzvoPWmeK8nEVOtS6NtjjRI9O+cqaKp3b66xGvU0cgWbGY0H SPKg== X-Gm-Message-State: AOAM5327T9ZgeQmUMtC9QM235JbCkslhTcocQ+K9GfvVjPOpOTvqtT+m EUhgQokkRDTg4ZyF6zEGogM5cN/nfM/+sS3EV10= X-Received: by 2002:a19:430e:: with SMTP id q14mr3954880lfa.374.1616116239896; Thu, 18 Mar 2021 18:10:39 -0700 (PDT) MIME-Version: 1.0 References: <1616003977-90612-1-git-send-email-kan.liang@linux.intel.com> <1616003977-90612-2-git-send-email-kan.liang@linux.intel.com> In-Reply-To: <1616003977-90612-2-git-send-email-kan.liang@linux.intel.com> From: Namhyung Kim Date: Fri, 19 Mar 2021 10:10:28 +0900 Message-ID: Subject: Re: [PATCH V2 1/5] perf/x86/intel/uncore: Parse uncore discovery tables To: Kan Liang Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-kernel , Alexander Shishkin , Jiri Olsa , Stephane Eranian , Andi Kleen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Kan, On Thu, Mar 18, 2021 at 3:05 AM wrote: > > From: Kan Liang > > A self-describing mechanism for the uncore PerfMon hardware has been > introduced with the latest Intel platforms. By reading through an MMIO > page worth of information, perf can 'discover' all the standard uncore > PerfMon registers in a machine. > > The discovery mechanism relies on BIOS's support. With a proper BIOS, > a PCI device with the unique capability ID 0x23 can be found on each > die. Perf can retrieve the information of all available uncore PerfMons > from the device via MMIO. The information is composed of one global > discovery table and several unit discovery tables. > - The global discovery table includes global uncore information of the > die, e.g., the address of the global control register, the offset of > the global status register, the number of uncore units, the offset of > unit discovery tables, etc. > - The unit discovery table includes generic uncore unit information, > e.g., the access type, the counter width, the address of counters, > the address of the counter control, the unit ID, the unit type, etc. > The unit is also called "box" in the code. > Perf can provide basic uncore support based on this information > with the following patches. > > To locate the PCI device with the discovery tables, check the generic > PCI ID first. If it doesn't match, go through the entire PCI device tree > and locate the device with the unique capability ID. > > The uncore information is similar among dies. To save parsing time and > space, only completely parse and store the discovery tables on the first > die and the first box of each die. The parsed information is stored in > an > RB tree structure, intel_uncore_discovery_type. The size of the stored > discovery tables varies among platforms. It's around 4KB for a Sapphire > Rapids server. > > If a BIOS doesn't support the 'discovery' mechanism, the uncore driver > will exit with -ENODEV. There is nothing changed. > > Add a module parameter to disable the discovery feature. If a BIOS gets > the discovery tables wrong, users can have an option to disable the > feature. For the current patchset, the uncore driver will exit with > -ENODEV. In the future, it may fall back to the hardcode uncore driver > on a known platform. > > Signed-off-by: Kan Liang > --- > arch/x86/events/intel/Makefile | 2 +- > arch/x86/events/intel/uncore.c | 31 ++- > arch/x86/events/intel/uncore_discovery.c | 318 +++++++++++++++++++++++++++++++ > arch/x86/events/intel/uncore_discovery.h | 105 ++++++++++ > 4 files changed, 448 insertions(+), 8 deletions(-) > create mode 100644 arch/x86/events/intel/uncore_discovery.c > create mode 100644 arch/x86/events/intel/uncore_discovery.h > > diff --git a/arch/x86/events/intel/Makefile b/arch/x86/events/intel/Makefile > index e67a588..10bde6c 100644 > --- a/arch/x86/events/intel/Makefile > +++ b/arch/x86/events/intel/Makefile > @@ -3,6 +3,6 @@ obj-$(CONFIG_CPU_SUP_INTEL) += core.o bts.o > obj-$(CONFIG_CPU_SUP_INTEL) += ds.o knc.o > obj-$(CONFIG_CPU_SUP_INTEL) += lbr.o p4.o p6.o pt.o > obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE) += intel-uncore.o > -intel-uncore-objs := uncore.o uncore_nhmex.o uncore_snb.o uncore_snbep.o > +intel-uncore-objs := uncore.o uncore_nhmex.o uncore_snb.o uncore_snbep.o uncore_discovery.o > obj-$(CONFIG_PERF_EVENTS_INTEL_CSTATE) += intel-cstate.o > intel-cstate-objs := cstate.o > diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c > index 33c8180..d111370 100644 > --- a/arch/x86/events/intel/uncore.c > +++ b/arch/x86/events/intel/uncore.c > @@ -4,7 +4,12 @@ > #include > #include > #include "uncore.h" > +#include "uncore_discovery.h" > > +static bool uncore_no_discover; > +module_param(uncore_no_discover, bool, 0); Wouldn't it be better to use a positive form like 'uncore_discover = true'? To disable, the module param can be set to 'uncore_discover = false'. > +MODULE_PARM_DESC(uncore_no_discover, "Don't enable the Intel uncore PerfMon discovery mechanism " > + "(default: enable the discovery mechanism)."); > static struct intel_uncore_type *empty_uncore[] = { NULL, }; > struct intel_uncore_type **uncore_msr_uncores = empty_uncore; > struct intel_uncore_type **uncore_pci_uncores = empty_uncore; [SNIP] > +enum uncore_access_type { > + UNCORE_ACCESS_MSR = 0, > + UNCORE_ACCESS_MMIO, > + UNCORE_ACCESS_PCI, > + > + UNCORE_ACCESS_MAX, > +}; > + > +struct uncore_global_discovery { > + union { > + u64 table1; > + struct { > + u64 type : 8, > + stride : 8, > + max_units : 10, > + __reserved_1 : 36, > + access_type : 2; > + }; > + }; > + > + u64 ctl; /* Global Control Address */ > + > + union { > + u64 table3; > + struct { > + u64 status_offset : 8, > + num_status : 16, > + __reserved_2 : 40; > + }; > + }; > +}; > + > +struct uncore_unit_discovery { > + union { > + u64 table1; > + struct { > + u64 num_regs : 8, > + ctl_offset : 8, > + bit_width : 8, > + ctr_offset : 8, > + status_offset : 8, > + __reserved_1 : 22, > + access_type : 2; > + }; > + }; > + > + u64 ctl; /* Unit Control Address */ > + > + union { > + u64 table3; > + struct { > + u64 box_type : 16, > + box_id : 16, > + __reserved_2 : 32; > + }; > + }; > +}; > + > +struct intel_uncore_discovery_type { > + struct rb_node node; > + enum uncore_access_type access_type; > + u64 box_ctrl; /* Unit ctrl addr of the first box */ > + u64 *box_ctrl_die; /* Unit ctrl addr of the first box of each die */ > + u16 type; /* Type ID of the uncore block */ > + u8 num_counters; > + u8 counter_width; > + u8 ctl_offset; /* Counter Control 0 offset */ > + u8 ctr_offset; /* Counter 0 offset */ I find it confusing and easy to miss - ctl and ctr. Some places you used ctrl or counter. Why not be consistent? :) Thanks, Namhyung > + u16 num_boxes; /* number of boxes for the uncore block */ > + unsigned int *ids; /* Box IDs */ > + unsigned int *box_offset; /* Box offset */ > +}; > + > +bool intel_uncore_has_discovery_tables(void); > +void intel_uncore_clear_discovery_tables(void); > -- > 2.7.4 >