From nobody Sun Feb 8 01:31:03 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 0AA3A1B1429 for ; Thu, 29 Aug 2024 15:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943735; cv=none; b=tv2xHZ1lXNNN/LyToEyKd6tK05JpRnFf6mC5j7atMBPqss2aM2r1hPI+yRAo1KpGYQhFyYSbQvheE9lTRR6OmY6Rv69pEAXucn+CW8E15tkAqIR4JYf0A4dr7X8m8COgiIgCLCD6PfEajE80mPUHYDGD7KWG20Cj/dLE3iNNMUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943735; c=relaxed/simple; bh=zgEgmrdD0ptR2rv9IaNbtPHc6vf0nOiTzwH2GpRCEzQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=cC+RHe3hExRcsj4hex6+rx6R+gP/3bGAucQsWRPHDTSEiLlpBeDRgorGb4Bm9B5cXfQCDt7r4aqTFTlmIXK+1sTHEsYObPzvbQhl5iDd+hsKk2uyUdq84PEGcQQEb2F+o/pr3sSnqWn9evgDG0ImUB14+OsNE8UfE7Nr2/z2seo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=NMHVrK1W; arc=none smtp.client-ip=209.85.128.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="NMHVrK1W" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b2822668c2so15417357b3.1 for ; Thu, 29 Aug 2024 08:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943733; x=1725548533; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=dluq5P0RLumNyO/9SBujDaYG7Xf4enGWH7djPxvSwQE=; b=NMHVrK1WxA5xHhkCsD8bF1dpr/PGQeDx1x9OlcNiTReOxJ7k4NxdCHggdXAVLMHsi6 ExF4mFfbZOoRCbLOZMhMBCox1gpY3/uofZ21yBTyDQONKXER0J14lH/9J+JC2hKxV0Dc yHG7wOvRSFCVILOpdsXEYhKzmiaQWUypZ1AhoXGeV2+8jWrkZ4VXaJwnNHS9NdHy/HSF UIHrB4kP24fmgxtjICZs0CRI0teQZIXOsRjbK/fNepH6m7EgPXVweUvvk1Os0hbQ66Ip o0fvnfTLd2nw9b4Zfo8f3mzkRfHKPXwH1c/tBZzEWU8ZllbMXRSf3betwQuF7cuT0j7e fO3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943733; x=1725548533; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dluq5P0RLumNyO/9SBujDaYG7Xf4enGWH7djPxvSwQE=; b=Exj5YWGYaNzwe5VQKbYkG5NgJZG2s5yNWfkNwDm+7VppFoGML1Xzy5zLaUWy2XfRwX uO9JBZi9UrYb2IFV4WxMOwobWDOLN0KeB+aKs8bpQ+R2kDwXwgMZarZiLTMacGVRvc0+ MVy/bKvW+I+lukHM40QAR8fSWxY1Rst7X2fS0o/zQdEww1ZdRRzelY8y3PSf4TD5ylHk aVrWG65qubxeHi2ZhXmKbiEdR6LY4RE6mqKGwImo8mMftt4TQM8dQz4iSPJWIsf0BP3O 69Mx/WZXKI9uvVSWkjvYqLw5mPYZbsgiuE5KK1mWBGowSzCtNimvOb4beVqK1K1GGBvD C+1Q== X-Forwarded-Encrypted: i=1; AJvYcCXGh+y34epuyKiZ9BL52V3tPFoSG8HuZVkceH+RL6dsqJIbf6O3XLM79Um90UmiYHcubRwqiEmLUi/AlrI=@vger.kernel.org X-Gm-Message-State: AOJu0YzSQTKA9n015uqAFBC3xoMaQESL9P5oUxOiP7pTMUXCiUs1YcW6 LG46Am3dKlhveDywvvgTNI955fyJvSMwiC1L4wvTI8QTgUBfnW2j+RHH4pDzU1tMyi/KIADaAov 6Tv4GCQ== X-Google-Smtp-Source: AGHT+IEdQzNDjrLSj8WCqHhsyY9AarRDhFOz9K/cT4ZO+HLVQ56DRWKoceVvIf15U6oWf+LD8VSWetf46MRm X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a81:d10b:0:b0:6ad:feb0:d010 with SMTP id 00721157ae682-6d2e94d0921mr376307b3.6.1724943733046; Thu, 29 Aug 2024 08:02:13 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:47 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 1/8] perf report: Name events in stats for pipe mode From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In stats mode PERF_RECORD_EVENT_UPDATE isn't being handled meaning the evsels aren't named when handling pipe mode output. Before: ``` $ perf record -e inst_retired.any -a -o - sleep 0.1|perf report --stats -i - ... Aggregated stats: TOTAL events: 23358 COMM events: 2608 (11.2%) EXIT events: 1 ( 0.0%) FORK events: 2607 (11.2%) SAMPLE events: 174 ( 0.7%) MMAP2 events: 17936 (76.8%) ATTR events: 2 ( 0.0%) FINISHED_ROUND events: 2 ( 0.0%) ID_INDEX events: 1 ( 0.0%) THREAD_MAP events: 1 ( 0.0%) CPU_MAP events: 1 ( 0.0%) EVENT_UPDATE events: 3 ( 0.0%) TIME_CONV events: 1 ( 0.0%) FEATURE events: 20 ( 0.1%) FINISHED_INIT events: 1 ( 0.0%) raw 0xc0 stats: SAMPLE events: 174 ``` After: ``` $ perf record -e inst_retired.any -a -o - sleep 0.1|perf report --stats -i - ... Aggregated stats: TOTAL events: 23742 COMM events: 2620 (11.0%) EXIT events: 2 ( 0.0%) FORK events: 2619 (11.0%) SAMPLE events: 165 ( 0.7%) MMAP2 events: 18304 (77.1%) ATTR events: 2 ( 0.0%) FINISHED_ROUND events: 2 ( 0.0%) ID_INDEX events: 1 ( 0.0%) THREAD_MAP events: 1 ( 0.0%) CPU_MAP events: 1 ( 0.0%) EVENT_UPDATE events: 3 ( 0.0%) TIME_CONV events: 1 ( 0.0%) FEATURE events: 20 ( 0.1%) FINISHED_INIT events: 1 ( 0.0%) inst_retired.any stats: SAMPLE events: 165 ``` This makes the pipe output match the regular output. Signed-off-by: Ian Rogers --- This bug pre-dates commit 113f614c6dd0 ("perf report: Use perf_tool__init()") --- tools/perf/builtin-report.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 1643113616f4..5c21ca33ca08 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -811,6 +811,7 @@ static void stats_setup(struct report *rep) rep->tool.attr =3D process_attr; rep->tool.sample =3D count_sample_event; rep->tool.lost_samples =3D count_lost_samples_event; + rep->tool.event_update =3D perf_event__process_event_update; rep->tool.no_warn =3D true; } =20 --=20 2.46.0.295.g3b9ea8a38a-goog From nobody Sun Feb 8 01:31:03 2026 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 9FED01B29AA for ; Thu, 29 Aug 2024 15:02:16 +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=1724943738; cv=none; b=Qzw7M7fdVQKJhbj1SAV7fZDQu1ucW/7ca+pt78slNlr2AnsBOgkkbZFyei0e0pcrMn9PQdATElwjmYxxuFwQ2jiYmtwDNxUcOyaVHy3oSMefdaFLSXXPuy6IGAVvfYcTH+Af6nS99Nf5YTnOpxCAkn0ofKAs665xRTqbMh/oy1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943738; c=relaxed/simple; bh=YbH/w7Q2IRfQc3HCYtBu77nA+Z23ro96SsDZawy8A6g=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Rn4jKwzDeHErNAmWjlLUFdQqak5lp43g1TNrkQW+TBFUeJQyokwrAqUNwwIEev1LeCc/40uf6o11eIRJ70p/UQLreF0Y6o2cXfoI22CcIKk3koSN68MRigkKTuaPiBPCuP0nh0yEHIrrYviHISEh1M/A1G7rorByyQeuvxHjPqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=2fagBM+X; 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2fagBM+X" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e02b5792baaso1241467276.2 for ; Thu, 29 Aug 2024 08:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943736; x=1725548536; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=26cUqoseK8PMtNLolCaTO1poipR4Q8jBH4RycCyqvMg=; b=2fagBM+XR4Ww+O1YYXwhVI76KAvuOv6sfbToDAGfIN6IBBx2TFXSpSnFtwfSh2004P HKDya02j0zajeZhe8cKgXzY2T7UN/KucVGKll7+BYD1hbEOyN3aT57IwrX76abt7w17J 8IQUmQrw/7Ekm8R9KqTjxw6/a2EzQy36SUZJt4KkvDPUelCQS6Kw8A7v6jiYa3MuGCwM v2u5TD4fNPrHAlGsy4ahD+581geDoC/6AWXQ22vJTafgA3cXv5+NeU9xw84A8izYVmZr nvAN89cF8SNdTMeyh/IPAfu6mSEsqEkR7vcF3PIR9S7GqvTnrHtgiWLRJwhzqjQ/HE13 SCdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943736; x=1725548536; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=26cUqoseK8PMtNLolCaTO1poipR4Q8jBH4RycCyqvMg=; b=CP8NAc9AmDhM5kKMz6Gtaa5SaP67qmJ0sPnKEET6dPb86uCVnvb9jt9CWAszT69anJ fETLg3r9dRirOg5ufgDEXt8UOF3A0sTSNZQtf3Ur0t7inJZtaIvRJctexrw3GlewVeJy nFKlERZYMg77YcBiynnG0+p60AvyLfycWFBP2L6WRstOrc96GplFcpWsY0UN+2DXeApC 7hQmly2clOHCT/qBvqfooNBQI24Q9TdtjbTGaYKB6bbMGHDfs219wEAJnybDoqaNOW40 aTD6o2sA2gIONy15TstYZ4HlO/F5pCDQt3vO/I/OYl4thnEsC4cbIS87tgvyrihGMfAD XXmg== X-Forwarded-Encrypted: i=1; AJvYcCURQOEb6KORBp3WVwDMnTUnQ9cjACYVhMD383igyAIt3Omugqy58aj+qDtMWSfrVLI9RySuzyjfvI6j3a4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyk2D9SyPIN0YaWaV3n0PjhMcH/Ok3HSPwsT63Jl+nDSY9soe0x rF4w8kDI/i7hfWy0HLzzc+krIevjz81Nh5Nr0uyxa3pgdG4ova77RKwUB3L9RkS9D6DLRcmhb9n bVP6QFA== X-Google-Smtp-Source: AGHT+IE5Puj8WGaPepDdvNVYEm+iM1nKWd1L3XPtWu5Ysb0Sv/gFkGsoPfS165yMmxR1Go63SQBsjBYpq0qu X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a25:8489:0:b0:e11:584f:c2ca with SMTP id 3f1490d57ef6-e1a5ac86f68mr33881276.6.1724943735472; Thu, 29 Aug 2024 08:02:15 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:48 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 2/8] perf session: Document struct and constify auxtrace From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_session is a central data structure to the tool so let's comment it. The auxtrace callbacks are never modified in session so constify. Signed-off-by: Ian Rogers --- tools/perf/util/session.h | 48 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 7c8dd6956330..e56518639711 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -26,26 +26,72 @@ struct decomp_data { struct zstd_data *zstd_decomp; }; =20 +/** + * struct perf_session- A Perf session holds the main state when the progr= am is + * working with live perf events or reading data from an input file. + * + * The rough organization of a perf_session is: + * ``` + * +--------------+ +-----------+ +------------+ + * | Session |1..* ----->| Machine |1..* ----->| Thread | + * +--------------+ +-----------+ +------------+ + * ``` + */ struct perf_session { + /** + * @header: The read version of a perf_file_header, or captures global + * information from a live session. + */ struct perf_header header; + /** @machines: Machines within the session a host and 0 or more guests. */ struct machines machines; + /** @evlist: List of evsels/events of the session. */ struct evlist *evlist; - struct auxtrace *auxtrace; + /** @auxtrace: callbacks to allow AUX area data decoding. */ + const struct auxtrace *auxtrace; + /** @itrace_synth_opts: AUX area tracing synthesis options. */ struct itrace_synth_opts *itrace_synth_opts; + /** @auxtrace_index: index of AUX area tracing events within a perf.data = file. */ struct list_head auxtrace_index; #ifdef HAVE_LIBTRACEEVENT + /** @tevent: handles for libtraceevent and plugins. */ struct trace_event tevent; #endif + /** @time_conv: Holds contents of last PERF_RECORD_TIME_CONV event. */ struct perf_record_time_conv time_conv; + /** + * @repipe: When set causes certain reading (header and trace events) to + * also write events. The written file descriptor must be provided for + * the header but is implicitly stdout for trace events. + */ bool repipe; + /** + * @one_mmap: The reader will use a single mmap by default. There may be + * multiple data files in particular for aux events. If this is true + * then the single big mmap for the data file can be assumed. + */ bool one_mmap; + /** @one_mmap_addr: Address of initial perf data file reader mmap. */ void *one_mmap_addr; + /** @one_mmap_offset: File offset in perf.data file when mapped. */ u64 one_mmap_offset; + /** @ordered_events: Used to turn unordered events into ordered ones. */ struct ordered_events ordered_events; + /** @data: Optional perf data file being read from. */ struct perf_data *data; + /** @tool: callbacks for event handling. */ const struct perf_tool *tool; + /** + * @bytes_transferred: Used by perf record to count written bytes before + * compression. + */ u64 bytes_transferred; + /** + * @bytes_compressed: Used by perf record to count written bytes after + * compression. + */ u64 bytes_compressed; + /** @zstd_data: Owner of global compression state, buffers, etc. */ struct zstd_data zstd_data; struct decomp_data decomp_data; struct decomp_data *active_decomp; --=20 2.46.0.295.g3b9ea8a38a-goog From nobody Sun Feb 8 01:31:03 2026 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 7B17F194C88 for ; Thu, 29 Aug 2024 15:02:19 +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=1724943740; cv=none; b=a+3hFtwfBSRokScNlQBc/uyZT9czpfztcNFXbMDDOKZrJ5Jt+MwNoyokM02o7JxdGRnS8sTcEuODekYpl7wKQ2iYyrB/og9+EHzmQE33+14sGgKJGIFLYOtbBQIZ4azKEmn4cJ2+jkqi85GH3HEkZ5LG9XJ/vU3fIJjvZJv1lvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943740; c=relaxed/simple; bh=nYv2bb7XfxKNsp6iwHeDKTU8xBSx4xj6FD8P1aDgmn8=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=pE81w33aYlalRvrrXe7V/P2CpRBNfQyPAer8rEyPK+etVe9LJEoj+erseCgY4doVLQu1sEs1CUg7lq2KpqpRXjrH/sNwIEgHn09n1OOHFnMWebqi+obACRGCOEFJFYYmt+S9593mncg2bWnuKvrVe+nvT1jYAfhx6/5nO8ksX1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WBB0GUsC; 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WBB0GUsC" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ad26d5b061so15501367b3.2 for ; Thu, 29 Aug 2024 08:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943738; x=1725548538; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=5M//MoxYK0AMxszDYFN10l0d6OyzAze+JY1w4Q9ZCo0=; b=WBB0GUsCEttr6p0XLWCo5ugJSCPTN0OJ+X3rJ1rpvEA9BIkMn79606RBmtmwQHndqu IPCYyWUQWiQMVc13ReC/e8ZYguzIWYOJ8NfMHzsmVzT1gP6U2TIigchmDvCxrfvNN1qy YeD2CsdfvyBMLDmRKpRJdYjmNUhNaXEnF9jYKnDg/uZQlj4Vt0f04VQZ5bfgVUBYhQuE /kLOTmGie6tkfPkJmE3nwKs7JLkCiF3NkWYFKzATQIOwHtsxEa8IkVYcKcs6Rd9vq2rd l8WNRUMWF9m0xExdHuBA2gRXvHHFyAm0n8/4f4x4K41V+ud9C15F5v+UndkUAMUX03QY +A7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943738; x=1725548538; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5M//MoxYK0AMxszDYFN10l0d6OyzAze+JY1w4Q9ZCo0=; b=FauXIpVJ8eGdkKiB36sSAtqYQBbuQlI/fX39IjHC3IPi2uzCkjJ2NI6kJpnfLVzGk/ YcuU50lE5bVKxIJSFgKD2xMytlwLyEzhRtJL0mE3JJ4vBkxxuGS4sUoVCOzvhTICTtNd Qp3xKNC2mQmqC76GXj/pgY4xLeQKCnr7S0iHIM877C29B92wDAfeRqC73Sx+/po0jV5k lwkPeBnv8YmqOcnMdJnt7LVyR/VI85K47xJXNCgHe/TY62PsElllGgUknMl1lAsc/YJ+ aRaZgFeztvIu1n2Ta+TmLomXQIklkxiNQrlY629Y/7vujWC0KviwbIWEjXZzyJUrCo5j k42g== X-Forwarded-Encrypted: i=1; AJvYcCUDs03y/XGLvHQeDW8aeLOLj2crBYBWSuAu7W5c5PJievn50533LcVo8uW3wR5lA7VYZqJwx3w4EAhd83A=@vger.kernel.org X-Gm-Message-State: AOJu0YwiCC8TgMD4AKUBJ21xd0rwZOQgFvz2wE8FMhrAt5SkoSfX3QhK gAyRWjt16rNRQJs28kE91Zdx2NzXmITVjDe+UmpsGN3vU8aGkvyTr2OYPHtCRIkJVQt/Hs0D8Vj My5U6xg== X-Google-Smtp-Source: AGHT+IHTmW8LfezKDBeNm1GiRh2MPaQCchyadCn8R7N6d4J0bgs53naPpqo8zLJglVVm2o8I/SAtbeInsOmc X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a81:f007:0:b0:64a:d1b0:4f24 with SMTP id 00721157ae682-6d2e93d5759mr637667b3.7.1724943738109; Thu, 29 Aug 2024 08:02:18 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:49 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 3/8] perf header: Add kerneldoc to perf_file_header From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some of the values are a little strange so add documentation to resolve ambiguity. Signed-off-by: Ian Rogers --- tools/perf/util/header.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 07ff647197ff..3285981948d7 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -61,14 +61,28 @@ struct perf_file_section { u64 size; }; =20 +/** + * struct perf_file_header: Header representation on disk. + */ struct perf_file_header { + /** @magic: Holds "PERFILE2". */ u64 magic; + /** @size: Size of this header - sizeof(struct perf_file_header). */ u64 size; + /** + * @attr_size: Size of attrs entries - sizeof(struct perf_event_attr) + + * sizeof(struct perf_file_section). + */ u64 attr_size; + /** @attrs: Offset and size of file section holding attributes. */ struct perf_file_section attrs; + /** @data: Offset and size of file section holding regular event data. */ struct perf_file_section data; - /* event_types is ignored */ + /** @event_types: Ignored. */ struct perf_file_section event_types; + /** + * @adds_features: Bitmap of features. The features are immediately after= the data section. + */ DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS); }; =20 --=20 2.46.0.295.g3b9ea8a38a-goog From nobody Sun Feb 8 01:31:03 2026 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 D53CF1B29AA for ; Thu, 29 Aug 2024 15:02:21 +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=1724943743; cv=none; b=L14uD0p1o7ULMklZfeODdBFKunnd8cjJ/LsTKLJaqXSliTJja3Afx2cu0LoGDL5Sv+LrZYo0XXE41tXyDifwIDBwjygnOyYRdkw/0w/E8mP2fXzsU0YOgLgNRbKLaVBovpMfnc5YxXog5UTRWdmlgxEt4DMJZmarUEorD+5hMeU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943743; c=relaxed/simple; bh=d8IwRgzU6IVwfT3fOB5yzVRUcKFqP32FXJTEN4UXaQc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=l6L9Zwt41QqzBEr/w/xN32S8MzGx8WcTQFZkgTGnFu5s+jkEDzwmwJ4SR4GdUtZn64Co2LX0uA3VOvFplCIjPPjpOtdwBSVvG6iYcBaL2yr28GZsnEd9nGMLOcw0q73QhXdv2UHliXPgwHBErPs4fNoxogvU3TKqr3QINqppnGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=QwdNzjPq; 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="QwdNzjPq" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e13cfd506b8so1214726276.0 for ; Thu, 29 Aug 2024 08:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943741; x=1725548541; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=hhwOndd672eQTsmeiahQCx8DV4+qjBSQD+DApZqBRQc=; b=QwdNzjPqpbrbNICxGyTlinbTLreCGYfWMpx1B0vArbVMIhl+DaUlkcFasV3dUwHSC6 w04dmyLmKD4jeDDYKWNGbcmeeIBJDe6TQDVZYfQNPgt0iSiRWKQtAJNnNrI76UVPF4DF RE4BSVqdEbYwoCEtEN4vgpfGfenkchXzt08WqyVVbnggpB4GHwxFQA1JbFCb0ftmYTxJ 8O/vrgdwm4dttSYAW6ZTpMLEDoAwNDcGW8aStX+k8vhWLj8qG9GUm16c7jjyu8DVpC9g yCG1/IK7xkC7haPH0kseB3DYPAbp916onYlikpns2Pay9IqLylqHUgDY1cvnz3VMdPny n3Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943741; x=1725548541; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hhwOndd672eQTsmeiahQCx8DV4+qjBSQD+DApZqBRQc=; b=o8KYGaVQU/XH9XbjUZzB8ShcXfVFtWsI9pDz+3mdNCnCR99uxvk2T3iy0FbX9RfRkt bL8H8wGvCco13gzAvWmWk0O8W5S9t3NQOeZg3hWrPptb+H2UaTaWBVT2UonCjfHcEd7A KJ7GqJnu6Y+sKAr8l/YrIDru1Emhp5tm8MPHDBI+tuzxZGEEicSBteqyzyd6Bi/CbfdI wtaMUPlmF/C6n51vjWaUdiBOkP4Hjv7OwtR8Ml0buKsEPrzGuLfaz1t5WCV2kCM7pslB l6R1F0NXa4WXRSmdKIlN71GEmEEG18QWkTFxBbcuXM19SiPMX/PWQF6EPBovvnH31vWE elag== X-Forwarded-Encrypted: i=1; AJvYcCXv3LqlaXVZTrRw1d/FZ9lmS6YsRpmdc9nHoqtjMCJA1FA5F3GpoiJic9GwNnhoTXE3a/NzMUBtQRQZ2r8=@vger.kernel.org X-Gm-Message-State: AOJu0YzsH9RYOsYaian/A4ZIhqf/2e94sqPOOissHpBkbdBzXfjmEKTw qNSK3ZXEqK0cq8AZOLFKICdLJIARF5YZsjAxIfGbQR2DKAEA9rNqjgtVn7xPkFsUHzQ/W2D9znX SbO06Jw== X-Google-Smtp-Source: AGHT+IGanMcnYgYr5sBz7VZyu73qNQxkHIbx4GJrBetIEyCLMHA+YYkqVY2DAscY/rtVLupMJi2rIh4g1d8n X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a25:7cc4:0:b0:e11:69f2:e39 with SMTP id 3f1490d57ef6-e1a5adee523mr37264276.9.1724943740764; Thu, 29 Aug 2024 08:02:20 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:50 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 4/8] perf header: Fail read if header sections overlap From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Buggy perf.data files can have the attributes and data overlapping. For example, when processing pipe data the attributes aren't known and so file offset header calculations can consider them not present. Later this can cause the attributes to overwrite the data. This can be seen in: ``` $ perf record -o - true > a.data [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.059 MB - ] $ perf inject -i a.data -o b.data $ perf report --stats -i b.data 0x68 [0]: failed to process type: 510379 [Invalid argument] Error: failed to process sample ``` This change makes reading the corrupt file fail: ``` $ perf report --stats -i b.data Perf file header corrupt: Attributes and data overlap incompatible file format (rerun with -v to learn more) ``` Which is more informative. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 3309fe7f1d12..65c9086610cb 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3986,6 +3986,24 @@ int perf_file_header__read(struct perf_file_header *= header, adds_features)); } =20 + if (header->size > header->attrs.offset) { + pr_err("Perf file header corrupt: header overlaps attrs\n"); + return -1; + } + + if (header->size > header->data.offset) { + pr_err("Perf file header corrupt: header overlaps data\n"); + return -1; + } + + if ((header->attrs.offset <=3D header->data.offset && + header->attrs.offset + header->attrs.size > header->data.offset) || + (header->attrs.offset > header->data.offset && + header->data.offset + header->data.size > header->attrs.offset)) { + pr_err("Perf file header corrupt: Attributes and data overlap\n"); + return -1; + } + if (header->size !=3D sizeof(*header)) { /* Support the previous format */ if (header->size =3D=3D offsetof(typeof(*header), adds_features)) --=20 2.46.0.295.g3b9ea8a38a-goog From nobody Sun Feb 8 01:31:03 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 EDBE71B3749 for ; Thu, 29 Aug 2024 15:02:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943746; cv=none; b=CLdHjCaFvebJYkXXnEmWCZJ9VTN/HERD1ujpoczOLKYNK0wsSPsMfSGureuYx1KF0DxeaPCsNxQkVw47G5Sxg84RNwZ+bHz3dKO3TdiijkjONLXBe5EgY5hUUXpitZh9ZDUMCCyqT+pw3Yccn2vAHoGTocDnO9tIwdnYL+JHilU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943746; c=relaxed/simple; bh=GEZaiWDFK631P0mdzERneiwEQkphONO54D8rmpn8U7M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=jETO4U7YehP8cOiktfrd80cFJr2QY45AfHCLJS37QAkBUSj8iUgqQvq67E/DPcvUddCI2BtqM8ebexu4MnX+FVAKuUmrkNMpT2eX1bfYPQCojQhqsgmGeJovuMZNXZRBzvr0tAox/Lux4fCVirJaFM6O1lWncJWn1M6ciBSR4QM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=UkN0ZfPf; arc=none smtp.client-ip=209.85.128.202 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="UkN0ZfPf" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6b8f13f2965so16081707b3.1 for ; Thu, 29 Aug 2024 08:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943743; x=1725548543; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=0ZFjdHl5ndv6dmHla3qSadBH36kVYzFr068YdbI0Xhc=; b=UkN0ZfPfhivQt+dElQp5KI1X+v177mKUylrH3SkPlYK0o9AjO437p5vGHtXl7RhnTN UjuPBtTxtBxsMMmDjb0VICTE/RQvKUhgrXSJPnncgDi07lg7kS3Zy/cuxwgBLNOHi9eu 4R9f+4Jy8woPnvaRBORppW5hFuXrFMr8u4FNuK2tyfKgQb9ce4xgjhVd4kUeFkw7QtLg 08llz/5Nz3uPGhbbny2QOhRG2SDSFqNmTY+NsGTtInTH3bfH/Tq7cuMCLfXADy15Mknx D74zSl+GEXwCD9tmyg11sHUJI9EHVSraZmB5XQTLun6u+mky1J+hZPGn0f1jCWhK84Vj iceQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943743; x=1725548543; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0ZFjdHl5ndv6dmHla3qSadBH36kVYzFr068YdbI0Xhc=; b=YZwXBhakCAnUgTaB/mbORPg96+whXLKMIA+Ua8mfnwbCPBCkukoAFwJ0oPk+xQ8kRs bHFNxMmjVhapJrRe9xvZbu2MwgDIkyA4+oQ1UEg+dY6mmXzMrp7BdC2yPBYrOEs4kpeP M+rg40k5nVt7fVniLy4dTSb/4QmiZJtuFyNZ05NomBXEbUnKUaN1txZZGnYP3pK3bSN2 ZlX6zSjuT+wsMKWxZ9Vu2bvMkeASqkkkyrvVBkssAvFtm3mW0s3mj28CNop7oz3IxPQ3 10WhwnxsNStwY7z0iNtf4PQ6fYWCY7p/rF6NKtWUDtrEl4UzR86PztgcnEKL1V0qgCTw Cq0A== X-Forwarded-Encrypted: i=1; AJvYcCWS085WCJrdh1Dif84zSNO1yCZVGbZYH85KrSJNp5IMDiuY+LXdC/fgjEmSfscEAsUZIBYVLoKxpfaEBRg=@vger.kernel.org X-Gm-Message-State: AOJu0YwzMnfI2HrrA/WdDAN/2VHqGxUUEBV589guJ7UoIVrt2UeOlefG iV/3bGeDnTgDPTGaXgC/u5xkb1Kito3yfzvU5iI4PssbvB7EK+DoxOmaqovZnuih/kJeSbV3Ikk hNfrXmQ== X-Google-Smtp-Source: AGHT+IEELMgnHZPPq1sGI0nkDr7BeKf8/zF6d4T6auMfStXzWs7I1S1Gxz4SLdE2SrLgnG9r095oYxv3xZYe X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a05:690c:6301:b0:68e:8de6:618b with SMTP id 00721157ae682-6d2e6f712dcmr1417277b3.2.1724943743131; Thu, 29 Aug 2024 08:02:23 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:51 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 5/8] perf header: Allow attributes to be written after data From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With a file, to write data an offset needs to be known. Typically data follows the event attributes in a file. However, if processing a pipe the number of event attributes may not be known. It is convenient in that case to write the attributes after the data. Expand perf_session__do_write_header to allow this when the data offset and size are known. This approach may be useful for more than just taking a pipe file to write into a data file, `perf inject --itrace` will reserve and additional 8kb for attributes, which would be unnecessary if the attributes were written after the data. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 106 +++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 65c9086610cb..4eb39463067e 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3676,32 +3676,50 @@ int perf_header__write_pipe(int fd) static int perf_session__do_write_header(struct perf_session *session, struct evlist *evlist, int fd, bool at_exit, - struct feat_copier *fc) + struct feat_copier *fc, + bool write_attrs_after_data) { struct perf_file_header f_header; - struct perf_file_attr f_attr; struct perf_header *header =3D &session->header; struct evsel *evsel; struct feat_fd ff =3D { .fd =3D fd, }; - u64 attr_offset; + u64 attr_offset =3D sizeof(f_header), attr_size =3D 0; int err; =20 - lseek(fd, sizeof(f_header), SEEK_SET); + if (write_attrs_after_data && at_exit) { + /* + * Write features at the end of the file first so that + * attributes may come after them. + */ + if (!header->data_offset && header->data_size) { + pr_err("File contains data but offset unknown\n"); + err =3D -1; + goto err_out; + } + header->feat_offset =3D header->data_offset + header->data_size; + err =3D perf_header__adds_write(header, evlist, fd, fc); + if (err < 0) + goto err_out; + attr_offset =3D lseek(fd, 0, SEEK_CUR); + } else { + lseek(fd, attr_offset, SEEK_SET); + } =20 evlist__for_each_entry(session->evlist, evsel) { - evsel->id_offset =3D lseek(fd, 0, SEEK_CUR); - err =3D do_write(&ff, evsel->core.id, evsel->core.ids * sizeof(u64)); - if (err < 0) { - pr_debug("failed to write perf header\n"); - free(ff.buf); - return err; + evsel->id_offset =3D attr_offset; + /* Avoid writing at the end of the file until the session is exiting. */ + if (!write_attrs_after_data || at_exit) { + err =3D do_write(&ff, evsel->core.id, evsel->core.ids * sizeof(u64)); + if (err < 0) { + pr_debug("failed to write perf header\n"); + goto err_out; + } } + attr_offset +=3D evsel->core.ids * sizeof(u64); } =20 - attr_offset =3D lseek(ff.fd, 0, SEEK_CUR); - evlist__for_each_entry(evlist, evsel) { if (evsel->core.attr.size < sizeof(evsel->core.attr)) { /* @@ -3711,40 +3729,46 @@ static int perf_session__do_write_header(struct per= f_session *session, */ evsel->core.attr.size =3D sizeof(evsel->core.attr); } - f_attr =3D (struct perf_file_attr){ - .attr =3D evsel->core.attr, - .ids =3D { - .offset =3D evsel->id_offset, - .size =3D evsel->core.ids * sizeof(u64), + /* Avoid writing at the end of the file until the session is exiting. */ + if (!write_attrs_after_data || at_exit) { + struct perf_file_attr f_attr =3D { + .attr =3D evsel->core.attr, + .ids =3D { + .offset =3D evsel->id_offset, + .size =3D evsel->core.ids * sizeof(u64), + } + }; + err =3D do_write(&ff, &f_attr, sizeof(f_attr)); + if (err < 0) { + pr_debug("failed to write perf header attribute\n"); + goto err_out; } - }; - err =3D do_write(&ff, &f_attr, sizeof(f_attr)); - if (err < 0) { - pr_debug("failed to write perf header attribute\n"); - free(ff.buf); - return err; } + attr_size +=3D sizeof(struct perf_file_attr); } =20 - if (!header->data_offset) - header->data_offset =3D lseek(fd, 0, SEEK_CUR); + if (!header->data_offset) { + if (write_attrs_after_data) + header->data_offset =3D sizeof(f_header); + else + header->data_offset =3D attr_offset + attr_size; + } header->feat_offset =3D header->data_offset + header->data_size; =20 - if (at_exit) { + if (!write_attrs_after_data && at_exit) { + /* Write features now feat_offset is known. */ err =3D perf_header__adds_write(header, evlist, fd, fc); - if (err < 0) { - free(ff.buf); - return err; - } + if (err < 0) + goto err_out; } =20 f_header =3D (struct perf_file_header){ .magic =3D PERF_MAGIC, .size =3D sizeof(f_header), - .attr_size =3D sizeof(f_attr), + .attr_size =3D sizeof(struct perf_file_attr), .attrs =3D { .offset =3D attr_offset, - .size =3D evlist->core.nr_entries * sizeof(f_attr), + .size =3D attr_size, }, .data =3D { .offset =3D header->data_offset, @@ -3757,21 +3781,24 @@ static int perf_session__do_write_header(struct per= f_session *session, =20 lseek(fd, 0, SEEK_SET); err =3D do_write(&ff, &f_header, sizeof(f_header)); - free(ff.buf); if (err < 0) { pr_debug("failed to write perf header\n"); - return err; + goto err_out; + } else { + lseek(fd, 0, SEEK_END); + err =3D 0; } - lseek(fd, header->data_offset + header->data_size, SEEK_SET); - - return 0; +err_out: + free(ff.buf); + return err; } =20 int perf_session__write_header(struct perf_session *session, struct evlist *evlist, int fd, bool at_exit) { - return perf_session__do_write_header(session, evlist, fd, at_exit, NULL); + return perf_session__do_write_header(session, evlist, fd, at_exit, /*fc= =3D*/NULL, + /*write_attrs_after_data=3D*/false); } =20 size_t perf_session__data_offset(const struct evlist *evlist) @@ -3793,7 +3820,8 @@ int perf_session__inject_header(struct perf_session *= session, int fd, struct feat_copier *fc) { - return perf_session__do_write_header(session, evlist, fd, true, fc); + return perf_session__do_write_header(session, evlist, fd, true, fc, + /*write_attrs_after_data=3D*/false); } =20 static int perf_header__getbuffer64(struct perf_header *header, --=20 2.46.0.295.g3b9ea8a38a-goog From nobody Sun Feb 8 01:31:03 2026 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 81E101B3759 for ; Thu, 29 Aug 2024 15:02:26 +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=1724943748; cv=none; b=aJg5jghfBgQc0HcWIYtAgVUAyhRYooLmp6CDH4GjN+nYb6j9UVTKMBVuF1TcPNzd8MrkWLlXPFf84rMPsw3vlqRMjfZcNIRiDxupvdbjeLmDWHwS9FKmMzj/UnNpYb4Alo3jtTyVDofbVW5OzTIURvzkjIz/1y25Y75kdwRJA/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943748; c=relaxed/simple; bh=XEt4LkPY8g7kYpF4m+pCtB85oOCHt9StmaLcp91SEtw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=kvJERM31tvvY39Wz43+tqN1Om7AkuBpcV7fuieK2TUniAB8aeG1++UJ9l+YV57xVJwMZ03zi4bxno+F9PZBlUUGVlt+oBuFhCa8QQpx/YNJECYSAQ0wZMVzMYrxD2xB8k8XM4SjXPp3SMRREr3CWOGmdsKGut9s4BqAxkjbABgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yIZjmTqL; 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yIZjmTqL" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6b46d8bc153so14747707b3.2 for ; Thu, 29 Aug 2024 08:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943745; x=1725548545; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=NDNxrcM0EUMB3Iw+/h0y6gDA4czLmrnPsI6Mf401mUY=; b=yIZjmTqLY+aZKn03nS5iQwGqA3JizPMHZKfaYHcybzS2iaKrwge0aC+7tLSOIQ6S3e 8qhVoaasNj/s+1wSNMUZUEqwHeMqaqU/8z4IM2D9cYbikQe8R9EBgDx5ulOAOYNVQY2t 98rZC2n1P4I5Qvk9YZ6nnLs/4AvqE4+Dx3LYT90l1ISY0Sb68Yew1MGvSQqwixZuvQT0 0mxIut1BpN+o1wpq+I4BpOOGwA0hM8CSbMwcUchM4xnvi58vdmNTXCBKSjkt52AqsbY/ dUYUrlgYNBqDcE0oxTf9JxQDxioJgg2/6Q8zZXfHB7a2ERSEwdC5nYOsy2eo/u90LR01 klXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943745; x=1725548545; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NDNxrcM0EUMB3Iw+/h0y6gDA4czLmrnPsI6Mf401mUY=; b=FlIjooXqjjQj2T+jwx0CkfCV/qaeX5/Az2jVsJFL2Bf7ofRBHEc4cT3F4+u0Tds/x4 TFCx2D3GnDchNm7GwxgroYfePAwSd78NyKn02yDhuTzO67DrSfyYzkX9MqXEgFq/L9+i 2RaFH876m2EZXvNlcyit7Vb1ggIikuznNq8RKT+iS7a/dWO6mOvxFIKyWk/0uYockVv/ Ujpiv6HncLBxXlMhm64uDkl9c2QxlHcmwOp0eZChR50hxp0AZdJ8GMQzGjBKOskb/uEg aIic2/QjQ8ZdvedILzzHwV+yZS6Aqh7DjMzc8hitG14LmvtX6OQjEknQVwXwHe9Xehwo /p4w== X-Forwarded-Encrypted: i=1; AJvYcCXZUhCt28pL24xvK3feUsduOlFTkgBvgIaKfoX4LO6W7rUsQXJjHaf+vZ7AXJWIYKZCsOt2jOuLQgUaO/M=@vger.kernel.org X-Gm-Message-State: AOJu0YxbXFD23X+dTIIMFQdT5ZUF/Y5PpL9LVswibt+Vh7GxT+VBSR/m AVvD+6o50ieNsd5ibBH3p0rva+RAEN8Z5QNhTDGYsBhK/XBUBDOdTkl7zGsIolSeSjU2A4hPiF6 fTMsZGA== X-Google-Smtp-Source: AGHT+IFi/0lV0K5vG/SObdV0BxBNjai9T/mcyyzfKgNXUXkyczFL7DKJTH4orXG7YDc2Z+USGMFzQXrORDDf X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a0d:f3c1:0:b0:68d:52a1:be9 with SMTP id 00721157ae682-6d2e6d839bbmr191697b3.1.1724943745481; Thu, 29 Aug 2024 08:02:25 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:52 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 6/8] perf inject: Overhaul handling of pipe files From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously inject->is_pipe was set if the input or output were a pipe. Determining the input was a pipe had to be done prior to starting the session and opening the file. This was done by comparing the input file name with '-' but it fails if the pipe file is written to disk. Opening a pipe file from disk will correcrtly set perf_data.is_pipe, but this is too late for perf inject and results in a broken file. A workaround is 'cat pipe_perf|perf inject -i - ...'. This change removes inject->is_pipe and changes the dependent conditions to use the is_pipe flag on the input (inject->session->data) and output files (inject->output). This ensures the is_pipe condition reflects things like the header being read. The change removes the use of perf file header repiping, that is writing the file header out while reading it in. The case of input pipe and output file cannot repipe as the attributes for the file are unknown. To resolve this, write the file header when writing to disk and as the attributes may be unknown, write them after the data. Update sessions repipe variable to be trace_event_repipe as those are the only events now impacted by it. Update __perf_session__new as the repipe_fd no longer needs passing. Fully removing repipe from session header reading will be done in a later change. Signed-off-by: Ian Rogers --- tools/perf/builtin-inject.c | 60 +++++++++++++++++++------------------ tools/perf/util/header.c | 12 ++++---- tools/perf/util/header.h | 3 +- tools/perf/util/session.c | 8 ++--- tools/perf/util/session.h | 14 ++++----- 5 files changed, 48 insertions(+), 49 deletions(-) diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c index a7c859db2e15..0ccf80fe8399 100644 --- a/tools/perf/builtin-inject.c +++ b/tools/perf/builtin-inject.c @@ -119,7 +119,6 @@ struct perf_inject { bool jit_mode; bool in_place_update; bool in_place_update_dry_run; - bool is_pipe; bool copy_kcore_dir; const char *input_name; struct perf_data output; @@ -205,7 +204,8 @@ static int perf_event__repipe_attr(const struct perf_to= ol *tool, if (ret) return ret; =20 - if (!inject->is_pipe) + /* If the output isn't a pipe then the attributes will be written as part= of the header. */ + if (!inject->output.is_pipe) return 0; =20 return perf_event__repipe_synth(tool, event); @@ -1966,7 +1966,13 @@ static int __cmd_inject(struct perf_inject *inject) struct guest_session *gs =3D &inject->guest_session; struct perf_session *session =3D inject->session; int fd =3D output_fd(inject); - u64 output_data_offset; + u64 output_data_offset =3D perf_session__data_offset(session->evlist); + /* + * Pipe input hasn't loaded the attributes and will handle them as + * events. So that the attributes don't overlap the data, write the + * attributes after the data. + */ + bool write_attrs_after_data =3D !inject->output.is_pipe && inject->sessio= n->data->is_pipe; =20 signal(SIGINT, sig_handler); =20 @@ -1980,8 +1986,6 @@ static int __cmd_inject(struct perf_inject *inject) #endif } =20 - output_data_offset =3D perf_session__data_offset(session->evlist); - if (inject->build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { inject->tool.sample =3D perf_event__inject_buildid; } else if (inject->sched_stat) { @@ -2075,7 +2079,7 @@ static int __cmd_inject(struct perf_inject *inject) if (!inject->itrace_synth_opts.set) auxtrace_index__free(&session->auxtrace_index); =20 - if (!inject->is_pipe && !inject->in_place_update) + if (!inject->output.is_pipe && !inject->in_place_update) lseek(fd, output_data_offset, SEEK_SET); =20 ret =3D perf_session__process_events(session); @@ -2094,7 +2098,7 @@ static int __cmd_inject(struct perf_inject *inject) } } =20 - if (!inject->is_pipe && !inject->in_place_update) { + if (!inject->output.is_pipe && !inject->in_place_update) { struct inject_fc inj_fc =3D { .fc.copy =3D feat_copy_cb, .inject =3D inject, @@ -2124,7 +2128,8 @@ static int __cmd_inject(struct perf_inject *inject) } session->header.data_offset =3D output_data_offset; session->header.data_size =3D inject->bytes_written; - perf_session__inject_header(session, session->evlist, fd, &inj_fc.fc); + perf_session__inject_header(session, session->evlist, fd, &inj_fc.fc, + write_attrs_after_data); =20 if (inject->copy_kcore_dir) { ret =3D copy_kcore_dir(inject); @@ -2161,7 +2166,6 @@ int cmd_inject(int argc, const char **argv) .use_stdio =3D true, }; int ret; - bool repipe =3D true; const char *known_build_ids =3D NULL; bool build_ids; bool build_id_all; @@ -2273,16 +2277,7 @@ int cmd_inject(int argc, const char **argv) inject.build_id_style =3D BID_RWS__INJECT_HEADER_ALL; =20 data.path =3D inject.input_name; - if (!strcmp(inject.input_name, "-") || inject.output.is_pipe) { - inject.is_pipe =3D true; - /* - * Do not repipe header when input is a regular file - * since either it can rewrite the header at the end - * or write a new pipe header. - */ - if (strcmp(inject.input_name, "-")) - repipe =3D false; - } + ordered_events =3D inject.jit_mode || inject.sched_stat || (inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY); perf_tool__init(&inject.tool, ordered_events); @@ -2325,9 +2320,9 @@ int cmd_inject(int argc, const char **argv) inject.tool.compressed =3D perf_event__repipe_op4_synth; inject.tool.auxtrace =3D perf_event__repipe_auxtrace; inject.tool.dont_split_sample_group =3D true; - inject.session =3D __perf_session__new(&data, repipe, - output_fd(&inject), - &inject.tool); + inject.session =3D __perf_session__new(&data, &inject.tool, + /*trace_event_repipe=3D*/inject.output.is_pipe); + if (IS_ERR(inject.session)) { ret =3D PTR_ERR(inject.session); goto out_close_output; @@ -2341,19 +2336,26 @@ int cmd_inject(int argc, const char **argv) if (ret) goto out_delete; =20 - if (!data.is_pipe && inject.output.is_pipe) { + if (inject.output.is_pipe) { ret =3D perf_header__write_pipe(perf_data__fd(&inject.output)); if (ret < 0) { pr_err("Couldn't write a new pipe header.\n"); goto out_delete; } =20 - ret =3D perf_event__synthesize_for_pipe(&inject.tool, - inject.session, - &inject.output, - perf_event__repipe); - if (ret < 0) - goto out_delete; + /* + * If the input is already a pipe then the features and + * attributes don't need synthesizing, they will be present in + * the input. + */ + if (!data.is_pipe) { + ret =3D perf_event__synthesize_for_pipe(&inject.tool, + inject.session, + &inject.output, + perf_event__repipe); + if (ret < 0) + goto out_delete; + } } =20 if (inject.build_id_style =3D=3D BID_RWS__INJECT_HEADER_LAZY) { diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 4eb39463067e..59e2f37c1cb4 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3818,10 +3818,11 @@ size_t perf_session__data_offset(const struct evlis= t *evlist) int perf_session__inject_header(struct perf_session *session, struct evlist *evlist, int fd, - struct feat_copier *fc) + struct feat_copier *fc, + bool write_attrs_after_data) { return perf_session__do_write_header(session, evlist, fd, true, fc, - /*write_attrs_after_data=3D*/false); + write_attrs_after_data); } =20 static int perf_header__getbuffer64(struct perf_header *header, @@ -4145,7 +4146,7 @@ static int perf_header__read_pipe(struct perf_session= *session, int repipe_fd) struct perf_pipe_file_header f_header; =20 if (perf_file_header__read_pipe(&f_header, header, session->data, - session->repipe, repipe_fd) < 0) { + /*repipe=3D*/false, repipe_fd) < 0) { pr_debug("incompatible file format\n"); return -EINVAL; } @@ -4560,15 +4561,14 @@ int perf_event__process_tracing_data(struct perf_se= ssion *session, SEEK_SET); } =20 - size_read =3D trace_report(fd, &session->tevent, - session->repipe); + size_read =3D trace_report(fd, &session->tevent, session->trace_event_rep= ipe); padding =3D PERF_ALIGN(size_read, sizeof(u64)) - size_read; =20 if (readn(fd, buf, padding) < 0) { pr_err("%s: reading input file", __func__); return -1; } - if (session->repipe) { + if (session->trace_event_repipe) { int retw =3D write(STDOUT_FILENO, buf, padding); if (retw <=3D 0 || retw !=3D padding) { pr_err("%s: repiping tracing data padding", __func__); diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 3285981948d7..7137509cf6d8 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -150,7 +150,8 @@ struct feat_copier { int perf_session__inject_header(struct perf_session *session, struct evlist *evlist, int fd, - struct feat_copier *fc); + struct feat_copier *fc, + bool write_attrs_after_data); =20 size_t perf_session__data_offset(const struct evlist *evlist); =20 diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index d2bd563119bc..23449d01093a 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -135,8 +135,8 @@ static int ordered_events__deliver_event(struct ordered= _events *oe, } =20 struct perf_session *__perf_session__new(struct perf_data *data, - bool repipe, int repipe_fd, - struct perf_tool *tool) + struct perf_tool *tool, + bool trace_event_repipe) { int ret =3D -ENOMEM; struct perf_session *session =3D zalloc(sizeof(*session)); @@ -144,7 +144,7 @@ struct perf_session *__perf_session__new(struct perf_da= ta *data, if (!session) goto out; =20 - session->repipe =3D repipe; + session->trace_event_repipe =3D trace_event_repipe; session->tool =3D tool; session->decomp_data.zstd_decomp =3D &session->zstd_data; session->active_decomp =3D &session->decomp_data; @@ -162,7 +162,7 @@ struct perf_session *__perf_session__new(struct perf_da= ta *data, session->data =3D data; =20 if (perf_data__is_read(data)) { - ret =3D perf_session__open(session, repipe_fd); + ret =3D perf_session__open(session, /*repipe_fd=3D*/-1); if (ret < 0) goto out_delete; =20 diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index e56518639711..bcf1bcf06959 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -59,12 +59,8 @@ struct perf_session { #endif /** @time_conv: Holds contents of last PERF_RECORD_TIME_CONV event. */ struct perf_record_time_conv time_conv; - /** - * @repipe: When set causes certain reading (header and trace events) to - * also write events. The written file descriptor must be provided for - * the header but is implicitly stdout for trace events. - */ - bool repipe; + /** @trace_event_repipe: When set causes read trace events to be written = to stdout. */ + bool trace_event_repipe; /** * @one_mmap: The reader will use a single mmap by default. There may be * multiple data files in particular for aux events. If this is true @@ -110,13 +106,13 @@ struct decomp { struct perf_tool; =20 struct perf_session *__perf_session__new(struct perf_data *data, - bool repipe, int repipe_fd, - struct perf_tool *tool); + struct perf_tool *tool, + bool trace_event_repipe); =20 static inline struct perf_session *perf_session__new(struct perf_data *dat= a, struct perf_tool *tool) { - return __perf_session__new(data, false, -1, tool); + return __perf_session__new(data, tool, /*trace_event_repipe=3D*/false); } =20 void perf_session__delete(struct perf_session *session); --=20 2.46.0.295.g3b9ea8a38a-goog From nobody Sun Feb 8 01:31:03 2026 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 4AA7C1B3B1E for ; Thu, 29 Aug 2024 15:02:28 +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=1724943749; cv=none; b=LyaNpEmBx+6YWbh97uvN1fq1J5lo3wn9JDMAIp/uDg9+/UYgQq+Osw8CrThtg794A6cT58WmJiNFLa36CIk7uuY/kea20AVBJxuTASfSv4YQ3gzr2mS7LS+EipVAe8X203F9ICTICsjsjeu7R7nkyy2j+fMnTM8PxbI3kx/S9I4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943749; c=relaxed/simple; bh=BtmlMrMAHzQZUpmltBgdlhBhq2zYxwAKCQUSA4rmo2g=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Q91qyai99X3xaiRGqCD/692SwBh/g9qyEqqVdSAcHy4TOviH86jxRkQgEblSuqcmKYM3SvIZ0u4SCu4ZdmclsURw18jekov1BZKvesGJNABAT4hNDEdpgJH4dn/A+sfBnZnNbf8HYPHOWdlnHtxpzoaxdyf630W1m9yk80Sonkw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=z5oNuDS7; 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="z5oNuDS7" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6d34c57a88eso6440887b3.0 for ; Thu, 29 Aug 2024 08:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943747; x=1725548547; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=zLDviNvuuZGMvTdlOAKtIuEnHhCZdbVpbH4SWUDE26w=; b=z5oNuDS7F98V0xuO+9yhd4e1FsIrneYbBnVYAYSrmJ/nXxtLN1K3grq7V5BRN3glSL GeDioxahrlMGB0Zm+HxEPMAHHngCrGdFCGBF+siDbm+UzFFDJvMJtKuMv2S44FRoCQyP a6EfD7Q5Opyt/egOxRSbW0/RRkYeWfWorQM3FY3OpO3fsosnMDiTD2XDvyuFWu7uLn2V 16jf6ewvrliH7fqtXJCbjbyqxPGD/JETaEwpGnpUF0YWmLvGJxKE1cGaVFi1KYaOCjkF 22Ml1PjOzVJ8xwbIe8Np3G7hBRrwm8UdnBleFRAZYBxLdMMCzCx/KkPHw+9pTvEwfnL+ vn+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943747; x=1725548547; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zLDviNvuuZGMvTdlOAKtIuEnHhCZdbVpbH4SWUDE26w=; b=X+04AtM47xBCQGGEXGRo2lscKfDPhHUomG85iSsyJCxT75Y088Tgw+8+rzNkkOZoTw YsQ6vL3FzQ7SbrcnUkUSY0mTKqwsv7jLDOMVv9HgIkD5xXVKGOaWoRFzhSPA4ISBCTSH hSL7isF9425YAi4BBt3p5e/2qARKyBquSt6PGc3uaGznxK8RhN3VYfy+hoFivfHtqfWZ 9WTMfY3/yUs8kQEdkA5twXYSyIrn+qqq6ZBx0ZNq+bUdBNPT5lbyi/JQkeHrrwpD2mrm kN7E7sHcWtJkcGtXPzsxqz2NEWLtLHVHErCeMvyGY2fsBPHFtfYJ/fnnEmJC1EH45EI3 V2wg== X-Forwarded-Encrypted: i=1; AJvYcCU35dke9zDS3Znc4EfLmx3ZBvtTfyhtqv3Sj7xo2oRxhfPKV/EkxcR4isBLuX0E2qvJ15SuqRC3Sbv+eyk=@vger.kernel.org X-Gm-Message-State: AOJu0YzZeNNBvATe655rJAnqAaF+fbzcncNfmlWzQY7AqBS5TwhF93sd zyYAp2KQeTQlx5OgpSWz/Egez+lPRGGYbj6PQ8xC2/K2Qk4P0w03vQtSYozxgGhiyGCzXRCTbBJ G3aZXlg== X-Google-Smtp-Source: AGHT+IGwsMKtEw0yeh+uAV4sy4WEt9ZJVXFDo6115QZAyihbKw+75lOKL3DGWFgr6WL0lHHspaVfE7SuoQHu X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a05:690c:6305:b0:680:cd2b:90ed with SMTP id 00721157ae682-6d2e745b27amr434437b3.3.1724943747495; Thu, 29 Aug 2024 08:02:27 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:53 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 7/8] perf header: Remove repipe option From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" No longer used by `perf inject` the repipe_fd is always -1 and repipe is always false. Remove the options and associated code knowing the constant values of the removed variables. Signed-off-by: Ian Rogers --- tools/perf/util/header.c | 19 +++++-------------- tools/perf/util/header.h | 2 +- tools/perf/util/session.c | 6 +++--- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 59e2f37c1cb4..a6386d12afd7 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -4113,13 +4113,8 @@ static int perf_file_section__process(struct perf_fi= le_section *section, =20 static int perf_file_header__read_pipe(struct perf_pipe_file_header *heade= r, struct perf_header *ph, - struct perf_data* data, - bool repipe, int repipe_fd) + struct perf_data *data) { - struct feat_fd ff =3D { - .fd =3D repipe_fd, - .ph =3D ph, - }; ssize_t ret; =20 ret =3D perf_data__read(data, header, sizeof(*header)); @@ -4134,19 +4129,15 @@ static int perf_file_header__read_pipe(struct perf_= pipe_file_header *header, if (ph->needs_swap) header->size =3D bswap_64(header->size); =20 - if (repipe && do_write(&ff, header, sizeof(*header)) < 0) - return -1; - return 0; } =20 -static int perf_header__read_pipe(struct perf_session *session, int repipe= _fd) +static int perf_header__read_pipe(struct perf_session *session) { struct perf_header *header =3D &session->header; struct perf_pipe_file_header f_header; =20 - if (perf_file_header__read_pipe(&f_header, header, session->data, - /*repipe=3D*/false, repipe_fd) < 0) { + if (perf_file_header__read_pipe(&f_header, header, session->data) < 0) { pr_debug("incompatible file format\n"); return -EINVAL; } @@ -4246,7 +4237,7 @@ static int evlist__prepare_tracepoint_events(struct e= vlist *evlist, struct tep_h } #endif =20 -int perf_session__read_header(struct perf_session *session, int repipe_fd) +int perf_session__read_header(struct perf_session *session) { struct perf_data *data =3D session->data; struct perf_header *header =3D &session->header; @@ -4267,7 +4258,7 @@ int perf_session__read_header(struct perf_session *se= ssion, int repipe_fd) * We can read 'pipe' data event from regular file, * check for the pipe header regardless of source. */ - err =3D perf_header__read_pipe(session, repipe_fd); + err =3D perf_header__read_pipe(session); if (!err || perf_data__is_pipe(data)) { data->is_pipe =3D true; return err; diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h index 7137509cf6d8..a63a361f20f4 100644 --- a/tools/perf/util/header.h +++ b/tools/perf/util/header.h @@ -131,7 +131,7 @@ union perf_event; =20 extern const char perf_version_string[]; =20 -int perf_session__read_header(struct perf_session *session, int repipe_fd); +int perf_session__read_header(struct perf_session *session); int perf_session__write_header(struct perf_session *session, struct evlist *evlist, int fd, bool at_exit); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 23449d01093a..578010be046b 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -45,11 +45,11 @@ static int perf_session__deliver_event(struct perf_sess= ion *session, u64 file_offset, const char *file_path); =20 -static int perf_session__open(struct perf_session *session, int repipe_fd) +static int perf_session__open(struct perf_session *session) { struct perf_data *data =3D session->data; =20 - if (perf_session__read_header(session, repipe_fd) < 0) { + if (perf_session__read_header(session) < 0) { pr_err("incompatible file format (rerun with -v to learn more)\n"); return -1; } @@ -162,7 +162,7 @@ struct perf_session *__perf_session__new(struct perf_da= ta *data, session->data =3D data; =20 if (perf_data__is_read(data)) { - ret =3D perf_session__open(session, /*repipe_fd=3D*/-1); + ret =3D perf_session__open(session); if (ret < 0) goto out_delete; =20 --=20 2.46.0.295.g3b9ea8a38a-goog From nobody Sun Feb 8 01:31:03 2026 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 6C3261B3F1C for ; Thu, 29 Aug 2024 15:02:30 +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=1724943751; cv=none; b=HrEN3Zj9yiXFkq4Jq0rwKaquQvezhC0QhlpxmGLIOCdRje7zuZcr+wQcWtYPKnJMjZIj4jle7Zx8qJIqi1HCLfGO0SUJDFD4inOm+cyKMSFtKQddDyMeoT1OmHYqn4e09+5Fm0gt2B8Nrxrx1HOo5SoeAGdRG7mvAEdfU1o1yLw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724943751; c=relaxed/simple; bh=6JtjT923jGc/V3FlUSejai1b0EYlPO9Lq7KBqzesy7A=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=aHQEyqANwZXhCfMSlHVAQibdwfpq+Og1oi0hij/ad93uRKuiiJOGkgy178nEIFEwIFv+l5MDHhumGpVdvlj8rCoPusKBkZ/1j+ZXJI+2Oao0EChfVK5z88xE0W3AA4NAKM+joLcECyD7wODJ3/QhnVWFn0f+xrMjnkU38U4s0TU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WQsyUIEa; 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--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WQsyUIEa" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e163641feb9so1742293276.0 for ; Thu, 29 Aug 2024 08:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724943749; x=1725548549; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Av0NGxXt1nyH9OnYaW8cLl1uNekiq9nEwkTz2fTJczM=; b=WQsyUIEadsJZNsHIriKVcJWmcDgeCjycIXmi7h2/XNl108Dm3DWiKJGEUSmHHpJOUh 4YUxF4eXRYkeqx86vQsX98XZ+v34Ace03Hgdhu4AXhiRAxZ5Uv595zePrnU208msWsDc UMRlc9Bp2k/L75OU5NlRwfp5c/vokH542CyF6BKqzDsF9YZorCMupg9Cv2QsP7tU1opF sV8Hi/jmloBzVFdGHw+PNw4bl3PrH1sUkaXFGSdmaQDx+CcaH+n+Ro9qE/4qG5RMDwuC ZUV/u8epjr2EyxBGMfxJ9ENZ0PCBmfYNKqDdkeihkFf6ugYwvXcTC0Y9sctSDktiMLCd hr+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724943749; x=1725548549; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Av0NGxXt1nyH9OnYaW8cLl1uNekiq9nEwkTz2fTJczM=; b=aW/LQcAPjRxQ1RDO5Krvh2g6rAKCXoP2FrAm90+0ts1NTaEC9mTT2VmdJblO68FC1v Wypf8X/OOjEvT18//G3KbXCoQlOYlIEUgglg5dQndQnUINxQuu5Rfjow9Uqhc/oCUyt0 W+gTU38Ft39zSX26vVsweAf3ADp16535N9mefAVmEkqQ5UtKBqxee06rHIg5kGIcK++F jxbEzywKEOY98/0bO/fOZgrl0cF3KHP4I/wSYeRRDH1K1HpE/PNRxuVEDhPcIIvbHkxH 1eqBBXTOXWStQFSCMpUNGb89rTx6zHkdgrXQGp3pHF+lyxIwZEvPsT0jrFeW/m5bdhEX 3p1g== X-Forwarded-Encrypted: i=1; AJvYcCW1c95yH18uGCW0zdLWNgrGRnsmjXp3OOibNFFyASvUMPJ8qB+nvjMg5MXVy06yI9lhh12xIGAH1jFuZXI=@vger.kernel.org X-Gm-Message-State: AOJu0YxkRaXWhSoGlbF/m2jaoDjBnTAytGfI3p5nBDi4XD71x6/iHFzo pLoZnkBBaFjpGmf+3h8ZEPPzKCRtwec/6brgkckinMLd/ZubfsFZQAGnGxGxSJLBcWkeS8ZlZOX LoYb/qg== X-Google-Smtp-Source: AGHT+IFJieNy9A3Uv3j3AZR9Z45ANYmI2LGJZlQ+SwIrR3g7cbpr9Y1OJRykDxOd+oXunJ3IU0lxYLvJDeLt X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:e51a:f73b:d117:cb13]) (user=irogers job=sendgmr) by 2002:a25:6b0b:0:b0:e0b:acc7:b1fd with SMTP id 3f1490d57ef6-e1a5c6b65bbmr54154276.4.1724943749450; Thu, 29 Aug 2024 08:02:29 -0700 (PDT) Date: Thu, 29 Aug 2024 08:01:54 -0700 In-Reply-To: <20240829150154.37929-1-irogers@google.com> Message-Id: <20240829150154.37929-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240829150154.37929-1-irogers@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog Subject: [PATCH v1 8/8] perf test: Additional pipe tests with pipe output written to a file From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Nick Terrell , Yanteng Si , Yicong Yang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Additional pipe tests where piped files are written to disk. This means that spotting a file name of "-" isn't a sufficient "is pipe?" test. Signed-off-by: Ian Rogers --- tools/perf/tests/shell/pipe_test.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/perf/tests/shell/pipe_test.sh b/tools/perf/tests/shell/p= ipe_test.sh index ad10012fdc29..a3c94b4182c2 100755 --- a/tools/perf/tests/shell/pipe_test.sh +++ b/tools/perf/tests/shell/pipe_test.sh @@ -11,6 +11,7 @@ sym=3D"noploop" skip_test_missing_symbol ${sym} =20 data=3D$(mktemp /tmp/perf.data.XXXXXX) +data2=3D$(mktemp /tmp/perf.data2.XXXXXX) prog=3D"perf test -w noploop" err=3D0 =20 @@ -19,6 +20,8 @@ set -e cleanup() { rm -rf "${data}" rm -rf "${data}".old + rm -rf "${data2}" + rm -rf "${data2}".old =20 trap - EXIT TERM INT } @@ -49,6 +52,14 @@ test_record_report() { return fi =20 + perf record -g -e task-clock:u -o - ${prog} > ${data} + if ! perf report -i ${data} --task | grep -q ${task} + then + echo "Record+report pipe test [Failed - cannot find the test file in t= he perf report #3]" + err=3D1 + return + fi + echo "Record+report pipe test [Success]" } =20 @@ -86,6 +97,21 @@ test_inject_bids() { return fi =20 + perf record -e task-clock:u -o - ${prog} > ${data} + if ! perf inject ${inject_opt} -i ${data} | perf report -i - | grep -q $= {sym}; then + echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploo= p function in pipe #5]" + err=3D1 + return + fi + + perf record -e task-clock:u -o - ${prog} > ${data} + perf inject ${inject_opt} -i ${data} -o ${data2} + if ! perf report -i ${data2} | grep -q ${sym}; then + echo "Inject ${inject_opt} build-ids test [Failed - cannot find noploo= p function in pipe #6]" + err=3D1 + return + fi + echo "Inject ${inject_opt} build-ids test [Success]" } =20 --=20 2.46.0.295.g3b9ea8a38a-goog