Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1151255rdh; Fri, 27 Oct 2023 06:17:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkdarXefvqJOcuoGx3bunmmpkjFEvpCo7U9pHmx+XVA/c5yM+aDVvWIIi2PQrWeiAh7sNt X-Received: by 2002:a05:6214:2466:b0:66d:20f5:23cb with SMTP id im6-20020a056214246600b0066d20f523cbmr2120923qvb.5.1698412628007; Fri, 27 Oct 2023 06:17:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698412627; cv=none; d=google.com; s=arc-20160816; b=iW/gFjTenMvqwK5B+p8EoOzwcly0Q20Au+6hHcgcQf+cmHSEhA73Nn0vkzJTRHcW7B 6K/4bbE1JIfWMcUK8VAdEXAlWq14CtBwldcLrrDJ2c9oRNfiZMV1f8RXb3XL2igcnxpi hVHvJUFZufpVnnma7388n832iaUXGdv1v5A4HxFKYZXHBRzhcdvgATU9wzJheZjByKuP bGsaZoCrmpRWG9DbOPdYpVlZ4oA/tAs6nYNHqAGu7IBn0NzraBUoQaY1bthe9ejfYAGJ Gvd7xBltrko9O7QHOAVb8HPO+o43aGVX0+TEknsOlor27n5uh6Vh9R3GTTe8dLlTC2Cu k7RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=T/39ktFhwdPeEfTfccsuAt5wKzh2w/3VDMlvZhp7o4k=; fh=hNrfQAbYh3Z2DJEENGJHk2DI4zZ1Z/35CV7+DFUZfaE=; b=p+xF/CGdzv8Xa+HLNMnNnDZeirOS0J4PFTvK7ujcUg9s8s9L8FqQBSfkA9vFm4jW4i mNiD0YtRjRPfiyJGXMznwfPZ2J89FRkam6zD6CXO4W8X0yfggfmdV9mrAvJtCVBjMYf5 Mv8TL2s6nHK/ol7goanWyc1ZYMkSbp3QG5kLFh4/KaXm128Dn04x4B4SDFYDjf8kQNq/ Aknh04LHcyIJ7KfnMmBFNnkGbuj05u3pcxY6kbJXBULK3MEhe9WI4wLlxxqzahmHL0mw AtLR5eaTguU6fvrW1oYXVt6rC4y4DDMbAbPFBtYCrcp7d8u31nFqRnhrnhpWpHlY/7tC KHCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e+2fFQOa; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id y12-20020ad445ac000000b0066d1790f92bsi769173qvu.314.2023.10.27.06.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 06:17:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=e+2fFQOa; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 42855830C33F; Fri, 27 Oct 2023 06:17:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345882AbjJ0NRA (ORCPT + 99 others); Fri, 27 Oct 2023 09:17:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231685AbjJ0NQ4 (ORCPT ); Fri, 27 Oct 2023 09:16:56 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777CBC4; Fri, 27 Oct 2023 06:16:53 -0700 (PDT) Date: Fri, 27 Oct 2023 13:16:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1698412612; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/39ktFhwdPeEfTfccsuAt5wKzh2w/3VDMlvZhp7o4k=; b=e+2fFQOaQix0c+iUlW97KH4cyBvg1/OFvLia6NwSbKs+HODWk4gIyiNMqbFHFZc+hTZBtT Q49kZpGU9+CoffM8/PkYOg11WHkU+zUfvxjZzV3yy4cMz9LwbmPTXCIK0pTMQKqqyJi0kf 65kbz0MXNvmkvl+b8et/Hlo4PyItfRAEo/lpxQJsdMCW40wydHjohcLr0MVFkJTQ4nd2JQ EVtlvBVkolcVeTxB61JHB6Rtq3wl673zixL69H2HgSrM9r7h+sd5YyQkNz6kISWFNEUHB7 RV943QkW/PZds66yLp5T+kNvn8W1Syu0xeCaU88dxkRSFkVV0n4gEr5DkLI6Yg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1698412612; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T/39ktFhwdPeEfTfccsuAt5wKzh2w/3VDMlvZhp7o4k=; b=+dlLZktxHE+zscb3ONpjYezHlYfjgwJQm5DP+/tHQAs1qhGQ4aBz0uwCtpYZkN83B5gDhm zsFgIYasXflSxFDg== From: "tip-bot2 for Kan Liang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag Cc: Kan Liang , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231025201626.3000228-2-kan.liang@linux.intel.com> References: <20231025201626.3000228-2-kan.liang@linux.intel.com> MIME-Version: 1.0 Message-ID: <169841261141.3135.2527427059573800876.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,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 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 06:17:06 -0700 (PDT) The following commit has been merged into the perf/core branch of tip: Commit-ID: 85846b27072defc7ab3dcee7ff36563a040079dc Gitweb: https://git.kernel.org/tip/85846b27072defc7ab3dcee7ff36563a040079dc Author: Kan Liang AuthorDate: Wed, 25 Oct 2023 13:16:20 -07:00 Committer: Peter Zijlstra CommitterDate: Fri, 27 Oct 2023 15:05:09 +02:00 perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag 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 Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20231025201626.3000228-2-kan.liang@linux.intel.com --- 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 41a1647..a99449c 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 1dc19b9..a168598 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 */