From nobody Sat Nov 23 23:00:42 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.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 B3AED1D63DC; Fri, 8 Nov 2024 20:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098508; cv=none; b=Ox9OjSIJNjCoI0K4TqSiU8W44U56VRuxU3ktkpJ5InFi4EOkZyzis+DVN0/csj8Hpk8dD91bFvKokXT5aW5WZzMrOYgWPFhJNF0au4lqEP3AFLZOrqjmOuTHEtugGCi6KJnqo11Aa5iQQXmIQ3TckScvEd1CylsG1q+O1PvJCnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098508; c=relaxed/simple; bh=7d2a59hjrXHo9LfQT3EC3YQbMy4Zy/NeVOWqAns9NwE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zl0q1pPSS9lDwWqgMVzdAj8aufy24dHGaDUCjpFyFyoSr+FPmcu9hBI3wYkCxTpNiSaks+xKSq+VE9q1HJmA/g6aZfnEQ7LT7/fOTcZJoqlhqTW/MowHmBbKsCz4qyAmCXtOf3eXONUvf6NO/one87uECPzw/Y4/qit+sv7aWDg= 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=HOMTwfAN; arc=none smtp.client-ip=209.85.210.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="HOMTwfAN" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e467c3996so2194662b3a.2; Fri, 08 Nov 2024 12:41:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098506; x=1731703306; 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=4e7d/fIuA3SMFMRnL/0dGJJps8hL64edz7Ln9wdsWNI=; b=HOMTwfANECdb/eW71/uv0UYn8Q0p4LWkkHl8NlYsSU67vMZwfgu6arG9gmalOUxiZu KWCvnIvgGIBP4Owp3soYlu1E7OfcUu3/ojo82CJ/GBOmZV3+MFD9mjNWltIj2xHNmKeu bDmopgB2k81/qQMFMGHWVeqcpHsPyeds3vkui2ZiAY++p5rW60Vzvfqo1Ey4py9h6Ir7 ir8Vxl+HisUQxXavVrI2ZQuEyfhCOVKmZZMv6u4r0CghAe+HqHqrEDr60rCVqdr0jCMX U8TOqOVqrXwmMdY4U8M5Z4ZuI/AzbFGI7rCKCS0ouYY47n5V0sMl3mPmpssRFiWbCYpg TgKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098506; x=1731703306; 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=4e7d/fIuA3SMFMRnL/0dGJJps8hL64edz7Ln9wdsWNI=; b=Eqs+SXtTqxk4koO+zdiagNYbxcWQthZyAyN8Kh2FfOtRQDvS1QSqRK/qbYEX9vwxKG ZUUBzMWB1vXjZQ5OEcQRoEzht1uG+RoaZDZrv+EET+RemnRQDLj1gEZpfUyq3vcg2oTF jEKUf0oCGsYv3srvIY1PbhURgWrNNnjHOCQ2mDx6eiLhsKjhvFbzxWkQ0amBfx4egHbj V7TtQzQjfPPS/g9O0s9kp2h84QUs56fsZEFhGX3ShnavRZ84qrv6DYVOyXoog46uBdsu NfsISnCu359q8RbQXFFqjR8rBZ6rpdv2LqPHtzO1s5IMCoE79vPhl13Ap7uIvdyNXSnO uVXQ== X-Forwarded-Encrypted: i=1; AJvYcCWuvp6fDoN9KZMu5nJqv3I4oAwJrzXbMzkvGAcqjRiTH8K9233MvCTPT/j8efqjZEBW92V8XsbWE+zn6XI7N9JVZw==@vger.kernel.org, AJvYcCXyQMCJ6FULTRD6Ln26tHsrkI5zMXgJ54AHOoMqtWRI2t72gwdTAsbE9YGOBiQWJXmkJ4aJZYuvQrKkYAI=@vger.kernel.org X-Gm-Message-State: AOJu0YyTKf7OM327gtszKKHJsJqDGMYmfPmkeXUAWIXCJrB7O/PKWi+i xeHkcqjSoe5BvPz0+Bj5wkJxxRfAd/P6qa3/c9A9fuCCKvzmicT9 X-Google-Smtp-Source: AGHT+IHN8BF0wU+hRWkj4JYDZSLcmTu7Irz7OzFjiIsWGcQblSV2cxN3uBWLsBxqazzEGMiYoT3O2Q== X-Received: by 2002:a05:6a20:9f04:b0:1d9:b78:2dd3 with SMTP id adf61e73a8af0-1dc22a42534mr5674962637.26.1731098505999; Fri, 08 Nov 2024 12:41: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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:45 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 01/10] perf record --off-cpu: Add --off-cpu-thresh option Date: Fri, 8 Nov 2024 12:41:28 -0800 Message-ID: <20241108204137.2444151-2-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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 500000us (500ms, 0.5s). Suggested-by: Ian Rogers Signed-off-by: Howard Chu Reviewed-by: Ian Rogers --- tools/perf/builtin-record.c | 26 ++++++++++++++++++++++++++ tools/perf/util/off_cpu.h | 1 + tools/perf/util/record.h | 1 + 3 files changed, 28 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index f83252472921..ee04fdd7f2ca 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; + + if (!str) + return -EINVAL; + + off_cpu_thresh =3D strtoull(str, &endptr, 10); + + /* threshold isn't string "0", yet strtoull() returns 0, parsing failed */ + if (*endptr || (off_cpu_thresh =3D=3D 0 && strcmp(str, "0"))) + return -EINVAL; + else + opts->off_cpu_thresh =3D off_cpu_thresh; + + 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 =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..3c11416e6627 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; }; =20 extern const char * const *record_usage; --=20 2.43.0 From nobody Sat Nov 23 23:00:42 2024 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 196A01EBFEC; Fri, 8 Nov 2024 20:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098509; cv=none; b=qqvquzov6/diOnSiDgrTRHzWc9WFkeg6ReVgPsvXPkw59zi7F1dbt2CM/C/XX3fkR0lje9+UGj+VEuxO4oz71EI7rP8A+8H58MagZeF4KVDRDMPvCMASt8lME0pn2XCVbRWnRRGwqxlnylyjnylbJWTMFtYgZQDH76VhGxa7zkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098509; c=relaxed/simple; bh=qfK32nrxof+TkZxXSG7rjc3Yo+eLtgY6yJxrTTp6k4k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G3mLKIXE507ZF/BjC31ilLY5OKjMMvVj8F0BdEAZRtfnTjcTMTlEVNhw2J3rOs1TuA9GCBhSRhQz/RV3Du8/iecyrhUuH1T5dSo9MgdiLUvUa6ZJUH0cfWPtO/b1ooV2CDs/Ww3hFBRT4vhEtBsCezgrPDiqFtgumFmGzdjHn6k= 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=Yq9Zj6+M; arc=none smtp.client-ip=209.85.215.174 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="Yq9Zj6+M" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so1873152a12.2; Fri, 08 Nov 2024 12:41:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098507; x=1731703307; 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=5DDTIIOXrlyRpPj2EqrJgznrv0EYT+anm2NNcd0r7hI=; b=Yq9Zj6+MmDVqHl/w6014E9viM/Ahut7qGhNY9c6HeGi26KofHmYHzvzFSWbcdR3XLs Y17V1yk9Wxavn3pzWFlr1bE5Ma8Sl9EvLUQmA36bIiaoVw78201EUnQgr+g2R8v4KDMv 3adUD1HSlnObrsS8Znu13UbAGvsSPmlGGbXWbw/HDuVYg5uNzQViNAAST8tbENeZTApH 3Nb5WKWtC4/0sqNXN7YwsRlE4xJ83wjQ6HLoOOTdiOW+uOxdY1Zi/QbYUk7nDB0Vgvjq NzFKEyj9nL3LbJYgmTEfTGNpTT83++BtKfUoz5OeSxpwStY4U/vQlfM3lfil0Q50/EvE kfZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098507; x=1731703307; 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=5DDTIIOXrlyRpPj2EqrJgznrv0EYT+anm2NNcd0r7hI=; b=c6OOwACn+bdfIfpT1InynA6r8c3D160iTqf0NHQKGcOSqQ0syVIHOzjea5w7ayEcIq bLucAL2zBVRLu3pPnhuoeTktjVvvoTRa5DyKW5HIU8UbGL11xXeo9mwv5emcW0g1Jv9C hbFI+SSfRER2kMTblBsZMicS1q0qAeqtqwURnX5NLX+r+02baitho8x25hv0QFySTmuH stT5oVeawynzS63cSILxMVHxMx0zZj0o5/fZmCfxVS2CIx6Tz2Oc9II5fuDUKsclZhQk FYZzM+K3+GWKWpD7eBjxtKcDWHYmmQOcWDiQ07cC/87/k/Fw+mnRcaujeDSPe2Bps4hT vkwg== X-Forwarded-Encrypted: i=1; AJvYcCVXPWWHg00OW4Ivl+nvSMGETk+lVZ9kGVTpt6JOfI73MarUE38RlPZaLbC22GhtCnqzzfWV5gHb5xv5N7w=@vger.kernel.org, AJvYcCXiyD2D4WdbBN7p5NGYpgfqmE1WbnmMP8cPIVqzYqzj7K72y1Nk6O2oqkldBxIRzXXHNT0TP6E1htR8Rf0Wso8UMg==@vger.kernel.org X-Gm-Message-State: AOJu0Yy9Xya8TVKV7KoJp/JzMH+NRTde24HdzoU6aNBvWGtMcpWo70rw 84FZSZMawp0n4xjDYkSVcBg3Zj7w23h3il9aORD5WHabvSqniUIW X-Google-Smtp-Source: AGHT+IH1Cbz6FiqOqAy/mf7i3pJOe+zl8gxK+fYOuqdD8wGHUxkwM1haOtTG0PoE8p1ZCwHA/GAsng== X-Received: by 2002:a05:6a21:66cb:b0:1d9:25d4:e8b1 with SMTP id adf61e73a8af0-1dc22a60aa2mr4411025637.25.1731098507442; Fri, 08 Nov 2024 12:41: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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:47 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 02/10] perf evsel: Expose evsel__is_offcpu_event() for future use Date: Fri, 8 Nov 2024 12:41:29 -0800 Message-ID: <20241108204137.2444151-3-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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" Signed-off-by: Howard Chu Reviewed-by: Ian Rogers --- 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 f780e30aa259..695f831b463d 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1193,7 +1193,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 23:00:42 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.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 9BC5A1F26E4; Fri, 8 Nov 2024 20:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098511; cv=none; b=IEDLk7dOmMbc8GTGe2eBZ8i0arN9aSDWHCKK8Z46QVnyQqu4iQ5TgKyguvDJ3F4jTPRd+FCmtby46HemT2r4SHpvCIPeVbw1vKMWXsW6Eietjiu9sAaM3ZNkb5aIv/wy2b71ae7Y/TNDaCm8a5A2BArwhop+apgvg/YU6ezilCE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098511; c=relaxed/simple; bh=KAEPyUMP2cinUNJZtTkPnMj8loQm7ritRd3p3n2vPRI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WxFuTNbwiQXMl231IQS3Yxp5WHi7+cT62pjOGjsFyQ/ydgjCc16fPgs3RbWPkH0AKtAycmy5vLFzef/Ha/+7YfLidaAizHLqgR1eklaHhO5SaWTEnacnwzsN4MBBJF4LlZOy4pDqi5Oo1dB8NNhnzlmglOBeQaBhIRavp3tq9Lo= 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=KmvbBopk; arc=none smtp.client-ip=209.85.210.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="KmvbBopk" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e625b00bcso2016693b3a.3; Fri, 08 Nov 2024 12:41:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098509; x=1731703309; 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=AX6/Xbf/UBZHrGsZsvktBK/Q1YsFh4ovVpWZ0bQhbXg=; b=KmvbBopk0e5qJXMUx7P9MhFYrI33ta6BNk2fBDDqZf/J3FRBFEiSvteqQeLaPq/qG2 M6ZlWLVaJdzRssdLPeQ5bzuqIRJ1BEdOBk2LGX+IILlwtEEL1Is78AE8bSpfEIjkDuwf AQ2UiHNyYVhIOHLpWPNJBohKXTQSOLZe5UsKLoofVyO8RtSF6TAFnvoHN7eNIpXlkXmh v9pAInt//QQzNs53NsGsVWpFMcVxvZYtShOSxXgp5CryAxVzobGwtEKFbcxL4Braaaud IW4+4Q9CyxkJwVkp76xekvUUIpNCP8zM5/QOjjB/hJSpz/6kCGBionyZTry3fMwRbLFm O+Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098509; x=1731703309; 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=AX6/Xbf/UBZHrGsZsvktBK/Q1YsFh4ovVpWZ0bQhbXg=; b=tSBlNyVs3woNITbCvEvmIn2+ZMJ4k+wDSDPqc2i3oseue8Lc1ysHAslqi6ZvoPrlGw UVeB3BUYgovLWAbFtOBYZ99SCkqhaERRj5NPr3bxVMvBVuINlEklB0YE1JWBy0Ia5Uy+ OUZRX0QJs1lXSpG6j0HMEfmt1cR2TO+d8617OedYquBak3JLGmCFu8tyMQ4lyDpVe1u7 51T6xnw/wcH54IBwMwYxaLAJ1WJDJEt38RxTd1tot5ASnzxy2ltV17ZjNjEPk8sLJvV2 3jGnjnc1Z94jE03raDDUZnDX/T08+gAYb/fpoTKJTarUi92igtRXzJqi0s5YWyYgyt53 RGVA== X-Forwarded-Encrypted: i=1; AJvYcCUr6p9fg7QbHy6LGTOMTr6xS70gCjsTCbnpWWHSZN3aR9Fn3WufIQmSYXgB6nKKZ/OgcPJxC0dUsF02bxo=@vger.kernel.org, AJvYcCXtL38Y6YcLUjlrDgtYXHQ43fwdmpKUW6lTFBwSKcWSWaOV8QfkQTx6/NEB1idy/p0xqNTTdWatS8kIh6XS5G/Yag==@vger.kernel.org X-Gm-Message-State: AOJu0YwzoBiTCPxCs+XGlojPSpEqDx2Q0Vi8hQNdk1VNA177k1AVvf5s Oi4xbWlmxzlgSq+KWy4ZbIPo7y3RgUe0df36obx3XYAVdZ3SPDyz X-Google-Smtp-Source: AGHT+IGEDiTz0kucWsEbjpEjj9gZl5wIynfTiQnYEWbBSzvuH0vb+0uZ0QeSPnX53LkWoEUzFFFxQQ== X-Received: by 2002:a05:6a00:3a29:b0:71e:680d:5e94 with SMTP id d2e1a72fcca58-724133510d7mr5616878b3a.19.1731098508845; Fri, 08 Nov 2024 12:41:48 -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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:48 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 03/10] perf record --off-cpu: Parse off-cpu event Date: Fri, 8 Nov 2024 12:41:30 -0800 Message-ID: <20241108204137.2444151-4-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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 is 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 Signed-off-by: Howard Chu Reviewed-by: Ian Rogers --- tools/perf/util/bpf_off_cpu.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index a590a8ac1f9d..558c5e5c2dc3 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/no-inherit=3D= 1,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; } --=20 2.43.0 From nobody Sat Nov 23 23:00:42 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.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 0B7A220B7F1; Fri, 8 Nov 2024 20:41:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098512; cv=none; b=KxupFhzDnTJCzsAKvjLt4iPoV8OVRc0scZ5ujJ5YJ3qgG0pj1Zq4XnMD4y0CGVkXF2zDmozKj4s3PKHEB4ukyFIYkFWkn2H0XWS9c4FaI9mmEpnW6UIXqDew+VxmUXzn9rSL1fju22pIHQYszuCsTnreIr5k/sPWFtEmG6fBUxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098512; c=relaxed/simple; bh=kU2mz8BbKOcRd2Dn2h3z3TC1djUFPkPBe7wwzIDw8eo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MuO9QQJE0jHE5X1kxSFKVIYevhYqQgkw9SxHCojXN+AOo+eP2AH8wFWHFv8+a2tp6yRnNYFWsDkhS3NHfKdBbSOI4SIbzzrLCvPw+Y4vuepkNUVGjD+R/cnsv6oUWkPM3FYieDgnZm3My4Lyb62KZRejSS32c0Y2ajS1zjJZ5JY= 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=DWXdFCUL; arc=none smtp.client-ip=209.85.210.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="DWXdFCUL" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71e61b47c6cso2263311b3a.2; Fri, 08 Nov 2024 12:41:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098510; x=1731703310; 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=cHhcbRkHBVYZ1gs3jQbFCFGApL4t6RWueBDb3aZux68=; b=DWXdFCULeyv/QBy/2uMKV4D0rGQMD4UKexDAFMDoDdcADlywgxXu9h07vhGU+lZ2sf oN0eRg6uhaPb7N7WULS10LBez7VpLxz/vFK3MSEqVT9AQerLPWXansd0qIizEwMB7Dl7 YYvEhaZP936OvvdSGx1Jx1o2MJxim8sF0qNvrgqEg88brmM9KKKN/ohVkix/PbN56d48 23owNMfv6+rSam1p1wAMp82NGiMKfUWlbjFWM6cPzC96RqDBS7AG6DCHbumCu7sI4Zl7 OFJLeOOPKlHt5UutZRZrnjyuBPEmAQ/tlkxubOh+pNjLyIihp/GT6dOFdDmCkBAQ7aRV ZfRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098510; x=1731703310; 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=cHhcbRkHBVYZ1gs3jQbFCFGApL4t6RWueBDb3aZux68=; b=HWxxz3NTnFspLWBUzM/ZuUkmWjTbUlSP62vvh8cPxsTeHeBzXVYxFtmg7AvSIa2hKX 065i6IkrEb/e5kPnow4kak+cQs4yIgYpKsUHPKNUtfEL1qZnqrHZ4/RV3JGL6VcnnQIJ zkc2O4IqTb/oXfLpxZgAGyroP2MoZDBknQBIgxZxrP2ZL2EsZ+Mp4RWsH3w5ZD5OAGL9 24XlL8lmnKloCcKELZ7XDjLjzY5MLD6wD8yWmgQRNQtyMXiQ8y1kpOPjzl/t6RfpDPs4 U5PVBE7mmLp0uV6ZWNo/aYBKGT1U1uiTBcGDmIEKql65BWQyRQ5/oMnz0OBq6FMpNuZ0 MqAw== X-Forwarded-Encrypted: i=1; AJvYcCWWhfWeDAqfQoa0Mk4jmarfi7oXX1XoYAgSdnyuSkg6auWxO0tP69TPvDYcSDsu5TU2YJPIzlwHFr2c7Mw=@vger.kernel.org, AJvYcCXtgrqW8uFmMdgUTenQOEz3v1OlOmljrdeByR7wwrf/UqLwxv/vlM///91yVx/J+ACCxDopDo1EKtlaQGgtpzNeyg==@vger.kernel.org X-Gm-Message-State: AOJu0YybpZNYINFAs7ZlyxRZt6DvIjvkxx4LGuBUAsruFPfzmeiKrAu2 LY2dP2eU2RS6gwokRn/72iY6kqTmeJ2o6DiQ/yBwT6U7nhXWRcWb X-Google-Smtp-Source: AGHT+IGXYvt9kIQbrdyodf6HiIih9pJ84IS2nevmoCyS/Yi4NVs04O4lPpnRfGNjPXpnpMqrldUZ/g== X-Received: by 2002:a05:6a00:198a:b0:71e:692e:7afb with SMTP id d2e1a72fcca58-7241325f64amr5306390b3a.5.1731098510276; Fri, 08 Nov 2024 12:41: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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:50 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 04/10] perf record --off-cpu: Preparation of off-cpu BPF program Date: Fri, 8 Nov 2024 12:41:31 -0800 Message-ID: <20241108204137.2444151-5-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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. Signed-off-by: Howard Chu Reviewed-by: Ian Rogers --- tools/perf/util/bpf_off_cpu.c | 20 ++++++++++++++++++++ tools/perf/util/bpf_skel/off_cpu.bpf.c | 2 ++ 2 files changed, 22 insertions(+) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index 558c5e5c2dc3..cfe5b17393e9 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 @@ -73,6 +74,23 @@ 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) { + 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 +279,8 @@ int off_cpu_prepare(struct evlist *evlist, struct targe= t *target, } } =20 + skel->bss->offcpu_thresh =3D opts->off_cpu_thresh * 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..dc6acafb9353 100644 --- a/tools/perf/util/bpf_skel/off_cpu.bpf.c +++ b/tools/perf/util/bpf_skel/off_cpu.bpf.c @@ -97,6 +97,8 @@ const volatile bool uses_cgroup_v1 =3D false; =20 int perf_subsys_id =3D -1; =20 +__u64 offcpu_thresh; + /* * 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 23:00:42 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 69A0D20B80C; Fri, 8 Nov 2024 20:41:52 +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=1731098513; cv=none; b=IfYaDOS8gCgdzKwyRyT95LhXANPHB2OYD2KJHdjn00qZSPZlphbTrC1oXifHWM6GKSd4ERSXoR52ZJu58kvwb+0eaMGAltfy0bEmU6kfa5uVE3dqHHBlDGLJc9r/caL6MXdJZFSSsIHi0F1S0I8ktCbdybxtCH2HXrpkQ8wdps8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098513; c=relaxed/simple; bh=Tl9AyEv3smIY7p3T198j57FdTS4TZIpXoQZrVbxqybY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QXWb+7uOqycemoe93xttcYg0n7mJ44tmaw7J7JUs3uPwWMzL19Sxtd/ERT+cQsNG+XuLjRsIjgDgG403rXEPh88Pn+NTSPeiwVd2WhXQY1PTpIzf8XQJhURD9djasP7N6N0DxCIIngW2/1zzVIFuXR0YrNQQm1mcQDri+gLNFZ4= 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=VIlBZMqp; 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="VIlBZMqp" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-7eab7622b61so1871743a12.1; Fri, 08 Nov 2024 12:41:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098512; x=1731703312; 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=T+BAbUCg60j3RuDc5ntxQHSalyoQVHFsNzlA4CMtOQA=; b=VIlBZMqpnf5YsSZCu1LbWGOFZKr3WXb4lSY841+svwG8BXlSxDpnClltQsBZw8NYwx RyuVQzhqDR6C21jpbtKcPAzMRRJlwHO6eVmSH22ntCQa2Co4M9dfH3q0TigeVqkCRJTv VL3d02DiqU2TSSieUHdQhUon4bW2FloP1rgkiIeT02KHzRJ3EWRgJoZk7CiJMkyZ8rzZ apxGJlnq+0pKrKFyWmJJ4163Uynk6U3UBNG7axQKAgPppCzm2gbtlHbA0IRierqa1WY9 rAGdmKzQJ3NOlHc0h1RJTxdRUY9UHXbEjDBGDm3tenXkNHEoNBOrFPAUqPjf+p3L4QkN d1Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098512; x=1731703312; 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=T+BAbUCg60j3RuDc5ntxQHSalyoQVHFsNzlA4CMtOQA=; b=MbJ6zxRaFKQXfjAqxpe9aq8HEggFvKqG04rTT4XzVTG4uDnzyGExAYtf/pon4vKbX1 7tqgqsejAu9V0XMDJ5/eiGV0vkQVmFTWj2kDpb3V+tpyXronigJiXEC/azET7Ed+CzQ1 g/77dkg3M9u7+nu3tz5CWO5sZGrbL9YIOSQOa8QUn62pIwI8TP9LQSgWxs89rDQOq1Ev 7gKihZYTYrbSErRaAn6JzgTVokq6Sl+jaMubluoEoGfD6xszzWyTrS0KMLcfEQibmRZe WfJDuyvmvnFsY+PUV9r0r98p5rM8Mq7RRsiaFJHN3EyeM+hrsjj1Mgk798D0syp3JHkP T1tA== X-Forwarded-Encrypted: i=1; AJvYcCV1yLILn72vt/3WNJPNGZTb9tLvCXFhUKeev+EIqUTV32WM5cha2wfDqtM8lhm5N7Dwbb738cGBXjF2AGw=@vger.kernel.org, AJvYcCWIkshbP72mfyfpp5ziOQPMxJMI/9uBGwqk6DdczBAR6s5URd0O7NokyjT7WEOt3aJTqOlhCmGw4+M4fxBbdExnfw==@vger.kernel.org X-Gm-Message-State: AOJu0YzmZZngodl1xVrr87pitvNTffZhggbjGFNNmQg48s5oKpGNEIhl QtsvjF93YYb+fAcbLu0qhlsAqSgaV4hzBz9dwkmrgan9WKa3GgCG X-Google-Smtp-Source: AGHT+IGqmQ4wNgdsf9GSvRWHeQMzuTah+ugDU5ZOuZgYAOIV8zPHcwI5VfsOOSwuOH0m/DDqauyfxA== X-Received: by 2002:a05:6a20:8421:b0:1d9:c6e8:60fc with SMTP id adf61e73a8af0-1dc228931b2mr6256266637.6.1731098511794; Fri, 08 Nov 2024 12:41:51 -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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:51 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 05/10] perf record --off-cpu: Dump off-cpu samples in BPF Date: Fri, 8 Nov 2024 12:41:32 -0800 Message-ID: <20241108204137.2444151-6-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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 --- tools/perf/util/bpf_skel/off_cpu.bpf.c | 83 ++++++++++++++++++++++++-- 1 file changed, 78 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 dc6acafb9353..bf652c30b1c9 100644 --- a/tools/perf/util/bpf_skel/off_cpu.bpf.c +++ b/tools/perf/util/bpf_skel/off_cpu.bpf.c @@ -18,10 +18,18 @@ #define MAX_STACKS 32 #define MAX_ENTRIES 102400 =20 +#define MAX_CPUS 4096 +#define MAX_OFFCPU_LEN 37 + +struct stack { + u64 array[MAX_STACKS]; +}; + struct tstamp_data { __u32 stack_id; __u32 state; __u64 timestamp; + struct stack stack; }; =20 struct offcpu_key { @@ -39,6 +47,24 @@ 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)); + __uint(value_size, sizeof(__u32)); + __uint(max_entries, MAX_CPUS); +} offcpu_output SEC(".maps"); + +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); @@ -185,6 +211,39 @@ 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; +} + +static int off_cpu_dump(void *ctx, struct offcpu_data *data, struct offcpu= _key *key, + struct stack *stack, __u64 delta, __u64 timestamp) +{ + /* dump tid, period, callchain, and cgroup id */ + 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) { @@ -209,6 +268,12 @@ 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)) { + } + next: pelem =3D bpf_task_storage_get(&tstamp, next, NULL, 0); =20 @@ -223,11 +288,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) { + 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, pelem->timestamp); + } 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 23:00:42 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.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 ED2D520DD4C; Fri, 8 Nov 2024 20:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098515; cv=none; b=J4JLZtlBU6EVrP1GriD9zpO0gw8doIiE6yT/9dvbUkzuLulLAeFiM25e3ynJisS4w9xTx00In0f7Xp45W6tEHn5Pz+0ell+jlttlPYboqgtYTdYuCI77jP4BpMlAyL+rCxASjsYoON1uYeSDxDqiPnwtDR3+5e5tWxKE1YD/GJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098515; c=relaxed/simple; bh=8n32HRLtvs6iq3hs0+jZ5tY+Ru8eByqiCSKs7/zhsw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mQNEH1bt2bdb2osl90c42uZakYdwahMqco+5mELTvzRo4wwgVR77S3WyJwO8k/7kNkzNtU4+tUizbZWo2xsyLPwIl85FxKZu01Sym8ieVBB0NO5VcANq856qntVWm6ATTao/qqF3+lgYguPfx9PQmY+i4ReAku+CSSqUgKGyOpA= 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=hFQJEPln; arc=none smtp.client-ip=209.85.210.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="hFQJEPln" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-72061bfec2dso2291534b3a.2; Fri, 08 Nov 2024 12:41:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098513; x=1731703313; 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=A76AXI5cz8vRJB121bfaR49vMSkcsOiddGBoLtpbHfA=; b=hFQJEPlnWgwiQLgyo/LHKpT2I986z9RdMFzR0NFn2o5fgOd6dU7nTSHfMq+Mpb6b8b 852qfCWH54dWfP4j3mN7lcnuRzbCLJZpafGlFU35xSLVkXU01Ne4HSWJH+/hsOcJvPLU DTDX4YJK75Dtj9SaABrNgx1yXU6b2zXLhwHXU7otrbnlf8PeVJqkw7NGy7Bhkhgvcp6e UUF/beV7d2Md+S80/SdDyAb4eY8IPVwcDldngnW21vS2lLYAdb6F41l+DekHZfhc51eP Iv3Yj86NkVUrIREtZr+/Qd/lzek3tvoPHAKfzAWMZFRuJy2InJ9Ce/h8xBXAssFmmYB4 YZ1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098513; x=1731703313; 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=A76AXI5cz8vRJB121bfaR49vMSkcsOiddGBoLtpbHfA=; b=r+wYqAsWPPqiDTBniKrDRNqCGnOhmD6lm72f9NIIkmivaM/no5SV81kzVgIxqwB9Qk n5nSOYGPiRLoxcIyS4TcmKw01R2cTZ/ZRg1fhJMc4mADADycSSaQq6YrKYrdZxEm/3v7 zUCAFItAEA3aFhY21niB/zrbRnSiwEyHEgIw6LFSUTQgpEcnaN77uKqUeC7KTy8TI/tU /IYQFM4a3NMo8+4xyCyyYsWXllcur3BzysaNOe9xFmMSZIpJ261H8YoqVfZs8x/y0OPO HRx4rt2ipqxwPApm6BFX2JKFocg73SBtearesnZD4s+vlDUOeKqfMaV8Lf7Y4cdGiKuO CVTQ== X-Forwarded-Encrypted: i=1; AJvYcCU0SB+rHcFD4kpJuoKRxcg95tFbi+hr0fiGdVhC9T+UTrtZsZsxVUV8ZL9+7TSAje5ist6aOA5xWCYJLSNivvWQUg==@vger.kernel.org, AJvYcCVrpTy9WuM6X7Ly0JnLj8PnbSexx/Xjj4Y8dJmoHMUPjluATd2BkxpD/hP8ldOlMl5d1Ozp61hBV4HQ/t8=@vger.kernel.org X-Gm-Message-State: AOJu0YxH+kF9XUK44X7jt/EUqUv302Wx6+fKvUtyW3XaEyeZUd/qnwE7 wfUHbeT+HKSR0dBcY1Ob1Xa0VEic2clAp+LWV30+6EtldOlNtoDS X-Google-Smtp-Source: AGHT+IFHXe9gX6Mr+ftZsG37P4waBj8EMIsdjjpgkgeHJu5nMMDmOTa0A/cI8QSGz7sjXRRocp5BKg== X-Received: by 2002:a05:6a00:198a:b0:71e:415:c4c6 with SMTP id d2e1a72fcca58-724133d215amr4899283b3a.26.1731098513271; Fri, 08 Nov 2024 12:41: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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:53 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 06/10] perf evsel: Assemble offcpu samples Date: Fri, 8 Nov 2024 12:41:33 -0800 Message-ID: <20241108204137.2444151-7-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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. Suggested-by: Namhyung Kim Signed-off-by: Howard Chu Reviewed-by: Ian Rogers --- tools/perf/util/evsel.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 695f831b463d..20f07597fac1 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2783,6 +2783,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) { @@ -3134,6 +3163,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 23:00:42 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.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 7DB5020DD6B; Fri, 8 Nov 2024 20:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098516; cv=none; b=Nuy6I+aoD9vIWR55nkKFyCbhqLBnHBxgTnwq6Q6RkAqE42HjVhE4/rdWFkz+GSnvH3VBNA6IgkQLPLjtS7jIb5KCFvESLTLhUo6t78biaap56wOeBqBvh38TYuzAapFfW6hHJd2WcyC8AzwDcFXwH2trEl4IV/0VLJkmZinCw+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098516; c=relaxed/simple; bh=0VqBggAnZ/aVhISlLbqJYsAchqRZWleo8grj8tMqfR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MllxY+H2kdrlTPpSQNR6s5HCHlY2eiHL9rw8TWxYtAk4rhTu5IkYhqIVWA4/XHhZP/ULAhBnAkksefxEX2qkkiaRSHRbgJiHx3IVHmrQt5X87fkUga4CwsVRdbBYtI1uooItrrGsqIP0ANR1fw5roYABKoZkxEzxhqFyDgn42N4= 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=mlWLEr+q; arc=none smtp.client-ip=209.85.210.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="mlWLEr+q" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-72410cc7be9so1803135b3a.0; Fri, 08 Nov 2024 12:41:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098515; x=1731703315; 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=+ZRYkmRoEbjG+5LuN5e7Pt9MK9b3QAXDr4tvqZiKfok=; b=mlWLEr+qDFN34JThQzbdd8K1DMJVXkI1w7j2ZeqwzkFZ0K3u2nBsNSpm3n3zpcMBsm uLC6Q69uLHJRnZZMaUkwJ0pUpEuA/yreH3yWzrL7vQ+TTYpmn87CAvh0QiGWhG6BfQp5 6QMSDQqFDLgw0GBwC8urTkqr91Lc2EwZ1C8w3O6tY6qxj/fh26itwB8h3CjmjYrxyyIA Df4STQW4rM1p1MDDSsRhZeIfnCnu1Gt0PKQWycG50nYL0moTFcmZntJHLp9U/AInT7TC Zq4Z2G/M2V6iScdNhvn23Jg9yhmh1vo48u3EHjNRzwJIxccvQUv9zbKdiJiX5sgH00UX zZRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098515; x=1731703315; 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=+ZRYkmRoEbjG+5LuN5e7Pt9MK9b3QAXDr4tvqZiKfok=; b=PQN/PNHqXZnYzj9rKJ9kuL6iI3YtJuoYjbdh1p7zWxHh0AwgxdRioSkc8jIJ1rra9F 4P+XfdZ5y/lvhIfHmbreZhve2ESGbpw0HvSKOlSQQnRYY8dUj8D5+rg9DGxi/UKnyq8F tl+4YGgp8mTJ+tYgqnkMILtN7ViO8PtRImqXJI0DKlf9JImT+CbiB1FQ8MDikO0AJZn/ 18Z1kl7AlWM8tWHmTE5BmUYW0cysj7L6KT1rAf7VhoqCibDriBdaJXX/F8gzyKV9C1Rk KLjxuah9mBTXt9VLAqN5pfp/Tbt8n2P7y07Yoh9S+id5WIGI+pfA0VKbqEyoz3JsDXR+ gmsQ== X-Forwarded-Encrypted: i=1; AJvYcCUK4JdDwylHNIYWRm8T0LiCrBfqEcKTW6053bA/nUtzVGj02iDJzo4fmZszBZEq84EmMoiqzdbz/118NBO/cB8eug==@vger.kernel.org, AJvYcCWHmI9vvR9NkXD588uA7mtQ2Zyzo/RS5TukzCr3uOf3tlOTXAnguHvyINFFSw8hMssqLl3DIpqG8mMrlQ8=@vger.kernel.org X-Gm-Message-State: AOJu0YyO9tv2GkY55DowfPsTFybGEnD6UOnDL11r5n1k+7BSgjRE6nAk N/jjbFcviDatSRD3Hu0iLXAhvaLPbeDXJ28ZPkAKDWzsQ0DPrKv3 X-Google-Smtp-Source: AGHT+IGIa/88RlgSbxAoFHUVQCbqiGmeWER8IHl2X4IZPbUl60XrkyMZRNKtZuiaLqmDhFxZIIlEHQ== X-Received: by 2002:a05:6a00:1488:b0:71e:6ef2:6c11 with SMTP id d2e1a72fcca58-72413286757mr5883731b3a.9.1731098514740; Fri, 08 Nov 2024 12:41:54 -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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:54 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 07/10] perf record --off-cpu: Disable perf_event's callchain collection Date: Fri, 8 Nov 2024 12:41:34 -0800 Message-ID: <20241108204137.2444151-8-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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 --- 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 23:00:42 2024 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 238C81F4268; Fri, 8 Nov 2024 20:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098518; cv=none; b=XQja5elqcwd1KBF1v33nq/yQisszeEBapwbWLYOPWxCOAPvZbb3gsxweG5E6P6bgyzLJWHitxqNIP7aajD5KsJLqAUUR85y7ZL+bAWIB2AljCu6P/mLEMx5qjHejNZRyUwGUz5mlply7VTIZbDxxsQ/5L1lgekCrIXgvNFykaJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098518; c=relaxed/simple; bh=12+uD049fjwkxVoV4WCg1PeWhTB94q+vKcGdt8+toqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PVzVRtEw7M0R0iJhLyoP8Oy18NPZetimH2PmQW6Joy4kpbzyW/ivgpbTJuG05BCx7o3tjaw94ks3GSjXaBIFc4ftZzZ+TNDS/cFxi7jCpY/UFJiivW9iX2Lu0LsSVJtTSsVRnfSj3pYUGCPkKSMNOArQ6X85HYkHz8rPQmn0Cwk= 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=VzAUxCUj; arc=none smtp.client-ip=209.85.210.177 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="VzAUxCUj" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-71ec997ad06so2175155b3a.3; Fri, 08 Nov 2024 12:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098516; x=1731703316; 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=HOpZE2LcrB80WvS5jTyTSJQgcV7CMCHPdi15yTc4/HU=; b=VzAUxCUj+5b8Il+aaNiaJvrOjlhPHrX4pAVpSPttCnE3oVwJ6GZvyKWcZJGXHOeM5e u7byNqr88VpcXEQIjHROxxyYpN3CMv3LaY+1VkaOm2HPvN0SwHyL2XyxdHTntnMG46t7 De7j8wvF7BIIKNErCKoP3zm2YQJwH+ni6LyrJfZd+ouUc/pbiUOSYORcRbnl6PsgDx2P cW4KyZqA7kQNe3XdBH6rEBcclPCBnOk3NCWhiDGcqoB7mjpi+GPRzK/eTeep5wbyu1pN bRv7Y/GmT5oDpXywOph17gCpQey1tNwEyq6nTMZWihnGBzoxajubkbTsZ3KYO5BMRNrX CSTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098516; x=1731703316; 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=HOpZE2LcrB80WvS5jTyTSJQgcV7CMCHPdi15yTc4/HU=; b=nVrdIM9bwHcPJihbfK7ip9eOHsAqNxNbsry5TSh4XkuuUvnLLZL2IgT60Xy3bO8DZ1 6R7czxugGn9IXlFZK1ELlMwiyD/z96db+80LEt2HxmE9A1nMP8NguI7qp9zrpYOtehs7 rq50wFrwOQlsJV812KPJaMkF3x+hC9H7aa+x6AFKVx4sIOqHWCVqswxX3UR8G1HZrMCm rSYTtkXoJOqLuKbY9T8MHRgBVe824J8vksz55VP9ywXinN0oVs4NkhahGa5kEt23XSBm 6OO+MLk6YEUt0z5NgdT18FxoruAoM0apkzD/D25BvxxMlGvBFGgHCXcq4ZbR95JmzLJh G03g== X-Forwarded-Encrypted: i=1; AJvYcCUGqRjROYav1aAhzr60BlfaNeYBledEwcv2K3vFEsimv5HXn7hCscWPpHFUqgYdq9JlT5oicA3fFeNGqSN3jKV2ig==@vger.kernel.org, AJvYcCWOErrvb8PScNPQE5u55FU1R4mMtazfLo3UoEVu4aFiOlPa03OK/x9y0Y41bBRaWJVvqzFpL7NScpX0p/U=@vger.kernel.org X-Gm-Message-State: AOJu0YyDbQgqwAlKBaU/VBhFhhevTpn6somEnNTzhroD/7jcZ2hY7ETq EYfQZX/iawtbxU1Mfd/2VXy7hCgULUV8jp4DZJIj5lzZGHm9iX3K X-Google-Smtp-Source: AGHT+IFyI4Nd9VSOBU81IqsVewbp5rZ0ZfhujkSQoBbxhadYaZ+78gPGZ+gEZ8z5c7yIg8YifZLL4g== X-Received: by 2002:a05:6a20:12d2:b0:1d9:386d:9441 with SMTP id adf61e73a8af0-1dc2292f447mr5839965637.10.1731098516228; Fri, 08 Nov 2024 12:41:56 -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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:55 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 08/10] perf script: Display off-cpu samples correctly Date: Fri, 8 Nov 2024 12:41:35 -0800 Message-ID: <20241108204137.2444151-9-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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 .... Signed-off-by: Howard Chu Reviewed-by: Ian Rogers --- 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 6b6d4472db6e..1893d2117aab 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 23:00:42 2024 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 6616B2123E6; Fri, 8 Nov 2024 20:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098519; cv=none; b=Au8bsexCf8gcYJH6hmtNaIEkcdM9PGIFA1Gt5ccmfWcvOJniXmARXcrEiFEbRSCrE/nESK5HqDPa02soviNigQymUUbcnZ7X7TqXkkODHZpnHVsa352vMFqb6SAPqC2iz55Vk552q0m6aq+hkreMKSoTyl7tag/i4PiQ04TdBB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098519; c=relaxed/simple; bh=D4yVMT2FcG4D5LyFEnoiF/UGY7U3Zo7ouqlCO2gU1/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e/fUVsNflopiXaaxqzfO/TP0oq7Voj8nmBWHcfIW/dcqLtNz/L7fs9lvYk5T2QUFlUmtsijBmq8VafnXB7KPXUVGQE4Bn3Maer733EFQYwAJwFhfND2Ff7hhq2SVd/fATvgTx1ey6suCcrBYPu694JASmPQMUyL95e/HzVhnrrw= 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=fvcFxtCW; arc=none smtp.client-ip=209.85.210.180 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="fvcFxtCW" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-71ec997ad06so2175178b3a.3; Fri, 08 Nov 2024 12:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098518; x=1731703318; 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=E2tyw1tOse2vzSiyEi9SCuAYRS4VzNw6M4PIA6JS/KU=; b=fvcFxtCWzp0LteVgCFmSyo4ebPyKQOfJz8bVOOgtcykWpuHT0SYMeIVduOePjLFr99 DHnOSI87Lsdo7YVHMd4Mv7XJPJza0gl+cKgWgqbw74r+RFHHjZU3+xqxTp6X5D5LcH0W J49EHq0EreM2+GKOcjDY+LHXnmenoVO02k56m+gWI29NucA6NbMdjEJqWV1VD6wgBRSJ BrY2j6J2HPXWbcMgnuMvjHu3E3rEvCqq1XjmrasaJvNw8JRzzFgpnzU94K03vRq2QV3y Gkm+xy38Uee/GZN8Yz4g1tn6wANRMqYI97HuZQDwy+21E8X6IrpgSZeDBfVvKWXAXhUK nX7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098518; x=1731703318; 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=E2tyw1tOse2vzSiyEi9SCuAYRS4VzNw6M4PIA6JS/KU=; b=jKQxymAMMc3b1UM0BTrhbwhTqj/MTKY93sVUhKXuXGNl0RvLCSdJ3zmOH7zwE+Ds7V HwtpBycglqfOBFN81sPB8bGzdKp0kmc/OZPTZo64LCkjqo/ljlUwdN77RuMpfIz1KFKz sNs0H5ODQai0plR5E+T7+V0nEjEAnX62yNR8N02AKGffBLcfjw/2C1smXTGDvuzGAYL0 rvB78x9dN12cbllpVj5RKelfbKbLJCzC8cekj5k4CyhMvy1KWlJVl4BA5ONpXkideTIy jw32CENHaSiWkmkTP2dolaUo9ctyebFY/xSXA7lx4POYi4AfLYyotRvnRTckHDu5UdI3 o2wQ== X-Forwarded-Encrypted: i=1; AJvYcCUVHLzyV56bO+v2Ykvw0bc6KXNxEtdQ7t+Ggalt4bnDPRC8/A3plZ1kfa0TwKz6USY73eVyKwnk4F1Mz84=@vger.kernel.org, AJvYcCVj4L+YndQlkSNuP5KJFz4kpmfT3+7JBFqpIRjZ1K4q7ofAAzdkzYfjGwkjikjzEeHWsoWu+VvkT3eYue0aucvFOw==@vger.kernel.org X-Gm-Message-State: AOJu0Yx9rs4syuu+Gamzv9bxQCjpL1ROcE/73GelBIuq4Y+D2zdyiWWM uWQvKCBBDsSNIHP9e30vTPIT4puYDKGS+NyBiH5f6ymRzVFcYmIA X-Google-Smtp-Source: AGHT+IHC5toUl0yKFimGX5HCCwEhUAH5gjmPf0a4kj4mHRrpqamvhXyrJkR2NfYTS3mmkm5BrrJGAw== X-Received: by 2002:a05:6a00:14d3:b0:71d:feb7:37f4 with SMTP id d2e1a72fcca58-724132a0015mr6215760b3a.6.1731098517701; Fri, 08 Nov 2024 12:41: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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:57 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 09/10] perf record --off-cpu: Dump the remaining samples in BPF's stack trace map Date: Fri, 8 Nov 2024 12:41:36 -0800 Message-ID: <20241108204137.2444151-10-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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 Signed-off-by: Howard Chu Reviewed-by: Ian Rogers --- tools/perf/util/bpf_off_cpu.c | 62 +++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index cfe5b17393e9..f1be354e2fe7 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]; @@ -61,6 +63,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, err; =20 /* update task filter for the given workload */ if (skel->rodata->has_task && skel->rodata->uses_tgid && @@ -304,6 +309,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; @@ -343,46 +349,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 23:00:42 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 E5674219E29; Fri, 8 Nov 2024 20:41:59 +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=1731098521; cv=none; b=AIOrC9LUN0jTXBz6GOTL2JMfB+inJN3EWmzulLiCTsYr/c5usBAE1z/sgFtHknWr+XT30u4F9EManzs+jmr8DmholM3P4rH+QO4poCDg3aJoQIIWhk0kblGfqHS1lhjnhhqFFWIsVGjpydtfF8zFg4yTRgOID4CQCXwfBbO0iX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731098521; c=relaxed/simple; bh=q4GbxqglWbwouKr8KdSERhNWfS9I5/5YSVXoB2PdQg0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dc2IOOjla9Npzi0fAwh/ihVN4fZEsyrH+W2tio/6I16a+k14wXtNsOEXUIFJ6wbv11nh5LBwY/VQQLL2NggC0lggKi35V8809JKNsjokTwAO5YoKVNQZjjGtx0TwxQ+kX2XrPwVKow6dV/CiJTIZR3mvJmYw6icB3CCYlWZ5bcc= 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=IN1U/bm+; 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="IN1U/bm+" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-720cb6ac25aso2334370b3a.3; Fri, 08 Nov 2024 12:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731098519; x=1731703319; 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=s9Lk9CTgyzuah9Ju7zGNf6f0xwTQJZoRr7qB88GnpTw=; b=IN1U/bm+2ajBF9w0NljuYWhOXhw8AgqEV+VbI0dnqNfMBldPRpWrIE1Ye3W2zC5Sis Mdis0QdvRZmDUdz47/T+XMRPo0eRGNGfbSnR35HS4mADCwYvIMrp3PZzMt3apn5UmLoh GIcpB/PkEKUqwJjgFACi9YZd6rPTPGyDmiKUfoSRTcJMXVQgvVnwd32w7h+ojXe6Zces HO24VLTATb5KI02n2d+c8SRLJ44HgZPw6oXcf26XkG1HPnl4BDU0Q8nl5FqjbtrRBEGO uYCqwVmPalZ7Te0vcQ9VcogWryKT99hvB9h3ZSy2fnPOBF2bmvLf+Vexu9a034Ui5JKh 6Wow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731098519; x=1731703319; 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=s9Lk9CTgyzuah9Ju7zGNf6f0xwTQJZoRr7qB88GnpTw=; b=oiW3NeXD2x7qHLwbHW7UPzlRWdXvwQu5nNbJtOyO53W22YYKqhAH2TYn8prk4K/gPG JXg4DOR4jTFhcY5VVTLtn+Ha7HF7JaeJRKWj+eqrI+D7WIDlP/3XMLTVLDqsz7MqcMJE soipvgUHkuD+agqgKJq0vvAfGdjHeoCwnR/cWi8RyH+DBky8D+Cr8/7N0yZ5MO+eHa0H 7tOS+WdM0wQqU1r75mQ80pe9BZelwzVIsM42rNK9nJ5UOB8bJ6h+Rwsx66YmQNDjDNy0 dI1u/ML11ZgLl25jqE3LSg52UEF2icnH6t8TYUwCk3+coKXbEXpHd5VPoFK8RYMmaZrx NmVQ== X-Forwarded-Encrypted: i=1; AJvYcCX7P76gFyBHc8HtpOs5RN2q0gGWyhPIse5fq1c6Dshz2/tKAp/kBaPD7TYPS4udJ1ZXedxXKU7v7YCukubjDXQOTQ==@vger.kernel.org, AJvYcCXs4gNhz+a4GMF3I6gtL2rYdv4CnmfL4TyxFvCSZb0PjXdqfQZwRINpzUhH2Vl1CIyGLyNHeRisR4dxh2U=@vger.kernel.org X-Gm-Message-State: AOJu0YzEthUTG5JM5yqFQP/vqHmIgmPDDOoO2vwd94r6iIiumjMxF1A1 XAZCWzHHOQQPadH0XzKCh3XxMzbN+ZlHN8Jyyoa8qMM8ENGAJGJS X-Google-Smtp-Source: AGHT+IEsMr5E8h+qnJG/vsq1MKhJingnqkuEUIg4BoJm7eKwa/JP2/THICiKY41oiUTy1y22yTPyag== X-Received: by 2002:a05:6a20:8404:b0:1d9:d9a7:dd36 with SMTP id adf61e73a8af0-1dc22b54192mr5234525637.32.1731098519167; Fri, 08 Nov 2024 12:41:59 -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 d2e1a72fcca58-7240785ffe3sm4221945b3a.2.2024.11.08.12.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Nov 2024 12:41:58 -0800 (PST) From: Howard Chu To: acme@kernel.org, peterz@infradead.org Cc: namhyung@kernel.org, irogers@google.com, mingo@redhat.com, mark.rutland@arm.com, james.clark@linaro.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Howard Chu Subject: [PATCH v7 10/10] perf test: Add direct off-cpu test Date: Fri, 8 Nov 2024 12:41:37 -0800 Message-ID: <20241108204137.2444151-11-howardchu95@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241108204137.2444151-1-howardchu95@gmail.com> References: <20241108204137.2444151-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 --- tools/perf/tests/builtin-test.c | 1 + tools/perf/tests/shell/record_offcpu.sh | 31 ++++++++++++++++++++++++- tools/perf/tests/tests.h | 1 + tools/perf/tests/workloads/Build | 1 + tools/perf/tests/workloads/offcpu.c | 16 +++++++++++++ 5 files changed, 49 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 d2cabaa8ad92..2228e6064d16 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -145,6 +145,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..fda1c1ad4555 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,7 @@ 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 + 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 +92,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 +124,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 af284dd47e5c..58de36e0edc5 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -216,6 +216,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