Skip to content

use upstream avx-turbo repo, apply patches #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@ endif
tar -xf async-profiler-$(ASYNC_PROFILER_VERSION)-linux-x64.tar.gz && mv async-profiler-$(ASYNC_PROFILER_VERSION)-linux-x64 async-profiler
endif

# Use a local copy of avx-turbo source until the upstream makes the required changes
AVX_TURBO_VERSION := "9cfe8bf"
avx-turbo:
ifeq ("$(wildcard avx-turbo)","")
git clone https://github.com/travisdowns/avx-turbo.git
else
cd avx-turbo && git checkout master && git pull
endif
cd avx-turbo && git checkout $(AVX_TURBO_VERSION)
# apply our patches to avx-turbo, aperf/mperf first because it doesn't add/remove any lines
cd avx-turbo && git apply ../avx-turbo-patches/0001-use-fixed-CPU-number-to-determine-if-APERF-MPERF-are.patch
cd avx-turbo && git apply ../avx-turbo-patches/0001-Add-CPU-ID-pinning-option.patch
cd avx-turbo && make

# if you change the version, check the sed hacks below
Expand Down
82 changes: 82 additions & 0 deletions tools/avx-turbo-patches/0001-Add-CPU-ID-pinning-option.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
From aedb82d512237e761abd909bbd5d9036a3b39bef Mon Sep 17 00:00:00 2001
From: "Harper, Jason M" <[email protected]>
Date: Fri, 30 May 2025 08:05:00 -0700
Subject: [PATCH] Add CPU ID pinning option

Signed-off-by: Harper, Jason M <[email protected]>
---
avx-turbo.cpp | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/avx-turbo.cpp b/avx-turbo.cpp
index c7d4dc0..c794b7b 100644
--- a/avx-turbo.cpp
+++ b/avx-turbo.cpp
@@ -189,7 +189,7 @@ args::ValueFlag<int> arg_min_threads{parser, "MIN", "The minimum number of threa
args::ValueFlag<int> arg_max_threads{parser, "MAX", "The maximum number of threads to use", {"max-threads"}};
args::ValueFlag<int> arg_num_cpus{parser, "CPUS", "Override number of available CPUs", {"num-cpus"}};
args::ValueFlag<uint64_t> arg_warm_ms{parser, "MILLISECONDS", "Warmup milliseconds for each thread after pinning (default 100)", {"warmup-ms"}, 100};
-
+args::ValueFlag<std::string> arg_cpuids{parser, "CPUIDS", "Pin threads to comma-separated list of CPU IDs (default sequential ids)", {"cpuids"}};

bool verbose;

@@ -614,6 +614,7 @@ struct warmup {

struct test_thread {
size_t id;
+ size_t cpu_id;
hot_barrier* start_barrier;
hot_barrier* stop_barrier;

@@ -627,8 +628,8 @@ struct test_thread {

std::thread thread;

- test_thread(size_t id, hot_barrier& start_barrier, hot_barrier& stop_barrier, const test_func *test, size_t iters, bool use_aperf) :
- id{id}, start_barrier{&start_barrier}, stop_barrier{&stop_barrier}, test{test},
+ test_thread(size_t id, size_t cpu_id, hot_barrier& start_barrier, hot_barrier& stop_barrier, const test_func *test, size_t iters, bool use_aperf) :
+ id{id}, cpu_id{cpu_id}, start_barrier{&start_barrier}, stop_barrier{&stop_barrier}, test{test},
iters{iters}, use_aperf{use_aperf}, thread{std::ref(*this)}
{
// if (verbose) printf("Constructed test in thread %lu, this = %p\n", id, this);
@@ -641,7 +642,7 @@ struct test_thread {
void operator()() {
// if (verbose) printf("Running test in thread %lu, this = %p\n", id, this);
if (!arg_no_pin) {
- pin_to_cpu(id);
+ pin_to_cpu(cpu_id);
}
aperf_ghz aperf_timer;
outer_timer& outer = use_aperf ? static_cast<outer_timer&>(aperf_timer) : dummy_outer::dummy;
@@ -839,6 +840,18 @@ int main(int argc, char** argv) {
zeroupper();
auto specs = filter_tests(isas_supported, cpus);

+ // parse comma separate list of cpu_ids into an array
+ std::vector<int> cpu_ids;
+ if (arg_cpuids) {
+ for (auto& id : split(arg_cpuids.Get(), ",")) {
+ cpu_ids.push_back(std::atoi(id.c_str()));
+ }
+ } else {
+ for (int i = 0; i < (int)cpus.size(); i++) {
+ cpu_ids.push_back(i);
+ }
+ }
+
size_t last_thread_count = -1u;
std::vector<result_holder> results_list;
for (auto& spec : specs) {
@@ -857,7 +870,7 @@ int main(int argc, char** argv) {
std::deque<test_thread> threads;
hot_barrier start{spec.count()}, stop{spec.count()};
for (auto& test : spec.thread_funcs) {
- threads.emplace_back(threads.size(), start, stop, &test, iters, use_aperf);
+ threads.emplace_back(threads.size(), cpu_ids[threads.size()], start, stop, &test, iters, use_aperf);
}

results_list.emplace_back(&spec);
--
2.34.1

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 261bb31a67dd21834150fdbbad07d1f094407752 Mon Sep 17 00:00:00 2001
From: "Harper, Jason M" <[email protected]>
Date: Fri, 30 May 2025 06:59:56 -0700
Subject: [PATCH] use fixed CPU number to determine if APERF/MPERF are
supported

---
avx-turbo.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/avx-turbo.cpp b/avx-turbo.cpp
index c7d4dc0..96bc1c2 100644
--- a/avx-turbo.cpp
+++ b/avx-turbo.cpp
@@ -279,8 +279,8 @@ struct aperf_ghz : outer_timer {
*/
static bool is_supported() {
uint64_t dummy;
- return read_msr_cur_cpu(MSR_IA32_MPERF, &dummy) == 0
- && read_msr_cur_cpu(MSR_IA32_APERF, &dummy) == 0;
+ return read_msr(1, MSR_IA32_MPERF, &dummy) == 0
+ && read_msr(1, MSR_IA32_APERF, &dummy) == 0;
}

virtual void start() override {
--
2.34.1

39 changes: 0 additions & 39 deletions tools/avx-turbo/.github/workflows/build.yml

This file was deleted.

59 changes: 0 additions & 59 deletions tools/avx-turbo/.gitignore

This file was deleted.

70 changes: 0 additions & 70 deletions tools/avx-turbo/.travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions tools/avx-turbo/LICENSE

This file was deleted.

61 changes: 0 additions & 61 deletions tools/avx-turbo/Makefile

This file was deleted.

Loading