Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758750AbcLAQev convert rfc822-to-8bit (ORCPT ); Thu, 1 Dec 2016 11:34:51 -0500 Received: from mga09.intel.com ([134.134.136.24]:35054 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756901AbcLAQer (ORCPT ); Thu, 1 Dec 2016 11:34:47 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,282,1477983600"; d="scan'208";a="793110775" From: "Liang, Kan" To: Andi Kleen CC: Jiri Olsa , Peter Zijlstra , "Jiri Olsa" , lkml , Ingo Molnar , Michael Petlan Subject: RE: [RFC] perf/x86/intel/uncore: pmu->type->single_fixed question Thread-Topic: [RFC] perf/x86/intel/uncore: pmu->type->single_fixed question Thread-Index: AQHSSzJ8QmQH3wRWmkOE9GJRGPB73aDzSKXg Date: Thu, 1 Dec 2016 16:34:43 +0000 Message-ID: <37D7C6CF3E00A74B8858931C1DB2F07750CA4D86@SHSMSX103.ccr.corp.intel.com> References: <20161130105105.GA25720@krava> <37D7C6CF3E00A74B8858931C1DB2F07750CA4697@SHSMSX103.ccr.corp.intel.com> <878ts0vos0.fsf@firstfloor.org> In-Reply-To: <878ts0vos0.fsf@firstfloor.org> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiODc5YjcxNGItMmIyMS00NTRmLWIyZTAtNTY0NzljYzFhYjU2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE1LjkuNi42IiwiVHJ1c3RlZExhYmVsSGFzaCI6Ikc4cDYyK2tIOGRUbVBQWFZOZlMxT2pmR0YzelZNS0crQ2pYUzN6XC81WU1NPSJ9 x-ctpclassification: CTP_IC x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5212 Lines: 167 > > "Liang, Kan" writes: > > > > Maybe we should create a clocktick box for client uncore to fix it. > > That would break all the user space code that uses the existing format. > OK. If so, I think we should remove the non-exist events for non-first boxes. What do you think about the patch as below? Andi? Jirka? ------ >From 844c12b5e6fc1e2c27b2f094c89098ea9405ea41 Mon Sep 17 00:00:00 2001 From: Kan Liang Date: Thu, 1 Dec 2016 03:29:29 -0500 Subject: [PATCH] perf/x86/intel/uncore: remove non-exist clockticks events For client cbox, only the first box can access the clockticks event. Other cboxes will not allow to open clocktick event, eventhough it's announced via /sys/../events/.. The client uncore has a standalone clocktick fixed counter. It doesn't belong to any boxes, which is different from server uncore. To make the code compatible, the client forces that only the first box can access the fixed counter. The clocktick event should be removed from other boxes. Currently, all the pmus of same type share the same attr_groups, which include all the events. no_fixed_attr_groups is introduced for other boxes, which remove the non-exist events. Signed-off-by: Kan Liang --- arch/x86/events/intel/uncore.c | 70 ++++++++++++++++++++++++++++++++---------- arch/x86/events/intel/uncore.h | 1 + 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index dbaaf7dc..6d3606e 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -739,6 +739,9 @@ static int uncore_pmu_register(struct intel_uncore_pmu *pmu) pmu->pmu.attr_groups = pmu->type->attr_groups; } + if (pmu->type->single_fixed && pmu->pmu_idx) + pmu->pmu.attr_groups = pmu->type->no_fixed_attr_groups; + if (pmu->type->num_boxes == 1) { if (strlen(pmu->type->name) > 0) sprintf(pmu->name, "uncore_%s", pmu->type->name); @@ -811,6 +814,8 @@ static void uncore_type_exit(struct intel_uncore_type *type) } kfree(type->events_group); type->events_group = NULL; + kfree(type->no_fixed_attr_groups[2]); + type->no_fixed_attr_groups[2] = NULL; } static void uncore_types_exit(struct intel_uncore_type **types) @@ -819,13 +824,45 @@ static void uncore_types_exit(struct intel_uncore_type **types) uncore_type_exit(*types); } -static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) +static struct attribute_group * +uncore_alloc_event_group(struct intel_uncore_type *type, + bool single_fixed) { - struct intel_uncore_pmu *pmus; struct attribute_group *attr_group; struct attribute **attrs; + char fixed_event_name[11]; + int i, j, index = 0; + + if (single_fixed) + snprintf(fixed_event_name, 11, "event=0x%x", UNCORE_FIXED_EVENT); + + for (i = 0; type->event_descs[i].attr.attr.name; i++) + ; + + attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) + + sizeof(*attr_group), GFP_KERNEL); + if (!attr_group) + return NULL; + + attrs = (struct attribute **)(attr_group + 1); + attr_group->name = "events"; + attr_group->attrs = attrs; + + for (j = 0; j < i; j++) { + if (single_fixed && !strncmp(type->event_descs[j].config, fixed_event_name, 10)) + continue; + + attrs[index++] = &type->event_descs[j].attr.attr; + } + + return attr_group; +} + +static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) +{ + struct intel_uncore_pmu *pmus; size_t size; - int i, j; + int i; pmus = kzalloc(sizeof(*pmus) * type->num_boxes, GFP_KERNEL); if (!pmus) @@ -848,24 +885,25 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) 0, type->num_counters, 0, 0); if (type->event_descs) { - for (i = 0; type->event_descs[i].attr.attr.name; i++); - - attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) + - sizeof(*attr_group), GFP_KERNEL); - if (!attr_group) + type->events_group = uncore_alloc_event_group(type, false); + if (!type->events_group) return -ENOMEM; + if (type->single_fixed) { + type->no_fixed_attr_groups[2] = uncore_alloc_event_group(type, true); + if (!type->no_fixed_attr_groups[2]) { + kfree(type->events_group); + return -ENOMEM; + } + } + } - attrs = (struct attribute **)(attr_group + 1); - attr_group->name = "events"; - attr_group->attrs = attrs; - - for (j = 0; j < i; j++) - attrs[j] = &type->event_descs[j].attr.attr; + type->pmu_group = &uncore_pmu_attr_group; - type->events_group = attr_group; + if (type->single_fixed) { + type->no_fixed_attr_groups[0] = type->pmu_group; + type->no_fixed_attr_groups[1] = type->format_group; } - type->pmu_group = &uncore_pmu_attr_group; return 0; } diff --git a/arch/x86/events/intel/uncore.h b/arch/x86/events/intel/uncore.h index ad986c1..23bf3ff 100644 --- a/arch/x86/events/intel/uncore.h +++ b/arch/x86/events/intel/uncore.h @@ -59,6 +59,7 @@ struct intel_uncore_type { struct intel_uncore_ops *ops; struct uncore_event_desc *event_descs; const struct attribute_group *attr_groups[4]; + const struct attribute_group *no_fixed_attr_groups[4]; struct pmu *pmu; /* for custom pmu ops */ }; -- 2.5.5