Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3232852pxb; Tue, 20 Apr 2021 03:48:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfi5fYW8VwiVPyePBDfRZcAdZQ3gLax3zwfM5vw1DGt/xCbVQQl4cuUCMumDVnP9mWFEJq X-Received: by 2002:a17:907:daa:: with SMTP id go42mr19749276ejc.120.1618915730166; Tue, 20 Apr 2021 03:48:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618915730; cv=none; d=google.com; s=arc-20160816; b=EcBQ7fa2bb1zYKXHCZAY/Wj8ZB2DX1mUfu0DFBKc+WBNXKye1q0T00JIbX/WcvIjfC DhLQn3aNT5TYzWRHiNptm9KuUGVbC4h5SafemdNkSk/fNrsKOcO5QsH3o25w9dUuYyDZ hOCJwUgZU6ndGKdUjcde+h9AANpR0V37Uapd05kbMP9h51/lEj9I2z1jaOCF7LoZzfox 9ih4vrIOCFaXoeNfnWsAmp/4DxOBRphDxtjbWQPyXPmTf05dlbSfyqHCxwJkHyIeK0FB C/koHIRfNBF9GbRtz6FLJXfXZDknuKmcJ/22ouWspXxoCeQVkjOZG6GQaNRKE2sFqjlp hGgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=KjYcKzRkK2wD9AtKmLxms+yCE01Kolf3kW+gMcr2hFc=; b=0lRO2T8K6EXyJjypUtrfwuqSEXKuMq3bVSE+B1iBwODBUdcgPrFwp0WBAJByKSxzUy mU82ypNrXnuK5SHRUYxR1SyvpEihNWvZnoiRmcaa2XYqzOqMC1jOg4cV7JXnoNo7J1zI kBxDdfbJQd2Ax+/gUHSaRy+s48P+cfbvzAjJTDOMVA+Hcp4dGLshLNTYZIUSe38SzZVp fub0LUcTDG7oPtGiBdnzFIAD+qx9Cwr6IznThGFJCMJZ85gRuawDV+NILm73EaONsUXc CSVjH2FxTjPA1AmxMFfe7ceeVyv8U3DZ9Ha9cX0Tid9x7GTI0YKrCfODu2xsNAdk4MT9 leRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=PfugoMCS; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si14436002ejm.291.2021.04.20.03.48.27; Tue, 20 Apr 2021 03:48:50 -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=@linutronix.de header.s=2020 header.b=PfugoMCS; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232032AbhDTKre (ORCPT + 99 others); Tue, 20 Apr 2021 06:47:34 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:51708 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231645AbhDTKrP (ORCPT ); Tue, 20 Apr 2021 06:47:15 -0400 Date: Tue, 20 Apr 2021 10:46:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1618915603; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjYcKzRkK2wD9AtKmLxms+yCE01Kolf3kW+gMcr2hFc=; b=PfugoMCSh0vQv/hT55e0KWSYsrF4THOAXvdAKMjnZ1oh0QPbn/XBPEOKIXpm+OJL61eM1l knY0OLJbRClrJ2JhMZjtAuE63HIVr7NNJHCRS4ADgYPC+btoi/Chvxvf0QyWl2CnPZEaWT yQPNZGa4MU10Ho8YGGolC18wsEXSwkfRDJWyy1mFvf8CM5DcUiKMmp9UADzEbWYJoIDWSY AZYwgLzWlhGWBU6ub6qUax+j/0f9rueGPRH1Z1nYxlerO7ferW45RQl5Dj/Y16JTqg1Q97 ltmGROH1uEorTV0v8H7HBT+jii0Mc1AKPY9JY+t7G8NSPP1Bwl3fcuUZSIogxQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1618915603; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KjYcKzRkK2wD9AtKmLxms+yCE01Kolf3kW+gMcr2hFc=; b=r/DZaa2jxArlTkDGmtuuAf9oBV1Bab1rUm/PgzUTlfhEfovVhcTqGfz9OdWl7dFBDLAEDf 5YEWJs5aufzVOGBw== From: "tip-bot2 for Kan Liang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/intel: Add attr_update for Hybrid PMUs Cc: Kan Liang , "Peter Zijlstra (Intel)" , Andi Kleen , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1618237865-33448-19-git-send-email-kan.liang@linux.intel.com> References: <1618237865-33448-19-git-send-email-kan.liang@linux.intel.com> MIME-Version: 1.0 Message-ID: <161891560321.29796.16996273968756721274.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 58ae30c29a370c09eb49e0007d881a9aed13c5a3 Gitweb: https://git.kernel.org/tip/58ae30c29a370c09eb49e0007d881a9aed13c5a3 Author: Kan Liang AuthorDate: Mon, 12 Apr 2021 07:30:58 -07:00 Committer: Peter Zijlstra CommitterDate: Mon, 19 Apr 2021 20:03:28 +02:00 perf/x86/intel: Add attr_update for Hybrid PMUs The attribute_group for Hybrid PMUs should be different from the previous cpu PMU. For example, cpumask is required for a Hybrid PMU. The PMU type should be included in the event and format attribute. Add hybrid_attr_update for the Hybrid PMU. Check the PMU type in is_visible() function. Only display the event or format for the matched Hybrid PMU. Signed-off-by: Kan Liang Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Andi Kleen Link: https://lkml.kernel.org/r/1618237865-33448-19-git-send-email-kan.liang@linux.intel.com --- arch/x86/events/intel/core.c | 120 ++++++++++++++++++++++++++++++++-- 1 file changed, 114 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 4881209..ba24638 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5118,6 +5118,106 @@ static const struct attribute_group *attr_update[] = { NULL, }; +static bool is_attr_for_this_pmu(struct kobject *kobj, struct attribute *attr) +{ + struct device *dev = kobj_to_dev(kobj); + struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); + struct perf_pmu_events_hybrid_attr *pmu_attr = + container_of(attr, struct perf_pmu_events_hybrid_attr, attr.attr); + + return pmu->cpu_type & pmu_attr->pmu_type; +} + +static umode_t hybrid_events_is_visible(struct kobject *kobj, + struct attribute *attr, int i) +{ + return is_attr_for_this_pmu(kobj, attr) ? attr->mode : 0; +} + +static inline int hybrid_find_supported_cpu(struct x86_hybrid_pmu *pmu) +{ + int cpu = cpumask_first(&pmu->supported_cpus); + + return (cpu >= nr_cpu_ids) ? -1 : cpu; +} + +static umode_t hybrid_tsx_is_visible(struct kobject *kobj, + struct attribute *attr, int i) +{ + struct device *dev = kobj_to_dev(kobj); + struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); + int cpu = hybrid_find_supported_cpu(pmu); + + return (cpu >= 0) && is_attr_for_this_pmu(kobj, attr) && cpu_has(&cpu_data(cpu), X86_FEATURE_RTM) ? attr->mode : 0; +} + +static umode_t hybrid_format_is_visible(struct kobject *kobj, + struct attribute *attr, int i) +{ + struct device *dev = kobj_to_dev(kobj); + struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); + struct perf_pmu_format_hybrid_attr *pmu_attr = + container_of(attr, struct perf_pmu_format_hybrid_attr, attr.attr); + int cpu = hybrid_find_supported_cpu(pmu); + + return (cpu >= 0) && (pmu->cpu_type & pmu_attr->pmu_type) ? attr->mode : 0; +} + +static struct attribute_group hybrid_group_events_td = { + .name = "events", + .is_visible = hybrid_events_is_visible, +}; + +static struct attribute_group hybrid_group_events_mem = { + .name = "events", + .is_visible = hybrid_events_is_visible, +}; + +static struct attribute_group hybrid_group_events_tsx = { + .name = "events", + .is_visible = hybrid_tsx_is_visible, +}; + +static struct attribute_group hybrid_group_format_extra = { + .name = "format", + .is_visible = hybrid_format_is_visible, +}; + +static ssize_t intel_hybrid_get_attr_cpus(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct x86_hybrid_pmu *pmu = + container_of(dev_get_drvdata(dev), struct x86_hybrid_pmu, pmu); + + return cpumap_print_to_pagebuf(true, buf, &pmu->supported_cpus); +} + +static DEVICE_ATTR(cpus, S_IRUGO, intel_hybrid_get_attr_cpus, NULL); +static struct attribute *intel_hybrid_cpus_attrs[] = { + &dev_attr_cpus.attr, + NULL, +}; + +static struct attribute_group hybrid_group_cpus = { + .attrs = intel_hybrid_cpus_attrs, +}; + +static const struct attribute_group *hybrid_attr_update[] = { + &hybrid_group_events_td, + &hybrid_group_events_mem, + &hybrid_group_events_tsx, + &group_caps_gen, + &group_caps_lbr, + &hybrid_group_format_extra, + &group_default, + &hybrid_group_cpus, + NULL, +}; + static struct attribute *empty_attrs; static void intel_pmu_check_num_counters(int *num_counters, @@ -5861,14 +5961,22 @@ __init int intel_pmu_init(void) snprintf(pmu_name_str, sizeof(pmu_name_str), "%s", name); + if (!is_hybrid()) { + group_events_td.attrs = td_attr; + group_events_mem.attrs = mem_attr; + group_events_tsx.attrs = tsx_attr; + group_format_extra.attrs = extra_attr; + group_format_extra_skl.attrs = extra_skl_attr; - group_events_td.attrs = td_attr; - group_events_mem.attrs = mem_attr; - group_events_tsx.attrs = tsx_attr; - group_format_extra.attrs = extra_attr; - group_format_extra_skl.attrs = extra_skl_attr; + x86_pmu.attr_update = attr_update; + } else { + hybrid_group_events_td.attrs = td_attr; + hybrid_group_events_mem.attrs = mem_attr; + hybrid_group_events_tsx.attrs = tsx_attr; + hybrid_group_format_extra.attrs = extra_attr; - x86_pmu.attr_update = attr_update; + x86_pmu.attr_update = hybrid_attr_update; + } intel_pmu_check_num_counters(&x86_pmu.num_counters, &x86_pmu.num_counters_fixed,