Rebase bpftrace to 0.23.5

Resolves: RHEL-78918
Resolves: RHEL-81775

This version comes with LLVM 20 support.

Also needs two extra patches:

- GCC in c9s is throwing some errors while compiling
  src/container/cstring_view.h. Since the file is dropped in a later
  version, just apply that patch.
- RHEL 9 kernel doesn't have 736c55a02c47 ("sched/fair: Rename
  cfs_rq.nr_running into nr_queued") so we need to use the older version
  of runqlen.bt.

Signed-off-by: Viktor Malik <vmalik@redhat.com>
This commit is contained in:
Viktor Malik 2025-06-06 06:55:38 +02:00
parent daef105b90
commit ded68d8989
No known key found for this signature in database
GPG Key ID: AF7A2E1F6EE74FB3
6 changed files with 315 additions and 2 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@
/bpftrace-0.20.4.tar.gz
/bpftrace-0.21.1.tar.gz
/bpftrace-0.22.1.tar.gz
/bpftrace-0.23.5.tar.gz

View File

@ -0,0 +1,207 @@
From 8c587382b686a776178e7fc105f3b5468cab360f Mon Sep 17 00:00:00 2001
From: Thierry Treyer <ttreyer@meta.com>
Date: Fri, 11 Apr 2025 09:04:29 -0700
Subject: [PATCH] Remove 'cstring_view'
The `cstring_view` class was a `std::string_view` with the added
guarantee that it is NULL-terminated. It was only used by BpfMap.
This commit replaces it by a `std::string`
Fixes: #4001
Signed-off-by: Thierry Treyer <ttreyer@meta.com>
---
src/bpfmap.cpp | 2 +-
src/bpfmap.h | 10 +++---
src/container/cstring_view.h | 39 -----------------------
tests/CMakeLists.txt | 1 -
tests/cstring_view.cpp | 60 ------------------------------------
5 files changed, 5 insertions(+), 107 deletions(-)
delete mode 100644 src/container/cstring_view.h
delete mode 100644 tests/cstring_view.cpp
diff --git a/src/bpfmap.cpp b/src/bpfmap.cpp
index 9464e8ed..eb65621e 100644
--- a/src/bpfmap.cpp
+++ b/src/bpfmap.cpp
@@ -12,7 +12,7 @@ libbpf::bpf_map_type BpfMap::type() const
return type_;
}
-cstring_view BpfMap::bpf_name() const
+const std::string &BpfMap::bpf_name() const
{
return name_;
}
diff --git a/src/bpfmap.h b/src/bpfmap.h
index 09153764..d48763ed 100644
--- a/src/bpfmap.h
+++ b/src/bpfmap.h
@@ -11,8 +11,6 @@ namespace libbpf {
#include "libbpf/bpf.h"
} // namespace libbpf
-#include "container/cstring_view.h"
-
namespace bpftrace {
class BpfMap {
@@ -28,12 +26,12 @@ public:
}
BpfMap(libbpf::bpf_map_type type,
- cstring_view name,
+ std::string name,
uint32_t key_size,
uint32_t value_size,
uint32_t max_entries)
: type_(type),
- name_(name),
+ name_(std::move(name)),
key_size_(key_size),
value_size_(value_size),
max_entries_(max_entries)
@@ -42,7 +40,7 @@ public:
int fd() const;
libbpf::bpf_map_type type() const;
- cstring_view bpf_name() const;
+ const std::string &bpf_name() const;
std::string name() const;
uint32_t key_size() const;
uint32_t value_size() const;
@@ -56,7 +54,7 @@ public:
private:
struct bpf_map *bpf_map_;
libbpf::bpf_map_type type_;
- cstring_view name_;
+ std::string name_;
uint32_t key_size_;
uint32_t value_size_;
uint32_t max_entries_;
diff --git a/src/container/cstring_view.h b/src/container/cstring_view.h
deleted file mode 100644
index 2e1c4602..00000000
--- a/src/container/cstring_view.h
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#include <string>
-#include <string_view>
-
-namespace bpftrace {
-
-// cstring_view
-//
-// A restricted version of std::string_view which guarantees that the underlying
-// string buffer will be null-terminated. This can be useful when interacting
-// with C APIs while avoiding the use of char* and unnecessary copies from using
-// std::string.
-//
-// We only allow constructing cstring_view from types which are guaranteed to
-// store null-terminated strings. All modifiers or operations on cstring_view
-// will also maintain the null-terminated property.
-class cstring_view : public std::string_view {
-public:
- constexpr cstring_view(const char *str) noexcept : std::string_view{ str }
- {
- }
- constexpr cstring_view(const std::string &str) noexcept
- : std::string_view{ str }
- {
- }
- constexpr const char *c_str() const noexcept
- {
- return data();
- }
-
-private:
- // Disallow use of functions which can break the null-termination invariant
- using std::string_view::copy;
- using std::string_view::remove_suffix;
- using std::string_view::substr;
-};
-
-} // namespace bpftrace
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c5d10f9c..d012cad7 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -33,7 +33,6 @@ add_executable(bpftrace_test
clang_parser.cpp
config.cpp
collect_nodes.cpp
- cstring_view.cpp
field_analyser.cpp
function_registry.cpp
log.cpp
diff --git a/tests/cstring_view.cpp b/tests/cstring_view.cpp
deleted file mode 100644
index 5b82a990..00000000
--- a/tests/cstring_view.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#include "container/cstring_view.h"
-#include "gtest/gtest.h"
-
-#include <type_traits>
-
-namespace bpftrace::test::cstring_view {
-
-using bpftrace::cstring_view;
-
-TEST(cstring_view, c_string)
-{
- const char *str = "abc";
- cstring_view sv{ str };
-
- EXPECT_EQ("abc", sv);
-
- EXPECT_EQ('a', sv[0]);
- EXPECT_EQ('b', sv[1]);
- EXPECT_EQ('c', sv[2]);
- EXPECT_EQ('\0', sv[3]);
-}
-
-TEST(cstring_view, std_string)
-{
- std::string str = "abc";
- cstring_view sv{ str };
-
- EXPECT_EQ("abc", sv);
-
- EXPECT_EQ('a', sv[0]);
- EXPECT_EQ('b', sv[1]);
- EXPECT_EQ('c', sv[2]);
- EXPECT_EQ('\0', sv[3]);
-}
-
-TEST(cstring_view, std_string_view)
-{
- EXPECT_FALSE((std::is_constructible_v<cstring_view, std::string_view>));
-
- // Sanity checks:
- EXPECT_TRUE((std::is_constructible_v<cstring_view, std::string>));
- EXPECT_TRUE((std::is_constructible_v<cstring_view, const char *>));
-}
-
-TEST(cstring_view, length)
-{
- cstring_view sv{ "abc" };
-
- EXPECT_EQ("abc", sv);
- EXPECT_EQ(3, sv.size());
- EXPECT_EQ(3, sv.length());
-}
-
-TEST(cstring_view, c_str)
-{
- cstring_view sv{ "abc" };
- EXPECT_EQ(0, strcmp(sv.c_str(), "abc"));
-}
-
-} // namespace bpftrace::test::cstring_view
--
2.49.0

View File

@ -0,0 +1,98 @@
From 2f1573fe27de4008faedd38ee9cdadc3eec31909 Mon Sep 17 00:00:00 2001
From: Viktor Malik <viktor.malik@gmail.com>
Date: Fri, 6 Jun 2025 07:54:19 +0200
Subject: [PATCH] runqlen.bt: Use old version of the tool
RHEL 9 doesn't have 736c55a02c47 ("sched/fair: Rename cfs_rq.nr_running
into nr_queued") so we need to use the old name of the struct fields.
Signed-off-by: Viktor Malik <viktor.malik@gmail.com>
---
tools/old/runqlen.bt | 41 -----------------------------------------
tools/runqlen.bt | 8 +++++---
2 files changed, 5 insertions(+), 44 deletions(-)
delete mode 100755 tools/old/runqlen.bt
diff --git a/tools/old/runqlen.bt b/tools/old/runqlen.bt
deleted file mode 100755
index 23a7fb85..00000000
--- a/tools/old/runqlen.bt
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/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 <linux/sched.h>
-
-// 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 394a7b3d..23a7fb85 100755
--- a/tools/runqlen.bt
+++ b/tools/runqlen.bt
@@ -5,6 +5,8 @@
*
* 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")
*
@@ -19,8 +21,8 @@
// your kernel version. It is from kernel/sched/sched.h:
struct cfs_rq {
struct load_weight load;
- unsigned int nr_queued;
- unsigned int h_nr_queued;
+ unsigned int nr_running;
+ unsigned int h_nr_running;
};
#endif
@@ -33,7 +35,7 @@ profile:hz:99
{
$task = (struct task_struct *)curtask;
$my_q = (struct cfs_rq *)$task->se.cfs_rq;
- $len = (uint64)$my_q->nr_queued;
+ $len = (uint64)$my_q->nr_running;
$len = $len > 0 ? $len - 1 : 0; // subtract currently running task
@runqlen = lhist($len, 0, 100, 1);
}
--
2.49.0

View File

@ -1,5 +1,5 @@
Name: bpftrace
Version: 0.22.1
Version: 0.23.5
Release: 1%{?dist}
Summary: High-level tracing language for Linux eBPF
License: ASL 2.0
@ -13,6 +13,8 @@ Source0: %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
# for build.
Source1: https://github.com/USCiLab/cereal/archive/v%{cereal_version}/cereal-%{cereal_version}.tar.gz
Patch0: %{name}-%{version}-Remove-cstring_view.patch
Patch1: %{name}-%{version}-runqlen.bt-Use-old-version-of-the-tool.patch
Patch10: %{name}-%{version}-RHEL-aarch64-fixes-statsnoop-and-opensnoop.patch
# Arches will be included as upstream support is added and dependencies are
@ -88,12 +90,17 @@ find %{buildroot}%{_datadir}/%{name}/tools -type f -exec \
%{_bindir}/%{name}
%{_bindir}/%{name}-aotrt
%{_mandir}/man8/*
%{_datadir}/bash-completion/completions/%{name}
%attr(0755,-,-) %{_datadir}/%{name}/tools/*.bt
%{_datadir}/%{name}/tools/doc/*.txt
# Do not include old versions of tools, they do not work on RHEL 9
%exclude %{_datadir}/%{name}/tools/old
%changelog
* Fri Jun 06 2025 Viktor Malik <vmalik@redhat.com> - 0.23.5-1
- Rebase on bpftrace 0.23.5 (RHEL-78918)
- Add LLVM 20 support (RHEL-81775)
* Wed Jan 29 2025 Viktor Malik <vmalik@redhat.com> - 0.22.1-1
- Rebase on bpftrace 0.22.1 (RHEL-63881)
- Add LLVM 19 support (RHEL-66061)

View File

@ -1,2 +1,2 @@
SHA512 (bpftrace-0.22.1.tar.gz) = 3bf00f97750092e66bd94b20b3889f29e932f45ae7f75966f1f364013fb9aeaad837617c0a28402fd9323d62773dd3dab0e9749d8dcb9da9c77093f17fce4d91
SHA512 (bpftrace-0.23.5.tar.gz) = 1e040bce7636da4e2ebeffc1c8fc3944feb26ef2c371ff287b323123ef89b839fbaa492a61e8164efedc7579e73aebc489f168ecad903f3cac6144d8bbc4b6f1
SHA512 (cereal-1.3.2.tar.gz) = 98d306d6292789129675f1c5c5aedcb90cfcc1029c4482893a8f9b23f3c9755e5ed4762d7a528f215345cae6392e87cd8d89467115b6f031b41c8673d6b4b109