Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Take page size into account.
Browse files Browse the repository at this point in the history
  • Loading branch information
vext01 committed Oct 18, 2022
1 parent 3c11ac8 commit a0ba640
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/collect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
use crate::{errors::HWTracerError, Trace};
use core::arch::x86_64::__cpuid_count;
use libc::size_t;
use libc::{size_t, sysconf, _SC_PAGESIZE};
use std::{convert::TryFrom, sync::LazyLock};
use strum::IntoEnumIterator;
use strum_macros::EnumIter;

Expand All @@ -12,7 +13,13 @@ pub(crate) mod perf;
pub(crate) use perf::PerfTraceCollector;

const PERF_DFLT_DATA_BUFSIZE: size_t = 64;
const PERF_DFLT_AUX_BUFSIZE: size_t = 16384; // 64MiB if the page size is 4096 bytes.
const PERF_DFLT_AUX_BUFSIZE: LazyLock<size_t> = LazyLock::new(|| {
// Allocate enough pages for a 64MiB trace buffer.
let mb64 = 1024 * 1024 * 64;
let page_sz = size_t::try_from(unsafe { sysconf(_SC_PAGESIZE) }).unwrap();
mb64 / page_sz + size_t::from(mb64 % page_sz != 0)
});

const PERF_DFLT_INITIAL_TRACE_BUFSIZE: size_t = 1024 * 1024; // 1MiB

/// The interface offered by all trace collectors.
Expand Down Expand Up @@ -100,7 +107,7 @@ impl Default for PerfCollectorConfig {
fn default() -> Self {
Self {
data_bufsize: PERF_DFLT_DATA_BUFSIZE,
aux_bufsize: PERF_DFLT_AUX_BUFSIZE,
aux_bufsize: *PERF_DFLT_AUX_BUFSIZE,
initial_trace_bufsize: PERF_DFLT_INITIAL_TRACE_BUFSIZE,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(clippy::upper_case_acronyms)]
#![allow(clippy::new_without_default)]
#![feature(once_cell)]

mod block;
pub use block::Block;
Expand Down

0 comments on commit a0ba640

Please sign in to comment.