瀏覽代碼

增加smp支持 (#4)

* add tiny-aya impl

* Fix perf_event_header read error

* feat: add hashmap support

* feat: add smp support
linfeng 5 月之前
父節點
當前提交
bac99a0ac7
共有 1 個文件被更改,包括 15 次插入17 次删除
  1. 15 17
      aya/src/util.rs

+ 15 - 17
aya/src/util.rs

@@ -2,7 +2,7 @@ use core::{
     slice,
     str::{FromStr, Utf8Error},
 };
-use std::io;
+use std::{fs, io};
 
 /// Represents a kernel version, in major.minor.release version.
 // Adapted from https://docs.rs/procfs/latest/procfs/sys/kernel/struct.Version.html.
@@ -127,14 +127,13 @@ pub(crate) const POSSIBLE_CPUS: &str = "/sys/devices/system/cpu/possible";
 ///
 /// See `/sys/devices/system/cpu/possible`.
 pub(crate) fn possible_cpus() -> Result<Vec<u32>, io::Error> {
-    // let data = fs::read_to_string(POSSIBLE_CPUS)?;
-    // parse_cpu_ranges(data.trim()).map_err(|_| {
-    //     io::Error::new(
-    //         io::ErrorKind::Other,
-    //         format!("unexpected {POSSIBLE_CPUS} format"),
-    //     )
-    // })
-    Ok(vec![0])
+    let data = fs::read_to_string(POSSIBLE_CPUS)?;
+    parse_cpu_ranges(data.trim()).map_err(|_| {
+        io::Error::new(
+            io::ErrorKind::Other,
+            format!("unexpected {POSSIBLE_CPUS} format"),
+        )
+    })
 }
 
 fn parse_cpu_ranges(data: &str) -> Result<Vec<u32>, ()> {
@@ -160,14 +159,13 @@ fn parse_cpu_ranges(data: &str) -> Result<Vec<u32>, ()> {
 
 /// Returns the numeric IDs of the CPUs currently online.
 pub fn online_cpus() -> Result<Vec<u32>, io::Error> {
-    // let data = fs::read_to_string(ONLINE_CPUS)?;
-    // parse_cpu_ranges(data.trim()).map_err(|_| {
-    //     io::Error::new(
-    //         io::ErrorKind::Other,
-    //         format!("unexpected {ONLINE_CPUS} format"),
-    //     )
-    // })
-    Ok(vec![0])
+    let data = fs::read_to_string(ONLINE_CPUS)?;
+    parse_cpu_ranges(data.trim()).map_err(|_| {
+        io::Error::new(
+            io::ErrorKind::Other,
+            format!("unexpected {ONLINE_CPUS} format"),
+        )
+    })
 }
 
 pub(crate) fn page_size() -> usize {