Skip to content

Commit 0cd4384

Browse files
committed
Support Mac 2
1 parent a92842b commit 0cd4384

5 files changed

Lines changed: 307 additions & 16 deletions

File tree

include/cxlcontroller.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ template <> struct std::formatter<CXLController> {
324324

325325
result += "CXLController:\n";
326326
// iterate through the topology map
327-
uint64_t total_capacity = 0;
327+
uint64_t cxl_capacity = 0;
328328

329329
std::function<void(const CXLSwitch *)> dfs_capacity = [&](const CXLSwitch *node) {
330330
if (!node)
@@ -333,7 +333,7 @@ template <> struct std::formatter<CXLController> {
333333
// Traverse expanders and sum their capacity
334334
for (const auto *expander : node->expanders) {
335335
if (expander) {
336-
total_capacity += expander->capacity;
336+
cxl_capacity += expander->capacity;
337337
}
338338
}
339339

@@ -344,7 +344,9 @@ template <> struct std::formatter<CXLController> {
344344
};
345345
dfs_capacity(&controller);
346346

347-
result += std::format("Total system memory capacity: {}GB\n", total_capacity);
347+
result += std::format("Configured memory capacity: {}GB\n", controller.capacity + cxl_capacity);
348+
result += std::format(" Local memory capacity: {}GB\n", controller.capacity);
349+
result += std::format(" CXL expander capacity: {}GB\n", cxl_capacity);
348350

349351
result += std::format(" Page Type: {}\n", [](page_type pt) {
350352
switch (pt) {
@@ -368,11 +370,11 @@ template <> struct std::formatter<CXLController> {
368370

369371
result += "Topology:\n";
370372

371-
std::function<void(const CXLSwitch *, int)> print_switch = [&result, &print_switch](const CXLSwitch *sw,
372-
int depth) {
373+
std::function<void(const CXLSwitch *, int)> print_switch = [&controller, &result,
374+
&print_switch](const CXLSwitch *sw, int depth) {
373375
std::string indent(depth * 2, ' ');
374376

375-
result += std::format("{}Switch:\n", indent);
377+
result += std::format("{}Switch id={}:\n", indent, sw->id);
376378
result += std::format("{} Events:\n", indent);
377379
result += std::format("{} Load: {}\n", indent, sw->counter.load.get());
378380
result += std::format("{} Store: {}\n", indent, sw->counter.store.get());
@@ -383,7 +385,17 @@ template <> struct std::formatter<CXLController> {
383385
}
384386

385387
for (const auto &endpoint : sw->expanders) {
386-
result += std::format("{}Expander:\n", indent + " ");
388+
std::string endpoint_name = std::format("internal_id={}", endpoint->id);
389+
for (size_t idx = 0; idx < controller.cur_expanders.size(); ++idx) {
390+
if (controller.cur_expanders[idx] == endpoint) {
391+
endpoint_name = std::format("endpoint={} internal_id={}", idx + 1, endpoint->id);
392+
break;
393+
}
394+
}
395+
result += std::format("{}Expander {} capacity={}GB read_bw={}GB/s write_bw={}GB/s "
396+
"read_lat={}ns write_lat={}ns:\n",
397+
indent + " ", endpoint_name, endpoint->capacity, endpoint->bandwidth.read,
398+
endpoint->bandwidth.write, endpoint->latency.read, endpoint->latency.write);
387399
result += std::format("{} Events:\n", indent + " ");
388400
result += std::format("{} Load: {}\n", indent + " ", endpoint->counter.load.get());
389401
result += std::format("{} Store: {}\n", indent + " ", endpoint->counter.store.get());
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# frozen_string_literal: true
2+
3+
class Bpftime < Formula
4+
desc "Userspace eBPF runtime and tooling"
5+
homepage "https://github.com/eunomia-bpf/bpftime"
6+
url "https://github.com/eunomia-bpf/bpftime.git",
7+
tag: "v0.2.0",
8+
revision: "20acd8835241805b08bf256d0cf8963fd1cfbcac"
9+
license "MIT"
10+
head "https://github.com/eunomia-bpf/bpftime.git", branch: "master"
11+
12+
depends_on "cmake" => :build
13+
depends_on "pkgconf" => :build
14+
depends_on "boost"
15+
depends_on "ncurses"
16+
17+
resource "frida-core-devkit" do
18+
url "https://github.com/frida/frida/releases/download/16.1.2/frida-core-devkit-16.1.2-macos-arm64.tar.xz"
19+
sha256 "7811e516e6b7bbc0153d30095560e0b1133f154060c5542764100d3e0eb2ab2b"
20+
end
21+
22+
resource "frida-gum-devkit" do
23+
url "https://github.com/frida/frida/releases/download/16.1.2/frida-gum-devkit-16.1.2-macos-arm64.tar.xz"
24+
sha256 "03f6085ae5330cf38e0a498784500675fc5bd7361bb551a9097ba5fe397aceda"
25+
end
26+
27+
def install
28+
odie "bpftime v0.2.0's macOS Frida build is arm64-only" if OS.mac? && !Hardware::CPU.arm?
29+
30+
mkdir_p "third_party/frida"
31+
resource("frida-core-devkit").fetch
32+
resource("frida-gum-devkit").fetch
33+
cp resource("frida-core-devkit").cached_download,
34+
"third_party/frida/frida-core-devkit-16.1.2-macos-arm64.tar.xz"
35+
cp resource("frida-gum-devkit").cached_download,
36+
"third_party/frida/frida-gum-devkit-16.1.2-macos-arm64.tar.xz"
37+
38+
inreplace "CMakeLists.txt",
39+
'set(DEST_DIR "$ENV{HOME}/.bpftime")',
40+
"set(DEST_DIR \"#{libexec}\")"
41+
42+
%w[
43+
CMakeLists.txt
44+
tools/cli/CMakeLists.txt
45+
tools/bpftimetool/CMakeLists.txt
46+
tools/aot/CMakeLists.txt
47+
vm/llvm-jit/cli/CMakeLists.txt
48+
].each do |cmake_file|
49+
inreplace cmake_file, "DESTINATION ~/.bpftime", "DESTINATION #{libexec}" if File.exist?(cmake_file)
50+
end
51+
52+
inreplace "runtime/agent/CMakeLists.txt",
53+
'target_link_options(bpftime-agent PUBLIC "-Wl,-export-dynamic")',
54+
<<~CMAKE.chomp
55+
if(NOT APPLE)
56+
target_link_options(bpftime-agent PUBLIC "-Wl,-export-dynamic")
57+
endif()
58+
CMAKE
59+
60+
inreplace "vm/compat/ubpf-vm/CMakeLists.txt",
61+
'target_link_options(bpftime_ubpf_vm PUBLIC "-Wl,--whole-archive" "$<TARGET_FILE:bpftime_ubpf_vm>" "-Wl,--no-whole-archive")',
62+
<<~CMAKE.chomp
63+
if(APPLE)
64+
target_link_options(bpftime_ubpf_vm PUBLIC "-Wl,-force_load,$<TARGET_FILE:bpftime_ubpf_vm>")
65+
else()
66+
target_link_options(bpftime_ubpf_vm PUBLIC "-Wl,--whole-archive" "$<TARGET_FILE:bpftime_ubpf_vm>" "-Wl,--no-whole-archive")
67+
endif()
68+
CMAKE
69+
70+
ENV.append "LDFLAGS", "-L#{Formula["ncurses"].opt_lib}"
71+
ENV.append "CPPFLAGS", "-I#{Formula["boost"].opt_include}"
72+
73+
args = %W[
74+
-DCMAKE_INSTALL_PREFIX=#{prefix}
75+
-DCMAKE_BUILD_TYPE=RelWithDebInfo
76+
-DBPFTIME_BUILD_WITH_LIBBPF=OFF
77+
-DBPFTIME_BUILD_KERNEL_BPF=OFF
78+
-DBUILD_BPFTIME_DAEMON=OFF
79+
-DBPFTIME_ENABLE_UNIT_TESTING=OFF
80+
-DBPFTIME_ENABLE_CUDA_ATTACH=OFF
81+
-DBPFTIME_ENABLE_IOURING_EXT=OFF
82+
-DBPFTIME_LLVM_JIT=OFF
83+
-DBPFTIME_UBPF_JIT=ON
84+
-DBoost_INCLUDE_DIR=#{Formula["boost"].opt_include}
85+
-DCMAKE_INSTALL_RPATH=#{libexec}
86+
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON
87+
]
88+
89+
system "cmake", "-S", ".", "-B", "build", *args
90+
system "cmake", "--build", "build", "--parallel"
91+
system "cmake", "--install", "build"
92+
93+
(bin/"bpftime").write <<~SH
94+
#!/bin/bash
95+
exec "#{libexec}/bpftime" --install-location "#{libexec}" "$@"
96+
SH
97+
chmod 0755, bin/"bpftime"
98+
99+
bin.install_symlink libexec/"bpftimetool" if (libexec/"bpftimetool").exist?
100+
end
101+
102+
def caveats
103+
<<~EOS
104+
This macOS formula installs bpftime runtime files in:
105+
#{opt_libexec}
106+
107+
The bpftime wrapper automatically passes:
108+
--install-location #{opt_libexec}
109+
110+
This build uses bpftime's non-Linux configuration:
111+
BPFTIME_BUILD_WITH_LIBBPF=OFF
112+
BPFTIME_BUILD_KERNEL_BPF=OFF
113+
BPFTIME_LLVM_JIT=OFF
114+
BPFTIME_UBPF_JIT=ON
115+
EOS
116+
end
117+
118+
test do
119+
assert_match "Usage", shell_output("#{bin}/bpftime --help")
120+
end
121+
end

packaging/homebrew-tap/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# CXLMemSim Homebrew Tap
2+
3+
This tap currently provides a macOS Apple Silicon formula for bpftime v0.2.0.
4+
5+
The formula builds bpftime in its non-Linux mode:
6+
7+
```sh
8+
BPFTIME_BUILD_WITH_LIBBPF=OFF
9+
BPFTIME_BUILD_KERNEL_BPF=OFF
10+
BPFTIME_LLVM_JIT=OFF
11+
BPFTIME_UBPF_JIT=ON
12+
```
13+
14+
That gives us the bpftime CLI/runtime first, without relying on Linux kernel
15+
eBPF pieces. The CXLMemSim LLVM pass / sanitizer-style instrumentation can then
16+
link against or communicate with this installed runtime.
17+
18+
## Install Into A Local Tap
19+
20+
```sh
21+
./install-local.sh
22+
```
23+
24+
This creates or reuses the local tap `cxlmemsim/bpftime`, copies the formula
25+
there, and runs:
26+
27+
```sh
28+
brew install cxlmemsim/bpftime/bpftime
29+
```
30+
31+
## Manual Local Tap
32+
33+
```sh
34+
brew tap-new cxlmemsim/bpftime
35+
cp /Users/yiweiyang/Documents/Lanxin/CXLMemSim/packaging/homebrew-tap/Formula/bpftime.rb \
36+
"$(brew --repository cxlmemsim/bpftime)/Formula/bpftime.rb"
37+
brew install cxlmemsim/bpftime/bpftime
38+
```
39+
40+
After installation:
41+
42+
```sh
43+
bpftime --help
44+
bpftimetool --help
45+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
tap_name="${1:-cxlmemsim/bpftime}"
5+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
formula_src="${script_dir}/Formula/bpftime.rb"
7+
8+
if ! brew tap | grep -qx "${tap_name}"; then
9+
brew tap-new "${tap_name}"
10+
fi
11+
12+
tap_repo="$(brew --repository "${tap_name}")"
13+
mkdir -p "${tap_repo}/Formula"
14+
cp "${formula_src}" "${tap_repo}/Formula/bpftime.rb"
15+
16+
brew install "${tap_name}/bpftime"

0 commit comments

Comments
 (0)