From patchwork Wed Oct 4 18:40:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liang, Kan" X-Patchwork-Id: 148455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp333178vqb; Wed, 4 Oct 2023 11:41:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkxyV65U1eIReBbYwEZcLQfndfLavlp6KSyppTqHD8EQq6QoxTSyZIojGdMUUi6SQ6Voo5 X-Received: by 2002:a17:90b:1e07:b0:268:535f:7c15 with SMTP id pg7-20020a17090b1e0700b00268535f7c15mr701389pjb.0.1696444896406; Wed, 04 Oct 2023 11:41:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696444896; cv=none; d=google.com; s=arc-20160816; b=PHxDhT9Ls2Q4VD6MsB3M04699qqv1ZgkysYH0Z6cusUq+8eWz4slu0TumedJtZcd6i zbPz4Uh3pqwrFnDXxQJqPQnF/1Hj+2jqH94+d1rGNtH1W1wvUeGRvF38wnkf+S3JpfVG mrzfFjcownlWmYOqqCoAi41nV+eLk29oywiUx5fM4NBZJeKga7nQlxgtJUHCtYr8NE6d ZDOIhqhex8WbPjuHYk1if7p4zBSkBZrSGU/6wcfn1jlu8cSE6d1QVgQM5W9CLL0qcHc3 Qf6TIevZI1B2GvDMNutaCm8gLHt+Q3GecDxWBFcZSa6CdLUVCKVOsOP7EagMfuZcpWFe xIFw== 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 Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id pj11-20020a17090b4f4b00b002791b62066csi2216244pjb.38.2023.10.04.11.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 11:41:36 -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 2E7F88047645; Wed, 4 Oct 2023 11:41:03 -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 S244471AbjJDSkx (ORCPT + 19 others); Wed, 4 Oct 2023 14:40:53 -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 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:41:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778851403638988146 X-GMAIL-MSGID: 1778851403638988146 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 */