Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp190520lqo; Thu, 9 May 2024 17:38:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUmO5qEa4v5qYX/CEI1izroQLau3MLqUdJ351if0crCexICPzjL6IIVM//6eXY2nWxKXp9bWzLFJgdptb+P/rGKs9AQxC5MkqZybCnExQ== X-Google-Smtp-Source: AGHT+IEwOxxGwrImvIhGmGs43wAuugxuAyN8VaseooZQnRa0sh97keHwkQmGnvhk9Lga8Nm6Xq/O X-Received: by 2002:a05:6102:1484:b0:480:758f:c7a4 with SMTP id ada2fe7eead31-48077eb1de5mr1724795137.34.1715301487478; Thu, 09 May 2024 17:38:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715301487; cv=pass; d=google.com; s=arc-20160816; b=DxUNZMPyHzKnNXNlKMGzepZhZlbYxoeglqIKYq/cDfcJiek8GohGA3pW2xQlcaNHen r8aFl6xmA7llDnf9MPxKu7wj/P+XG53caOqaWbs4q9FhLeT34ErTZ+OQgPXBPSgg8GTL qs+X5rozg+YtttFiQ0rPNLgrF/NUgA8xREtpMF8BLLaNqF08jmMkmyyWFxhk7/BRa5jz h/zW5CGufSWek/vcitci84aTdvhEZqj1ap/uqIBsrofw8Me/pyTVxcvYtG8GgQjo51NB 6h4ldEXentj6nNrfvsnR6hOQkY1LR0mFNatP0xUSXIUetXVZo4BI8St2+VBVNo5D1J0Z ogQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=ot0TEs4BvD2J9QyiZT5bC39KllHj7+HFnRVXvIw7CTU=; fh=PLwnsgSev/4Bt3lAQJGiGRe0wrJOWEUnxEHDNcfBEXc=; b=a0znbilEiPZkXWcNz/i8+t72s6YgddOHcWfLZX0gMNDZ9Mt99xUncjgbv9gHik7SJf tuPmbUTDusalVX/vgYobI1tt4bGZJQV843pQb6hrXavup3zUih7jVv/PuZSXJNrgRDSh IHU5Bi8riHmzN8ITuM7wptp8gFFU5stYkSDgaST5keF1EPm+GoHoknDG028yNoi8Uggf 5xurryRN7BlIVfgluBWkU/a306p9+oVARyIKJqjW9sWJQ1y14bxfS3BwsNyrFvmMa8Jt FnoLiS86Dh7S8qwda4NONAflt2Ns4fXHBDUNwB8AUurXEl77TRFxrqvIwGm3VAWK6xxZ Ih/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="VO/sDB54"; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43df56d162dsi26107861cf.646.2024.05.09.17.38.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 17:38:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="VO/sDB54"; arc=pass (i=1 spf=pass spfdomain=flex--yabinc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-175174-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175174-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C00511C230EC for ; Fri, 10 May 2024 00:37:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 478DD4D59E; Fri, 10 May 2024 00:24:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="VO/sDB54" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2ED950275 for ; Fri, 10 May 2024 00:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715300694; cv=none; b=rWlMUQH7/tWCqVaQkTA/SZsulZzafmvt4V1fp/JHl6u2B882RjBMEHTae3QqNoznuZqYrkjIOvxjzNMNdnpRwRGDImNNwYyL5kbWHabSgAKB2MlhpPX0gfboVIXbjx5T82rCM7+3ncnNybaYnQia/zd5lZ7ca0Wonk36h81G8sk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715300694; c=relaxed/simple; bh=cGpULC1B1HXkvRfCSn3TdeH+Xj5EwEpr4DGLnTg+pCQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ZgWIgTqzoZJw0buXYC2h8tVjWpcZrdXAUjalbIn+N9du6r2l/ksF77N5PxEqBAzLtNraobQ3L7Rfs2PS/OPDgqo5pmNFlWlXn4geJzOLe8evSOLhIqZBkovI1QIyI1Mhf2z9Son/2HNWjUjjkF6bSACDGsI824uTredgzUIuHKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=VO/sDB54; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yabinc.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-61be23bb01aso28388247b3.2 for ; Thu, 09 May 2024 17:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715300692; x=1715905492; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ot0TEs4BvD2J9QyiZT5bC39KllHj7+HFnRVXvIw7CTU=; b=VO/sDB54S3qSxJVTmyoabGla9DZoE2c3nPIwrgewoiuNBvaOau+sH0G8BuFGcpEpQO T653MqpMHs7sFSBrgomGTU0DJsPyVccE4wG6ZKzLYCFHR8mVnplA2bBZbpNLlrAQl6F7 Uibqgs0s0vruoPqNx4FKbueKm7DGE9blJO0oXtLBjuBvtSsDmYVzvzYe4fQMF4oYJIGe bNXjzJO6t06FyVPXNdoEdjZroYxXm7Cuh2gYIzFIKAeBMmL8ux8oE8FwIPV3CgD5UiV6 RTqqUDcV/fmgs7JIL7pahZd1vwa+GiMImqsPlNLazX/spy13kMf5TDA8Hc+gk9y3vWVm XH0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715300692; x=1715905492; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ot0TEs4BvD2J9QyiZT5bC39KllHj7+HFnRVXvIw7CTU=; b=EhuRnd1c6HGfVpPkRkg0S99IIZ3KYXr+DBC3RWBUxLwJfsCW2vM2z12dAzvsHoy7IK aRXAT9RYbgjdGM4p/2cozZwHnFQ2Y9WWOQv0hfw10e2dv1Ia/iM3Dln/KhpAIlgOTXR3 /uaYI4Fvfv/1VH6VvMRDul9NeymoFopPeYs6rpTpCDLTQ1rkVpB5KTODVnzH+R2nixjQ 8FRl7ZpgZnKtPc+IWMmvOMjWK8XPr2Yl+bf2ycb/5RU4qUzs+HRP9+o3lLRRsxaIzBJP ergFTqfWRBSVHkd641Qt60Tue+SrPD3l7aBGX0mlKr03zWF5lmpUiBMVMCV6cYpQK2AQ SyQg== X-Forwarded-Encrypted: i=1; AJvYcCVGrkAtNFrfNTg//KtbSQgwDoaEpM8RA2G65SHucpajGRqzWJxM7QAxHLvBLwdnIuCKKtjmM3QeCNNtgENa1esxhSKGkXwHuGJZiFqF X-Gm-Message-State: AOJu0YxbAP9sFChNuboGrUnm5NYdIOpylw7wciFaohjXojmCd0vKfQtE dzCfnmM6FhOF6F5J9VKLQD0EMEGfA6Rj0mE2J3O7MfQKI7RKPsuhn5bds1U8vt7QrOZgvT8PatV + X-Received: from yabinc-desktop.mtv.corp.google.com ([2620:15c:211:202:1b7d:8132:c198:e24f]) (user=yabinc job=sendgmr) by 2002:a05:690c:b10:b0:61c:89a4:dd5f with SMTP id 00721157ae682-622afcbec26mr3237517b3.0.1715300692087; Thu, 09 May 2024 17:24:52 -0700 (PDT) Date: Thu, 9 May 2024 17:24:24 -0700 In-Reply-To: <20240510002424.1277314-1-yabinc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240510002424.1277314-1-yabinc@google.com> X-Mailer: git-send-email 2.45.0.118.g7fe29c98d7-goog Message-ID: <20240510002424.1277314-4-yabinc@google.com> Subject: [PATCH v3 3/3] perf: core: Check sample_type in perf_sample_save_brstack From: Yabin Cui To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Yabin Cui Content-Type: text/plain; charset="UTF-8" Check sample_type in perf_sample_save_brstack() to prevent saving branch stack data when it isn't required. Suggested-by: Namhyung Kim Signed-off-by: Yabin Cui --- arch/x86/events/amd/core.c | 3 +-- arch/x86/events/core.c | 3 +-- arch/x86/events/intel/ds.c | 3 +-- include/linux/perf_event.h | 3 +++ 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c index 985ef3b47919..fb9bf3aa1b42 100644 --- a/arch/x86/events/amd/core.c +++ b/arch/x86/events/amd/core.c @@ -967,8 +967,7 @@ static int amd_pmu_v2_handle_irq(struct pt_regs *regs) if (!x86_perf_event_set_period(event)) continue; - if (has_branch_stack(event)) - perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL); + perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL); if (perf_event_overflow(event, &data, regs)) x86_pmu_stop(event, 0); diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 5b0dd07b1ef1..ff5577315938 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -1702,8 +1702,7 @@ int x86_pmu_handle_irq(struct pt_regs *regs) perf_sample_data_init(&data, 0, event->hw.last_period); - if (has_branch_stack(event)) - perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL); + perf_sample_save_brstack(&data, event, &cpuc->lbr_stack, NULL); if (perf_event_overflow(event, &data, regs)) x86_pmu_stop(event, 0); diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index c2b5585aa6d1..f25236ffa28f 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1754,8 +1754,7 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event, if (x86_pmu.intel_cap.pebs_format >= 3) setup_pebs_time(event, data, pebs->tsc); - if (has_branch_stack(event)) - perf_sample_save_brstack(data, event, &cpuc->lbr_stack, NULL); + perf_sample_save_brstack(data, event, &cpuc->lbr_stack, NULL); } static void adaptive_pebs_save_regs(struct pt_regs *regs, diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 8617815456b0..8cff96782446 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1276,6 +1276,9 @@ static inline void perf_sample_save_brstack(struct perf_sample_data *data, { int size = sizeof(u64); /* nr */ + if (!has_branch_stack(event)) + return; + if (branch_sample_hw_index(event)) size += sizeof(u64); size += brs->nr * sizeof(struct perf_branch_entry); -- 2.45.0.118.g7fe29c98d7-goog