From 4def7ef14fb38134bb1387ef904b11360826a04c Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Thu, 3 Oct 2024 23:08:41 +0200 Subject: [PATCH 1/6] Add profiling executable for cache analysis --- profiling/CMakeLists.txt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/profiling/CMakeLists.txt b/profiling/CMakeLists.txt index 2b7e0baee..c79b67b8b 100644 --- a/profiling/CMakeLists.txt +++ b/profiling/CMakeLists.txt @@ -7,17 +7,21 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -# Set the C++ flags -string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -Os") - # Set the folder for the executable set(EXECUTABLE_OUTPUT_PATH ../) # Define the executable add_executable(prof.out main.cpp) target_include_directories(prof.out PRIVATE ../src/) -target_compile_options(prof.out PRIVATE -pg) +target_compile_options(prof.out PRIVATE -pg -Os) target_link_options(prof.out PRIVATE -pg) + add_executable(mem.out main.cpp) target_include_directories(mem.out PRIVATE ../src/) +target_compile_options(mem.out PRIVATE -Os) + add_executable(parse_massif.out parse_massif.cpp) + +add_executable(cache.out main.cpp) +target_include_directories(cache.out PRIVATE ../src/) +target_compile_options(cache.out PRIVATE -pg -O2) From b029258fca54622ec6cbedeca43d97355e3de37e Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Thu, 3 Oct 2024 23:08:57 +0200 Subject: [PATCH 2/6] Update gitignore --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3de1a023b..3bbcecca7 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ # valgrind generated files *vgcore.* *massif.* +*cachegrind* + +# perf generated files +*perf.data* # profiling log files *.log @@ -29,4 +33,4 @@ examples/*.csv # Utils generated folders __pycache__ -images \ No newline at end of file +images From 4e513f9f409987380191f8f870e088031ab726ea Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Thu, 3 Oct 2024 23:09:05 +0200 Subject: [PATCH 3/6] Workflow for profiling cache with `cachegrind` and `perf` --- .github/workflows/cache_profiler.yml | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/cache_profiler.yml diff --git a/.github/workflows/cache_profiler.yml b/.github/workflows/cache_profiler.yml new file mode 100644 index 000000000..591d4353a --- /dev/null +++ b/.github/workflows/cache_profiler.yml @@ -0,0 +1,35 @@ +name: Profile the use of CPU caches + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v3 + + - name: Install Valgrind + run: sudo apt-get install -y valgrind perf + + - name: Build test simulation + working-directory: ${{github.workspace}}/profiling + run: cmake -S . -B build && cmake --build build + + - name: Profile using cachegrind + working-directory: ${{github.workspace}}/profiling + run: | + valgrind --tool=cachegrind ./cache.out + cg_annotate cachegrind.out.* + + - name: Profile using perf + working-directory: ${{github.workspace}}/profiling + run: | + perf stat -B -e cache-references,cache-misses,cycles,instructions,branches ./cache.out + perf record ./cache.out + perf record -e cache-misses ./cache.out + perf report -v From 3f190356dc7a908766bbe4a33c6cebeed623f799 Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Thu, 3 Oct 2024 23:19:56 +0200 Subject: [PATCH 4/6] Fix installation of perf --- .github/workflows/cache_profiler.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cache_profiler.yml b/.github/workflows/cache_profiler.yml index 591d4353a..e9bccce1e 100644 --- a/.github/workflows/cache_profiler.yml +++ b/.github/workflows/cache_profiler.yml @@ -14,7 +14,9 @@ jobs: - uses: actions/checkout@v3 - name: Install Valgrind - run: sudo apt-get install -y valgrind perf + run: | + sudo apt-get install -y valgrind perf + sudo apt-get install -y linux-tools-common linux-tools-generic - name: Build test simulation working-directory: ${{github.workspace}}/profiling From f6a5f9dfa4075a41662bbf0592856d8085754343 Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Thu, 3 Oct 2024 23:20:54 +0200 Subject: [PATCH 5/6] Fix typo --- .github/workflows/cache_profiler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cache_profiler.yml b/.github/workflows/cache_profiler.yml index e9bccce1e..ce78df85c 100644 --- a/.github/workflows/cache_profiler.yml +++ b/.github/workflows/cache_profiler.yml @@ -15,7 +15,7 @@ jobs: - name: Install Valgrind run: | - sudo apt-get install -y valgrind perf + sudo apt-get install -y valgrind sudo apt-get install -y linux-tools-common linux-tools-generic - name: Build test simulation From bb1eeb29f0ed85dae0ecf73554d3c8585a4d33bc Mon Sep 17 00:00:00 2001 From: Simone Balducci Date: Thu, 3 Oct 2024 23:30:40 +0200 Subject: [PATCH 6/6] Test --- .github/workflows/cache_profiler.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/cache_profiler.yml b/.github/workflows/cache_profiler.yml index ce78df85c..032475f1e 100644 --- a/.github/workflows/cache_profiler.yml +++ b/.github/workflows/cache_profiler.yml @@ -18,6 +18,9 @@ jobs: sudo apt-get install -y valgrind sudo apt-get install -y linux-tools-common linux-tools-generic + - name: Relax perf_event_paranoid + run: sudo sysctl kernel.perf_event_paranoid=-1 + - name: Build test simulation working-directory: ${{github.workspace}}/profiling run: cmake -S . -B build && cmake --build build