-
Notifications
You must be signed in to change notification settings - Fork 248
Add getcpu system call support for getting a NUMA node of the current thread
#1575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,8 @@ use core::{fmt, hash}; | |
| /// - [Linux] | ||
| /// | ||
| /// [Linux]: https://man7.org/linux/man-pages/man3/CPU_SET.3.html | ||
| /// [`sched_setaffinity`]: crate::thread::sched_setaffinity | ||
| /// [`sched_getaffinity`]: crate::thread::sched_getaffinity | ||
| /// [`sched_setaffinity`]: sched_setaffinity | ||
| /// [`sched_getaffinity`]: sched_getaffinity | ||
| #[repr(transparent)] | ||
| #[derive(Clone, Copy)] | ||
| pub struct CpuSet { | ||
|
|
@@ -159,3 +159,25 @@ pub fn sched_getaffinity(pid: Option<Pid>) -> io::Result<CpuSet> { | |
| pub fn sched_getcpu() -> usize { | ||
| backend::thread::syscalls::sched_getcpu() | ||
| } | ||
|
|
||
| /// `sched_getcpu()`—Get the CPU and NUMA node that the current thread is currently on. | ||
| /// | ||
| /// # Example | ||
| /// | ||
| /// ```rust | ||
| /// use rustix::thread::getcpu; | ||
| /// | ||
| /// let (core, numa_node) = getcpu(); | ||
| /// | ||
| /// println!("The current thread was on the {core} core and {numa_node} numa node."); | ||
| /// ``` | ||
| /// | ||
| /// # References | ||
| /// - [Linux] | ||
| /// | ||
| /// [Linux]: https://man7.org/linux/man-pages/man2/getcpu.2.html | ||
| #[cfg(linux_kernel)] | ||
| #[inline] | ||
| pub fn getcpu() -> (usize, usize) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the Linux docs, the values written by
Would it be better to reflect them here as I see that
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to do the same as |
||
| backend::thread::syscalls::getcpu() | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.