Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4201415pxb; Mon, 8 Feb 2021 10:14:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHmY8Px3nIWdkbuonkFHOzrJk0KgP/gy2ucL32TCDnSnA7xRXXoNHnh3vZ8BrsVmnghVxW X-Received: by 2002:a17:906:3781:: with SMTP id n1mr17935306ejc.296.1612808071236; Mon, 08 Feb 2021 10:14:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612808071; cv=none; d=google.com; s=arc-20160816; b=AfFH93apxS+s1AhSTdxHsoDTdxeEk6NpuREVSWHp69kFl0Xq5QPqbDwIofN8UAkHKG T9rbxLhkt8Z0ibmYd8FqjnHO45yG/R8teqhgawge/6TO/84C0tXyZPLVckKgeDtzTU+i 8G0f3Kad9e18EZKFf+jjTh8OFXNsG86Cv9oFGsfys8O+03mzTrbyLSM/dhGK9+z838Sm +T3dn2r6rnbWNFbGecW4qG2xZ6l08LProH2NnSwm5FiRT2dJns3Ltf7ae+yWegzX61QS a2JpgEWndOPwng6Dd1Mm4931JP22eT4P0E2+BqvcRJH5hSRS7EXI3QOw1gAPMFUbDJc7 qS0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=J2fd/HPRENI6qCBp9J4urnhWYrhi8EIsNSJwWKjm1+w=; b=PgsE/Z4AwU7vd0i1c2CmrgPTTYppkTiGC1hRVFoNal1BPT/hakSdE66rFWXpHZwoEN mtBq7IVp9ApCwF/CpnHe7iIXL1qHhErAQ9zMmzjluVTYdFb3qq1JdGRKd481SJCAOJ8/ 2X8cRSicLJnhrWkUSxlH4fhFxl6MTtVMa+qj/d3RTK2BVbWemZeplcnlBOzAl4jWoJd/ GPcDxfXXyYKOUSx+5oJoaMNYTbMa5jBTZfs0JCAOfo/nJ7E7BDFzzoc9ydHT2A+YZg4B 6GNBO7nRnshd3LoeiKzVmdu5n2ZLPS7x100N7n1pHAAtYdvgl7JSLhRhXfETOt0Id4t1 4TNA== 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rl11si13348765ejb.688.2021.02.08.10.14.08; Mon, 08 Feb 2021 10:14:31 -0800 (PST) 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235539AbhBHSNG (ORCPT + 99 others); Mon, 8 Feb 2021 13:13:06 -0500 Received: from mga14.intel.com ([192.55.52.115]:62781 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233572AbhBHPkx (ORCPT ); Mon, 8 Feb 2021 10:40:53 -0500 IronPort-SDR: YQdt5ZAOvCfUPeG3ObF/tLmhfwEd+jmAxBpA5kBRU4DeJDPGhkYd9I1ekFDXtErkhFWa2a08fU kco8zRKflcDQ== X-IronPort-AV: E=McAfee;i="6000,8403,9889"; a="180951974" X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="180951974" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2021 07:30:20 -0800 IronPort-SDR: TiXbb33aLK5PelU3+K/kwDwyawGwZZpuFzv7jOPViWj6KjJH5cKzpC6P74w9cSr4/jPviq65mI 59U4n/anXn+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,162,1610438400"; d="scan'208";a="358820703" Received: from otc-lr-04.jf.intel.com ([10.54.39.41]) by orsmga003.jf.intel.com with ESMTP; 08 Feb 2021 07:30:20 -0800 From: kan.liang@linux.intel.com To: peterz@infradead.org, acme@kernel.org, mingo@kernel.org, linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, bp@alien8.de, namhyung@kernel.org, jolsa@redhat.com, ak@linux.intel.com, yao.jin@linux.intel.com, alexander.shishkin@linux.intel.com, adrian.hunter@intel.com, Kan Liang Subject: [PATCH 18/49] perf/x86/intel: Add attr_update for Hybrid PMUs Date: Mon, 8 Feb 2021 07:25:15 -0800 Message-Id: <1612797946-18784-19-git-send-email-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612797946-18784-1-git-send-email-kan.liang@linux.intel.com> References: <1612797946-18784-1-git-send-email-kan.liang@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang 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. Reviewed-by: Andi Kleen Signed-off-by: Kan Liang --- 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 d2de342..ea2541b 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5254,6 +5254,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; __init int intel_pmu_init(void) @@ -5884,14 +5984,22 @@ __init int intel_pmu_init(void) snprintf(pmu_name_str, sizeof(pmu_name_str), "%s", name); + if (!IS_X86_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, -- 2.7.4