-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subsystem-bench: cache misses profiling (#2893)
## Why we need it To provide another level of understanding to why polkadot's subsystems may perform slower than expected. Cache misses occur when processing large amounts of data, such as during availability recovery. ## Why Cachegrind Cachegrind has many drawbacks: it is slow, it uses its own cache simulation, which is very basic. But unlike `perf`, which is a great tool, Cachegrind can run in a virtual machine. This means we can easily run it in remote installations and even use it in CI/CD to catch possible regressions. Why Cachegrind and not Callgrind, another part of Valgrind? It is simply empirically proven that profiling runs faster with Cachegrind. ## First results First results have been obtained while testing of the approach. Here is an example. ``` $ target/testnet/subsystem-bench --n-cores 10 --cache-misses data-availability-read $ cat cachegrind_report.txt I refs: 64,622,081,485 I1 misses: 3,018,168 LLi misses: 437,654 I1 miss rate: 0.00% LLi miss rate: 0.00% D refs: 12,161,833,115 (9,868,356,364 rd + 2,293,476,751 wr) D1 misses: 167,940,701 ( 71,060,073 rd + 96,880,628 wr) LLd misses: 33,550,018 ( 16,685,853 rd + 16,864,165 wr) D1 miss rate: 1.4% ( 0.7% + 4.2% ) LLd miss rate: 0.3% ( 0.2% + 0.7% ) LL refs: 170,958,869 ( 74,078,241 rd + 96,880,628 wr) LL misses: 33,987,672 ( 17,123,507 rd + 16,864,165 wr) LL miss rate: 0.0% ( 0.0% + 0.7% ) ``` The CLI output shows that 1.4% of the L1 data cache missed, which is not so bad, given that the last-level cache had that data most of the time missing only 0.3%. Instruction data of the L1 has 0.00% misses of the time. Looking at an output file with `cg_annotate` shows that most of the misses occur during reed-solomon, which is expected.
- Loading branch information
1 parent
82c057e
commit ec7bfae
Showing
3 changed files
with
121 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (C) Parity Technologies (UK) Ltd. | ||
// This file is part of Polkadot. | ||
|
||
// Polkadot is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Polkadot is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use color_eyre::eyre; | ||
|
||
/// Show if the app is running under Valgrind | ||
pub(crate) fn is_valgrind_running() -> bool { | ||
match std::env::var("LD_PRELOAD") { | ||
Ok(v) => v.contains("valgrind"), | ||
Err(_) => false, | ||
} | ||
} | ||
|
||
/// Stop execution and relaunch the app under valgrind | ||
/// Cache configuration used to emulate Intel Ice Lake (size, associativity, line size): | ||
/// L1 instruction: 32,768 B, 8-way, 64 B lines | ||
/// L1 data: 49,152 B, 12-way, 64 B lines | ||
/// Last-level: 2,097,152 B, 16-way, 64 B lines | ||
pub(crate) fn relaunch_in_valgrind_mode() -> eyre::Result<()> { | ||
use std::os::unix::process::CommandExt; | ||
let err = std::process::Command::new("valgrind") | ||
.arg("--tool=cachegrind") | ||
.arg("--cache-sim=yes") | ||
.arg("--log-file=cachegrind_report.txt") | ||
.arg("--I1=32768,8,64") | ||
.arg("--D1=49152,12,64") | ||
.arg("--LL=2097152,16,64") | ||
.arg("--verbose") | ||
.args(std::env::args()) | ||
.exec(); | ||
|
||
Err(eyre::eyre!( | ||
"Сannot run Valgrind, check that it is installed and available in the PATH\n{}", | ||
err | ||
)) | ||
} |