Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2797584rdb; Wed, 4 Oct 2023 11:41:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbuql0aa0RpeCf3uSRJL0IHVUejY/NWFaG9hSGwMRCxyIr6UVhp9r8HP7JKjcgwEq52olt X-Received: by 2002:a05:6a21:32a1:b0:13a:dd47:c31a with SMTP id yt33-20020a056a2132a100b0013add47c31amr672555pzb.20.1696444898491; Wed, 04 Oct 2023 11:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696444898; cv=none; d=google.com; s=arc-20160816; b=PuvYmF5JNg4eaWHmvpdCaBrYJeH68WWxgRAPCdX5+xlsbpAwTj17NS+gIhaqR/xvLO gKbhvFkvbTJorsYlsDyLwyGpyw7zh7e64HYiBRv+fUdEGjOYnOvnmZUgxS3kW7fbOk0/ uP8lYKe1i2ISuPGs35/dbCrLbc/63UK4qCwF03eZeRgKOwx432n+i1aH+szPCPYFLiZo 1xfUB+o5h3KU1afJ6b8HOKGLf0UtrCKYGLkcHSSZKz/hSXYBI5jcL1fn8VqURtRY7tWF vSvAvqdpeDp50fTWHoP0Z0CikgS5yyJiAr0z/WA2/kGOamUTN34X+BgkvJxZpY7TnQPx 8ahg== 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=mMcZSGLu/j2Cini1CoEPpPxC1vvQXzYd4WZZ5K1d8BM=; fh=PWMgxgslqMjOtye8I2qVy8I5pPekyJtpFTusQltnkEg=; b=I8uv5dVunmSjW5j/wdfRcZ0wiDoUR2jTFw+mQkmseezgR2S8hponOcwUJbEX7RwQ0h KRXfqTUQE0EaWmu8zj84WP6gLhnRyVIan5v+2ffhY3SX1XV1VPtHcrz2LqpR/BOxmrtG VCJLWbbt4MIjKxNYu+Ya3CO9LHe8Goq+PqqpWYjj7MOigOhRqH4Obb7EOoz3i9FBkLDO 4UbM5gU9pn0CF//Q6eoXqeHAED1quSVUYcmEfNUPqDG5tofp+JzBlSIxmKi7N9lJZnmH +XUJVkTkk21YN5rxHeRoCA18eSLJF5F7sSwKd2b0LMB+IZdXHHmozWT0jHoyBcuqBRz5 WUHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eU1D3wL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t25-20020a639559000000b005777bea0b5esi4106852pgn.901.2023.10.04.11.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 11:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eU1D3wL8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id F3FFD80A854C; Wed, 4 Oct 2023 11:40:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244470AbjJDSkw (ORCPT + 99 others); Wed, 4 Oct 2023 14:40:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233409AbjJDSks (ORCPT ); Wed, 4 Oct 2023 14:40:48 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6D7EEC for ; Wed, 4 Oct 2023 11:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696444843; x=1727980843; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jQgPOe5NH396br31I0Ovdo2DX5aYXqmioMy/hZgz9B0=; b=eU1D3wL8ur2DCFx0ESTw6V/dw8mQTumm/cLDOvo7So3O2rzdipF44e63 D98gv9IhbsnlLOmnla56wAdQuGte3JAv8VPafhBPzsSVRIZJjp/UyuoEK VWfCvyRbz65FOR2SDsi5hqaVbotqTb+F31ndNosb7OcAO6M7VKeTBKTp9 6fGeMRAfOdMy/Gp2FRdaFPgEBeFQgayF+52iKOU9pkd4oLeDPSUNbePgK jbDi7L7fl/cTVCPHVGy6c8BUGFQ2BKTiXtHfTQBUSAqUHWxvLJ/1tSI1i Eq6+6z2RcqBPF0h666cSG8a+slb6GE9neDwvXMNOUw53vnUpSZkaB8gG2 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10853"; a="469537681" X-IronPort-AV: E=Sophos;i="6.03,201,1694761200"; d="scan'208";a="469537681" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2023 11:40:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10853"; a="786625991" X-IronPort-AV: E=Sophos;i="6.03,201,1694761200"; d="scan'208";a="786625991" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by orsmga001.jf.intel.com with ESMTP; 04 Oct 2023 11:40:42 -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 V4 2/7] perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag Date: Wed, 4 Oct 2023 11:40:39 -0700 Message-Id: <20231004184044.3062788-2-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20231004184044.3062788-1-kan.liang@linux.intel.com> References: <20231004184044.3062788-1-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 11:40:58 -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 V3 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