Commit 23bb415e authored by Sven Liefgen's avatar Sven Liefgen
Browse files

Add feature gate to enable xlap

This means xlap is disabled by default
parent c7b85aa6
...@@ -6,6 +6,9 @@ edition = "2018" ...@@ -6,6 +6,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
xlap = []
[dependencies] [dependencies]
strum = { version = "0.20", features = ["derive"] } strum = { version = "0.20", features = ["derive"] }
......
...@@ -25,7 +25,8 @@ fn main() { ...@@ -25,7 +25,8 @@ fn main() {
.len(); .len();
let mut static_xlap = format!( let mut static_xlap = format!(
"static XLAP: [AtomicPtr<TimestampTable>; {}] = [\n", "#[cfg(feature = \"xlap\")]\n\
static XLAP: [AtomicPtr<TimestampTable>; {}] = [\n",
packet_types_count packet_types_count
); );
for _ in 0..packet_types_count { for _ in 0..packet_types_count {
...@@ -35,7 +36,8 @@ fn main() { ...@@ -35,7 +36,8 @@ fn main() {
// Create constants for kinds // Create constants for kinds
let mut kind_enum = String::from("#[derive(EnumIter, Copy, Clone)]\n"); let mut kind_enum = String::from("#[cfg(feature = \"xlap\")]\n");
kind_enum.push_str("#[derive(EnumIter, Copy, Clone)]\n");
kind_enum.push_str("#[allow(non_camel_case_types)]\n"); kind_enum.push_str("#[allow(non_camel_case_types)]\n");
kind_enum.push_str("pub enum Kind {\n"); kind_enum.push_str("pub enum Kind {\n");
for kind in packet_types.as_hash().unwrap().keys() { for kind in packet_types.as_hash().unwrap().keys() {
...@@ -49,8 +51,8 @@ fn main() { ...@@ -49,8 +51,8 @@ fn main() {
let timestamps = &yaml["stamps"]; let timestamps = &yaml["stamps"];
let mut timestamp_id_enum = let mut timestamp_id_enum = String::from("#[cfg(feature = \"xlap\")]");
String::from("#[derive(EnumCount, EnumIter, AsRefStr, Copy, Clone)]\n"); timestamp_id_enum.push_str("#[derive(EnumCount, EnumIter, AsRefStr, Copy, Clone)]\n");
timestamp_id_enum.push_str("pub enum TimestampId {\n"); timestamp_id_enum.push_str("pub enum TimestampId {\n");
for timestamp_id in timestamps for timestamp_id in timestamps
.as_hash() .as_hash()
...@@ -67,7 +69,11 @@ fn main() { ...@@ -67,7 +69,11 @@ fn main() {
let count = &yaml["rows"].as_i64().unwrap_or(4098); let count = &yaml["rows"].as_i64().unwrap_or(4098);
let ts_rows = format!("const TS_ROWS: usize = {};\n", count + 1); let ts_rows = format!(
"#[cfg(feature = \"xlap\")]\n\
const TS_ROWS: usize = {};\n",
count + 1
);
fs::write( fs::write(
&dest_path, &dest_path,
......
...@@ -45,18 +45,22 @@ struct Timestamp { ...@@ -45,18 +45,22 @@ struct Timestamp {
t: Instant, t: Instant,
} }
#[cfg(feature = "xlap")]
/// A row wit timestamps /// A row wit timestamps
struct TimestampTableRow { struct TimestampTableRow {
timestamp: [Timestamp; TimestampId::COUNT], timestamp: [Timestamp; TimestampId::COUNT],
} }
#[cfg(feature = "xlap")]
/// Table containing all the timestamps /// Table containing all the timestamps
pub struct TimestampTable { pub struct TimestampTable {
rows: [TimestampTableRow; TS_ROWS], rows: [TimestampTableRow; TS_ROWS],
} }
#[cfg(feature = "xlap")]
static mut ZERO: Option<Instant> = None; static mut ZERO: Option<Instant> = None;
#[cfg(feature = "xlap")]
/// Update the clock and cycle value of a timestamp by setting them to en explicit value /// Update the clock and cycle value of a timestamp by setting them to en explicit value
#[inline(always)] #[inline(always)]
pub unsafe fn set_timestamp(kind: Kind, row: usize, id: TimestampId, (t, c): (Instant, u64)) { pub unsafe fn set_timestamp(kind: Kind, row: usize, id: TimestampId, (t, c): (Instant, u64)) {
...@@ -64,6 +68,7 @@ pub unsafe fn set_timestamp(kind: Kind, row: usize, id: TimestampId, (t, c): (In ...@@ -64,6 +68,7 @@ pub unsafe fn set_timestamp(kind: Kind, row: usize, id: TimestampId, (t, c): (In
set_timestamp_cycle(kind, row, id, c); set_timestamp_cycle(kind, row, id, c);
} }
#[cfg(feature = "xlap")]
/// Update the clock value of a timestamp by setting it to an explicit value /// Update the clock value of a timestamp by setting it to an explicit value
#[inline(always)] #[inline(always)]
pub unsafe fn set_timestamp_clock(kind: Kind, row: usize, id: TimestampId, value: Instant) { pub unsafe fn set_timestamp_clock(kind: Kind, row: usize, id: TimestampId, value: Instant) {
...@@ -71,6 +76,7 @@ pub unsafe fn set_timestamp_clock(kind: Kind, row: usize, id: TimestampId, value ...@@ -71,6 +76,7 @@ pub unsafe fn set_timestamp_clock(kind: Kind, row: usize, id: TimestampId, value
value; value;
} }
#[cfg(feature = "xlap")]
/// Update the clock value of a cyclestamp by setting it to an explicit value /// Update the clock value of a cyclestamp by setting it to an explicit value
#[inline(always)] #[inline(always)]
pub unsafe fn set_timestamp_cycle(kind: Kind, row: usize, id: TimestampId, value: u64) { pub unsafe fn set_timestamp_cycle(kind: Kind, row: usize, id: TimestampId, value: u64) {
...@@ -78,6 +84,7 @@ pub unsafe fn set_timestamp_cycle(kind: Kind, row: usize, id: TimestampId, value ...@@ -78,6 +84,7 @@ pub unsafe fn set_timestamp_cycle(kind: Kind, row: usize, id: TimestampId, value
value; value;
} }
#[cfg(feature = "xlap")]
/// Update the clock value of a timestamp /// Update the clock value of a timestamp
#[inline(always)] #[inline(always)]
pub unsafe fn timestamp_clock(kind: Kind, row: usize, id: TimestampId) { pub unsafe fn timestamp_clock(kind: Kind, row: usize, id: TimestampId) {
...@@ -85,6 +92,7 @@ pub unsafe fn timestamp_clock(kind: Kind, row: usize, id: TimestampId) { ...@@ -85,6 +92,7 @@ pub unsafe fn timestamp_clock(kind: Kind, row: usize, id: TimestampId) {
Instant::now(); Instant::now();
} }
#[cfg(feature = "xlap")]
/// Update the cycle value of a timestamp /// Update the cycle value of a timestamp
#[inline(always)] #[inline(always)]
pub unsafe fn timestamp_cycle(kind: Kind, row: usize, id: TimestampId) { pub unsafe fn timestamp_cycle(kind: Kind, row: usize, id: TimestampId) {
...@@ -92,18 +100,21 @@ pub unsafe fn timestamp_cycle(kind: Kind, row: usize, id: TimestampId) { ...@@ -92,18 +100,21 @@ pub unsafe fn timestamp_cycle(kind: Kind, row: usize, id: TimestampId) {
current_cycle(); current_cycle();
} }
#[cfg(feature = "xlap")]
/// Create a clock value without saving it to a table /// Create a clock value without saving it to a table
#[inline(always)] #[inline(always)]
pub fn get_timestamp_clock() -> Instant { pub fn get_timestamp_clock() -> Instant {
Instant::now() Instant::now()
} }
#[cfg(feature = "xlap")]
/// Create a cycle value without saving it to a table /// Create a cycle value without saving it to a table
#[inline(always)] #[inline(always)]
pub fn get_timestamp_cycle() -> u64 { pub fn get_timestamp_cycle() -> u64 {
unsafe { current_cycle() } unsafe { current_cycle() }
} }
#[cfg(feature = "xlap")]
/// Install a timestamp table /// Install a timestamp table
/// ///
/// Allocate memory for the empty timestamp tables and store pointers in the XLAP static /// Allocate memory for the empty timestamp tables and store pointers in the XLAP static
...@@ -119,6 +130,7 @@ pub unsafe fn init() { ...@@ -119,6 +130,7 @@ pub unsafe fn init() {
} }
} }
#[cfg(feature = "xlap")]
impl TimestampTable { impl TimestampTable {
/// Dump the collected timestamps to a csv file /// Dump the collected timestamps to a csv file
pub unsafe fn dump_all(file: &str) -> std::io::Result<()> { pub unsafe fn dump_all(file: &str) -> std::io::Result<()> {
...@@ -153,3 +165,78 @@ impl TimestampTable { ...@@ -153,3 +165,78 @@ impl TimestampTable {
Ok(()) Ok(())
} }
} }
#[cfg(not(feature = "xlap"))]
/// Table containing all the timestamps
pub struct TimestampTable;
#[cfg(not(feature = "xlap"))]
pub struct Kind;
#[cfg(not(feature = "xlap"))]
pub struct TimestampId;
#[cfg(not(feature = "xlap"))]
/// Update the clock and cycle value of a timestamp by setting them to en explicit value
#[inline(always)]
pub unsafe fn set_timestamp(_: Kind, _: usize, _: TimestampId, _: (Instant, u64)) {}
#[cfg(not(feature = "xlap"))]
/// Update the clock value of a timestamp by setting it to an explicit value
#[inline(always)]
pub unsafe fn set_timestamp_clock(_: Kind, _: usize, _: TimestampId, _: Instant) {}
#[cfg(not(feature = "xlap"))]
/// Update the clock value of a cyclestamp by setting it to an explicit value
#[inline(always)]
pub unsafe fn set_timestamp_cycle(_: Kind, _: usize, _: TimestampId, _: u64) {}
#[cfg(not(feature = "xlap"))]
/// Update the clock value of a timestamp
#[inline(always)]
pub unsafe fn timestamp_clock(_: Kind, _: usize, _: TimestampId) {}
#[cfg(not(feature = "xlap"))]
/// Update the cycle value of a timestamp
#[inline(always)]
pub unsafe fn timestamp_cycle(_: Kind, _: usize, _: TimestampId) {}
#[cfg(not(feature = "xlap"))]
/// Create a clock value without saving it to a table
#[inline(always)]
pub fn get_timestamp_clock() -> Instant {
Instant::now()
}
#[cfg(not(feature = "xlap"))]
/// Create a cycle value without saving it to a table
#[inline(always)]
pub fn get_timestamp_cycle() -> u64 {
0
}
#[cfg(not(feature = "xlap"))]
/// Install a timestamp table
///
/// Allocate memory for the empty timestamp tables and store pointers in the XLAP static
pub unsafe fn init() {}
#[cfg(not(feature = "xlap"))]
impl TimestampTable {
/// Dump the collected timestamps to a csv file
pub unsafe fn dump_all(file: &str) -> std::io::Result<()> {
Self::dump(file, &[])
}
/// Dump the collected timestamps of the given tables to a csv file
pub unsafe fn dump(file: &str, _: &[Kind]) -> std::io::Result<()> {
let mut file = std::fs::File::create(file)?;
Self::dump_header(&mut file)?;
Ok(())
}
fn dump_header(file: &mut std::fs::File) -> std::io::Result<()> {
write!(file, "XLAP was disabled")?;
Ok(())
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment