From 903e233a80fc4681d6f13ed74b1049bfe5c5838d Mon Sep 17 00:00:00 2001 From: Weisson Date: Thu, 12 Jun 2025 17:40:12 +0800 Subject: [PATCH] tools/runqlen.bt: rename nr_running to nr_queued With "sched/fair: Fix statistics with delayed dequeue" series (more specifically torvalds/linux@736c55a02c47) several fields in "struct cfs_rq" is renamed, leading to runqlen.bt to fail at runtime with the following error: ERROR: Struct/union of type 'struct cfs_rq' does not contain a field named 'nr_running' $len = $my_q->nr_running; Move existing runqlen script to tools/old/, create a copy of the original with with nr_running changed to nr_queued in its place, and has GitHub CI use the old version of runqlen for testing. While at it, also touch up the comment regarding BTF. Link: https://lore.kernel.org/all/20241202174606.4074512-1-vincent.guittot@linaro.org/ from upstream #2968c084650593cdb17364ca0d647e133a6cea60 Signed-off-by: Shung-Hsi Yu Signed-off-by: Weisson --- ...en.bt-rename-nr_running-to-nr_queued.patch | 111 ++++++++++++++++++ bpftrace.spec | 6 +- 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 0002-tools-runqlen.bt-rename-nr_running-to-nr_queued.patch diff --git a/0002-tools-runqlen.bt-rename-nr_running-to-nr_queued.patch b/0002-tools-runqlen.bt-rename-nr_running-to-nr_queued.patch new file mode 100644 index 0000000..ece0b35 --- /dev/null +++ b/0002-tools-runqlen.bt-rename-nr_running-to-nr_queued.patch @@ -0,0 +1,111 @@ +From 04ea29b6cf114e6345ba5a1dc9d4f24daaec1403 Mon Sep 17 00:00:00 2001 +From: Weisson +Date: Thu, 12 Jun 2025 17:35:46 +0800 +Subject: [PATCH] tools/runqlen.bt: rename nr_running to nr_queued + +With "sched/fair: Fix statistics with delayed dequeue" series (more +specifically torvalds/linux@736c55a02c47) several fields in "struct +cfs_rq" is renamed, leading to runqlen.bt to fail at runtime with the +following error: + + ERROR: Struct/union of type 'struct cfs_rq' does not contain a field named 'nr_running' + $len = $my_q->nr_running; + +Move existing runqlen script to tools/old/, create a copy of the original with +with nr_running changed to nr_queued in its place, and has GitHub CI use the +old version of runqlen for testing. + +While at it, also touch up the comment regarding BTF. + +Link: https://lore.kernel.org/all/20241202174606.4074512-1-vincent.guittot@linaro.org/ + +from upstream #2968c084650593cdb17364ca0d647e133a6cea60 + +Signed-off-by: Shung-Hsi Yu +Signed-off-by: Weisson +--- + tools/old/runqlen.bt | 41 +++++++++++++++++++++++++++++++++++++++++ + tools/runqlen.bt | 8 ++++---- + 2 files changed, 45 insertions(+), 4 deletions(-) + create mode 100755 tools/old/runqlen.bt + +diff --git a/tools/old/runqlen.bt b/tools/old/runqlen.bt +new file mode 100755 +index 0000000..23a7fb8 +--- /dev/null ++++ b/tools/old/runqlen.bt +@@ -0,0 +1,41 @@ ++#!/usr/bin/env bpftrace ++/* ++ * runqlen.bt CPU scheduler run queue length as a histogram. ++ * For Linux, uses bpftrace, eBPF. ++ * ++ * This is a bpftrace version of the bcc tool of the same name. ++ * ++ * For Linux < 6.14. ++ * ++ * Copyright 2018 Netflix, Inc. ++ * Licensed under the Apache License, Version 2.0 (the "License") ++ * ++ * 07-Oct-2018 Brendan Gregg Created this. ++ */ ++ ++#ifndef BPFTRACE_HAVE_BTF ++#include ++ ++// Without BTF, we'll need to declare some of this struct manually, ++// since it isn't available to be #included. This will need maintenance to match ++// your kernel version. It is from kernel/sched/sched.h: ++struct cfs_rq { ++ struct load_weight load; ++ unsigned int nr_running; ++ unsigned int h_nr_running; ++}; ++#endif ++ ++BEGIN ++{ ++ printf("Sampling run queue length at 99 Hertz... Hit Ctrl-C to end.\n"); ++} ++ ++profile:hz:99 ++{ ++ $task = (struct task_struct *)curtask; ++ $my_q = (struct cfs_rq *)$task->se.cfs_rq; ++ $len = (uint64)$my_q->nr_running; ++ $len = $len > 0 ? $len - 1 : 0; // subtract currently running task ++ @runqlen = lhist($len, 0, 100, 1); ++} +diff --git a/tools/runqlen.bt b/tools/runqlen.bt +index b3f0fe6..6751765 100755 +--- a/tools/runqlen.bt ++++ b/tools/runqlen.bt +@@ -14,13 +14,13 @@ + #ifndef BPFTRACE_HAVE_BTF + #include + +-// Until BTF is available, we'll need to declare some of this struct manually, ++// Without BTF, we'll need to declare some of this struct manually, + // since it isn't available to be #included. This will need maintenance to match + // your kernel version. It is from kernel/sched/sched.h: + struct cfs_rq { + struct load_weight load; +- unsigned int nr_running; +- unsigned int h_nr_running; ++ unsigned int nr_queued; ++ unsigned int h_nr_queued; + }; + #endif + +@@ -33,7 +33,7 @@ profile:hz:99 + { + $task = (struct task_struct *)curtask; + $my_q = (struct cfs_rq *)$task->se.cfs_rq; +- $len = $my_q->nr_running; ++ $len = $my_q->nr_queued; + $len = $len > 0 ? $len - 1 : 0; // subtract currently running task + @runqlen = lhist($len, 0, 100, 1); + } +-- +2.43.5 + diff --git a/bpftrace.spec b/bpftrace.spec index e4602d0..934df88 100644 --- a/bpftrace.spec +++ b/bpftrace.spec @@ -1,4 +1,4 @@ -%define anolis_release 2 +%define anolis_release 3 %global __os_install_post %{nil} %global _find_debuginfo_opts -g @@ -11,6 +11,7 @@ License: Apache-2.0 URL: https://github.com/iovisor/bpftrace Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz Patch1: 0001-Workaround-OpaquePointers-for-LLVM-15.patch +Patch2: 0002-tools-runqlen.bt-rename-nr_running-to-nr_queued.patch # Arches will be included as upstream support is added and dependencies are # satisfied in the respective arches @@ -80,6 +81,9 @@ find %{buildroot}%{_datadir}/%{name}/tools -type f -exec \ %doc README.md CONTRIBUTING-TOOLS.md %changelog +* Thu Jun 12 2025 Weisson - 0.20.1-3 +- tools/runqlen.bt: rename nr_running to nr_queued. + * Thu May 8 2025 Yihao Yan - 0.20.1-2 - add support for riscv64 -- Gitee