From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 D044F15688C; Fri, 22 Nov 2024 04:38:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250328; cv=none; b=ETTV+D/qdLBzfq2DzLaxn/g6yzKREs7PVGlFTel1npV55tEYRYhB8i7IW2TDOkBvB6AWS3KyzOzyM8vdU/TJOPxt4XoA625rCMhkDSTbtgQTzsH+zSLotzs3XbykEPRysW+2T6Blv/T8ajQ6VsrrVnRvBy/x4IzvSiO2ID77G+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250328; c=relaxed/simple; bh=ZMUyrpoRvBaFb7l+97Ql8XtqR55copvH+5CmlUDTTfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jz4ZxT5RdJkXDElz6MBftk4ZvjMcTo1G9Vfs++SeVdpg+HRLQqR0OiNy63BHUa9T8Qg/zmgjulwrrkJomOwnsokXSYmpA/zhae7Up0RAqxT5F3ye2mtTe5r5VtOAwxSZgvbx4pcqdnU38lOTAjVPrh0MKAZS38kitu41jHWe8pQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LBfiYSnA; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LBfiYSnA" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so1334942a12.3; Thu, 21 Nov 2024 20:38:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250326; x=1732855126; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7tlVPJG6c2iOy9djXpDowD5/zOoImGMk2kTxgQTN4OM=; b=LBfiYSnALpuUcMoBGVKtC4fHVzIqqUUHO7uEWZe2kVcJHzyDvsQ6vwmEloKmIgl5tU mgg59j+x7vcnxuIF6VsSgQdE0p0PKDeFyIwoPgy3mQIjZ4f1bBdN5+euy0mwJtwMsKMp 9Nsu088Hnbo+5WR7J/O4XreA6/Nda8Bp8iLW0l67SQr3G4wXPNcuk0aG0GEFqumDbsoG tHb8eMw4BDUrLKnVF8iosDvq07wl2C4jYNz6azAfoJFYUkLAcJkZOb4LBjM3G11tP8aY +EU1EpigZArYBI1LhfBGkdcgMmVIjmRJ1DOvqVZkH4cb/9f2/uc6YtRQtTDkesbjQ7o7 skFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250326; x=1732855126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7tlVPJG6c2iOy9djXpDowD5/zOoImGMk2kTxgQTN4OM=; b=J640MO1vcj5yFAI/7uyFAxSu53gvknSjbsxjojXgECe8Fx2xsyHiTOgzJiwwYAicAq 2+V+2zVIk7V6DxgoGH3wksvju6DOBY10a5KBkJ6DxdshOBjYD07A6Tqwx/zOJdCPOQvy dBWdIFbbpDcQ7LV+u1DL1UwxN1yjZz/YupCbeKpbuRHhKFmuuNPyXNRIrkWZgnOUghhC dQaRcWjgE6TwMKikrRg+IIclSIPiRXka9+0BO9TCJ9Phgsd2C+O1IISgZLNDDJMNtveX cwoiF/keZDvlfwbuRpTT1ujYpFYGIRiSRVOcCOP9kcgMe2cCeVUXPXiYXE4YkeEKvi2x de3g== X-Forwarded-Encrypted: i=1; AJvYcCU9hgnV7ApCoADSO8DRWnrhbbKxt5oVAna8cjF9VSkonFj6DbpXq2ravnJKH+BhSJKXsJ5AzfdstleF5Iqf5lABmg==@vger.kernel.org, AJvYcCVVXqH9Nb5lZLQ39Jdf7rX7IOBCVMyeO3jUTcVMl3RqyZcXaaYu/yQcq7V4KpGa6ybhFanHWan2pqonxRA=@vger.kernel.org X-Gm-Message-State: AOJu0YwVgnUt3yRM7jx35v6qdYvQUspJEQEkZscjIVBFYLghJ8U5bICz 94cX0Kjp+TUrNNFBCigz+x5Jfj0OQUM7vUFxoxjoBMAO/1FuyiiV X-Gm-Gg: ASbGncuDd7JsI0m38/G3FLa656cI6BCrL+crfNOaSPMFyv/hVxmSqnDL5yffqxXfTLJ RN/ZjrYdNoghP8HXSfuRtlSAxaL4UEuFmxNbCAGZbWFlighiIQft6pKV3YAdushx3ej2mlIxNZC qVw2hJZD+RdyPzy1HkqrkQN5EeEcYCAww8EjPdZqB0/E850CQ5vu3yPYE3klDwPG8IxXAZYypVa IDGrA9Y736PrVW8311IsnhHYrpi2DzWOkqrZhNf1fxBbiDy2NK4bLlUEOziEJArZp/LY+R/L35V wzeILp16WRE= X-Google-Smtp-Source: AGHT+IHL30BoFijeNwRxWWqMPTNP/mMD4tXldqdnwcDf6ti7JORGZgB1xWpfHnScJkd7QZxJWYgy9w== X-Received: by 2002:a05:6a20:9188:b0:1d9:25d4:e8b1 with SMTP id adf61e73a8af0-1e09e4edaf5mr2359047637.25.1732250325999; Thu, 21 Nov 2024 20:38:45 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:45 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , Arnaldo Carvalho de Melo , James Clark Subject: [PATCH v9 01/10] perf record --off-cpu: Add --off-cpu-thresh option Date: Thu, 21 Nov 2024 20:38:31 -0800 Message-ID: <20241122043840.217453-2-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Specify the threshold for dumping offcpu samples with --off-cpu-thresh, the unit is us (microsecond). Default value is 500,000us (500ms, 0.5s). Example: perf record --off-cpu --off-cpu-thresh 400000 The example above collects off-cpu samples whose off-cpu time is longer than 400,000us Suggested-by: Ian Rogers Suggested-by: Namhyung Kim Suggested-by: Arnaldo Carvalho de Melo Reviewed-by: Ian Rogers Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-2-howardchu95@gmail.= com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-record.txt | 9 ++++++++ tools/perf/builtin-record.c | 26 ++++++++++++++++++++++++ tools/perf/util/off_cpu.h | 1 + tools/perf/util/record.h | 1 + 4 files changed, 37 insertions(+) diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Document= ation/perf-record.txt index 242223240a08..05c8977983de 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -829,6 +829,15 @@ filtered through the mask provided by -C option. only, as of now. So the applications built without the frame pointer might see bogus addresses. =20 + off-cpu profiling consists two types of samples: direct samples, which + share the same behavior as regular samples, and the accumulated + samples, stored in BPF stack trace map, presented after all the regular + samples. + +--off-cpu-thresh:: + Once a task's off-cpu time reaches this threshold, it generates a + direct off-cpu sample. + --setup-filter=3D:: Prepare BPF filter to be used by regular users. The action should be either "pin" or "unpin". The filter can be used after it's pinned. diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index f83252472921..c069000efe5c 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3149,6 +3149,28 @@ static int record__parse_mmap_pages(const struct opt= ion *opt, return ret; } =20 +static int record__parse_off_cpu_thresh(const struct option *opt, + const char *str, + int unset __maybe_unused) +{ + struct record_opts *opts =3D opt->value; + char *endptr; + u64 off_cpu_thresh_us; + + if (!str) + return -EINVAL; + + off_cpu_thresh_us =3D strtoull(str, &endptr, 10); + + /* threshold isn't string "0", yet strtoull() returns 0, parsing failed */ + if (*endptr || (off_cpu_thresh_us =3D=3D 0 && strcmp(str, "0"))) + return -EINVAL; + else + opts->off_cpu_thresh_us =3D off_cpu_thresh_us; + + return 0; +} + void __weak arch__add_leaf_frame_record_opts(struct record_opts *opts __ma= ybe_unused) { } @@ -3342,6 +3364,7 @@ static struct record record =3D { .ctl_fd =3D -1, .ctl_fd_ack =3D -1, .synth =3D PERF_SYNTH_ALL, + .off_cpu_thresh_us =3D OFFCPU_THRESH, }, }; =20 @@ -3564,6 +3587,9 @@ static struct option __record_options[] =3D { OPT_BOOLEAN(0, "off-cpu", &record.off_cpu, "Enable off-cpu analysis"), OPT_STRING(0, "setup-filter", &record.filter_action, "pin|unpin", "BPF filter action"), + OPT_CALLBACK(0, "off-cpu-thresh", &record.opts, "us", + "Dump off-cpu samples if off-cpu time reaches this threshold. The u= nit is microsecond (default: 500000)", + record__parse_off_cpu_thresh), OPT_END() }; =20 diff --git a/tools/perf/util/off_cpu.h b/tools/perf/util/off_cpu.h index 2dd67c60f211..c6edc0f7c40d 100644 --- a/tools/perf/util/off_cpu.h +++ b/tools/perf/util/off_cpu.h @@ -16,6 +16,7 @@ struct record_opts; PERF_SAMPLE_PERIOD | PERF_SAMPLE_CALLCHAIN | \ PERF_SAMPLE_CGROUP) =20 +#define OFFCPU_THRESH 500000ull =20 #ifdef HAVE_BPF_SKEL int off_cpu_prepare(struct evlist *evlist, struct target *target, diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h index a6566134e09e..2ca74add26c0 100644 --- a/tools/perf/util/record.h +++ b/tools/perf/util/record.h @@ -79,6 +79,7 @@ struct record_opts { int synth; int threads_spec; const char *threads_user_spec; + u64 off_cpu_thresh_us; }; =20 extern const char * const *record_usage; --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 414BE159583; Fri, 22 Nov 2024 04:38:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250329; cv=none; b=SvTRMTPVXml/DnlSOXRCkj9K853Vkmfhk0V0mYRdwcqbQ+7PSvYftSXiof4NjZUWPru2JOaE93iIDQS9xM1IOpsJwKiucimICthEusCrcyBKgEero+oPgxjNFuumUSwfwXOyMhrPIDWMdk4D7xQhDp3tWZQgCRorDkgZT4LhhuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250329; c=relaxed/simple; bh=k1MvbZqv805gektgE0goJNI/HxV1JhVVKX8JGAJXSvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fQ8eQ42b9RRsoAHtRaVfqmehI3zt6aagEANGOh5UgmHVMST3ggaWP2W/UnrFpM+6UJk+wNjMprXyxW+0lYqySq4I0Y4BGEesXSYpihL446bNN9LnLvJU4x3YY81S7Ty14AB6h8p681B4+LXErPXsWf7WVvFb6xdHYER1YcyOC7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cZccF4ux; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cZccF4ux" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-21260209c68so21053205ad.0; Thu, 21 Nov 2024 20:38:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250327; x=1732855127; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IpYScqwzO6WE7u35hrRfQ2TMuWp9RDhpSIjI9CQVyMs=; b=cZccF4uxEsg84+toFFuJ0zTbFvLRO+/GAWt9+rFQ2wLEretW0hmyvFEGs9XI3QRwbN A+5yx225fvu+6uXZL5xergCGwtFMVTue1Pp+QPu2w8tzA1Ud3J2m4NaipBDc8tt1mKum HEUeaTUOUAmGqOw8cuocGWIbuWRhosszn7YTCEAI22qUpvEzrOU94mP9WqziAgjoP2cv FX+j0ngpXJldsDAyAhINETGfzUEkJ3vSot3+n45Z+MKN/EfJ7u4iScxdA0j7+97zjTV1 okWmKCmE5+sixpYW0brbnr4oAEcDFl4fKIIH7/geT7AITKTmUUIDQIi3qp8hMxgEGcyL Eqcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250327; x=1732855127; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IpYScqwzO6WE7u35hrRfQ2TMuWp9RDhpSIjI9CQVyMs=; b=aPYHdQZBy5VhqDcI7MEMtsh/U17/exAskjynv5vuzKabdkYgCOinKG04S1ulZwDg27 59p0Lc+zy4SfSmnuiNW2QvUDYgmTWZ2MhR8sNJUrTRzFAvqdUaYU4gKstxqUo3/uionI jIywd71NmB2CKKOSM2OktukvG75uoQUyq+DBhPLFy8rx1C4RsXuWt61ae0ylEnwuXVnq pnEaNFYunR8WEaXwKbN/8S6JR+deKyNs2EYNDhf8aD7rRFZu5TQu4TVdzQWXVPzPLCQS gI7aB32Wnr8HoDMcoQ0TUplj8+dRz+iVi/xmdUEkrIoJh+JZVHIZ2E2g+YYRvvHy0aVd wd1A== X-Forwarded-Encrypted: i=1; AJvYcCXMZxDDh2ZeyyHbO+lDUyBTM7VdgLYL0AZM9meIuHtwFP/PKx4ve70BUokk1HHVIAvl+4Vni2UaOgCI0o5Qiiun4g==@vger.kernel.org, AJvYcCXgCSpo1NauqcxbJWZ98AWwyCcawc5bI6MESWXU+qNeaV0AxXbECfYyEdSiexWZyOzbvWoyqzqZdO+lawA=@vger.kernel.org X-Gm-Message-State: AOJu0Yz378BTkLClTS+pzZ56mSD7NSyk3ifabxnymQLMlasgHkP3T2Rg DqWqrljNmF+qbJqUmHR35QyTZcHNU/lsmlMsrpSpw/B4zcIHgEms X-Gm-Gg: ASbGncslY0YybrNQbdE/Zaij+TYazQfhfVnTJA+P/4s9io86LtX3yC/LfImtode27Xa wQ237lIEaHCjktlWbOubhCr7tjMUUAPrGNzrArhHMv9IPHD4tb+HLHkb8HjwoDZXNY9Cw8+C59n jolf7uQfuyMymDBIfFooaq9zdjxHg6kGxvs0UVke1xQLC2pSshEs3rKDG+WBW0s/FpJ7TW1QEo3 e86MLjxDWL0AMBgdgeEOArQ3Zoi9UCUip0sQS7ypGHAhtvoZ4FYnIpPwWDf84358DwwFmERVaAt 9uHi5Lpz05g= X-Google-Smtp-Source: AGHT+IHEsYXCnGUS+xbgwdVIS4PlPTbRyWdTOZh+GSk7YqOWmmy6VECf4G/ZC3wuyIrzkBW6O8LjbQ== X-Received: by 2002:a17:903:187:b0:212:f7d:9284 with SMTP id d9443c01a7336-2129fe2842emr19204955ad.8.1732250327486; Thu, 21 Nov 2024 20:38:47 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:47 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 02/10] perf evsel: Expose evsel__is_offcpu_event() for future use Date: Thu, 21 Nov 2024 20:38:32 -0800 Message-ID: <20241122043840.217453-3-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Expose evsel__is_offcpu_event() so it can be used in off_cpu_config(), evsel__parse_sample(), and perf script. Reviewed-by: Ian Rogers Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-3-howardchu95@gmail.= com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 2 +- tools/perf/util/evsel.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f745723d486b..8d0308f62484 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1194,7 +1194,7 @@ static void evsel__set_default_freq_period(struct rec= ord_opts *opts, } } =20 -static bool evsel__is_offcpu_event(struct evsel *evsel) +bool evsel__is_offcpu_event(struct evsel *evsel) { return evsel__is_bpf_output(evsel) && evsel__name_is(evsel, OFFCPU_EVENT); } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 04934a7af174..7f68004507d8 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -554,4 +554,6 @@ u64 evsel__bitfield_swap_branch_flags(u64 value); void evsel__set_config_if_unset(struct perf_pmu *pmu, struct evsel *evsel, const char *config_name, u64 val); =20 +bool evsel__is_offcpu_event(struct evsel *evsel); + #endif /* __PERF_EVSEL_H */ --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 E87E31632FB; Fri, 22 Nov 2024 04:38:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250331; cv=none; b=oT3lf4MKHxQ4eU93DL2RtYD+K6/+DINWpkOmeH73Z2PlC02dLOZGRZijYvg5jxozsoDPMv25x1Xy0upsfQYK4asx3dRkZBUyyG2+6rbszV3WkbdRmf+lbc8u8n9kpsD70Iirl1mKrId/QEzDmT7dJ0qGAzytYGEKuH01bTBLKUM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250331; c=relaxed/simple; bh=8CnrooDgL1ZMe4pHFbOHuSGnNr0AfwT8FADkckYog48=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BOVM613htvNE3uD7Ghdh4fUec15UYDSdVhyM9lNRCTQQEriRJI0QaWTwhJA0SDTKAv3+qbiJOYjfwtji9UxVH0vbH4c9KZYU0gQOMhliVEachlErsfHMDMoCtwMKxdV9lHJ9XBtZJV0NsnEf3TtS8/K2Mepel4DccDqwmzNLcA4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cZmOn/ho; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cZmOn/ho" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-724d8422dbaso951546b3a.0; Thu, 21 Nov 2024 20:38:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250329; x=1732855129; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ngRoEqDR4XbeZwV1sZ8tw8Ja26BhVSigArtxA/HtW1w=; b=cZmOn/hohAdhxrucD++hOo8mD+DUaeeaNm67JFNKbywOj8pr9OG0yJsuK5BlIN4h+T Bm3w4ydTqOm1adtRLZF0NoOi43EJszNI0xb2szZ1yTUrQQzc7qx7KzpvCFQ1jPHWM6vo 8SGWqvP7syEuKpptMI9loS+J87nqLSyGpcaSZVQGIGAQtzgQLPn2MFke8riRRkD5upEN 4h3x/VSXd/+auG3Q5jDHUl51yU4T9LCsLe9YXybNagodWjvQekJ8RIEv80K9PFJy3DQG pYnuNO9D/zIkIaZ1VsTOZ+9vBByflK5RqU0hzPp4KJ65zUriSTuSp9Fgcr63RbZ/hMAF eAzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250329; x=1732855129; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ngRoEqDR4XbeZwV1sZ8tw8Ja26BhVSigArtxA/HtW1w=; b=FzPLy9wRjrCbwz1XH0NF0Tm0GDV2XGrpNF+bqWnMgS2tXzhvbBPPOj+Mbl445Vdwrn CrtCLRfRCEhWqqvgptuaq7B3Yz8/9yacZTwaogrxIVGhZ9OPsQoBjF7VhXyZEFYuyMZl wzmlKytwORLb32EM2qUnILNnjQ5ERAgvV9nbTiKv6iQ7rl5S353eWhNHXK/7y2lHd6c+ ZMxgew9F4nU7TizmR4W++m939HEja4EASaM1riUqbSZSkZLeesFmOhqLndOlg6OVTSrf B1HVqKdsIxZnhBYSy2KEzSZFVAN2kdGN4ij5V9Y7C44oZiDxSb3D9hGXbGs6aClmyJk0 yOWg== X-Forwarded-Encrypted: i=1; AJvYcCVqOr3htT1lYUNvLQuk+gqgI8BObtYWnB9Z89R7VAC1tJ23KKu8EhlEBWqCnjHDw/DWy+2XaSlJuc6uxU8=@vger.kernel.org, AJvYcCXL1rweDdVgmk+FWdmApvoOhS40+fd8MhZG3vmmn8eNuTPT6HnK9se2x1z7T/9l+SldRGEUeaBjEYLcY3G8hwpIHA==@vger.kernel.org X-Gm-Message-State: AOJu0YyNscc06jS7r+AlmHxRCFsa2A18RmLO40LeFzJczpQR/ykIIIAu cQEvgOioU8oLd/TYoka1DdiUwG+QxekVgqdgtbyg43IuhM3nvYBr X-Gm-Gg: ASbGncsSWEsL71MMkX4v3kq8suvt+Mhle8RqMrEVjrZI73QbUHyqRXbyV0w/jC2U469 D72klXBhpbo+Pjm+nxjx2KAZcllCoMJZXvmoJbQlwgwyfZbKqQj9MJ04UIJ1ZCvquOOz09OYyc8 YwNBiEmStaxQfskPQXV3XI9uYtWJ6IH0dnM3N1iokn1iRKFFGAxWYfvvXJ6FGf9GkLLqOJNIXb0 xMbzHzoa3DNnONXHcsEokfOploxQ+XcP2BLStv88sIP/YTQ0ThgSsddewAtKmkCnV/z/2kJNZYL aNHjYNvGcco= X-Google-Smtp-Source: AGHT+IGUJVNevOHmCq5izMnWCtT+ya85fS4XC0LBW5jLDC+Qk8qHUmwDXHw8nC/ldOc7aphiyEoITg== X-Received: by 2002:a17:903:18f:b0:20e:55b0:35f2 with SMTP id d9443c01a7336-2129f217e22mr25592125ad.1.1732250329050; Thu, 21 Nov 2024 20:38:49 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:48 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 03/10] perf record --off-cpu: Parse off-cpu event Date: Thu, 21 Nov 2024 20:38:33 -0800 Message-ID: <20241122043840.217453-4-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Parse the off-cpu event using parse_event(), as bpf-output. no-inherit should be set to 1, here's the reason: We update the BPF perf_event map for direct off-cpu sample dumping (in following patches), it executes as follows: bpf_map_update_value() bpf_fd_array_map_update_elem() perf_event_fd_array_get_ptr() perf_event_read_local() In perf_event_read_local(), there is: int perf_event_read_local(struct perf_event *event, u64 *value, u64 *enabled, u64 *running) { ... /* * It must not be an event with inherit set, we cannot read * all child counters from atomic context. */ if (event->attr.inherit) { ret =3D -EOPNOTSUPP; goto out; } Which means no-inherit has to be true for updating the BPF perf_event map. Moreover, for bpf-output events, we primarily want a system-wide event instead of a per-task event. The reason is that in BPF's bpf_perf_event_output(), BPF uses the CPU index to retrieve the perf_event file descriptor it outputs to. Making a bpf-output event system-wide naturally satisfies this requirement by mapping CPU appropriately. Suggested-by: Namhyung Kim Reviewed-by: Ian Rogers Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-4-howardchu95@gmail.= com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/bpf_off_cpu.c | 33 +++++++++++---------------------- tools/perf/util/evsel.c | 4 +++- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index a590a8ac1f9d..9275b022b2ea 100644 --- a/tools/perf/util/bpf_off_cpu.c +++ b/tools/perf/util/bpf_off_cpu.c @@ -38,32 +38,21 @@ union off_cpu_data { =20 static int off_cpu_config(struct evlist *evlist) { + char off_cpu_event[64]; struct evsel *evsel; - struct perf_event_attr attr =3D { - .type =3D PERF_TYPE_SOFTWARE, - .config =3D PERF_COUNT_SW_BPF_OUTPUT, - .size =3D sizeof(attr), /* to capture ABI version */ - }; - char *evname =3D strdup(OFFCPU_EVENT); - - if (evname =3D=3D NULL) - return -ENOMEM; =20 - evsel =3D evsel__new(&attr); - if (!evsel) { - free(evname); - return -ENOMEM; + scnprintf(off_cpu_event, sizeof(off_cpu_event), "bpf-output/name=3D%s/", = OFFCPU_EVENT); + if (parse_event(evlist, off_cpu_event)) { + pr_err("Failed to open off-cpu event\n"); + return -1; } =20 - evsel->core.attr.freq =3D 1; - evsel->core.attr.sample_period =3D 1; - /* off-cpu analysis depends on stack trace */ - evsel->core.attr.sample_type =3D PERF_SAMPLE_CALLCHAIN; - - evlist__add(evlist, evsel); - - free(evsel->name); - evsel->name =3D evname; + evlist__for_each_entry(evlist, evsel) { + if (evsel__is_offcpu_event(evsel)) { + evsel->core.system_wide =3D true; + break; + } + } =20 return 0; } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8d0308f62484..d7a68d450080 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1473,8 +1473,10 @@ void evsel__config(struct evsel *evsel, struct recor= d_opts *opts, if (evsel__is_dummy_event(evsel)) evsel__reset_sample_bit(evsel, BRANCH_STACK); =20 - if (evsel__is_offcpu_event(evsel)) + if (evsel__is_offcpu_event(evsel)) { evsel->core.attr.sample_type &=3D OFFCPU_SAMPLE_TYPES; + attr->inherit =3D 0; + } =20 arch__post_evsel_config(evsel, attr); } --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 A1BA816C453; Fri, 22 Nov 2024 04:38:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250333; cv=none; b=GKx2oJyzSh0nxhqoFSmExxumlNl01eZq5+LFRHOcsscjJk/LeOHGj0KTOlFAiDNkExdJ0PPNYRZ3zpc4uU8F7qo0HfBsdQj7kL2sgtm6WrO1FvnTiMkdYxrFzL9EYR1Z61o9RPHYxK8W3xqGwby74glEub6uAAjLaGd+k3nKFEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250333; c=relaxed/simple; bh=mTlC+dsjuz20TP9NXLl05x5MvL2ZF8LuKq6YVidbn2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WA0GXDYgHdkNwGt7Ej7xPFArwHgnHbYQGOXOttsLqDRmaymaDANwE5vnBcGoSG6YpM/MP2FDmXN8V9kTePXtymTrp51+QjuENBJXzECk6sIJtBLmEFqOGnQSgh5CJkFGHRKNhVn9Yjb0Di6aIIiN9WP3chziFH5uLHzbXMqt6OQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mwm1nfCj; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mwm1nfCj" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-21290973bcbso15569905ad.3; Thu, 21 Nov 2024 20:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250331; x=1732855131; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JmHn/bdBOF0dPUymMSGq/r40vYqC7wwLOGiFt6IT0Mc=; b=mwm1nfCj4owc9lce0h61attRjX8FOdj0bS5/o+1Oy5em7HhQMD+VfqjF5Z10+8AhqA h0G8TpcdyLt29K8S4Ds2gq9WtLoyqjLPtOluEQizjMNO2Rech/Tl/2YpeNft3S+Pe6tM Ww9h6kgLCAuoXiEgTNd4Es/1StFmJVYoz93jOviRHJD7TDwX5nJzYSkpVrvohd35neXg RnR4at5kE1wQZBXZFwR8Nnnze2qVNJmBO0R0jZ2TkrAopiG8tWUPiSyzynjD+TABCrAd AF2TOoPaFcxndxSnoAD7Q6no7z/V5it1shC+QdEU88N4CL+Q422zCJuZ6DzboJbItIiv jr4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250331; x=1732855131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JmHn/bdBOF0dPUymMSGq/r40vYqC7wwLOGiFt6IT0Mc=; b=bt1H7kNr0yF0pzH7HD5QNVpjLj3owb0nl3vCi0qW2GMXFEU3wr5N8pmi44lEkFRd0p PEhUfYvCKGgCELJ6UsbYUEo0GVqV6Y4ugKIJa+EYZ8QvLjyQ98DgxM1Al/lIaJrLgLZ/ /AyvHpg3xIOT/JXd5Ughaw87QvG4MXievHLNrpI6XGo7fqLR0vxNJCFu4BoLz1fDjhaM WwYDW5/kmgaybdC4ouzuywDVK5yiAbdJfmBfNZG6f2QtshpJNIR+ew7pXKTZux/6KoSr UPS5XvY5eVaxythZ2D5TbTxPnYteQ61MEdI7mtvM/I0wMc8kQROsJUcqwVSZWHtKZfOU VMdg== X-Forwarded-Encrypted: i=1; AJvYcCU+dIlGfeIgAp6eYQYzyc5MapODW3/uYhVAJzRI+e2jTrjL+MvjbEPaZhDtd5SWpeEwgB7G6dz+eghEe8I=@vger.kernel.org, AJvYcCVTGlSWNyB/W190dMbeUocmXU4DpWPJius91AOe/838eNzZvTegHkPX9deKQVVq1XX1Zw+JVORuacL8N6NDDIZztw==@vger.kernel.org X-Gm-Message-State: AOJu0YyFt7p2I48nH7wp7y2e9V+pu8S8n82+JLLUJF69dNKJYP0MIYLr Cxt3+CVSAflJC42MCYUGWkR7p97gSIZb/BJ3REMXzrX0nLuz9Udn X-Gm-Gg: ASbGnctjeoGvhF0YCwfn2e704V7ihIAdI6IsG/jjkUSEWevfKNiiDoDysi3O1W9xB5X bUkgK2LiZ1xP0EjoFCDl+lJMuKhYum8B9Xm4DHGS/PxOkQUChG34QpW+EIkQvwpheywQAw1LKn4 wEYULpLDR3it/5KSkAv2hq8yetJfHPlFR2jQ2dNEgGTC8oVAAP/Fov6CIC0WvnVZryoi/p497xm ydQmJJbHSYNK4kdGf217BDG0H/5ZK9F3508UxHzHZectXsJhgdS6TI4kj4v/oP7oOelwnHgcdVE tcpNBOZDb6I= X-Google-Smtp-Source: AGHT+IHm5T5Rb+fS5Wzz+Aa9U7EoOcMPQHYNmHgS5vI+QSn+mN1Bo3eZa07IZKFVZp4MHxZt7kCGfQ== X-Received: by 2002:a17:902:ccc6:b0:20b:861a:25c7 with SMTP id d9443c01a7336-2129f6129e9mr20824795ad.54.1732250330973; Thu, 21 Nov 2024 20:38:50 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:50 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 04/10] perf record --off-cpu: Preparation of off-cpu BPF program Date: Thu, 21 Nov 2024 20:38:34 -0800 Message-ID: <20241122043840.217453-5-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Set the perf_event map in BPF for dumping off-cpu samples. Set the offcpu_thresh to specify the threshold. Reviewed-by: Ian Rogers Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-5-howardchu95@gmail.= com [ Added some missing iteration variables to off_cpu_config() and fixed up a manually edited patch hunk line boundary line ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/bpf_off_cpu.c | 25 +++++++++++++++++++++++++ tools/perf/util/bpf_skel/off_cpu.bpf.c | 11 +++++++++++ 2 files changed, 36 insertions(+) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index 9275b022b2ea..2378fb5a893f 100644 --- a/tools/perf/util/bpf_off_cpu.c +++ b/tools/perf/util/bpf_off_cpu.c @@ -13,6 +13,7 @@ #include "util/cgroup.h" #include "util/strlist.h" #include +#include =20 #include "bpf_skel/off_cpu.skel.h" =20 @@ -60,6 +61,9 @@ static int off_cpu_config(struct evlist *evlist) static void off_cpu_start(void *arg) { struct evlist *evlist =3D arg; + struct evsel *evsel; + struct perf_cpu pcpu; + int i; =20 /* update task filter for the given workload */ if (skel->rodata->has_task && skel->rodata->uses_tgid && @@ -73,6 +77,25 @@ static void off_cpu_start(void *arg) bpf_map_update_elem(fd, &pid, &val, BPF_ANY); } =20 + /* update BPF perf_event map */ + evsel =3D evlist__find_evsel_by_str(evlist, OFFCPU_EVENT); + if (evsel =3D=3D NULL) { + pr_err("%s evsel not found\n", OFFCPU_EVENT); + return; + } + + perf_cpu_map__for_each_cpu(pcpu, i, evsel->core.cpus) { + int err; + + err =3D bpf_map__update_elem(skel->maps.offcpu_output, &pcpu.cpu, sizeof= (__u32), + xyarray__entry(evsel->core.fd, i, 0), + sizeof(__u32), BPF_ANY); + if (err) { + pr_err("Failed to update perf event map for direct off-cpu dumping\n"); + return; + } + } + skel->bss->enabled =3D 1; } =20 @@ -261,6 +284,8 @@ int off_cpu_prepare(struct evlist *evlist, struct targe= t *target, } } =20 + skel->bss->offcpu_thresh_ns =3D opts->off_cpu_thresh_us * 1000; + err =3D off_cpu_bpf__attach(skel); if (err) { pr_err("Failed to attach off-cpu BPF skeleton\n"); diff --git a/tools/perf/util/bpf_skel/off_cpu.bpf.c b/tools/perf/util/bpf_s= kel/off_cpu.bpf.c index c152116df72f..c87132e01eb3 100644 --- a/tools/perf/util/bpf_skel/off_cpu.bpf.c +++ b/tools/perf/util/bpf_skel/off_cpu.bpf.c @@ -18,6 +18,8 @@ #define MAX_STACKS 32 #define MAX_ENTRIES 102400 =20 +#define MAX_CPUS 4096 + struct tstamp_data { __u32 stack_id; __u32 state; @@ -39,6 +41,13 @@ struct { __uint(max_entries, MAX_ENTRIES); } stacks SEC(".maps"); =20 +struct { + __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(__u32)); + __uint(max_entries, MAX_CPUS); +} offcpu_output SEC(".maps"); + struct { __uint(type, BPF_MAP_TYPE_TASK_STORAGE); __uint(map_flags, BPF_F_NO_PREALLOC); @@ -97,6 +106,8 @@ const volatile bool uses_cgroup_v1 =3D false; =20 int perf_subsys_id =3D -1; =20 +__u64 offcpu_thresh_ns; + /* * Old kernel used to call it task_struct->state and now it's '__state'. * Use BPF CO-RE "ignored suffix rule" to deal with it like below: --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 31B11170854; Fri, 22 Nov 2024 04:38:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250334; cv=none; b=JmQYa7cDbOpt7y7H45VwH6tYzPX2QBVO/uD6iCGaP4G64VS3Kz6bn5Ym5eneDUSVl0KbjOmDXZyCCE/jahPazjObgOP6TIsgussP1hNfk5bK6tkldbaC9bMLRsHWbR4m61jGQP5LMdskxiwa/nGlZvzZmjRDzUbNQY0bxGuRea8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250334; c=relaxed/simple; bh=FhYBFcBipaHcJVExkC+3V5vt7nolG31xdwTCXFsCPv8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U2CiMsMO/5toNIVwI2q2f9hLrv69sz0BUw+Aonh8Y4MtIOQdO48xUfxWZjgTcqhSXgVy34jJweh3QX9RcXgS072CbytbCS2KMvBBH1fskH8L8VGYvdCRhGBbW84gvFDKyEnL1AkZeHIS3vE3tF0L2dwkgrpa2Jdyp6KSjzWtZ7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S+kdRIrh; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S+kdRIrh" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7eb0bc007edso1178550a12.3; Thu, 21 Nov 2024 20:38:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250332; x=1732855132; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HM89nxEPCN1/mXqArlw/4nxHHrqhLHtRHulGS1q1v6g=; b=S+kdRIrh9r8bWowy/IBMrou8RWPP5lldKs04HdkNGqaAKCkoDwEvWpLB6sgp5YWE0Q nt0pcPy5TWpayCNtIqGQGW6gEZkXPsAOcc51XL1kqysghI06lH+/TQqvAJVkKb2pjya1 wDReUohQDQvyV/R2VTrv4EiZU2yvvp7kdytEw+jUhYFiAdPU4DsZ19tfneyfv+hCoSx5 ch3dCllYzVHLW1TiC0THr6qYweQneCGUFuHHkAgZESbfQndLIyIxBaxxfR5KR84AZwoO AJAOX00d2BOnkiXVsbRJsFhsDK8DRp59ddmDYLWAxxt1NVQFYDa3xM206bGcHyRomjF0 g2AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250332; x=1732855132; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HM89nxEPCN1/mXqArlw/4nxHHrqhLHtRHulGS1q1v6g=; b=tycwyAa6YMsRGV6HNTs5Mc1UZ37c8Zbilt/7A2NftpRO3ESrh/wrA+eX2y04RNJI2t kqEZ2dK1xkHPymDs81w+HxflL1Zh1xkivCU9uSj5QQ/GsBw7gERVp4d4JRK7hu4cZ/P0 N+22j5rcLnUqzmch4vJZl0jClY+ljrKVoZYA2P7f3EecwURCn/4EUR5vLMctfC5ib94e 1DIUWw1BrNCy2EwHATjjLKUheeRbIczMtO4BlksXif4/g9oWWktTg0Sa8b4DOwNcCQG9 ol7w2N9Jo9HJU7m58P8fTXLRfTc/vqZlMrL9c4V6TDTNaf02nD9fJimmbd9oaeqTrRaP kXcQ== X-Forwarded-Encrypted: i=1; AJvYcCUEJcQ3U3gasGUzkIdNc6faDo03VSk6S5mRC7DkdD++qDmGz3/HuyFN/CkKDMIYBpI4Bdkyh6+lFFqz1i4=@vger.kernel.org, AJvYcCVBBef0r26xsGaPOHYW1THQO59Tszx96E0Azo96Z0Ry9NW7RdS5o3CYRyksBfeKyxuyGi2Y6YHPw2AeneM+1JPGXA==@vger.kernel.org X-Gm-Message-State: AOJu0Yyzf7+d512OllZrEYmThiEPdkU+c5gnI5l2WB6NiwUmNkeE4ioc 5OLLYYiaJ+ej2XSMesXuABbbwOYoTQxThN6Nk3K/NTWuViB6Zj8s X-Gm-Gg: ASbGnctxavris/uUqqm0ER6PaxrTCymjpSGXfJRGR5tkQXjsuk7XRudq+/5FZR5UiNU hZErKK1EiwkUpfPGTlH+phEuiudUv6kzU2UjyLD+fLlAxFTj3d+vi5S5SeTbaWnEUAuPxm5bj6C mqTV6nwK1b3iViReOr+DbK0ks1tg5GsvJhx6PH0up9loz1Le/KiA0SG82eU7wa1PV1KGNbcBaDq +YCR8HEsOahI9mKvKTX6lNitxVn4Iw6Z1t/nbeFYAB0glJHSl3t+bBLJY6edExKuDqsFUc2q63v 5zbYS2mnHKM= X-Google-Smtp-Source: AGHT+IEFWw3TaTwAKGV1sSZ/OGFz7T8nnDb8tmmjryeRN9fGo9PilPEl//PZqMc7KD5AhGljbHhC1Q== X-Received: by 2002:a05:6a20:72ab:b0:1d9:2705:699e with SMTP id adf61e73a8af0-1e09e3a33c8mr1754210637.7.1732250332479; Thu, 21 Nov 2024 20:38:52 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:52 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 05/10] perf record --off-cpu: Dump off-cpu samples in BPF Date: Thu, 21 Nov 2024 20:38:35 -0800 Message-ID: <20241122043840.217453-6-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Collect tid, period, callchain, and cgroup id and dump them when off-cpu time threshold is reached. We don't collect the off-cpu time twice (the delta), it's either in direct samples, or accumulated samples that are dumped at the end of perf.data. Suggested-by: Namhyung Kim Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-6-howardchu95@gmail.= com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/bpf_skel/off_cpu.bpf.c | 86 ++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/bpf_skel/off_cpu.bpf.c b/tools/perf/util/bpf_s= kel/off_cpu.bpf.c index c87132e01eb3..aae63d999abb 100644 --- a/tools/perf/util/bpf_skel/off_cpu.bpf.c +++ b/tools/perf/util/bpf_skel/off_cpu.bpf.c @@ -19,11 +19,17 @@ #define MAX_ENTRIES 102400 =20 #define MAX_CPUS 4096 +#define MAX_OFFCPU_LEN 37 + +struct stack { + u64 array[MAX_STACKS]; +}; =20 struct tstamp_data { __u32 stack_id; __u32 state; __u64 timestamp; + struct stack stack; }; =20 struct offcpu_key { @@ -41,6 +47,10 @@ struct { __uint(max_entries, MAX_ENTRIES); } stacks SEC(".maps"); =20 +struct offcpu_data { + u64 array[MAX_OFFCPU_LEN]; +}; + struct { __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); __uint(key_size, sizeof(__u32)); @@ -48,6 +58,13 @@ struct { __uint(max_entries, MAX_CPUS); } offcpu_output SEC(".maps"); =20 +struct { + __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); + __uint(key_size, sizeof(__u32)); + __uint(value_size, sizeof(struct offcpu_data)); + __uint(max_entries, 1); +} offcpu_payload SEC(".maps"); + struct { __uint(type, BPF_MAP_TYPE_TASK_STORAGE); __uint(map_flags, BPF_F_NO_PREALLOC); @@ -194,6 +211,47 @@ static inline int can_record(struct task_struct *t, in= t state) return 1; } =20 +static inline int copy_stack(struct stack *from, struct offcpu_data *to, i= nt n) +{ + int len =3D 0; + + for (int i =3D 0; i < MAX_STACKS && from->array[i]; ++i, ++len) + to->array[n + 2 + i] =3D from->array[i]; + + return len; +} + +/** + * off_cpu_dump - dump off-cpu samples to ring buffer + * @data: payload for dumping off-cpu samples + * @key: off-cpu data + * @stack: stack trace of the task before being scheduled out + * + * If the threshold of off-cpu time is reached, acquire tid, period, callc= hain, and cgroup id + * information of the task, and dump it as a raw sample to perf ring buffer + */ +static int off_cpu_dump(void *ctx, struct offcpu_data *data, struct offcpu= _key *key, + struct stack *stack, __u64 delta) +{ + int n =3D 0, len =3D 0; + + data->array[n++] =3D (u64)key->tgid << 32 | key->pid; + data->array[n++] =3D delta; + + /* data->array[n] is callchain->nr (updated later) */ + data->array[n + 1] =3D PERF_CONTEXT_USER; + data->array[n + 2] =3D 0; + len =3D copy_stack(stack, data, n); + + /* update length of callchain */ + data->array[n] =3D len + 1; + n +=3D len + 2; + + data->array[n++] =3D key->cgroup_id; + + return bpf_perf_event_output(ctx, &offcpu_output, BPF_F_CURRENT_CPU, data= , n * sizeof(u64)); +} + static int off_cpu_stat(u64 *ctx, struct task_struct *prev, struct task_struct *next, int state) { @@ -218,6 +276,16 @@ static int off_cpu_stat(u64 *ctx, struct task_struct *= prev, pelem->state =3D state; pelem->stack_id =3D stack_id; =20 + /* + * If stacks are successfully collected by bpf_get_stackid(), collect the= m once more + * in task_storage for direct off-cpu sample dumping + */ + if (stack_id > 0 && bpf_get_stack(ctx, &pelem->stack, MAX_STACKS * sizeof= (u64), BPF_F_USER_STACK)) { + /* + * This empty if block is used to avoid 'result unused warning' from bpf= _get_stack(). + * If the collection fails, continue with the logic for the next task. + */ + } next: pelem =3D bpf_task_storage_get(&tstamp, next, NULL, 0); =20 @@ -232,11 +300,19 @@ static int off_cpu_stat(u64 *ctx, struct task_struct = *prev, __u64 delta =3D ts - pelem->timestamp; __u64 *total; =20 - total =3D bpf_map_lookup_elem(&off_cpu, &key); - if (total) - *total +=3D delta; - else - bpf_map_update_elem(&off_cpu, &key, &delta, BPF_ANY); + if (delta >=3D offcpu_thresh_ns) { + int zero =3D 0; + struct offcpu_data *data =3D bpf_map_lookup_elem(&offcpu_payload, &zero= ); + + if (data) + off_cpu_dump(ctx, data, &key, &pelem->stack, delta); + } else { + total =3D bpf_map_lookup_elem(&off_cpu, &key); + if (total) + *total +=3D delta; + else + bpf_map_update_elem(&off_cpu, &key, &delta, BPF_ANY); + } =20 /* prevent to reuse the timestamp later */ pelem->timestamp =3D 0; --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 A55DB1714CB; Fri, 22 Nov 2024 04:38:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250336; cv=none; b=BIzmhEUP3FmWxbgpwi4G0YbVmtahM0SJANJvbukgu8sT1y2+rFad41LtYJaYvSR0RWvNhiJfSpNbVGxhzhsQQCueqsbuis69Rrit8hwKxpoaA7UuphBhxoqN6UmCWEck/WX6ks3ER0i4WeIQph9CcZf/oiU8gqKseKi/3C1M+gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250336; c=relaxed/simple; bh=fDlu79Z+JpLP6VkGzzSNhkvNzPqx/5aR8Zculu83bq8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=k1efC9cbgm7HDAmpN1Noxyxj1brmxjdPTRfa45C8NOfmdfkw0lsdAJCkd5zTjfKnryFE5z2C5eiQ11O9aHgLd2qMJg/C6uTC3SX+SO/X7xVFq9JGtse8UKPXnFTRcn6dMTJS553jBlfTAPd/nmJ/Xv4uqz6JYmd3/CAO/JLPWIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=np1m7D8u; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="np1m7D8u" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-21278f3d547so13655355ad.1; Thu, 21 Nov 2024 20:38:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250334; x=1732855134; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sj7FgNlmIDqfkOn9oqIGg3b9ST9EW/2dbnHWahYJAtY=; b=np1m7D8uLNAhoVL1UL26Lvsmrg4k2ACouBp26hPt9Tp6YpOy2cm+RRdx+ZTlRYIL78 PAjHr0qGhN6gm2EwGeR1TIL4FbHCpgBdUix6kyhArAdkYZB0rPL/ta2eMBmmKg2QHw2y HDK6TXpZICEEidhGQsEO+qRHY+XMLT7N1qzhUxwFPFLGagSrPQSKrRDXt9H7cEOuX9Jd 2GVhUKhJ2BNBBXMXsIDXtP1ztTYvZTI4zGD3B1quRTRS4qVNUfAFl+qlO4+9Spt0imgt 6Zgjvk+oEgujbUN/eYERtzwrv7p1CiEZeo4ui7lffakelJir5ukNiZaviBE2VkAAMU17 bWEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250334; x=1732855134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sj7FgNlmIDqfkOn9oqIGg3b9ST9EW/2dbnHWahYJAtY=; b=WXG7B7EArKRLUPzNZ/zTwOB8JqdOt2Mbdp4Ai76OxzkA99x7g8Q+JRq5fezTaTNvdl dnWxDjPPVr4/EX9kE1si0g9qIGJDXYRSDkb2L8Xl32uKL+NOENE1DiJVRsMrnfk1S7pp SXAat/PNcHHH1qbkt1Ao4qTlEXVTB3U57N+zJjZj9GdPkJ5joUpVKfMoiMVmwD/IzrMF CfK+5wjtOQ5l1TQnTA1DNPjccflF9FCfKLGLxuDA7oYh0gMhWSFN7YUcFWHsWHLp6CRQ DGFIpeSkeJsbFFy8L/0/5VsL7qSDdBvezTzJIZWvD7B963h2MWZh05/eZkP5ez3kB+Hs Gr4w== X-Forwarded-Encrypted: i=1; AJvYcCWrdz4ndQrqRbgAu1X/LRXYiyo4UN3/E1gwAW/vU/v7FcIN2fuKNhaXwXF+UR3d6MpLpegXZAOUzyZUqouFx2wvug==@vger.kernel.org, AJvYcCXrv6do9zIzPHEcPWhI7lRn7t5I2EI4PU4vKjWa+GuiolCWqMqT7Vyeuan4cuqHqh4lNLJbhyaHpJ6+VEU=@vger.kernel.org X-Gm-Message-State: AOJu0YxwHniSR5H14Lblpbt/doxgLdxD8svEJG1hqak4d6YUBPjKvitb 2ViL7p4gm+qEUKtwVASThxfxZKgU4u822olO5GWa38wF2Neut/Ux X-Gm-Gg: ASbGncunolvncZjzUd6IDwUwecMhlivCrvSccehWfZSm1vsdLLDednklViUzBonzf46 IY3hbTJFOjPFnWmP3dKUO9UpjRBoK/O9sDEHRw5mpuLmprse5ZWoue2h51JijdD+JLJkPHthBg1 jEMFmDYirSvM08ayzaz8NwFGcraKGFPsTf+O9XFjEiVj3KOqBRZEe5hr+mDvQUNzCVellBy9llm ogwQ3TsBRlgO5KYllmXo2gKsZkewFCA2yEimRgV+l6QJT3ZrrHt2ItAlo1LKgxI+yFUBnsBtxbQ Jt4ANFG9Kqo= X-Google-Smtp-Source: AGHT+IH112d+7FpaStLKCx/p1fGKn5j/gvILIRpBT64bbX+8DBOrRX4Y1gNS7/3Ko/HjnCu5z+Y8yQ== X-Received: by 2002:a17:902:f548:b0:211:f6e4:d68f with SMTP id d9443c01a7336-2129f7302d2mr16990245ad.6.1732250333994; Thu, 21 Nov 2024 20:38:53 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:53 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 06/10] perf evsel: Assemble offcpu samples Date: Thu, 21 Nov 2024 20:38:36 -0800 Message-ID: <20241122043840.217453-7-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use the data in bpf-output samples, to assemble offcpu samples. In evsel__is_offcpu_event(), Check if sample_type is PERF_SAMPLE_RAW to support off-cpu sample data created by an older version of perf. Testing compatibility on offcpu samples collected by perf before this patch= series: See below, the sample_type still uses PERF_SAMPLE_CALLCHAIN $ perf script --header -i ./perf.data.ptn | grep "event : name =3D offcpu-t= ime" # event : name =3D offcpu-time, , id =3D { 237917, 237918, 237919, 237920 = }, type =3D 1 (software), size =3D 136, config =3D 0xa (PERF_COUNT_SW_BPF_O= UTPUT), { sample_period, sample_freq } =3D 1, sample_type =3D IP|TID|TIME|C= ALLCHAIN|CPU|PERIOD|IDENTIFIER, read_format =3D ID|LOST, disabled =3D 1, fr= eq =3D 1, sample_id_all =3D 1 The output is correct. $ perf script -i ./perf.data.ptn | grep offcpu-time gmain 2173 [000] 18446744069.414584: 100102015 offcpu-time: NetworkManager 901 [000] 18446744069.414584: 5603579 offcpu-time: Web Content 1183550 [000] 18446744069.414584: 46278 offcpu-time: gnome-control-c 2200559 [000] 18446744069.414584: 11998247014 offcpu-time: And after this patch series: $ perf script --header -i ./perf.data.off-cpu-v9 | grep "event : name =3D o= ffcpu-time" # event : name =3D offcpu-time, , id =3D { 237959, 237960, 237961, 237962 = }, type =3D 1 (software), size =3D 136, config =3D 0xa (PERF_COUNT_SW_BPF_O= UTPUT), { sample_period, sample_freq } =3D 1, sample_type =3D IP|TID|TIME|C= PU|PERIOD|RAW|IDENTIFIER, read_format =3D ID|LOST, disabled =3D 1, freq =3D= 1, sample_id_all =3D 1 perf $ ./perf script -i ./perf.data.off-cpu-v9 | grep offcpu-time gnome-shell 1875 [001] 4789616.361225: 100097057 offcpu-time: gnome-shell 1875 [001] 4789616.461419: 100107463 offcpu-time: firefox 2206821 [002] 4789616.475690: 255257245 offcpu-time: Suggested-by: Namhyung Kim Reviewed-by: Ian Rogers Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-7-howardchu95@gmail.= com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d7a68d450080..e0fd0a3eaa7f 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1196,7 +1196,8 @@ static void evsel__set_default_freq_period(struct rec= ord_opts *opts, =20 bool evsel__is_offcpu_event(struct evsel *evsel) { - return evsel__is_bpf_output(evsel) && evsel__name_is(evsel, OFFCPU_EVENT); + return evsel__is_bpf_output(evsel) && evsel__name_is(evsel, OFFCPU_EVENT)= && + evsel->core.attr.sample_type & PERF_SAMPLE_RAW; } =20 /* @@ -2794,6 +2795,35 @@ static inline bool evsel__has_branch_counters(const = struct evsel *evsel) return false; } =20 +static int __set_offcpu_sample(struct perf_sample *data) +{ + u64 *array =3D data->raw_data; + u32 max_size =3D data->raw_size, *p32; + const void *endp =3D (void *)array + max_size; + + if (array =3D=3D NULL) + return -EFAULT; + + OVERFLOW_CHECK_u64(array); + p32 =3D (void *)array++; + data->pid =3D p32[0]; + data->tid =3D p32[1]; + + OVERFLOW_CHECK_u64(array); + data->period =3D *array++; + + OVERFLOW_CHECK_u64(array); + data->callchain =3D (struct ip_callchain *)array++; + OVERFLOW_CHECK(array, data->callchain->nr * sizeof(u64), max_size); + data->ip =3D data->callchain->ips[1]; + array +=3D data->callchain->nr; + + OVERFLOW_CHECK_u64(array); + data->cgroup =3D *array; + + return 0; +} + int evsel__parse_sample(struct evsel *evsel, union perf_event *event, struct perf_sample *data) { @@ -3145,6 +3175,9 @@ int evsel__parse_sample(struct evsel *evsel, union pe= rf_event *event, array =3D (void *)array + sz; } =20 + if (evsel__is_offcpu_event(evsel)) + return __set_offcpu_sample(data); + return 0; } =20 --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 4B1CA175D45; Fri, 22 Nov 2024 04:38:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250338; cv=none; b=one/I5iAJWXruvgib/L1Nr2ABpvsnzqee9c/AGSZrwJOKYBjKb6cSG+tknwChQo3ksu1GKvgiOPlJ+Yqhr4esN9MPD4uKRdcvRAXZELJqhOtN3VFYAkj38CsHB/mfIzJYAHIdtwCuLabl5LTlnX3dBw1n4K7j5F44DprQ5CRT3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250338; c=relaxed/simple; bh=vccFHYr8ZR9cgyM4HGgwFgDtARhDnJAfANCV1e9IKOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WaMoKI5MWXFOMP/Vl7pafwABrLfdNQF4Lu0F4QG44jB4zvnXErlwZ+GKfqVp2Q5J5UqCWdtbQpfteztGqXXr/n9u+FvpnS9Kpfbvyfklo62B9quH9sE6AjOY+TYSL4x7ef2Vx96EqQrchuaG8sBqdJ7KJkuxccUpfSuBnRz/6Q4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mEG/6jOl; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mEG/6jOl" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-21288402a26so16202985ad.0; Thu, 21 Nov 2024 20:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250335; x=1732855135; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hBlhrPHwwByaR2iQ3j+uYlOmJcTMAeh7R4Wsq+6yt50=; b=mEG/6jOlGHtxwRp96XnYJdi/vzV6Auh2UUaR6ONvfrcULEX8vDZeUsZemv8d680GT6 uK3eR4nxsMdkFlWfWHBB1NX8uBxKzDnuQru9otnWsA4FjcEwDHm/A2Q0KnbgfWewjoZR D95ejupCtYnlTbKgP00x2Lr1AjzdfAEzgpphKnZ1RGaZJvyLHuMBLjC0E/FMq6TI1Xag 6TIR5HDziJAt19G2+dCB8sjGyUBQWirC84bReVW+TMtSWY5+n0ZdgwYMZLey8hC9r0ew 9IdOJME8/KteI12Dw+g2DVXHxZjLkMXOJzilOs4+/TN/moleTo5p0el1h3yhwjZaW4V5 rgGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250335; x=1732855135; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hBlhrPHwwByaR2iQ3j+uYlOmJcTMAeh7R4Wsq+6yt50=; b=i2Jrkq0r9rcsdybVY2543kTSrgvwpf6sL73gQs2yzBGIp24BYp2tacCGNiVtOauZeQ uTft1VFaYkwAfxBFd2Xbw8OeYfVFBCjMoBanR6fsx8BoBVCPzxt+z/J0UZNhuXdt+4tn ptEyIolHU18Xbyg4hRGDy47pqMBMYBAULt09Uv/vu+OUDO08lVT5sENUrmPQj1zgeCBY Ci9zMMEc7svoqIykWYc4jRtcmeSldvu7FVkJAPFpTOEhIC+QZVo2S7f/BPE947H5JBTp d5NaJZOKyBQjSiM9CvOtpMcTQ3Xll6DA8RJWWcxy5svj0TpNFye2qhw2kHDPDbH2+muc w7Rw== X-Forwarded-Encrypted: i=1; AJvYcCV1SXqkqBmNowwUCUzWRioqPj+9RLLLvHqSMhZnkL9cl+ltv9HdU/E53xkLK3CCQgGD3oDK4yfoAAz1xR8=@vger.kernel.org, AJvYcCXCZUXTYLJJtVXqINt/HrKUGYnduPyi0lsrkWoyLcKmWB4UJ8AD5MiUn6m9l7yT7x+QcXSAk4TqSiBM+f04wo3Fow==@vger.kernel.org X-Gm-Message-State: AOJu0Yx/AWmUblOSqSVfqPIh2iISxMRYLy/sSn856NOcJDScUsCYgqkR yYSOJ3/cyMjDaGB9OcFbvVHcYkGgclf5yF3WgcbnU9fqnc0qTrdd X-Gm-Gg: ASbGncucRCu6eFzY+M13v6/OekSVDh6KEEPedr7e3P1525h0Tsm1OOW7RXKQVA/PTra BZUU6z298v8J5cNZvlHbxYJWwxoHv/++ISQdYmpjMTs29MhxwJIBMZwrambvsByVxvEOEikjfah ORFNrNANEl2pZLqBObnW75m4/wZHrWFCWHKwQIdtskYGuT2UUBGXObuK6BUSGcEQhU+ZAtynGL8 kKrKEKh5OYOMYd2OSQW89qFSrjgVkg8egF6iAY+0RQ+rV2PixDsbENT7BZIhtVkHMn2MRUy8OZy au4xNvdxlOM= X-Google-Smtp-Source: AGHT+IHIqoWLIXPnm5MeU74XzSsIm2/O9Rr3IPv3Q5s77pnEkhraKsXuMvxngzkgcBCuqpT08tDHGg== X-Received: by 2002:a17:902:dac8:b0:211:e686:760 with SMTP id d9443c01a7336-2129f2a53a6mr25806335ad.53.1732250335525; Thu, 21 Nov 2024 20:38:55 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:55 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 07/10] perf record --off-cpu: Disable perf_event's callchain collection Date: Thu, 21 Nov 2024 20:38:37 -0800 Message-ID: <20241122043840.217453-8-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There is a check in evsel.c that does this: if (evsel__is_offcpu_event(evsel)) evsel->core.attr.sample_type &=3D OFFCPU_SAMPLE_TYPES; This along with: #define OFFCPU_SAMPLE_TYPES (PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_IP | \ PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \ PERF_SAMPLE_ID | PERF_SAMPLE_CPU | \ PERF_SAMPLE_PERIOD | PERF_SAMPLE_CALLCHAIN | \ PERF_SAMPLE_CGROUP) will tell perf_event to collect callchain. We don't need the callchain from perf_event when collecting off-cpu samples, because it's prev's callchain, not next's callchain. (perf_event) (task_storage) (needed) prev next | | ---sched_switch----> Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-8-howardchu95@gmail.= com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/off_cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/off_cpu.h b/tools/perf/util/off_cpu.h index c6edc0f7c40d..f07ab2e36317 100644 --- a/tools/perf/util/off_cpu.h +++ b/tools/perf/util/off_cpu.h @@ -13,7 +13,7 @@ struct record_opts; #define OFFCPU_SAMPLE_TYPES (PERF_SAMPLE_IDENTIFIER | PERF_SAMPLE_IP | \ PERF_SAMPLE_TID | PERF_SAMPLE_TIME | \ PERF_SAMPLE_ID | PERF_SAMPLE_CPU | \ - PERF_SAMPLE_PERIOD | PERF_SAMPLE_CALLCHAIN | \ + PERF_SAMPLE_PERIOD | PERF_SAMPLE_RAW | \ PERF_SAMPLE_CGROUP) =20 #define OFFCPU_THRESH 500000ull --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 C02B1178CEC; Fri, 22 Nov 2024 04:38:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250339; cv=none; b=ar/MQv3719WwLcfLk/F5vRUBfEGOsr5dQSBJoWFI1AuOxPu9ySYNSoqLh7wsPuG0TTwWfpuBYVDHLxKueN58lKsdDnkAQ06DrUDcBnj95WXhUPu/7Ms/6o3L/TvJPPkR8VbxvDp8TK2APCsWkrdJ/yT8kWlcom2TwCVB202NXGI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250339; c=relaxed/simple; bh=k1Tn5Q4+wHFYp0tK7QptT/pbuAUsO9q/uZ8bPfpXGOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mJQIDU5/4PzCTAzcJ66Kk+IR2evQJUHQQbEi+F4WJq6TdxKe1xj4xK60OzgT4otA4YM9pcBo6qSSfJZbAThwrJPflJTA9D9j8P568ZnuWMsx1VVTArTWkhKEXsF9EDRmBBR5NKtjNKar/RoeEGwjj+qo8dKE97/iE96+KURe434= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PYJmMZUY; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PYJmMZUY" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-211fd6a0a9cso13451505ad.3; Thu, 21 Nov 2024 20:38:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250337; x=1732855137; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o/ufGw+ywqZDjP+CMDcVLPSB5OERM7z6+MoX4VJalRo=; b=PYJmMZUYsyes6Auxu5Spuro8z1E8I0W0VF7wuNBGjgxZhTHFMYjIb0FUpLF0QkYVoP yfhs4j/pxursUq7D29chp/SludJE07b8J4Fc29Z4jptbs6RcZhael05lngadjrHv/7rS UmtOn5M9tEL4kL5tGko7KRsSxagfl9BHu2vhNwp9jn88zLsUkn6+CcZSK2PZ9SgPGyqn 3xbcm/nwUK0EKsq1IKBA/omTmSyw5CD9VsZpK7vIMldpvwoGyhzsj5heDjtydFTUgeBq hzsY1w1XKVjhO0dJkO5dI4XhmZCvWndOLYLOQJ4peP81qXkP8HoH49qRZYZgf0zha4Hk 0gqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250337; x=1732855137; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o/ufGw+ywqZDjP+CMDcVLPSB5OERM7z6+MoX4VJalRo=; b=DsPOHMmMY0VQRO2Efrlo+w3SjrPiQ6NxKjXgIP9tUb0g364K8pWxIm/QnQkI66sQbm kQfBxYSP/Z/dFSa2PN9dRqaBtTVxrNSgBc09qUtOAO/VtyJAr5jMT3CUAu1kaiNuKF1W dcTTzb37C3cW8NViFv/xpoO3b+4s4fkbN4DDC35gAfqsTRZa9ozl33DSbE0rkmD36L/L Jtd8CTlMKtwzNGL14s65t3KKTXPZiXZgxTieTPtsE3ROZu+k91ZtWBtVpwr/a+2G3M2R QClmZY8WWUDiJzq2W966WOws/srnJ1qA6Egm+R1t8PgxHCWCguAiJSFw9N1hgVT9U6UH QCzA== X-Forwarded-Encrypted: i=1; AJvYcCVXKnn3/1GReL5mPYZBi5jRb5hsVtcpD0z8aSHC9LYeeu6cZEJSywq3wp7ji2Hmetg8tjfA05zWtfBsAOT3Tsln/w==@vger.kernel.org, AJvYcCVpF7+aiIPpzNRZS7Sba5sJXVlyz/4vCXYhnQs4R2N2+eKDbJ8eVoI7mlCpknn8DjCpAEnZU+gcJloHWC4=@vger.kernel.org X-Gm-Message-State: AOJu0YzDvlotvs+cF7e/1j7IhdWwUS+YIBE67bRAEDQZvG12RvzwSMO2 ApRocjnsYcEPOnYZd8WW2l9kHbBfEssvW1aOZoW0JCsaCBgUvHps X-Gm-Gg: ASbGncsm85XC+ZL8HmoHRi19bmbnPTWIUUaymgUaRbVsAwc7tSAKm7xt/8lpsj1O/C1 /D46qLh/Z3hcdX7ZjXPARDX1oVjiODG1CC5vF+F7lWbkv+ylADAydCfNmbKjp5foX8VmwCD3Hr/ xNUGTyrg7CqwgljQ3h3VfTaTDxEzN8j51Wj9PeP63rqHtTIpRfsXNPYgykctuzSS2ap3W7BwfnF Wp86KqOVYDUADe8ahqmcbgUPcQGgx3Ze9GS3cfWewOJjkZlVQwgHv2ReT44S7G7a6wbWgoGN1DD f7dhPaQ1BsE= X-Google-Smtp-Source: AGHT+IG/vsXjfORiqcE/D0/VZ78u8WumP4LMWP2uzjUHQE/j9P8Tj3OU/FsK6IqjwACcLNr82CA3MQ== X-Received: by 2002:a17:902:f685:b0:20c:9326:559 with SMTP id d9443c01a7336-2129f240de5mr23803355ad.29.1732250337056; Thu, 21 Nov 2024 20:38:57 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:56 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 08/10] perf script: Display off-cpu samples correctly Date: Thu, 21 Nov 2024 20:38:38 -0800 Message-ID: <20241122043840.217453-9-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable No PERF_SAMPLE_CALLCHAIN in sample_type, but I need perf script to display a callchain, have to specify manually. Also, prefer displaying a callchain: gvfs-afc-volume 2267 [001] 3829232.955656: 1001115340 offcpu-time: 77f05292603f __pselect+0xbf (/usr/lib/x86_64-linux-gnu/libc.so.= 6) 77f052a1801c [unknown] (/usr/lib/x86_64-linux-gnu/libusbmuxd-2.= 0.so.6.0.0) 77f052a18d45 [unknown] (/usr/lib/x86_64-linux-gnu/libusbmuxd-2.= 0.so.6.0.0) 77f05289ca94 start_thread+0x384 (/usr/lib/x86_64-linux-gnu/libc= .so.6) 77f052929c3c clone3+0x2c (/usr/lib/x86_64-linux-gnu/libc.so.6) to a raw binary BPF output: BPF output: 0000: dd 08 00 00 db 08 00 00
...... 0008: cc ce ab 3b 00 00 00 00 =CE=AB;.... 0010: 06 00 00 00 00 00 00 00 ........ 0018: 00 fe ff ff ff ff ff ff . 0020: 3f 60 92 52 f0 77 00 00 ?`.Rw.. 0028: 1c 80 a1 52 f0 77 00 00 ..Rw.. 0030: 45 8d a1 52 f0 77 00 00 E.Rw.. 0038: 94 ca 89 52 f0 77 00 00 ..Rw.. 0040: 3c 9c 92 52 f0 77 00 00 <..Rw.. 0048: 00 00 00 00 00 00 00 00 ........ 0050: 00 00 00 00 .... Reviewed-by: Ian Rogers Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-9-howardchu95@gmail.= com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 9e47905f75a6..dd0f95c51571 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -662,7 +662,7 @@ static int perf_session__check_output_opt(struct perf_s= ession *session) =20 evlist__for_each_entry(session->evlist, evsel) { not_pipe =3D true; - if (evsel__has_callchain(evsel)) { + if (evsel__has_callchain(evsel) || evsel__is_offcpu_event(evsel)) { use_callchain =3D true; break; } @@ -2353,7 +2353,7 @@ static void process_event(struct perf_script *script, else if (PRINT_FIELD(BRSTACKOFF)) perf_sample__fprintf_brstackoff(sample, thread, attr, fp); =20 - if (evsel__is_bpf_output(evsel) && PRINT_FIELD(BPF_OUTPUT)) + if (evsel__is_bpf_output(evsel) && !evsel__is_offcpu_event(evsel) && PRIN= T_FIELD(BPF_OUTPUT)) perf_sample__fprintf_bpf_output(sample, fp); perf_sample__fprintf_insn(sample, evsel, attr, thread, machine, fp, al); =20 --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 3090217C7C6; Fri, 22 Nov 2024 04:38:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250342; cv=none; b=ejnBJuKJbPBd5guPUtpOpUy0FFyzgbYR04WGNwOkeV7KqKgzR/WM/BfMQ2gcNWDhAr7GHiL0Kmx83g6lwtAnQYs0S3IRqUK+XqANb0k+ypmbpB6UAJhYAVa2ofMDImq5sHOXLawJTqT1Fz6hLMzBMZgI6lokKDMVoV5ikHDCL50= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250342; c=relaxed/simple; bh=goTdjk11qmBk6a5P1AA+giS5yljV5oLTjYAh1YgVF+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PyCXMqJAK9pLvXNU2nvQCvmoqT8Clu0+xyjn/jwo+BJIYSIE+idAawQ8TKp1R/4EZ9Mc0SxQpHbUMS/uy0YfYtA9Zf1g7nK+TJFDLXB57NmbAxPhKY8VtUPgh+WZbG14N8ceXeBwNj7R7kelGTmXZbROZYBEZeCSCZgb72iM0Ic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bLWtdEQ6; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bLWtdEQ6" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2129fd7b1a5so3370985ad.1; Thu, 21 Nov 2024 20:38:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250338; x=1732855138; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L7PbFB0EtVCviJ5bhbaIb04d6odUROmdh06maH/pBNc=; b=bLWtdEQ6sfSsZP9+ymmLrTHOxVAG/MMF4L3hZGNgkoaHfzCHVvPmHd9jJoN+FUgh+a Lx19fLQxPyn8V/GMC3Vzm5a85u+e0Embyp+YU93+maYna9lA2O0Jjpj/AmPWHcCk3B0M 5+9TZOKubXQ13OXGJ2lO/+JBgv4qMvlkOUP+RdEq37Jurjpm7n83S3GP16ZR8Nu95bR8 KO79gl8rcKARfO9HvrLZXYHAbf/9B7m01QyopQcmmJ0cVp/6ReZLxFWvtPuMFeCeREs3 +0JWcBsC+UTgs9SL+7jdaUC3gzzudyPfuAMC7BvILb+FAyFSqnW+j3ncoMsk7RaJHb8N GXqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250338; x=1732855138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L7PbFB0EtVCviJ5bhbaIb04d6odUROmdh06maH/pBNc=; b=gvWvRu/vYiJfqJ6DEo/T/iA4hZXQuA6rSo03jvmj0vUSaxpad4klxC8amcfSO3jxEk Uf2UefyiEMoceb6/9SrEqdgoqvWL7HcfhzlebghMz1u7fUmo54V6+ppNDO3oAAjO6VcO +xq3shm5HJyv1TYhx5M0N5H197JP1bKDS+JTF6rCJ79FYuOV0zKd/bDZk6lmKRTvFxRe u4c36Wi9VU8Jt7yB3OdTCf5wfvEAh1A3Vog2C2kxuAPRR588vVrgnUrZXrLSEtUFEXbX 3/zvgKD48TCVMWivoUXCL6KKSJltYubFgYFaxkkZuPIIbOTpSVn5BI9wNg/h17RQf+ta B6Rw== X-Forwarded-Encrypted: i=1; AJvYcCUDAL0n6r47mBfGQM27HqSS9+CV7tlMmlYdgUxWJ2YBFFx1E2aP8t2rt6axo9Disj1sJ3QTYb1yFmwbFWsdqmc9nQ==@vger.kernel.org, AJvYcCW3kqkIgCGDIZu1pNDTqjSreiAyUucARvVqnSxPnYLam7hfZD1Uw0nU065DGQ1Tn/hz5UFYjNbMb8uWlVk=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3+y9V1YSo5N2FqoE+SgG/xY8AwnwJ+nOtg7O/IAWje61IXxP8 WFXO74YxQW7+Hyc4FM4bllyjrjReRfEzCwq5VpiEDdDFA9O/sDjH X-Gm-Gg: ASbGncvs1NVPRP1ouUTDbSGhU1v9FktLJUgbZQcGGipETPSqZIFx2hXrmPektUi8Nv0 /vwH7AvUbWAgd7fXc9JEnFWqFZZszg4hFvuf8bi3/4g0JHenOM2nowfNnZSoAayjRS5IdkkuFFL 0oTeK+tflBTQFTN6KOjp8xnKAIOasGCdzV6UdsngHF1NuXP1eq3hrkm36w/rkdsp2PkMpWQWwcU gg15Bm1YQQpM/QYtEgTkOrRqwhxNNE9yort1bJDBeqHNDUpqsXjoPwKRImLF7Bq2zXnELkps6vs dvfxGkeE9h0= X-Google-Smtp-Source: AGHT+IFakci6wd+SwbI7M/tBtmwb9/0itlK4/Wzl9Sv7NXBCtZa/WM4AqH351Nhf5/50lGUGZY0tUg== X-Received: by 2002:a17:902:db07:b0:211:efa9:a4df with SMTP id d9443c01a7336-2129f22b9b1mr18783525ad.17.1732250338554; Thu, 21 Nov 2024 20:38:58 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:58 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 09/10] perf record --off-cpu: Dump the remaining samples in BPF's stack trace map Date: Thu, 21 Nov 2024 20:38:39 -0800 Message-ID: <20241122043840.217453-10-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Dump the remaining samples, as if it is dumping a direct sample. Put the stack trace, tid, off-cpu time and cgroup id into the raw_data section, just like a direct off-cpu sample coming from BPF's bpf_perf_event_output(). This ensures that evsel__parse_sample() correctly parses both direct samples and accumulated samples. Suggested-by: Namhyung Kim Reviewed-by: Ian Rogers Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-10-howardchu95@gmail= .com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/bpf_off_cpu.c | 59 +++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index 2378fb5a893f..d6f015362e85 100644 --- a/tools/perf/util/bpf_off_cpu.c +++ b/tools/perf/util/bpf_off_cpu.c @@ -37,6 +37,8 @@ union off_cpu_data { u64 array[1024 / sizeof(u64)]; }; =20 +u64 off_cpu_raw[MAX_STACKS + 5]; + static int off_cpu_config(struct evlist *evlist) { char off_cpu_event[64]; @@ -309,6 +311,7 @@ int off_cpu_write(struct perf_session *session) { int bytes =3D 0, size; int fd, stack; + u32 raw_size; u64 sample_type, val, sid =3D 0; struct evsel *evsel; struct perf_data_file *file =3D &session->data->file; @@ -348,46 +351,54 @@ int off_cpu_write(struct perf_session *session) =20 while (!bpf_map_get_next_key(fd, &prev, &key)) { int n =3D 1; /* start from perf_event_header */ - int ip_pos =3D -1; =20 bpf_map_lookup_elem(fd, &key, &val); =20 + /* zero-fill some of the fields, will be overwritten by raw_data when pa= rsing */ if (sample_type & PERF_SAMPLE_IDENTIFIER) data.array[n++] =3D sid; - if (sample_type & PERF_SAMPLE_IP) { - ip_pos =3D n; + if (sample_type & PERF_SAMPLE_IP) data.array[n++] =3D 0; /* will be updated */ - } if (sample_type & PERF_SAMPLE_TID) - data.array[n++] =3D (u64)key.pid << 32 | key.tgid; + data.array[n++] =3D 0; if (sample_type & PERF_SAMPLE_TIME) data.array[n++] =3D tstamp; - if (sample_type & PERF_SAMPLE_ID) - data.array[n++] =3D sid; if (sample_type & PERF_SAMPLE_CPU) data.array[n++] =3D 0; if (sample_type & PERF_SAMPLE_PERIOD) - data.array[n++] =3D val; - if (sample_type & PERF_SAMPLE_CALLCHAIN) { - int len =3D 0; - - /* data.array[n] is callchain->nr (updated later) */ - data.array[n + 1] =3D PERF_CONTEXT_USER; - data.array[n + 2] =3D 0; - - bpf_map_lookup_elem(stack, &key.stack_id, &data.array[n + 2]); - while (data.array[n + 2 + len]) + data.array[n++] =3D 0; + if (sample_type & PERF_SAMPLE_RAW) { + /* + * [ size ][ data ] + * [ data ] + * [ data ] + * [ data ] + * [ data ][ empty] + */ + int len =3D 0, i =3D 0; + void *raw_data =3D (void *)data.array + n * sizeof(u64); + + off_cpu_raw[i++] =3D (u64)key.pid << 32 | key.tgid; + off_cpu_raw[i++] =3D val; + + /* off_cpu_raw[i] is callchain->nr (updated later) */ + off_cpu_raw[i + 1] =3D PERF_CONTEXT_USER; + off_cpu_raw[i + 2] =3D 0; + + bpf_map_lookup_elem(stack, &key.stack_id, &off_cpu_raw[i + 2]); + while (off_cpu_raw[i + 2 + len]) len++; =20 - /* update length of callchain */ - data.array[n] =3D len + 1; + off_cpu_raw[i] =3D len + 1; + i +=3D len + 2; + + off_cpu_raw[i++] =3D key.cgroup_id; =20 - /* update sample ip with the first callchain entry */ - if (ip_pos >=3D 0) - data.array[ip_pos] =3D data.array[n + 2]; + raw_size =3D i * sizeof(u64) + sizeof(u32); /* 4 bytes for alignment */ + memcpy(raw_data, &raw_size, sizeof(raw_size)); + memcpy(raw_data + sizeof(u32), off_cpu_raw, i * sizeof(u64)); =20 - /* calculate sample callchain data array length */ - n +=3D len + 2; + n +=3D i + 1; } if (sample_type & PERF_SAMPLE_CGROUP) data.array[n++] =3D key.cgroup_id; --=20 2.43.0 From nobody Sat Nov 23 12:46:08 2024 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 CBBF018593A; Fri, 22 Nov 2024 04:39:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250342; cv=none; b=bKGoENM4uAuY/PeHfMqmjxKglC4eGhw1uAYWAf/tsAmy9RU6cAIHTjpun53CT6+YVz5KbY37xQvMxR6DTW1uvzgSqRgn+jTRTehD1M/Hdo43GEQyD8aYAXOqxaa7rUDyUZU/Yls2j2qrUhH5dkHCK6doFdHVSXMC8TsXgaoysxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732250342; c=relaxed/simple; bh=i38KITFoXQxHV5vC+zLrvHnE4A5s7OsP/Virq4w9OTo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ur9sYkHcb/ColRTtIHBDg3lwBYVZNuWS6cXEhES0zhAm/ajNxG7OiWpEkz2b4I0EJu9uKQIroICFArugtJmFkY9Yh5K3fPniU7WUmb9BvyuswSgS4n0gwl+PYZ+0xQu5X54Nd4mEsNDcGflixX29sWMXFrpKaSjy6qMBANyNdnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=H9R9ebXv; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="H9R9ebXv" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-21207f0d949so15752645ad.2; Thu, 21 Nov 2024 20:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732250340; x=1732855140; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ghYLYuPX8XvrvfkfC7VIB18q5PzN1p3CvZzBe/JSGjo=; b=H9R9ebXvX3Keqq4p/eJlfrvpxi2M88pi7OA5e7AT/u55d4rM/Qbr0eObFNXo+QmQKM 9PF6YV8f9I/WNKEsHV1jafoto7XY6fRDMYpkbvvutOayQX37zSmYr5AaeUlP4Eh9bzl6 zcCl6iyEz73wiSVt127vKaFJZjTM1o+PaVtFrTA6cOnOPC3gcmunalny32H9pdvjwXSu 5yh+fkGNdpxU7c8NUaX4rY6hI2/JUgzrQjkYQ/rn3awL5WtXSOADYwAeHLtlKx2DmrNS zF135dkkPta5NjKXv/zLLZPGG1wCz3qlbghb6qOnLTCOMtZY8XWL3TG0nHVZ0qvTuBlb df0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732250340; x=1732855140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ghYLYuPX8XvrvfkfC7VIB18q5PzN1p3CvZzBe/JSGjo=; b=egf6y4EB/ihpKPcvqipZxolJpC7+kvOWzIGxYje82IyjiGasjmQJ6Sh+eaF7LZnS+X YD7QadYY5EyzE5CCZ8YMjrFLNMa8C9S7gRFdSamCkUAH85yu05kS5+70UIcsLktx1utq OgN3NKaHoBREM30IDRBS091Txd6oIKRBD5iVx41EiSTapi1zNy60RZ/Ebrl5srRaTbXI WQ72iO4rs3lJpOQHGNg55lITOQZaKfMMry30z4i2Hfmto/WAaivyk1v2W+blkWF3CXhh 1mIPnhxnK85Gy9hbeTq42SxCsfZ+6DKjbvw/ryucxJuEYuM6v32kCHtaOFwpjNgkCr/Z 4buA== X-Forwarded-Encrypted: i=1; AJvYcCW6S/IQB2KVOSiJBLZF+a1ibDXT3k2EQQ+/2kEP0GJ2NcQ4O2DjNvU39wTFxwRnmp5iqnTMZZ7+eLnPn+9efRzk9g==@vger.kernel.org, AJvYcCXFZ9rINuQ2Fn31yXX1ZTAjiojvLm/KxgWW532JJ4Id31qK1NuaVej8irgGh7bYDFSa2CDS3gvRhWUVv2I=@vger.kernel.org X-Gm-Message-State: AOJu0YwNka0LRw3nzySFltN0PJq1rVp+onk5e8K/fpbFBEnPJHlNq/Gl DYy8Le3RpK1yyPt9CbAS6uPbon5q+3gGGkf1UUYqk/QPa2ZuwVbu X-Gm-Gg: ASbGncuj8w6pEnqoDaXrf0/wrmGf4auAMfpHe3KN+vPiiWjHyMJc5+4R8GgLkGaXmVT p2/JQZhbQXic+pK8f5QIIHFtjiJMZBBbLDVjxmdASmpl9TWnBdPP2i4/D6aEl8XmQAxK6gSPsEY G9B4FNBLRginKt2sAu/oT4tPnbjwM1OaQgRqZfIC0l/CiEOtCd6H4eO71aJp9A1gw2B0W0A0XKO sjMdp1taWpglXTurSaS7onEoZ0Nztp9He84TcNxYmBWQA35iJ3BEPSN/pq2scfAIG7oL+I/XWE0 iitXKFf3u54= X-Google-Smtp-Source: AGHT+IGIxtkFFLur8UVdFDG0iwtb4KDnzz7Zl10IsNEo3w/bPPCZ5sC5/M5XIKfo/6AHXo/zF2Rczg== X-Received: by 2002:a17:902:ebc4:b0:212:5120:f212 with SMTP id d9443c01a7336-2129f51d710mr20643365ad.5.1732250340020; Thu, 21 Nov 2024 20:39:00 -0800 (PST) Received: from mbp.lan (c-67-174-206-244.hsd1.ca.comcast.net. [67.174.206.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dc1544bsm6638135ad.193.2024.11.21.20.38.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 20:38:59 -0800 (PST) From: Howard Chu To: peterz@infradead.org Cc: mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu , James Clark , Arnaldo Carvalho de Melo Subject: [PATCH v9 10/10] perf test: Add direct off-cpu test Date: Thu, 21 Nov 2024 20:38:40 -0800 Message-ID: <20241122043840.217453-11-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241122043840.217453-1-howardchu95@gmail.com> References: <20241122043840.217453-1-howardchu95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Why is there a --off-cpu-thresh 2000000? We collect an off-cpu period __ONLY ONCE__, either in direct sample form, or in accumulated form (in BPF stack trace map). If I don't add --off-cpu-thresh 200000, the sample in the original test goes into the ring buffer instead of the BPF stack trace map. Additionally, when using -e dummy, the ring buffer is not open, causing us to lose a sample. Signed-off-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241108204137.2444151-11-howardchu95@gmail= .com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/record_offcpu.sh | 35 ++++++++++++++++++++++++- tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 1 + tools/perf/tests/workloads/offcpu.c | 16 +++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tools/perf/tests/workloads/offcpu.c diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index 8dcf74d3c0a3..43dc04075ecb 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -146,6 +146,7 @@ static struct test_workload *workloads[] =3D { &workload__brstack, &workload__datasym, &workload__landlock, + &workload__offcpu, }; =20 #define workloads__for_each(workload) \ diff --git a/tools/perf/tests/shell/record_offcpu.sh b/tools/perf/tests/she= ll/record_offcpu.sh index 678947fe69ee..8719130fbf70 100755 --- a/tools/perf/tests/shell/record_offcpu.sh +++ b/tools/perf/tests/shell/record_offcpu.sh @@ -6,6 +6,10 @@ set -e =20 err=3D0 perfdata=3D$(mktemp /tmp/__perf_test.perf.data.XXXXX) +TEST_PROGRAM=3D"perf test -w offcpu" + +ts=3D$(printf "%u" $((~0 << 32))) # OFF_CPU_TIMESTAMP +dummy_timestamp=3D${ts%???} # remove the last 3 digits to match perf script =20 cleanup() { rm -f ${perfdata} @@ -39,7 +43,11 @@ test_offcpu_priv() { test_offcpu_basic() { echo "Basic off-cpu test" =20 - if ! perf record --off-cpu -e dummy -o ${perfdata} sleep 1 2> /dev/null + # We collect an off-cpu period __ONLY ONCE__, either in direct sample fo= rm, or in accumulated form + # (in BPF stack trace map). Without the --off-cpu-thresh 200000 below, t= he sample will go into the + # ring buffer instead of the BPF stack trace map. Additionally, when usi= ng -e dummy, the ring + # buffer is not enabled, resulting in a lost sample. + if ! perf record --off-cpu --off-cpu-thresh 2000000 -e dummy -o ${perfda= ta} sleep 1 2> /dev/null then echo "Basic off-cpu test [Failed record]" err=3D1 @@ -88,6 +96,27 @@ test_offcpu_child() { echo "Child task off-cpu test [Success]" } =20 +test_offcpu_direct() { + echo "Direct off-cpu test" + + # dump off-cpu samples for task blocked for more than 1.999999s + # -D for initial delay, to enable evlist + if ! perf record -e dummy -D 500 --off-cpu --off-cpu-thresh 1999999 -o $= {perfdata} ${TEST_PROGRAM} 2> /dev/null + then + echo "Direct off-cpu test [Failed record]" + err=3D1 + return + fi + # Direct sample's timestamp should be lower than the dummy_timestamp of = the at-the-end sample. + if ! perf script -i ${perfdata} -F time,period | sed "s/[\.:]//g" | \ + awk "{ if (\$1 < ${dummy_timestamp} && \$2 > 1999999999) exit 0; el= se exit 1; }" + then + echo "Direct off-cpu test [Failed missing direct sample]" + err=3D1 + return + fi + echo "Direct off-cpu test [Success]" +} =20 test_offcpu_priv =20 @@ -99,5 +128,9 @@ if [ $err =3D 0 ]; then test_offcpu_child fi =20 +if [ $err =3D 0 ]; then + test_offcpu_direct +fi + cleanup exit $err diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index cb58b43aa063..2e655a617b30 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -217,6 +217,7 @@ DECLARE_WORKLOAD(sqrtloop); DECLARE_WORKLOAD(brstack); DECLARE_WORKLOAD(datasym); DECLARE_WORKLOAD(landlock); +DECLARE_WORKLOAD(offcpu); =20 extern const char *dso_to_test; extern const char *test_objdump_path; diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/= Build index 5af17206f04d..0e78fd01eaf1 100644 --- a/tools/perf/tests/workloads/Build +++ b/tools/perf/tests/workloads/Build @@ -7,6 +7,7 @@ perf-test-y +=3D sqrtloop.o perf-test-y +=3D brstack.o perf-test-y +=3D datasym.o perf-test-y +=3D landlock.o +perf-test-y +=3D offcpu.o =20 CFLAGS_sqrtloop.o =3D -g -O0 -fno-inline -U_FORTIFY_SOURCE CFLAGS_leafloop.o =3D -g -O0 -fno-inline -fno-omit-frame-pointer -= U_FORTIFY_SOURCE diff --git a/tools/perf/tests/workloads/offcpu.c b/tools/perf/tests/workloa= ds/offcpu.c new file mode 100644 index 000000000000..57cee201a4c3 --- /dev/null +++ b/tools/perf/tests/workloads/offcpu.c @@ -0,0 +1,16 @@ +#include +#include +#include "../tests.h" + +static int offcpu(int argc __maybe_unused, const char **argv __maybe_unuse= d) +{ + /* get past the initial delay */ + sleep(1); + + /* what we want to collect as a direct sample */ + sleep(2); + + return 0; +} + +DEFINE_WORKLOAD(offcpu); --=20 2.43.0