mirror of
https://github.com/facebookexperimental/reverie.git
synced 2025-01-23 13:10:04 +00:00
Fix bug in check_for_xen_pmi_bug
Summary: The `count` wasn't getting initialized properly, so it was possible in theory that the check could have been failing. I noticed this while attempting to convert this chunk of `llvm_asm!()` to the new `asm!()` syntax. Also added documentation explaining what this code is doing because it's not easy to read. Reviewed By: johnhurt Differential Revision: D34542806 fbshipit-source-id: 0f79b9d36757756a1cf76e98830f9cc76f06336c
This commit is contained in:
parent
c2d7dc125f
commit
cd68557b4c
1 changed files with 28 additions and 2 deletions
|
@ -438,7 +438,8 @@ fn check_for_kvm_in_txcp_bug() -> Result<(), PmuValidationError> {
|
|||
}
|
||||
|
||||
fn check_for_xen_pmi_bug(precise_ip: bool) -> Result<(), PmuValidationError> {
|
||||
let mut count: i32;
|
||||
#[allow(unused_assignments)]
|
||||
let mut count: i32 = -1;
|
||||
let mut attr = ticks_attr(precise_ip);
|
||||
attr.__bindgen_anon_1.sample_period = NUM_BRANCHES - 1;
|
||||
let fd = start_counter(0, -1, &mut attr, None)?;
|
||||
|
@ -468,6 +469,31 @@ fn check_for_xen_pmi_bug(precise_ip: bool) -> Result<(), PmuValidationError> {
|
|||
|
||||
#[allow(deprecated)]
|
||||
unsafe {
|
||||
// The following asm block does this:
|
||||
// ```
|
||||
// let ret = syscall!(sys_ioctl, raw_fd, _PERF_EVENT_IOC_ENABLE, 0);
|
||||
// if ret >= -4095 as u64 { return; }
|
||||
// let ret = syscall!(SYS_ioctl, raw_fd, _PERF_EVENT_IOC_RESET, 0);
|
||||
// // From this point on, all conditional branches count!
|
||||
// if ret >= -4095 as u64 { return; }
|
||||
// // Reset the counter period to the desired value.
|
||||
// let ret = syscall!(SYS_ioctl, raw_fd, _PERF_EVENT_IOC_PERIOD, attr.sample_period);
|
||||
// if ret >= -4095 as u64 { return; }
|
||||
// let mut iterations = NUM_BRANCHES - 2;
|
||||
// loop {
|
||||
// iterations -= 1;
|
||||
// accumulator *= 7;
|
||||
// accumulator += 2;
|
||||
// accumulator &= 0xffffff;
|
||||
// if iterations == 0 {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// let ret = syscall!(SYS_ioctl, raw_fd, _PERF_EVENT_IOC_DISABLE, 0);
|
||||
// if ret >= -4095 as u64 { return; }
|
||||
// count = 0;
|
||||
// ```
|
||||
llvm_asm!(
|
||||
"
|
||||
mov $2, %rax;
|
||||
|
@ -548,7 +574,7 @@ fn check_for_xen_pmi_bug(precise_ip: bool) -> Result<(), PmuValidationError> {
|
|||
)));
|
||||
}
|
||||
|
||||
let has_xen_pmi_bug = (count > 0 && count as u64 > NUM_BRANCHES) || count == -1;
|
||||
let has_xen_pmi_bug = count as u64 > NUM_BRANCHES || count == -1;
|
||||
|
||||
if has_xen_pmi_bug {
|
||||
Err(PmuValidationError::IntelXenPmiBugDetected)
|
||||
|
|
Loading…
Reference in a new issue