Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5157034ybl; Tue, 10 Dec 2019 01:16:00 -0800 (PST) X-Google-Smtp-Source: APXvYqxXJAnTpCeWOdZAO+xA+vKAaBXzhEHp2zANOS1jQTbnGwIdk657iEAk4pS02EKqxPeJeOcx X-Received: by 2002:a05:6808:103:: with SMTP id b3mr2906574oie.89.1575969360194; Tue, 10 Dec 2019 01:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575969360; cv=none; d=google.com; s=arc-20160816; b=Q6Nw8ELCMgni9CcgFOUNoxsmfDBhR6/2RbwoHEArXZesRni1h8ZXzC+WXQygvfF1lY 9RSursBWk5gVGZONywmLjKRxecdqTYca3jqDoy4uAKNV1DJoaAPBRaDipQ7jCug7+OOR dGRZs8yNptZmOrumVz84lPrYygQFYoGP6+2e12NYDTpk5zjtVndGBz/3l3bNiqQ6X74k /IbvuzhmycewGNOGnRiYunBFQhu6OVZdKlzjTI2VPMbKgd0bUsdZKgNrT0i7zXnF424I 6ktjLfBfLg0Y3D8TnuF0bSp8cb60GRadBvxMFjP8z0zzC/dzBN/2LyjVY+KiWSOobvY8 Aufw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tMXGDcyeDZ+AemJSEI7MbWzWkq1m6hnzMIQTGsgXHi8=; b=qCTjq/GUKiCzJrRhMMYr7mG5wuJjBjY9E8sQ5b72GeQD81p664IZOgu0Q7/hH/64IG pfrwSltSEJUM9PWcaXilQQtNHBeDhF30EAbPzurhyJsDtWROZ9/ddWD7EHhGbXbXHIyk gIY9SoeTxCHWC4zKnwy/UdxhfBiyPfl3F6g2dUZtD/nQqc45cye9r33XH+B+VKkyC6ov PlACXmcyRfjuMYZhcjdHcAONrgHm7YN+HC0tCbKq18Zst/+RdcbgwEvR5B2/UwGNF+nb OYurqZxkEq/XRdYXp3mb2K+Wn+8LlZK7s5O37pl1zVQiiJ9Mab/1/MbDckZ2H/POPSy0 zeTw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si1565676oif.255.2019.12.10.01.15.47; Tue, 10 Dec 2019 01:16:00 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727409AbfLJJPD (ORCPT + 99 others); Tue, 10 Dec 2019 04:15:03 -0500 Received: from mga12.intel.com ([192.55.52.136]:29109 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbfLJJPC (ORCPT ); Tue, 10 Dec 2019 04:15:02 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Dec 2019 01:15:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,299,1571727600"; d="scan'208";a="244777952" Received: from nntpdsd52-183.inn.intel.com ([10.125.52.183]) by fmsmga002.fm.intel.com with ESMTP; 10 Dec 2019 01:14:58 -0800 From: roman.sudarikov@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, eranian@google.com, bgregg@netflix.com, ak@linux.intel.com, kan.liang@linux.intel.com Cc: alexander.antonov@intel.com, roman.sudarikov@linux.intel.com Subject: [PATCH v2 2/3] perf x86: Add compaction function for uncore attributes Date: Tue, 10 Dec 2019 12:14:50 +0300 Message-Id: <20191210091451.6054-3-roman.sudarikov@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20191210091451.6054-1-roman.sudarikov@linux.intel.com> References: <20191210091451.6054-1-roman.sudarikov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roman Sudarikov In current design, there is an implicit assumption that array of pointers to uncore type attributes is NULL terminated. However, not all attributes are mandatory for each Uncore unit type, e.g. "events" is required for IMC but doesn't exist for CHA. That approach correctly supports only one optional attribute which also must be the last in the row. The patch removes limitation by safely removing embedded NULL elements. Co-developed-by: Alexander Antonov Signed-off-by: Alexander Antonov Signed-off-by: Roman Sudarikov --- arch/x86/events/intel/uncore.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index 24e120289018..a05352c4fc01 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -923,6 +923,22 @@ static void uncore_types_exit(struct intel_uncore_type **types) uncore_type_exit(*types); } +static void uncore_type_attrs_compaction(struct intel_uncore_type *type) +{ + int i, j; + int size = ARRAY_SIZE(type->attr_groups); + + for (i = 0, j = 0; i < size; i++) { + if (!type->attr_groups[i]) + continue; + if (i > j) { + type->attr_groups[j] = type->attr_groups[i]; + type->attr_groups[i] = NULL; + } + j++; + } +} + static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) { struct intel_uncore_pmu *pmus; @@ -980,6 +996,12 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) if (!type->get_topology(type) && !type->set_mapping(type)) type->mapping_group = &uncore_mapping_group; + /* + * For optional attributes, we can safely remove embedded NULL + * attr_groups elements. + */ + uncore_type_attrs_compaction(type); + return 0; err: -- 2.19.1