From e15d0f9b0c2af13ed53e7e4de0be2af2c2a9d365 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 12 Nov 2023 16:29:02 +0000 Subject: [PATCH] haiku adding subset of cpu topology api. --- libc-test/build.rs | 32 ++++++++-- src/unix/haiku/native.rs | 122 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 5 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index d2d822dd70a38..8189a40ac2e0b 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4644,6 +4644,7 @@ fn test_haiku(target: &str) { ("sigaction", "sa_sigaction") => true, ("sigevent", "sigev_value") => true, ("fpu_state", "_fpreg") => true, + ("cpu_topology_node_info", "data") => true, // these fields have a simplified data definition in libc ("fpu_state", "_xmm") => true, ("savefpu", "_fp_ymm") => true, @@ -4664,13 +4665,33 @@ fn test_haiku(target: &str) { cfg.type_name(move |ty, is_struct, is_union| { match ty { // Just pass all these through, no need for a "struct" prefix - "area_info" | "port_info" | "port_message_info" | "team_info" | "sem_info" - | "team_usage_info" | "thread_info" | "cpu_info" | "system_info" - | "object_wait_info" | "image_info" | "attr_info" | "index_info" | "fs_info" - | "FILE" | "DIR" | "Dl_info" => ty.to_string(), + "area_info" + | "port_info" + | "port_message_info" + | "team_info" + | "sem_info" + | "team_usage_info" + | "thread_info" + | "cpu_info" + | "system_info" + | "object_wait_info" + | "image_info" + | "attr_info" + | "index_info" + | "fs_info" + | "FILE" + | "DIR" + | "Dl_info" + | "topology_level_type" + | "cpu_topology_node_info" + | "cpu_topology_root_info" + | "cpu_topology_package_info" + | "cpu_topology_core_info" => ty.to_string(), // enums don't need a prefix - "directory_which" | "path_base_directory" => ty.to_string(), + "directory_which" | "path_base_directory" | "cpu_platform" | "cpu_vendor" => { + ty.to_string() + } // is actually a union "sigval" => format!("union sigval"), @@ -4689,6 +4710,7 @@ fn test_haiku(target: &str) { "type_" if struct_ == "sem_t" => "type".to_string(), "type_" if struct_ == "attr_info" => "type".to_string(), "type_" if struct_ == "index_info" => "type".to_string(), + "type_" if struct_ == "cpu_topology_node_info" => "type".to_string(), "image_type" if struct_ == "image_info" => "type".to_string(), s => s.to_string(), } diff --git a/src/unix/haiku/native.rs b/src/unix/haiku/native.rs index 44bcc1e3b75f4..62d6392fabdf5 100644 --- a/src/unix/haiku/native.rs +++ b/src/unix/haiku/native.rs @@ -197,6 +197,50 @@ e! { B_UTILITIES_DIRECTORY, B_PACKAGE_LINKS_DIRECTORY, } + + // kernel/OS.h + + pub enum topology_level_type { + B_TOPOLOGY_UNKNOWN, + B_TOPOLOGY_ROOT, + B_TOPOLOGY_SMT, + B_TOPOLOGY_CORE, + B_TOPOLOGY_PACKAGE, + } + + pub enum cpu_platform { + B_CPU_UNKNOWN, + B_CPU_x86, + B_CPU_x86_64, + B_CPU_PPC, + B_CPU_PPC_64, + B_CPU_M68K, + B_CPU_ARM, + B_CPU_ARM_64, + B_CPU_ALPHA, + B_CPU_MIPS, + B_CPU_SH, + B_CPU_SPARC, + B_CPU_RISC_V + } + + pub enum cpu_vendor { + B_CPU_VENDOR_UNKNOWN, + B_CPU_VENDOR_AMD, + B_CPU_VENDOR_CYRIX, + B_CPU_VENDOR_IDT, + B_CPU_VENDOR_INTEL, + B_CPU_VENDOR_NATIONAL_SEMICONDUCTOR, + B_CPU_VENDOR_RISE, + B_CPU_VENDOR_TRANSMETA, + B_CPU_VENDOR_VIA, + B_CPU_VENDOR_IBM, + B_CPU_VENDOR_MOTOROLA, + B_CPU_VENDOR_NEC, + B_CPU_VENDOR_HYGON, + B_CPU_VENDOR_SUN, + B_CPU_VENDOR_FUJITSU + } } s! { @@ -310,6 +354,19 @@ s! { pub events: u16 } + pub struct cpu_topology_root_info { + pub platform: cpu_platform, + } + + pub struct cpu_topology_package_info { + pub vendor: cpu_vendor, + pub cache_line_size: u32, + } + + pub struct cpu_topology_core_info { + pub model: u32, + pub default_frequency: u64, + } // kernel/fs_attr.h pub struct attr_info { pub type_: u32, @@ -412,6 +469,23 @@ s_no_extra_traits! { pub as_chars: [::c_char; 16], pub regs: __c_anonymous_regs, } + + #[cfg(libc_union)] + pub union __c_anonymous_cpu_topology_info_data { + pub root: cpu_topology_root_info, + pub package: cpu_topology_package_info, + pub core: cpu_topology_core_info, + } + + pub struct cpu_topology_node_info { + pub id: u32, + pub type_: topology_level_type, + pub level: u32, + #[cfg(libc_union)] + pub data: __c_anonymous_cpu_topology_info_data, + #[cfg(not(libc_union))] + pub data: cpu_topology_core_info, + } } cfg_if! { @@ -446,6 +520,50 @@ cfg_if! { } } } + + #[cfg(libc_union)] + impl PartialEq for __c_anonymous_cpu_topology_info_data { + fn eq(&self, other: &__c_anonymous_cpu_topology_info_data) -> bool { + unsafe { + self.root == other.root + || self.package == other.package + || self.core == other.core + } + } + } + #[cfg(libc_union)] + impl Eq for __c_anonymous_cpu_topology_info_data {} + #[cfg(libc_union)] + impl ::fmt::Debug for __c_anonymous_cpu_topology_info_data { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + unsafe { + f.debug_struct("__c_anonymous_cpu_topology_info_data") + .field("root", &self.root) + .field("package", &self.package) + .field("core", &self.core) + .finish() + } + } + } + + impl PartialEq for cpu_topology_node_info { + fn eq(&self, other: &cpu_topology_node_info) -> bool { + self.id == other.id + && self.type_ == other.type_ + && self.level == other.level + } + } + + impl Eq for cpu_topology_node_info {} + impl ::fmt::Debug for cpu_topology_node_info { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("cpu_topology_node_info") + .field("id", &self.id) + .field("type", &self.type_) + .field("level", &self.level) + .finish() + } + } } } @@ -1026,6 +1144,10 @@ extern "C" { info: *mut cpu_info, size: ::size_t, ) -> status_t; + pub fn get_cpu_topology_info( + topologyInfos: *mut cpu_topology_node_info, + topologyInfoCount: *mut u32, + ) -> status_t; pub fn is_computer_on() -> i32; pub fn is_computer_on_fire() -> ::c_double; pub fn send_signal(threadID: thread_id, signal: ::c_uint) -> ::c_int;