Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp130666lqp; Thu, 4 Apr 2024 08:47:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVg2OcmGTkBgH0N2SDFfnACvGemSLSDRfll3wrMZYlkGu+vUATUF4o78vHu2K+hu06G/f2CVJWP/ZskOxI7nbrvNTSA83tf7eFs9kt9Fg== X-Google-Smtp-Source: AGHT+IE9STdGfVLpujGxRnFiH3bHsQQNDNgz+EfGkApTEbuwNtZKY5BpUs3Zuz9ykxBdlBfkXKm/ X-Received: by 2002:a67:af06:0:b0:479:c35e:482b with SMTP id v6-20020a67af06000000b00479c35e482bmr2765510vsl.3.1712245628821; Thu, 04 Apr 2024 08:47:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712245628; cv=pass; d=google.com; s=arc-20160816; b=dM+Nl1I3XKnLUCZgyOvmGavI4Y4fM2ILV+ExhszglYOdW/5Rj1G2V6C22aP9GIIb/S oZFdEakzaWjbJaWUowu/GoIwnkxdaJIM5w3awHKrMcVH4ti2dsQf009ZNoZFlKVG66p2 4Ib9eGIfzAhUNFHfL2HKsdwmOLf/nRhuDmJGkplaboNKy+KsLjTvUV9/ktcCRQCuGqa9 MVrk5GgHPyHpla7kyB3102OSVac9B7qJoEAdJGhJKne9iWI3FwPXt+M09uA54swfFwcv IW5SfPfXD3uShNQ6B3xCZpZ504zhWGwxQvEw//yuwJBX1/yHyPzYWzVSjzIH67rs3g+T 18xA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=KTLjeHFVffD+SgcaRoPiZIcoPi3V6hDc6xTLQKEG5UQ=; fh=JXROtR/v77zDyJnKXsQ1uL/Od6ef5T6BdmyrNcniUwA=; b=opHhBLydm1H5P9KwuJuw/hZNW2+Sbf3aTTn5NO31EFeF/n10guJyQhlXUhDmOxIW94 yYqkQCqwVk7KIatgi3VlnXLCURPXqPYVN+iao8IQKRlvnOmarMv74YWrNyeGGI+HeQLn 3+4Hf4Xeg78rV5SRrUmgNjqj+5/WUJ6eFxmmVSa5ZEeme0l80hfUbELxLqd2FKEUhPpU CjoGaHqB1psPbMHPQeE8JisSNhiLWI7K58WVJxpuPhw4Pkqguc4GNLF3ixsb70+ewi0P Hw1UFKclCjBlXdEzOUZO7H37g2OkqQxTYKPlMKbAqUqakcl2X0EbH7wCxqAr4dodTq7v E1LA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XN+BjBK4; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131556-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v8-20020a056102302800b00478503d63aesi2025583vsa.190.2024.04.04.08.47.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 08:47:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XN+BjBK4; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131556-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131556-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9E7BC1C2713A for ; Thu, 4 Apr 2024 14:07:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6A92129E88; Thu, 4 Apr 2024 14:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XN+BjBK4" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AF7312883A for ; Thu, 4 Apr 2024 14:07:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712239660; cv=none; b=HbooRn+1sFP2AkfTO16/N6YKI5BgZajECfUqvJ3dEhJEXbOkaYl8uQRNz6nr3HUdq7k2+ft7M9D7I7G0n2yFBAuAdQ8Mn5WnUC47rpWrAGNPUhhTFb2rPlu5fc00Fd5IAzpbVwPzQVpybAk7S5U6yYOUTQLzMISkqLWOti30134= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712239660; c=relaxed/simple; bh=s4JJsoMKMgAG9ip2qjlQgIvTEYnZrRpwCUXCl6YsmN4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q+lyqNWHpv0hAgGMk/OcB9pmQUXy9BzNJaSsWiabhpzueCxawFmTtUlBqDXxVwewB8zlgzwckQkXbmBU9+TKk2qtRI1dDwooDlRLgkXXHldNJZ1GZNwCtCoG00DhhRW0tNjM3P7wLI4zbKu/KFkcPDzoI8oTi2Dv4W2RhAP/Jrs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XN+BjBK4; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712239659; x=1743775659; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s4JJsoMKMgAG9ip2qjlQgIvTEYnZrRpwCUXCl6YsmN4=; b=XN+BjBK40g4EPd8JPHe44xjiyd85rVl0Ka9W6MDlq9NoyK0tLp2LnOlU uDpsf8X4hzSn2oDuET/NFlH0PODboyatQaX4sflans+4i+92TaXMVrHf1 rnTnEhIynCXsfrr8yf5sLXu4FdXYzkj6NCsoWM+tjF3NTYuXcOk5vp1ZL DYSfMBkKihmQkY0YgA7qzg7Jm4Bgt2kiaydWFJ6+CbAGt7BVNIUwuwF4C uCUNCcn4poDuY+0KmDMV2d0mrko5wAE/T3257ceL4HiYz7Aq73MGWLvJS QQxOuLWoY9SnpRVKtjN3tsqrgzrLKsaOVkineHlRyDD9YcaFuXXZaBLb0 Q==; X-CSE-ConnectionGUID: IG4iwSUuTmGlHvDlVocG5Q== X-CSE-MsgGUID: eYv9wHQjSBC/wynkxtwtnQ== X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="11346494" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="11346494" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 07:07:38 -0700 X-CSE-ConnectionGUID: 9lnTalpfSgaohXdh+jmNKQ== X-CSE-MsgGUID: d5KL/5dhSrWJmj+cfY6SQQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="23258847" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmviesa005.fm.intel.com with ESMTP; 04 Apr 2024 07:07:38 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org Cc: ak@linux.intel.com, Kan Liang Subject: [PATCH 01/12] perf/x86/intel: Support the PEBS event mask Date: Thu, 4 Apr 2024 07:06:26 -0700 Message-Id: <20240404140637.1232635-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20240404140637.1232635-1-kan.liang@linux.intel.com> References: <20240404140637.1232635-1-kan.liang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kan Liang The current perf assumes that the counters that support PEBS are contiguous. But it's not guaranteed with the new leaf 0x23 introduced. The counters are enumerated with a counter mask. There may be holes in the counter mask for future platforms or in a virtualization environment. Store the PEBS event mask rather than the maximum number of PEBS counters in the x86 PMU structures. Reviewed-by: Andi Kleen Signed-off-by: Kan Liang --- arch/x86/events/intel/core.c | 8 ++++---- arch/x86/events/intel/ds.c | 14 +++++++------- arch/x86/events/perf_event.h | 4 ++-- arch/x86/include/asm/intel_ds.h | 6 ++++++ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 768d1414897f..c173e35a5660 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -4728,7 +4728,7 @@ static void intel_pmu_check_hybrid_pmus(struct x86_hybrid_pmu *pmu) { intel_pmu_check_num_counters(&pmu->num_counters, &pmu->num_counters_fixed, &pmu->intel_ctrl, (1ULL << pmu->num_counters_fixed) - 1); - pmu->max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, pmu->num_counters); + pmu->pebs_events_mask = intel_pmu_pebs_mask(GENMASK_ULL(pmu->num_counters - 1, 0)); pmu->unconstrained = (struct event_constraint) __EVENT_CONSTRAINT(0, (1ULL << pmu->num_counters) - 1, 0, pmu->num_counters, 0, 0); @@ -6077,7 +6077,7 @@ static __always_inline int intel_pmu_init_hybrid(enum hybrid_pmu_type pmus) pmu->num_counters = x86_pmu.num_counters; pmu->num_counters_fixed = x86_pmu.num_counters_fixed; - pmu->max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, pmu->num_counters); + pmu->pebs_events_mask = intel_pmu_pebs_mask(GENMASK_ULL(pmu->num_counters - 1, 0)); pmu->unconstrained = (struct event_constraint) __EVENT_CONSTRAINT(0, (1ULL << pmu->num_counters) - 1, 0, pmu->num_counters, 0, 0); @@ -6200,7 +6200,7 @@ __init int intel_pmu_init(void) x86_pmu.events_maskl = ebx.full; x86_pmu.events_mask_len = eax.split.mask_length; - x86_pmu.max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, x86_pmu.num_counters); + x86_pmu.pebs_events_mask = intel_pmu_pebs_mask(GENMASK_ULL(x86_pmu.num_counters - 1, 0)); x86_pmu.pebs_capable = PEBS_COUNTER_MASK; /* @@ -6829,7 +6829,7 @@ __init int intel_pmu_init(void) pmu->num_counters_fixed = x86_pmu.num_counters_fixed; } - pmu->max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, pmu->num_counters); + pmu->pebs_events_mask = intel_pmu_pebs_mask(GENMASK_ULL(pmu->num_counters - 1, 0)); pmu->unconstrained = (struct event_constraint) __EVENT_CONSTRAINT(0, (1ULL << pmu->num_counters) - 1, 0, pmu->num_counters, 0, 0); diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index 20ddfed3e721..a5d861093335 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1137,7 +1137,7 @@ void intel_pmu_pebs_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sche static inline void pebs_update_threshold(struct cpu_hw_events *cpuc) { struct debug_store *ds = cpuc->ds; - int max_pebs_events = hybrid(cpuc->pmu, max_pebs_events); + int max_pebs_events = hweight64(hybrid(cpuc->pmu, pebs_events_mask)); int num_counters_fixed = hybrid(cpuc->pmu, num_counters_fixed); u64 threshold; int reserved; @@ -2157,6 +2157,7 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d void *base, *at, *top; short counts[INTEL_PMC_IDX_FIXED + MAX_FIXED_PEBS_EVENTS] = {}; short error[INTEL_PMC_IDX_FIXED + MAX_FIXED_PEBS_EVENTS] = {}; + int max_pebs_events = hweight64(x86_pmu.pebs_events_mask); int bit, i, size; u64 mask; @@ -2168,8 +2169,8 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d ds->pebs_index = ds->pebs_buffer_base; - mask = (1ULL << x86_pmu.max_pebs_events) - 1; - size = x86_pmu.max_pebs_events; + mask = x86_pmu.pebs_events_mask; + size = max_pebs_events; if (x86_pmu.flags & PMU_FL_PEBS_ALL) { mask |= ((1ULL << x86_pmu.num_counters_fixed) - 1) << INTEL_PMC_IDX_FIXED; size = INTEL_PMC_IDX_FIXED + x86_pmu.num_counters_fixed; @@ -2208,8 +2209,8 @@ static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs, struct perf_sample_d pebs_status = p->status = cpuc->pebs_enabled; bit = find_first_bit((unsigned long *)&pebs_status, - x86_pmu.max_pebs_events); - if (bit >= x86_pmu.max_pebs_events) + max_pebs_events); + if (bit >= max_pebs_events) continue; /* @@ -2267,7 +2268,6 @@ static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_d { short counts[INTEL_PMC_IDX_FIXED + MAX_FIXED_PEBS_EVENTS] = {}; struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); - int max_pebs_events = hybrid(cpuc->pmu, max_pebs_events); int num_counters_fixed = hybrid(cpuc->pmu, num_counters_fixed); struct debug_store *ds = cpuc->ds; struct perf_event *event; @@ -2283,7 +2283,7 @@ static void intel_pmu_drain_pebs_icl(struct pt_regs *iregs, struct perf_sample_d ds->pebs_index = ds->pebs_buffer_base; - mask = ((1ULL << max_pebs_events) - 1) | + mask = hybrid(cpuc->pmu, pebs_events_mask) | (((1ULL << num_counters_fixed) - 1) << INTEL_PMC_IDX_FIXED); size = INTEL_PMC_IDX_FIXED + num_counters_fixed; diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h index fb56518356ec..047aa1c8d5c6 100644 --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -684,7 +684,7 @@ struct x86_hybrid_pmu { cpumask_t supported_cpus; union perf_capabilities intel_cap; u64 intel_ctrl; - int max_pebs_events; + u64 pebs_events_mask; int num_counters; int num_counters_fixed; struct event_constraint unconstrained; @@ -852,7 +852,7 @@ struct x86_pmu { pebs_ept :1; int pebs_record_size; int pebs_buffer_size; - int max_pebs_events; + u64 pebs_events_mask; void (*drain_pebs)(struct pt_regs *regs, struct perf_sample_data *data); struct event_constraint *pebs_constraints; void (*pebs_aliases)(struct perf_event *event); diff --git a/arch/x86/include/asm/intel_ds.h b/arch/x86/include/asm/intel_ds.h index 2f9eeb5c3069..d11f0f480ccb 100644 --- a/arch/x86/include/asm/intel_ds.h +++ b/arch/x86/include/asm/intel_ds.h @@ -9,6 +9,7 @@ /* The maximal number of PEBS events: */ #define MAX_PEBS_EVENTS_FMT4 8 #define MAX_PEBS_EVENTS 32 +#define MAX_PEBS_EVENTS_MASK GENMASK_ULL(MAX_PEBS_EVENTS - 1, 0) #define MAX_FIXED_PEBS_EVENTS 16 /* @@ -35,4 +36,9 @@ struct debug_store_buffers { char pebs_buffer[PEBS_BUFFER_SIZE]; }; +static inline u64 intel_pmu_pebs_mask(u64 cntr_mask) +{ + return MAX_PEBS_EVENTS_MASK & cntr_mask; +} + #endif -- 2.35.1