Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2407963rdf; Mon, 6 Nov 2023 13:19:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFjqeoEFGyZDTs5mxvumjQ9LOGuLd09K32WRGprEaKTbFavaF9C5HbB7FYNO8mJExm+FJr5 X-Received: by 2002:a05:6a00:3a08:b0:6be:5367:211b with SMTP id fj8-20020a056a003a0800b006be5367211bmr26085748pfb.3.1699305573542; Mon, 06 Nov 2023 13:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699305573; cv=none; d=google.com; s=arc-20160816; b=Y67bTWV++q57byEaOWvT2WY7HekF547MGSvYxTRgfWTax4Appfv1vy6CQcF3oYGj6D JG4u8KLcKvLBTnh52kRXebURadTBbbWAG+wlJTjYcFD87ysfjIFXOBkMOqx0W6uzjL/c w+Maa8IELtxy9pCwnaw2wuJGQoctTm/OCJ6SiM21Kfkwbs+zO1j9vd6fkkhMLT75adhS v02gAfpIUqvSJ/89i963tnMr6+GZxwQWl/FE7/QjM+s/5ON4wDuCQO86PXbW67rJwU9j yZlEXx4CYUEWpsOLSGViZ2zJOIXraQw7j0K2iRjMFONjG4Xl0SrwYbpNQrP0mbTqm6aY xl3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=nP925uNBJhWtIAPiVRXGw0mM12XEjvgfz6GzxTjqsN8=; fh=fiFKj73xNHbegIoNGOcxKxuZxMbST2f9ltgluCM9UAM=; b=Zv3e0nfN7v6vDUnDUmEsbEzHKJlH6RWc4nIS5ImxKNd1vlhT7vW1T6lUtuQewFEIQJ xUPXYKeunppFfsNmdNLiuGBHoRVRSHQzgVipY0VBP6IHGcgYpwmHbr0T7JYCFPSetUA0 1VrVpdkgD9E8t0gfkhhjOM5mfL/xVWY9r7kZJYBvfaMw0QrQmOPIoCVrgrL/HDTX+T8F DUgNn29SUn41faEdBD33LEy9kEFt9tuOhHCqtnVhrrjHIu7WfLJ2PSe5kIcxPQGF9TWv Ye141qqcDpzOgn6Th6EIj2kkprAkQK3UHpKGMrXg7NOYJ4ro+ziGCU8mfCyUKhm9Vjbs sUkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nj+Ca+uQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y191-20020a638ac8000000b005bdbd8e9f5esi95502pgd.65.2023.11.06.13.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 13:19:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nj+Ca+uQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id C0C3C8031AFB; Mon, 6 Nov 2023 13:19:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233079AbjKFVTU (ORCPT + 99 others); Mon, 6 Nov 2023 16:19:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232527AbjKFVTU (ORCPT ); Mon, 6 Nov 2023 16:19:20 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31CEEAF for ; Mon, 6 Nov 2023 13:19:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699305557; x=1730841557; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=mpCWcrut8F62PbVYjjL5lHvEe1d7GJoXVDQ8V9vdBdQ=; b=nj+Ca+uQFenqHKojku1/DxxmXDzDMuAiUuXWCM2pOfsvvwLhslJGmtQu 2hwOS9SkZCed2oDDHH++z31+TD8k8NOj/S4on2VhvZ3+8Lz9+PvUSJqtk rxnQ7Ubd082dyMByfpaYdAwrt4Yk4owp/SamcrayOT2Deg8DrDiFg+TnH 6EdNHyDm3g1r1ZEG7BEmGUIOWtREECOyBjMI+MW+6ySAAlU5St7oeGrTW 4mw5GHsnFKenD1f3SBPqGEjJE2R5LH6U26n8NcOkwtoaCC0TPm/PINeG6 GXaJtK0u5bL6B9sYY21YathVf1pJmf0y/tHY0oys/hPkxxJaZ1leKjRrs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="10911431" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="10911431" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 13:19:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10886"; a="755964159" X-IronPort-AV: E=Sophos;i="6.03,282,1694761200"; d="scan'208";a="755964159" Received: from linux.intel.com ([10.54.29.200]) by orsmga007.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2023 13:19:16 -0800 Received: from [10.212.114.233] (kliang2-mobl1.ccr.corp.intel.com [10.212.114.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by linux.intel.com (Postfix) with ESMTPS id 91DF7580D4E; Mon, 6 Nov 2023 13:19:14 -0800 (PST) Message-ID: Date: Mon, 6 Nov 2023 16:19:13 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V5 2/8] perf/x86: Add PERF_X86_EVENT_NEEDS_BRANCH_STACK flag To: Arnaldo Carvalho de Melo Cc: peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org, 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 References: <20231025201626.3000228-1-kan.liang@linux.intel.com> <20231025201626.3000228-2-kan.liang@linux.intel.com> Content-Language: en-US From: "Liang, Kan" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Mon, 06 Nov 2023 13:19:30 -0800 (PST) On 2023-11-06 4:12 p.m., Arnaldo Carvalho de Melo wrote: > Em Wed, Oct 25, 2023 at 01:16:20PM -0700, kan.liang@linux.intel.com escreveu: >> 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 > > So I saw this on tip/perf/urgent, I'm picking the tools bits then. Thanks Arnaldo. Ian has already reviewed the tool parts. But I still owe a test case for the feature. I will post a patch later. https://lore.kernel.org/lkml/acbb895a-475e-4679-98fc-6b90c05a00af@linux.intel.com/ Thanks, Kan > > - Arnaldo > >> 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 >> >