From e7cdd0db8d9b3db20c01d862c878e3a7864bbb80 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Wed, 15 Mar 2023 10:34:47 -0700 Subject: [PATCH] third-party/rust: vendor a fork of perf-event Summary: For https://github.com/jimblandy/perf-event/pull/29 which sets CLOEXEC by default. Reviewed By: edward-shen Differential Revision: D43983384 Privacy Context Container: L1123788 fbshipit-source-id: 478c0e11bd815e916094b48ce7763b4dfc3e5f79 --- reverie-ptrace/Cargo.toml | 2 +- reverie-ptrace/src/perf.rs | 24 ++++++++---------------- reverie-ptrace/src/validation.rs | 22 +++++++--------------- 3 files changed, 16 insertions(+), 32 deletions(-) diff --git a/reverie-ptrace/Cargo.toml b/reverie-ptrace/Cargo.toml index f4c3e18..69f6763 100644 --- a/reverie-ptrace/Cargo.toml +++ b/reverie-ptrace/Cargo.toml @@ -20,7 +20,7 @@ libc = "0.2.139" nix = "0.25" num-traits = "0.2" paste = "1.0" -perf-event-open-sys = "1.0" +perf-event-open-sys = "4.0" procfs = "0.9" raw-cpuid = "10.6.0" reverie = { version = "0.1.0", path = "../reverie" } diff --git a/reverie-ptrace/src/perf.rs b/reverie-ptrace/src/perf.rs index 6d78d81..71cbd02 100644 --- a/reverie-ptrace/src/perf.rs +++ b/reverie-ptrace/src/perf.rs @@ -95,22 +95,20 @@ pub struct PerfCounter { impl Event { fn attr_type(self) -> u32 { match self { - Event::Hardware(_) => perf::perf_type_id_PERF_TYPE_HARDWARE, - Event::Software(_) => perf::perf_type_id_PERF_TYPE_SOFTWARE, - Event::Raw(_) => perf::perf_type_id_PERF_TYPE_RAW, + Event::Hardware(_) => perf::PERF_TYPE_HARDWARE, + Event::Software(_) => perf::PERF_TYPE_SOFTWARE, + Event::Raw(_) => perf::PERF_TYPE_RAW, } } fn attr_config(self) -> u64 { match self { Event::Raw(x) => x, - Event::Hardware(HardwareEvent::Instructions) => { - perf::perf_hw_id_PERF_COUNT_HW_INSTRUCTIONS.into() - } + Event::Hardware(HardwareEvent::Instructions) => perf::PERF_COUNT_HW_INSTRUCTIONS.into(), Event::Hardware(HardwareEvent::BranchInstructions) => { - perf::perf_hw_id_PERF_COUNT_HW_BRANCH_INSTRUCTIONS.into() + perf::PERF_COUNT_HW_BRANCH_INSTRUCTIONS.into() } - Event::Software(SoftwareEvent::Dummy) => perf::perf_sw_ids_PERF_COUNT_SW_DUMMY.into(), + Event::Software(SoftwareEvent::Dummy) => perf::PERF_COUNT_SW_DUMMY.into(), } } } @@ -301,14 +299,8 @@ impl PerfCounter { // This ioctl shouldn't mutate it's argument per its API. But in case it // does, create a mutable copy to avoid Rust UB. let mut ticks = ticks; - Errno::result(unsafe { - libc::ioctl( - self.fd, - perf::perf_event_ioctls_PERIOD as _, - &mut ticks as *mut u64, - ) - }) - .and(Ok(())) + Errno::result(unsafe { libc::ioctl(self.fd, perf::PERIOD as _, &mut ticks as *mut u64) }) + .and(Ok(())) } /// Call the `PERF_EVENT_IOC_ID` ioctl. Returns a unique identifier for this diff --git a/reverie-ptrace/src/validation.rs b/reverie-ptrace/src/validation.rs index aea7965..f9d0819 100644 --- a/reverie-ptrace/src/validation.rs +++ b/reverie-ptrace/src/validation.rs @@ -104,18 +104,14 @@ fn init_perf_event_attr( /// Create a template perf_event_attr for ticks fn ticks_attr(precise_ip: bool) -> perf::perf_event_attr { - init_perf_event_attr( - perf::perf_type_id_PERF_TYPE_RAW, - get_rcb_perf_config(), - precise_ip, - ) + init_perf_event_attr(perf::PERF_TYPE_RAW, get_rcb_perf_config(), precise_ip) } /// Create a template perf_event_attr for cycles fn cycles_attr(precise_ip: bool) -> perf::perf_event_attr { init_perf_event_attr( - perf::perf_type_id_PERF_TYPE_HARDWARE, - perf::perf_hw_id_PERF_COUNT_HW_CPU_CYCLES.into(), + perf::PERF_TYPE_HARDWARE, + perf::PERF_COUNT_HW_CPU_CYCLES.into(), precise_ip, ) } @@ -163,11 +159,7 @@ fn check_for_ioc_period_bug(precise_ip: bool) -> Result<(), PmuValidationError> let mut new_period = 1_u64; - let _ioctl = ioctl( - &bug_fd, - perf::perf_event_ioctls_PERIOD.into(), - &mut new_period, - )?; + let _ioctl = ioctl(&bug_fd, perf::PERIOD.into(), &mut new_period)?; let mut poll_bug_fd = libc::pollfd { fd: bug_fd.0, @@ -396,7 +388,7 @@ fn check_for_zen_speclockmap() -> Result<(), PmuValidationError> { // 0x25 == RETIRED_LOCK_INSTRUCTIONS - Counts the number of retired locked instructions // + 0x08 == SPECLOCKMAPCOMMIT - let mut attr = init_perf_event_attr(perf::perf_type_id_PERF_TYPE_RAW, 0x510825, false); + let mut attr = init_perf_event_attr(perf::PERF_TYPE_RAW, 0x510825, false); let fd = start_counter(0, -1, &mut attr, None)?; @@ -434,8 +426,8 @@ fn check_for_kvm_in_txcp_bug() -> Result<(), PmuValidationError> { let mut arg = 0_u64; if !disabled_txcp { - ioctl(&fd, perf::perf_event_ioctls_DISABLE.into(), &mut arg)?; - ioctl(&fd, perf::perf_event_ioctls_ENABLE.into(), &mut arg)?; + ioctl(&fd, perf::DISABLE.into(), &mut arg)?; + ioctl(&fd, perf::ENABLE.into(), &mut arg)?; do_branches(NUM_BRANCHES); count = read_counter(&fd)?; }