Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2924754rwb; Mon, 15 Aug 2022 14:09:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR65+dxD880gXl3gqNl8qZ+cbntLUqUwI7+k6xkHMTAa9QHLjXJOgya5nZWoHHWwnsDRM+Gj X-Received: by 2002:a17:907:2c78:b0:730:df57:1237 with SMTP id ib24-20020a1709072c7800b00730df571237mr11056027ejc.196.1660597783874; Mon, 15 Aug 2022 14:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660597783; cv=none; d=google.com; s=arc-20160816; b=FAEv4rs5bBbKqqjxDuABkGdHSEG2vmPwPB/7I/9odnD3UPZNpTyD+UJ1nE5QX2BYFq 24FRwFLxElUWGFgbB3Ug+YJqJ1FlmvR/rHTi+wJ77yTofk/qZhQFErCuetgvE9vfgV7c QuEELJvrl7YlYBLaWJZE+LcSzK+YhV/fU7wPiZCBjb7s5apoVdv1TbDSjfgcG8hNf2bx OMcDwuD1BZjFb/OC27e4QEVd3m70nzIotI1ZG1E/K/8CLOis8ArQToufluNcL7GAPfei qFJ1fvcPtU64QdeiFn7h1V4pWVGBje+xZJuFKFXOKFlGnLZorKCyXg8Rij8COjBQNqo7 Bu6w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aULRvjneXS6PzsfOw4nWKCmN2L3WsMWzp9Cw6hJFCDg=; b=okoaXkQAL+AzZsNXu5peReastLnTiUbZptwYRmCK2hJ109cN2G6ejin4x6EDDYlRC8 ojV3RKmfzB0MnXMXtlLrOz28jhiEw2x5Wschy+aXByhcy++iVd7ubdfUKt7S9b+U3KZv 8jGSfnMYMbDJVbWkMAMnFttFG9EFWgTuZGP9o7sjueTBs5VxyA8u+D3Bbby2lL5WPpfg D0J46rRejvXLuUb813thgdQ2QuQ6qCGuuWx3hwTLcuXaoFAbmUfzsvA5Fhfrzs4zWw9T vz/OqMs9jVz/veMamnmXet1Don8GyyjVLB8Po+7ioB0tFJc6qU6mIk/I70q4lp/xqyK7 h0AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KXtkYuyw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020a1709065e5600b0072f579adddcsi7438266eju.519.2022.08.15.14.09.18; Mon, 15 Aug 2022 14:09:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KXtkYuyw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346731AbiHOUl4 (ORCPT + 99 others); Mon, 15 Aug 2022 16:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346778AbiHOUgi (ORCPT ); Mon, 15 Aug 2022 16:36:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BBC34E852; Mon, 15 Aug 2022 12:06:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 97A4661299; Mon, 15 Aug 2022 19:06:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D143C433C1; Mon, 15 Aug 2022 19:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660590415; bh=yC+VSmPMf/FABXJ3eAcT1Ky9QRksUqiRrbWGIp/BIj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KXtkYuywnegnru14cY69oHtccKtHMJ5ovnt8p+VHtV2d6Oc7LO2d+n0FIek7Li0p9 m2HqRq7enr0lBIQmLSVvQ7WPuYaY8PeokJotKUlguYrSXHBAJ+GnJZs0ir3QW0URix IM/8WUyAyD5xnLmFqgq48a0FQD2PVM8YJ6vVU1vY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephane Eranian , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.18 0252/1095] perf/core: Add perf_clear_branch_entry_bitfields() helper Date: Mon, 15 Aug 2022 19:54:11 +0200 Message-Id: <20220815180440.172989977@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 From: Stephane Eranian [ Upstream commit bfe4daf850f45d92dcd3da477f0b0456620294c3 ] Make it simpler to reset all the info fields on the perf_branch_entry by adding a helper inline function. The goal is to centralize the initialization to avoid missing a field in case more are added. Signed-off-by: Stephane Eranian Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20220322221517.2510440-2-eranian@google.com Signed-off-by: Sasha Levin --- arch/x86/events/intel/lbr.c | 36 +++++++++++++++++------------------- include/linux/perf_event.h | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c index 1f156098a5bf..4f70fb6c2c1e 100644 --- a/arch/x86/events/intel/lbr.c +++ b/arch/x86/events/intel/lbr.c @@ -769,6 +769,7 @@ void intel_pmu_lbr_disable_all(void) void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc) { unsigned long mask = x86_pmu.lbr_nr - 1; + struct perf_branch_entry *br = cpuc->lbr_entries; u64 tos = intel_pmu_lbr_tos(); int i; @@ -784,15 +785,11 @@ void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc) rdmsrl(x86_pmu.lbr_from + lbr_idx, msr_lastbranch.lbr); - cpuc->lbr_entries[i].from = msr_lastbranch.from; - cpuc->lbr_entries[i].to = msr_lastbranch.to; - cpuc->lbr_entries[i].mispred = 0; - cpuc->lbr_entries[i].predicted = 0; - cpuc->lbr_entries[i].in_tx = 0; - cpuc->lbr_entries[i].abort = 0; - cpuc->lbr_entries[i].cycles = 0; - cpuc->lbr_entries[i].type = 0; - cpuc->lbr_entries[i].reserved = 0; + perf_clear_branch_entry_bitfields(br); + + br->from = msr_lastbranch.from; + br->to = msr_lastbranch.to; + br++; } cpuc->lbr_stack.nr = i; cpuc->lbr_stack.hw_idx = tos; @@ -807,6 +804,7 @@ void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc) { bool need_info = false, call_stack = false; unsigned long mask = x86_pmu.lbr_nr - 1; + struct perf_branch_entry *br = cpuc->lbr_entries; u64 tos = intel_pmu_lbr_tos(); int i; int out = 0; @@ -878,15 +876,14 @@ void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc) if (abort && x86_pmu.lbr_double_abort && out > 0) out--; - cpuc->lbr_entries[out].from = from; - cpuc->lbr_entries[out].to = to; - cpuc->lbr_entries[out].mispred = mis; - cpuc->lbr_entries[out].predicted = pred; - cpuc->lbr_entries[out].in_tx = in_tx; - cpuc->lbr_entries[out].abort = abort; - cpuc->lbr_entries[out].cycles = cycles; - cpuc->lbr_entries[out].type = 0; - cpuc->lbr_entries[out].reserved = 0; + perf_clear_branch_entry_bitfields(br+out); + br[out].from = from; + br[out].to = to; + br[out].mispred = mis; + br[out].predicted = pred; + br[out].in_tx = in_tx; + br[out].abort = abort; + br[out].cycles = cycles; out++; } cpuc->lbr_stack.nr = out; @@ -951,6 +948,8 @@ static void intel_pmu_store_lbr(struct cpu_hw_events *cpuc, to = rdlbr_to(i, lbr); info = rdlbr_info(i, lbr); + perf_clear_branch_entry_bitfields(e); + e->from = from; e->to = to; e->mispred = get_lbr_mispred(info); @@ -959,7 +958,6 @@ static void intel_pmu_store_lbr(struct cpu_hw_events *cpuc, e->abort = !!(info & LBR_INFO_ABORT); e->cycles = get_lbr_cycles(info); e->type = get_lbr_br_type(info); - e->reserved = 0; } cpuc->lbr_stack.nr = i; diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index af97dd427501..a411080d5169 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1063,6 +1063,22 @@ static inline void perf_sample_data_init(struct perf_sample_data *data, data->txn = 0; } +/* + * Clear all bitfields in the perf_branch_entry. + * The to and from fields are not cleared because they are + * systematically modified by caller. + */ +static inline void perf_clear_branch_entry_bitfields(struct perf_branch_entry *br) +{ + br->mispred = 0; + br->predicted = 0; + br->in_tx = 0; + br->abort = 0; + br->cycles = 0; + br->type = 0; + br->reserved = 0; +} + extern void perf_output_sample(struct perf_output_handle *handle, struct perf_event_header *header, struct perf_sample_data *data, -- 2.35.1