Received: by 10.223.164.221 with SMTP id h29csp2585717wrb; Thu, 2 Nov 2017 13:34:04 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TzUc+SQ9HBng7y0jFyRSBtcYltbnzTznwv12QO0d4A4exr2jZ+FDsfutqLcinpp1Frqgwa X-Received: by 10.159.253.9 with SMTP id p9mr4567762pls.323.1509654844758; Thu, 02 Nov 2017 13:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509654844; cv=none; d=google.com; s=arc-20160816; b=Jg1Iqqll2JEEUAnQXS5HY481KL4m9jJPNzR6k4guBihS+WV2epYrSJbO2Q7HqHzyWo UpBEwGsVEZqWQO7vxfscmeOwKTb8OK35x038iUtPHY8Cjo8EJTva4oP3h2zlO8Gx+Ko9 DwLKSP5KiffMrCKXUs4NIw8OGXoFhdotOpuOi/QHxzGuEeHhWhQ/Y3TjXQOJ6P8rGH+w +nsARyPYzVJHiqmGvCznyWWb9sv/6ZRZADDHz9sFJ9j/LO8LKM/W8vpHFec479E9q5kU 7gC3LTxSWnZ1n/WTn+y+BgD5EQPchbA/kArstW83niv/2LktzmWgy5U44f6UQnVh79bx hVXw== 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=WAJTuxVuL0eNpK9Fn/a37aDv0uxXXIJ9zqBEeORD6E8=; b=ZYyKa9tObeUBnxmOd+XlOqJ2Vopcal/bai1QVp5TA+WhiG3yVtarYUhdL3DXYN7dXA 9ExV5csY4l+p1zuC54QI2el5+PFyajk88PJ8jcRhBb/8EBCgxXwUc60ys4mffojBGl9p L7KQyrg5tLDWxyMtez3sxPpLzzqqFVm6gVT3etGtdovDDGAzE4fqPXhhtlC+kU63xMKs gMKjLZdDz1CsKhHnePFyIN71THzr6VD+Aqs6KbsbWWIKeqCn4s0Z7E69PBty9hKhizIM mk5fbOg+wpatsl84S3YGSWHjdWOjMd9HwFFOHKH6WFlPmXyROFqaRTcd1qSXTaJ64yED k4EA== 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 f21si4499232pgv.505.2017.11.02.13.33.51; Thu, 02 Nov 2017 13:34:04 -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 S934552AbdKBUco (ORCPT + 99 others); Thu, 2 Nov 2017 16:32:44 -0400 Received: from mga11.intel.com ([192.55.52.93]:31294 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964794AbdKBUaY (ORCPT ); Thu, 2 Nov 2017 16:30:24 -0400 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Nov 2017 13:30:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,335,1505804400"; d="scan'208";a="145287044" Received: from otc-lr-04.jf.intel.com ([10.54.39.138]) by orsmga004.jf.intel.com with ESMTP; 02 Nov 2017 13:30:22 -0700 From: kan.liang@intel.com To: tglx@linutronix.de, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org Cc: acme@kernel.org, eranian@google.com, ak@linux.intel.com, Kan Liang Subject: [PATCH V4 4/8] perf/x86/intel/uncore: add new data structures for free running counters Date: Thu, 2 Nov 2017 13:29:49 -0700 Message-Id: <1509654593-4446-4-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509654593-4446-1-git-send-email-kan.liang@intel.com> References: <1509654593-4446-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang There are a number of free running counters introduced for uncore, which provide highly valuable information to a wide array of customers. For example, Skylake Server has IIO free running counters to collect Input/Output x BW/Utilization. The precious generic counters could be saved to collect other customer interested data. The free running counter is read-only and always active. Current generic uncore code does not support this kind of counters. Introduce a new index to indicate the free running counters. Only one index is enough for all free running counters. Because the free running countes are always active, and the event and free running counter are always 1:1 mapped. It does not need extra index to indicate the assigned counter. Introduce some rules to encode the event for free running counters. - The event for free running counter has the same event code 0xff as the event for fixed counter. - The umask of the event starts from 0x10. The umask which is less than 0x10 is reserved for the event of fixed counter. - The free running counters can be divided into different types according to the MSR location, bit width or definition. The start point of the umask for different type has 0x10 offset. For example, there are three types of IIO free running counters on Skylake server, IO CLOCKS counters, BANDWIDTH counters and UTILIZATION counters. The event code for all free running counters is 0xff. 'ioclk' is the first counter of IO CLOCKS. IO CLOCKS is the first type of free running counters, which umask starts from 0x10. So 'ioclk' is encoded as event=0xff,umask=0x10 'bw_in_port2' is the third counter of BANDWIDTH counters. BANDWIDTH is the second type which umask starts from 0x20. So 'bw_in_port2' is encoded as event=0xff,umask=0x22. Introduce a new data structure to store free running counters related information for each type. It includes the number of counters, bit width, base address, offset between counters and offset between boxes. Introduce several inline helpers to check index for fixed counter and free running counter, validate free running counter event, and retrieve the free running counter information according to box and event. Signed-off-by: Kan Liang --- Changes since V3: - Split the patch to add the new data structures and struct members along with the inline helpers. arch/x86/events/intel/uncore.h | 118 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 1 deletion(-) diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index df5989f..a508bc5 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -11,8 +11,13 @@ #define UNCORE_FIXED_EVENT 0xff #define UNCORE_PMC_IDX_MAX_GENERIC 8 +#define UNCORE_PMC_IDX_MAX_FIXED 1 +#define UNCORE_PMC_IDX_MAX_FREERUNNING 1 #define UNCORE_PMC_IDX_FIXED UNCORE_PMC_IDX_MAX_GENERIC -#define UNCORE_PMC_IDX_MAX (UNCORE_PMC_IDX_FIXED + 1) +#define UNCORE_PMC_IDX_FREERUNNING (UNCORE_PMC_IDX_FIXED + \ + UNCORE_PMC_IDX_MAX_FIXED) +#define UNCORE_PMC_IDX_MAX (UNCORE_PMC_IDX_FREERUNNING + \ + UNCORE_PMC_IDX_MAX_FREERUNNING) #define UNCORE_PCI_DEV_FULL_DATA(dev, func, type, idx) \ ((dev << 24) | (func << 16) | (type << 8) | idx) @@ -34,6 +39,7 @@ struct intel_uncore_ops; struct intel_uncore_pmu; struct intel_uncore_box; struct uncore_event_desc; +struct freerunning_counters; struct intel_uncore_type { const char *name; @@ -41,6 +47,7 @@ struct intel_uncore_type { int num_boxes; int perf_ctr_bits; int fixed_ctr_bits; + int num_freerunning_types; unsigned perf_ctr; unsigned event_ctl; unsigned event_mask; @@ -58,6 +65,7 @@ struct intel_uncore_type { struct intel_uncore_pmu *pmus; struct intel_uncore_ops *ops; struct uncore_event_desc *event_descs; + struct freerunning_counters *freerunning; const struct attribute_group *attr_groups[4]; struct pmu *pmu; /* for custom pmu ops */ }; @@ -128,6 +136,14 @@ struct uncore_event_desc { const char *config; }; +struct freerunning_counters { + unsigned int counter_base; + unsigned int counter_offset; + unsigned int box_offset; + unsigned int num_counters; + unsigned int bits; +}; + struct pci2phy_map { struct list_head list; int segment; @@ -156,6 +172,16 @@ static ssize_t __uncore_##_var##_show(struct kobject *kobj, \ static struct kobj_attribute format_attr_##_var = \ __ATTR(_name, 0444, __uncore_##_var##_show, NULL) +static inline bool uncore_pmc_fixed(int idx) +{ + return idx == UNCORE_PMC_IDX_FIXED; +} + +static inline bool uncore_pmc_freerunning(int idx) +{ + return idx == UNCORE_PMC_IDX_FREERUNNING; +} + static inline unsigned uncore_pci_box_ctl(struct intel_uncore_box *box) { return box->pmu->type->box_ctl; @@ -213,6 +239,55 @@ static inline unsigned uncore_msr_fixed_ctr(struct intel_uncore_box *box) return box->pmu->type->fixed_ctr + uncore_msr_box_offset(box); } + +/* + * Free running counter is similar as fixed counter, except it is read-only + * and always active when the uncore box is powered up. + * + * Here are the rules which are used to encode the event for free running + * counter. + * - The event for free running counter has the same event code 0xff as + * the event for fixed counter. + * - The umask of the event starts from 0x10. The umask which is less + * than 0x10 is reserved for the event of fixed counter. + * - The free running counters can be divided into different types according + * to the MSR location, bit width or definition. The start point of the + * umask for different type has 0x10 offset. + * + * For example, there are three types of IIO free running counters on Skylake + * server, IO CLOCKS counters, BANDWIDTH counters and UTILIZATION counters. + * The event code for all the free running counters is 0xff. + * 'ioclk' is the first counter of IO CLOCKS. IO CLOCKS is the first type, + * which umask starts from 0x10. + * So 'ioclk' is encoded as event=0xff,umask=0x10 + * 'bw_in_port2' is the third counter of BANDWIDTH counters. BANDWIDTH is + * the second type, which umask starts from 0x20. + * So 'bw_in_port2' is encoded as event=0xff,umask=0x22 + */ +static inline unsigned int uncore_freerunning_idx(u64 config) +{ + return ((config >> 8) & 0xf); +} + +#define UNCORE_FREERUNNING_UMASK_START 0x10 +static inline unsigned int uncore_freerunning_type(u64 config) +{ + return ((((config >> 8) - UNCORE_FREERUNNING_UMASK_START) >> 4) & 0xf); +} + +static inline +unsigned int uncore_freerunning_counter(struct intel_uncore_box *box, + struct perf_event *event) +{ + unsigned int type = uncore_freerunning_type(event->attr.config); + unsigned int idx = uncore_freerunning_idx(event->attr.config); + struct intel_uncore_pmu *pmu = box->pmu; + + return pmu->type->freerunning[type].counter_base + + pmu->type->freerunning[type].counter_offset * idx + + pmu->type->freerunning[type].box_offset * pmu->pmu_idx; +} + static inline unsigned uncore_msr_event_ctl(struct intel_uncore_box *box, int idx) { @@ -275,11 +350,52 @@ static inline int uncore_fixed_ctr_bits(struct intel_uncore_box *box) return box->pmu->type->fixed_ctr_bits; } +static inline +unsigned int uncore_freerunning_bits(struct intel_uncore_box *box, + struct perf_event *event) +{ + unsigned int type = uncore_freerunning_type(event->attr.config); + + return box->pmu->type->freerunning[type].bits; +} + +static inline int uncore_num_freerunning(struct intel_uncore_box *box, + struct perf_event *event) +{ + unsigned int type = uncore_freerunning_type(event->attr.config); + + return box->pmu->type->freerunning[type].num_counters; +} + +static inline int uncore_num_freerunning_types(struct intel_uncore_box *box, + struct perf_event *event) +{ + return box->pmu->type->num_freerunning_types; +} + +static inline bool check_valid_freerunning_event(struct intel_uncore_box *box, + struct perf_event *event) +{ + unsigned int type = uncore_freerunning_type(event->attr.config); + unsigned int idx = uncore_freerunning_idx(event->attr.config); + + return (type < uncore_num_freerunning_types(box, event)) && + (idx < uncore_num_freerunning(box, event)); +} + static inline int uncore_num_counters(struct intel_uncore_box *box) { return box->pmu->type->num_counters; } +static inline bool is_freerunning_event(struct perf_event *event) +{ + u64 cfg = event->attr.config; + + return ((cfg & UNCORE_FIXED_EVENT) == UNCORE_FIXED_EVENT) && + (((cfg >> 8) & 0xff) >= UNCORE_FREERUNNING_UMASK_START); +} + static inline void uncore_disable_box(struct intel_uncore_box *box) { if (box->pmu->type->ops->disable_box) -- 2.7.4 From 1583026180422018994@xxx Fri Nov 03 06:43:30 +0000 2017 X-GM-THRID: 1583026180422018994 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread