Skip to content

Commit 607566b

Browse files
author
Quincy
committed
Arithmetic overflow is allowed. Overflow does not affect the overall calculation result.
1 parent b8708e9 commit 607566b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/tscns.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(arithmetic_overflow)]
2+
13
extern crate crossbeam_utils;
24

35
use std::ptr::addr_of_mut;
@@ -93,8 +95,7 @@ pub fn calibrate() {
9395
}
9496
let (tsc, ns) = sync_time();
9597
let calculated_ns = tsc2ns(tsc);
96-
let ns_err = calculated_ns.checked_sub(ns).unwrap_or_else(|| 0);
97-
// let ns_err = (calculated_ns - ns); // Calculate the error in converting the current TSC timestamp to a nanosecond timestamp.
98+
let ns_err = calculated_ns - ns; // Calculate the error in converting the current TSC timestamp to a nanosecond timestamp.
9899
let expected_err_at_next_calibration = ns_err + (ns_err - unsafe { BASE_NS_ERR }) * unsafe { CALIBATE_INTERVAL_NS } / (ns - unsafe { BASE_NS } + unsafe { BASE_NS_ERR });
99100
let new_ns_per_tsc = unsafe { NS_PER_TSC } * (1.0 - (expected_err_at_next_calibration as f64) / unsafe { CALIBATE_INTERVAL_NS } as f64); // Calculate the number of nanoseconds for each new clock cycle.
100101
save_param(tsc, calculated_ns, ns, new_ns_per_tsc);
@@ -153,8 +154,7 @@ fn save_param(
153154
new_ns_per_tsc: f64,
154155
) {
155156
unsafe {
156-
*addr_of_mut!(BASE_NS) = base_ns.checked_sub(sys_ns).unwrap_or_else(|| 0);
157-
// *addr_of_mut!(BASE_NS) = base_ns - sys_ns; // Error in calculating benchmark nanoseconds.
157+
*addr_of_mut!(BASE_NS) = base_ns - sys_ns; // Error in calculating benchmark nanoseconds.
158158
*addr_of_mut!(NEXT_CALIBRATE_TSC) = base_tsc + ((CALIBATE_INTERVAL_NS - 1000) as f64 / new_ns_per_tsc) as u64; // Calculate the clock cycle for the next calibration.
159159
let param_seq_ref = &*addr_of_mut!(PARAM_SEQ);
160160
let seq = param_seq_ref.load(Ordering::Relaxed);

0 commit comments

Comments
 (0)