From patchwork Mon Jan 9 17:02:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 40986 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2267973wrt; Mon, 9 Jan 2023 09:04:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXtD6Ecpfbm+uPIG3PUs6rWpTAPXoKOjITH31AnWjjstg0ZNPdEGcfwapccR4+r0HmL+4rZ5 X-Received: by 2002:a05:6402:5145:b0:475:32d2:7486 with SMTP id n5-20020a056402514500b0047532d27486mr59316512edd.31.1673283859908; Mon, 09 Jan 2023 09:04:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673283859; cv=none; d=google.com; s=arc-20160816; b=qQaXx3n4uY1BdOqG7opqHAJu3qzmJvBPJvgv6i9noXF7cY2ug/d02Q1eTvwR7SlT1N reF0vE6GqlkYHNGlxPYn9eYrnfwsglVKWp6hWrNX+b/cbLfobtKQugPIk+xZ1eHf2yj4 cdjbBZu2mjz2CXs8I68+5KBc27CdrAD9JXjxAR/ZKJbBO5H+RH/ssiZRkE+UESQPctYy w2sdhiNa70IZ/5VSWGsJVLfIhdllG3tiK80D5SG77r5Fs3EtK2WyhZjMVysbZI/OMNum Ii/EIKaT8ieiftlfmPpFh/TK50bMI5Ft38bNfUyZJZDNpWQIFdLFjYEfQ2/Z/V97Rvyq Un8Q== 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=RqvY0nZ53Ev1fKsm+wsJ7IJW7g25Ot+ctkp/1+36tBM=; b=eQ1ZWJ4lGZaN9j6hQnIjxoTf9lb/fzwE+nrTvZKZM48pWoayQM7PAOzArN9X/2kUZc OMUNNUjq5wg/MVQUuQkELsQKa77fxtHuxP+Y+NAQ+FmH/UX7BOPJSQp2pqfRorhtfIvf A1I04GE+sCLL6J87+7uMv0Dee/ulWGZPx4c59NhxBWcrNPM8gr8XO2Lg9DdSC2aBQvi0 ptfeXGuOtUBM37UiHbppBKHaP1lWmKJ3BM1Fz/LxHIHPF55XupGM0Snb6FQNkHdUwL3L D+NRNT5NCy37MNax2uXULmf9CvPl1eI+hshSIE7XbILGl84YrLWjmvxuGQ7JKYpkS26h 5ZoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=EONpgTzu; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020aa7c541000000b0046ad8dfcfbasi9151663edr.344.2023.01.09.09.03.56; Mon, 09 Jan 2023 09:04:19 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=EONpgTzu; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229824AbjAIRCe (ORCPT + 99 others); Mon, 9 Jan 2023 12:02:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234288AbjAIRCK (ORCPT ); Mon, 9 Jan 2023 12:02:10 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4AE03FA1B; Mon, 9 Jan 2023 09:02:08 -0800 (PST) Date: Mon, 09 Jan 2023 17:02:07 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673283727; 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=RqvY0nZ53Ev1fKsm+wsJ7IJW7g25Ot+ctkp/1+36tBM=; b=EONpgTzu9S99sbZRju1yTx1vICWR+qyAhxaax4MY2rQsIOfhB7np40EotBTCU5PN85PsFw apiwl47rZnYf1+RccyugsEAxgO+n6vqI9ynmeizG6LS6H4lyQFPU64rn81sLWsgk4p6lmH UJ3PtP4/miZ64lTzoZ7Zhl8+l+B/ET/DaKqBSLdanCYQziXAFBQhMCtYq1FMjgBZExAoKN TYRomFdHeZ1xUGnqqeYgsguihLAEHV94mnDVM684Y0tLbQC+rgCtNP5XnYANprPjGSj3dX FFrUareax1wYf1DP588eZzFQZo/msq3BSpk4UkLxRSmxNEWMz1fy2R7gXLO90w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673283727; 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=RqvY0nZ53Ev1fKsm+wsJ7IJW7g25Ot+ctkp/1+36tBM=; b=m8c9nyuP/Cg6jpykiSsANOV+jjVIxn5/5L8E4i6ztz7TBHJNkddJugu3Qct9ThofZHMiRy z97tc5gHan0k6gBA== From: "tip-bot2 for Namhyung Kim" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/core: Save calculated sample data size Cc: Namhyung Kim , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221229204101.1099430-3-namhyung@kernel.org> References: <20221229204101.1099430-3-namhyung@kernel.org> MIME-Version: 1.0 Message-ID: <167328372716.4906.7029023036298572576.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753582635892579526?= X-GMAIL-MSGID: =?utf-8?q?1754565296482277750?= The following commit has been merged into the perf/core branch of tip: Commit-ID: 0ecc518e5c1a83fbfc6262d20d0df289eafc2207 Gitweb: https://git.kernel.org/tip/0ecc518e5c1a83fbfc6262d20d0df289eafc2207 Author: Namhyung Kim AuthorDate: Thu, 29 Dec 2022 12:41:01 -08:00 Committer: Ingo Molnar CommitterDate: Mon, 09 Jan 2023 12:22:09 +01:00 perf/core: Save calculated sample data size To avoid duplicate work in perf_prepare_sample(), save the final header size in data->saved_size. It's initialized to 0 and set to an actual value at the end of perf_prepare_sample(). If it sees a non-zero value that means it's the second time of the call and it knows the sample data is populated already. So update the header size with the data->saved_size and bail out. Signed-off-by: Namhyung Kim Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20221229204101.1099430-3-namhyung@kernel.org --- include/linux/perf_event.h | 2 ++ kernel/events/core.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index 03949d0..656b6ea 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -1103,6 +1103,7 @@ struct perf_sample_data { */ u64 sample_flags; u64 period; + u64 saved_size; /* * Fields commonly set by __perf_event_header__init_id(), @@ -1158,6 +1159,7 @@ static inline void perf_sample_data_init(struct perf_sample_data *data, /* remaining struct members initialized in perf_prepare_sample() */ data->sample_flags = PERF_SAMPLE_PERIOD; data->period = period; + data->saved_size = 0; if (addr) { data->addr = addr; diff --git a/kernel/events/core.c b/kernel/events/core.c index 70bff8a..dac4d76 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7576,6 +7576,15 @@ void perf_prepare_sample(struct perf_event_header *header, header->misc |= perf_misc_flags(regs); /* + * If it called perf_prepare_sample() already, it set the all data fields + * and recorded the final size to data->saved_size. + */ + if (data->saved_size) { + header->size = data->saved_size; + return; + } + + /* * Clear the sample flags that have already been done by the * PMU driver. */ @@ -7796,6 +7805,8 @@ void perf_prepare_sample(struct perf_event_header *header, * do here next. */ WARN_ON_ONCE(header->size & 7); + + data->saved_size = header->size; } static __always_inline int