solana_perf/
lib.rs

1pub mod cuda_runtime;
2pub mod data_budget;
3pub mod discard;
4pub mod packet;
5pub mod perf_libs;
6pub mod recycler;
7pub mod recycler_cache;
8pub mod sigverify;
9pub mod test_tx;
10pub mod thread;
11
12#[macro_use]
13extern crate lazy_static;
14
15#[macro_use]
16extern crate log;
17
18#[cfg(test)]
19#[macro_use]
20extern crate matches;
21
22#[macro_use]
23extern crate solana_metrics;
24
25fn is_rosetta_emulated() -> bool {
26    #[cfg(target_os = "macos")]
27    {
28        use std::str::FromStr;
29        std::process::Command::new("sysctl")
30            .args(&["-in", "sysctl.proc_translated"])
31            .output()
32            .map_err(|_| ())
33            .and_then(|output| String::from_utf8(output.stdout).map_err(|_| ()))
34            .and_then(|stdout| u8::from_str(stdout.trim()).map_err(|_| ()))
35            .map(|enabled| enabled == 1)
36            .unwrap_or(false)
37    }
38    #[cfg(not(target_os = "macos"))]
39    {
40        false
41    }
42}
43
44pub fn report_target_features() {
45    warn!(
46        "CUDA is {}abled",
47        if crate::perf_libs::api().is_some() {
48            "en"
49        } else {
50            "dis"
51        }
52    );
53
54    // Validator binaries built on a machine with AVX support will generate invalid opcodes
55    // when run on machines without AVX causing a non-obvious process abort.  Instead detect
56    // the mismatch and error cleanly.
57    if !is_rosetta_emulated() {
58        #[cfg(all(
59            any(target_arch = "x86", target_arch = "x86_64"),
60            build_target_feature_avx
61        ))]
62        {
63            if is_x86_feature_detected!("avx") {
64                info!("AVX detected");
65            } else {
66                error!(
67                "Incompatible CPU detected: missing AVX support. Please build from source on the target"
68            );
69                std::process::abort();
70            }
71        }
72
73        #[cfg(all(
74            any(target_arch = "x86", target_arch = "x86_64"),
75            build_target_feature_avx2
76        ))]
77        {
78            if is_x86_feature_detected!("avx2") {
79                info!("AVX2 detected");
80            } else {
81                error!(
82                    "Incompatible CPU detected: missing AVX2 support. Please build from source on the target"
83                );
84                std::process::abort();
85            }
86        }
87    }
88}