Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp193600lqo; Thu, 9 May 2024 17:47:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWEz7sm0WDvOXi8gPBHI2/ooCPVsrBOx6YbqhOYCEnJU3exn/Fm/iIJyYPHk7jq3r2ealK+pmq/lND1dvvK1VbuzlxFxmGp54X5KHHD0Q== X-Google-Smtp-Source: AGHT+IGeS/thU0NZcCqVgTiVFDNLr9E/Z5lgx8EzIzFV/TSj3WrA+JhkDR72hcR41hlfkfO7lkrG X-Received: by 2002:a05:6870:c685:b0:241:314f:5c0d with SMTP id 586e51a60fabf-241728f4d68mr1461571fac.9.1715302077166; Thu, 09 May 2024 17:47:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715302077; cv=pass; d=google.com; s=arc-20160816; b=M01k4hHasRqLArqwuHuo+rUWh1k196g5nWtwvnywPaSxtCcOjwDvOg1FQ6gXNTkKWi 5RCif6oBd8ONWTjXZWWC8z6wIyd0jzUBEaE+pl0TYOmmqWojDIY0jjY+WQK4Po0loKDL 3iRtQDQvJZq3IFHhaY7KcRj5jAXyo/d2d0gCjj5YrhbDfrERArqaf3Vt5N0jeyzTiHhp a5ns4hfIHlpJZUXKdBvQCSbpDepaQhgJ7QvVLSqN0IXd+ST7LwcWjJj2KaWz1Y/vp+lG JflAlW5mKCP+JpukVrZ+mLZlV9bOcvN5tMtVRPcGoZztO1o4/7MYe2s2oNubp6AFbmKT +/Gg== 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=v9grz5MJy3ZdpaUQrWKUMUhoIXt+TwKDu1fmP3H2Mh8=; fh=IosByBuhTpJ5eoFaum8ms0bnMP8oI58griLq8RzklV8=; b=PXb+bQzIwKkThna4Sj70jz/qXlB7ak+cpfDdgrSKVIvL82v+0fccP5t04NzPwVZoHe KEyvkZ8/4MYRe7gwGZZfKkn2cxhAUchcv2SY+Slp+tnJW8tD61LIF0A8J67Ltoquf/ZV 4Gcn4VWKBsy3OZYhDHUFv5SVkXhpxd6RTJg4ePIVDKCG4RpF+Um7fONS3GL7bcY2UMUV 89Plz7C+VZ+kMKsIpYLu9iuQdysf5Gx2Xe/s5cTipwLuqMBQLrKrszNFzBcm2nVMjGHy 2SoGtTQLoMUAN5QFLhhLZhjXor9YmNqlqEt/BPfp61UaK5vYcIuiwWWIla6yXQBcER8E K/YQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BymfKGwF; 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-175173-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6340b2a0b4fsi2353974a12.212.2024.05.09.17.47.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 17:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175173-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BymfKGwF; 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-175173-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175173-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 88942B224B8 for ; Fri, 10 May 2024 00:37:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73E564E1CF; Fri, 10 May 2024 00:24:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BymfKGwF" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 042D84E1D9 for ; Fri, 10 May 2024 00:24:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715300691; cv=none; b=BkESg9DKNrT0UXMJu6RS/ExPpolLuBgbkxFK2IfDeNLDsmPLdFdGMZt/0E3JCvSvoKEPXxLiygqsrTbIb9JE9SrGjqmz34RWh2z8Ep6Wf9BqbEDHd36xzfElwg3Woavd/dgrXmjNKbNiwBDOl9a5/1Zi685p+QAP8JVzwuezP6c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715300691; c=relaxed/simple; bh=xySRyI8fWJdGd1hvqSCkes+7dSi689oW4NVcWrWQsMc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=An6fgl0bINk7DXDiNYEaFj/Z2p26P2NtWj8Fjfb+i8A8pds1wu3K4s+B67CtlUGJ3Kyohaqtb3qxiRqHLdgouNDiALXRpUKWaDk+az/90va0t5wmAVXCnyFldXlbDgYVQPARrVAtDgnS5c+U0oHYTi19wdycg3DGVKcvuLcbsnc= 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=BymfKGwF; arc=none smtp.client-ip=209.85.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-de54ccab44aso2651747276.3 for ; Thu, 09 May 2024 17:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715300689; x=1715905489; 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=v9grz5MJy3ZdpaUQrWKUMUhoIXt+TwKDu1fmP3H2Mh8=; b=BymfKGwFbC1BrDHa5dWfHA2ArKzw2sM9A/hITwqL6MGAExRIVzDFf8BWWw08pSCDUO RvZJ6Fz+1DLNKaV/pusm+iqoCfqzlTnhJd8vRIqdxuuFCjizQsz8Sfis3PIqiSzByBEn 7L26JpIBYiv0oWBsAQJG6Fw5rA6/gi3kx1pnPS0WSXXld1yQU565C8NfZnrsPZGUmjYt VcjKcIdEpx8BgXl3W5V/8atC97MSctnsTHVwngTf8vlLbKcXfAlixwPrHGQR1IwWw1WK rmf7sBdtLGJ/6JMWqmmqF1bR5cNhtTMs9hpG85fjlfattOpuLjl6AU46qQxnP3eR+joK Ea7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715300689; x=1715905489; 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=v9grz5MJy3ZdpaUQrWKUMUhoIXt+TwKDu1fmP3H2Mh8=; b=hWDm+Xu68hE3+2r7AFjzijAm6+9tQkmKNLvmtkuI347VKFvHuGlcmTCGVGaD94z/9m IE0QdKNPtXqe0IFN+NQD74FulvAAKNju2VeKOKtD7dMEtcshnWlH1M84riLtajm7HOTg EsAPOn6EXKy/htu5Z1hcS9O6xSPeHdDghNrk/OamHqwD1hV0frv96fKYh+V+1uEp5IPE sov4ngZhpBm6X51OTepzeeZtFpORElBImnrC0zVXvZoeMGw+ZLc6aX208brlvQrMm3Lb /HoOBRPO5dwCsluVGMUuOuRnclpH6pOuBlUe0JfKo81AwwaOKa5OINFFffl2xw24ssVR 1NMQ== X-Forwarded-Encrypted: i=1; AJvYcCXqNwJLpjFyTevUdnW0iwDPz5Fh0CBBADQCz9sXvFDWXfO19ak+hJ00zLtjK+41n92ClG3irvIXS1EanGvrHLYeP6k4CbYCD1NYcaH+ X-Gm-Message-State: AOJu0Yyj09XOFxbWuI5qi4cXiOlfPomf1Ek1HYPDQYdsAbDtr6o3bDDy qTjwaWgSaloA0R0GkCWaSZzRozp+kNhC50xiAUseH4KJYzqokodw9G8BWxUKT287AYhat98l0Bj I X-Received: from yabinc-desktop.mtv.corp.google.com ([2620:15c:211:202:1b7d:8132:c198:e24f]) (user=yabinc job=sendgmr) by 2002:a05:6902:a8b:b0:dc7:7ce9:fb4d with SMTP id 3f1490d57ef6-dee4f322140mr265064276.12.1715300688967; Thu, 09 May 2024 17:24:48 -0700 (PDT) Date: Thu, 9 May 2024 17:24:23 -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-3-yabinc@google.com> Subject: [PATCH v3 2/3] perf: core: Check sample_type in perf_sample_save_callchain 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_callchain() to prevent saving callchain data when it isn't required. Suggested-by: Namhyung Kim Signed-off-by: Yabin Cui --- arch/x86/events/amd/ibs.c | 3 +-- arch/x86/events/intel/ds.c | 6 ++---- include/linux/perf_event.h | 3 +++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c index c3a2f6f57770..f02939655b2a 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -1129,8 +1129,7 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) * recorded as part of interrupt regs. Thus we need to use rip from * interrupt regs while unwinding call stack. */ - if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) - perf_sample_save_callchain(&data, event, iregs); + perf_sample_save_callchain(&data, event, iregs); throttle = perf_event_overflow(event, &data, ®s); out: diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c index e010bfed8417..c2b5585aa6d1 100644 --- a/arch/x86/events/intel/ds.c +++ b/arch/x86/events/intel/ds.c @@ -1655,8 +1655,7 @@ static void setup_pebs_fixed_sample_data(struct perf_event *event, * previous PMI context or an (I)RET happened between the record and * PMI. */ - if (sample_type & PERF_SAMPLE_CALLCHAIN) - perf_sample_save_callchain(data, event, iregs); + perf_sample_save_callchain(data, event, iregs); /* * We use the interrupt regs as a base because the PEBS record does not @@ -1823,8 +1822,7 @@ static void setup_pebs_adaptive_sample_data(struct perf_event *event, * previous PMI context or an (I)RET happened between the record and * PMI. */ - if (sample_type & PERF_SAMPLE_CALLCHAIN) - perf_sample_save_callchain(data, event, iregs); + perf_sample_save_callchain(data, event, iregs); *regs = *iregs; /* The ip in basic is EventingIP */ diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 9fc55193ff99..8617815456b0 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1232,6 +1232,9 @@ static inline void perf_sample_save_callchain(struct perf_sample_data *data, { int size = 1; + if (!(event->attr.sample_type & PERF_SAMPLE_CALLCHAIN)) + return; + data->callchain = perf_callchain(event, regs); size += data->callchain->nr; -- 2.45.0.118.g7fe29c98d7-goog