Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2819604rda; Wed, 25 Oct 2023 13:16:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQC2c8LIvRQYq9q2ffE4KMlLZQiiGYjunA+p6JgiE0CWvZ9Pxfiip+jNUDn8yc9/c7GxNX X-Received: by 2002:a0d:dfca:0:b0:5a7:d368:bf88 with SMTP id i193-20020a0ddfca000000b005a7d368bf88mr16770829ywe.2.1698265017628; Wed, 25 Oct 2023 13:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698265017; cv=none; d=google.com; s=arc-20160816; b=d7iAQ22I92tnEHzVi8K7Fwn+fJdcM4PhRw+ZFz/mrZDHGje5ga5+xM62qQB1t4K0f+ W2LvX5iglQrdUSI9rGJkMVahnOYMEfhCxMqJWDgUuxKlDaxQwLgnduo1I3L8xfs2hK2x t3WJqbvNQSNPH6viKkEM7rZYSL34vdIH5/UkqUM1v4dHU1kROEQUKgoWFkk8XnvJoil7 F63TcUiYrkgmKqyC0LajYkoeDyMVKhuTyOrQ/HmbHn8iWE94Gg2eDVN5UTCrZMxwTM5j yu3FbtWkC/swO+jsY5YtHef7ugBn9klYp+Aw+FeUESIukig+KtjlGme4hpEH0AGwvkOh xqRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Nzhh7ZzV/NsCllJ9reMiCA6rW/NprHYTgssSMFuI6vo=; fh=PWMgxgslqMjOtye8I2qVy8I5pPekyJtpFTusQltnkEg=; b=Anc7Uj6WbCayOgoMRdlLGz9sVDq1y1lydWO9thaS23pKHxtWhBj08BexrJ6qsbDXoJ KzzZlIvH+QRGJ50+vhcWhIXSA5e5WLncobqP+KfEM1I5L92GKdQxXxnN4pjK5Q6YXjhJ vfeYXjbUgs9BpYtRjbcHxhHZ9l4iz/04DmZwtzvJiIPcNP3Z+Q9wKx4HU/uTKv60vtVj TgnwU0VmnLvTlMajeKe+5TUFJRKrFTWEhxCRlRvezrXMi+7K2WUiVh5mYVX98OGd/unD uoefCMUl6gO0xRM7qa2KFe3CoXRb2kcx4nYwcUrmT/s9ALCTzOwn1JVlSN8MeXqUS2Dt iEGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jJzGeo6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id v189-20020a0dd3c6000000b0059f7fc7d457si12307193ywd.507.2023.10.25.13.16.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 13:16:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jJzGeo6K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0E0F5802989E; Wed, 25 Oct 2023 13:16:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229909AbjJYUQ0 (ORCPT + 99 others); Wed, 25 Oct 2023 16:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjJYUQZ (ORCPT ); Wed, 25 Oct 2023 16:16:25 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42D87A4 for ; Wed, 25 Oct 2023 13:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698264983; x=1729800983; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bzAVLl150qefmHRBLwjRputEvGGAeaLEmSFq7E81WUg=; b=jJzGeo6Kt6wC/vusub7/XWOCb9fUCqzBHfrcVhJEvevUwTIkXX8tp+VC 5R96gYqF9E/jIo9KED5sORJhD2gHKqfxPbuidF/bQ+wTfnSvG1iEHz7En cUVn5zjsVr6YDrL7OD23SbIUpyvvPoUKl66hwsUtzgdEiZ/bqud0grc6v Kg2nT/Fb1oq9E4eEPiU2KESYdhqG0cTp9hnRVd1OGbtnijvCo92GSlDUy ZK8EYsFnFzfC6CeH7TvyyQzwNXbzejOFUajRGq+KBVy6cVH9kGlXIKClr YMl1UiyiFr/KLzjTOYsna7Ux6GC+56Jw8mzBygygrOHVxlvzDdAstg6I0 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="377758201" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="377758201" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 13:16:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10874"; a="752459065" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="752459065" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga007.jf.intel.com with ESMTP; 25 Oct 2023 13:16:22 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, linux-kernel@vger.kernel.org Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com, alexey.v.bayduraev@linux.intel.com, tinghao.zhang@intel.com, Kan Liang Subject: [PATCH V5 2/8] perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag Date: Wed, 25 Oct 2023 13:16:20 -0700 Message-Id: <20231025201626.3000228-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231025201626.3000228-1-kan.liang@linux.intel.com> References: <20231025201626.3000228-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 25 Oct 2023 13:16:39 -0700 (PDT) From: Kan Liang Currently, branch_sample_type !=0 is used to check whether a branch stack setup is required. But it doesn't check the sample type, unnecessary branch stack setup may be done for a counting event. E.g., perf record -e "{branch-instructions,branch-misses}:S" -j any Also, the event only with the new PERF_SAMPLE_BRANCH_COUNTERS branch sample type may not require a branch stack setup either. Add a new flag NEEDS_BRANCH_STACK to indicate whether the event requires a branch stack setup. Replace the needs_branch_stack() by checking the new flag. The counting event check is implemented here. The later patch will take the new PERF_SAMPLE_BRANCH_COUNTERS into account. Signed-off-by: Kan Liang --- No changes since V4 arch/x86/events/intel/core.c | 14 +++++++++++--- arch/x86/events/perf_event_flags.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index 41a164764a84..a99449c0d77c 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -2527,9 +2527,14 @@ static void intel_pmu_assign_event(struct perf_event *event, int idx) perf_report_aux_output_id(event, idx); } +static __always_inline bool intel_pmu_needs_branch_stack(struct perf_event *event) +{ + return event->hw.flags & PERF_X86_EVENT_NEEDS_BRANCH_STACK; +} + static void intel_pmu_del_event(struct perf_event *event) { - if (needs_branch_stack(event)) + if (intel_pmu_needs_branch_stack(event)) intel_pmu_lbr_del(event); if (event->attr.precise_ip) intel_pmu_pebs_del(event); @@ -2820,7 +2825,7 @@ static void intel_pmu_add_event(struct perf_event *event) { if (event->attr.precise_ip) intel_pmu_pebs_add(event); - if (needs_branch_stack(event)) + if (intel_pmu_needs_branch_stack(event)) intel_pmu_lbr_add(event); } @@ -3897,7 +3902,10 @@ static int intel_pmu_hw_config(struct perf_event *event) x86_pmu.pebs_aliases(event); } - if (needs_branch_stack(event)) { + if (needs_branch_stack(event) && is_sampling_event(event)) + event->hw.flags |= PERF_X86_EVENT_NEEDS_BRANCH_STACK; + + if (intel_pmu_needs_branch_stack(event)) { ret = intel_pmu_setup_lbr_filter(event); if (ret) return ret; diff --git a/arch/x86/events/perf_event_flags.h b/arch/x86/events/perf_event_flags.h index 1dc19b9b4426..a1685981c520 100644 --- a/arch/x86/events/perf_event_flags.h +++ b/arch/x86/events/perf_event_flags.h @@ -20,3 +20,4 @@ PERF_ARCH(TOPDOWN, 0x04000) /* Count Topdown slots/metrics events */ PERF_ARCH(PEBS_STLAT, 0x08000) /* st+stlat data address sampling */ PERF_ARCH(AMD_BRS, 0x10000) /* AMD Branch Sampling */ PERF_ARCH(PEBS_LAT_HYBRID, 0x20000) /* ld and st lat for hybrid */ +PERF_ARCH(NEEDS_BRANCH_STACK, 0x40000) /* require branch stack setup */ -- 2.35.1