Skip to content

Commit 1ab1874

Browse files
committed
Auto merge of #3440 - devnexen:haiku_cpu_topology, r=JohnTitor
haiku adding subset of cpu topology api.
2 parents 78a3d13 + e15d0f9 commit 1ab1874

File tree

2 files changed

+149
-5
lines changed

2 files changed

+149
-5
lines changed

libc-test/build.rs

+27-5
Original file line numberDiff line numberDiff line change
@@ -4649,6 +4649,7 @@ fn test_haiku(target: &str) {
46494649
("sigaction", "sa_sigaction") => true,
46504650
("sigevent", "sigev_value") => true,
46514651
("fpu_state", "_fpreg") => true,
4652+
("cpu_topology_node_info", "data") => true,
46524653
// these fields have a simplified data definition in libc
46534654
("fpu_state", "_xmm") => true,
46544655
("savefpu", "_fp_ymm") => true,
@@ -4669,13 +4670,33 @@ fn test_haiku(target: &str) {
46694670
cfg.type_name(move |ty, is_struct, is_union| {
46704671
match ty {
46714672
// Just pass all these through, no need for a "struct" prefix
4672-
"area_info" | "port_info" | "port_message_info" | "team_info" | "sem_info"
4673-
| "team_usage_info" | "thread_info" | "cpu_info" | "system_info"
4674-
| "object_wait_info" | "image_info" | "attr_info" | "index_info" | "fs_info"
4675-
| "FILE" | "DIR" | "Dl_info" => ty.to_string(),
4673+
"area_info"
4674+
| "port_info"
4675+
| "port_message_info"
4676+
| "team_info"
4677+
| "sem_info"
4678+
| "team_usage_info"
4679+
| "thread_info"
4680+
| "cpu_info"
4681+
| "system_info"
4682+
| "object_wait_info"
4683+
| "image_info"
4684+
| "attr_info"
4685+
| "index_info"
4686+
| "fs_info"
4687+
| "FILE"
4688+
| "DIR"
4689+
| "Dl_info"
4690+
| "topology_level_type"
4691+
| "cpu_topology_node_info"
4692+
| "cpu_topology_root_info"
4693+
| "cpu_topology_package_info"
4694+
| "cpu_topology_core_info" => ty.to_string(),
46764695

46774696
// enums don't need a prefix
4678-
"directory_which" | "path_base_directory" => ty.to_string(),
4697+
"directory_which" | "path_base_directory" | "cpu_platform" | "cpu_vendor" => {
4698+
ty.to_string()
4699+
}
46794700

46804701
// is actually a union
46814702
"sigval" => format!("union sigval"),
@@ -4694,6 +4715,7 @@ fn test_haiku(target: &str) {
46944715
"type_" if struct_ == "sem_t" => "type".to_string(),
46954716
"type_" if struct_ == "attr_info" => "type".to_string(),
46964717
"type_" if struct_ == "index_info" => "type".to_string(),
4718+
"type_" if struct_ == "cpu_topology_node_info" => "type".to_string(),
46974719
"image_type" if struct_ == "image_info" => "type".to_string(),
46984720
s => s.to_string(),
46994721
}

src/unix/haiku/native.rs

+122
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,50 @@ e! {
197197
B_UTILITIES_DIRECTORY,
198198
B_PACKAGE_LINKS_DIRECTORY,
199199
}
200+
201+
// kernel/OS.h
202+
203+
pub enum topology_level_type {
204+
B_TOPOLOGY_UNKNOWN,
205+
B_TOPOLOGY_ROOT,
206+
B_TOPOLOGY_SMT,
207+
B_TOPOLOGY_CORE,
208+
B_TOPOLOGY_PACKAGE,
209+
}
210+
211+
pub enum cpu_platform {
212+
B_CPU_UNKNOWN,
213+
B_CPU_x86,
214+
B_CPU_x86_64,
215+
B_CPU_PPC,
216+
B_CPU_PPC_64,
217+
B_CPU_M68K,
218+
B_CPU_ARM,
219+
B_CPU_ARM_64,
220+
B_CPU_ALPHA,
221+
B_CPU_MIPS,
222+
B_CPU_SH,
223+
B_CPU_SPARC,
224+
B_CPU_RISC_V
225+
}
226+
227+
pub enum cpu_vendor {
228+
B_CPU_VENDOR_UNKNOWN,
229+
B_CPU_VENDOR_AMD,
230+
B_CPU_VENDOR_CYRIX,
231+
B_CPU_VENDOR_IDT,
232+
B_CPU_VENDOR_INTEL,
233+
B_CPU_VENDOR_NATIONAL_SEMICONDUCTOR,
234+
B_CPU_VENDOR_RISE,
235+
B_CPU_VENDOR_TRANSMETA,
236+
B_CPU_VENDOR_VIA,
237+
B_CPU_VENDOR_IBM,
238+
B_CPU_VENDOR_MOTOROLA,
239+
B_CPU_VENDOR_NEC,
240+
B_CPU_VENDOR_HYGON,
241+
B_CPU_VENDOR_SUN,
242+
B_CPU_VENDOR_FUJITSU
243+
}
200244
}
201245

202246
s! {
@@ -310,6 +354,19 @@ s! {
310354
pub events: u16
311355
}
312356

357+
pub struct cpu_topology_root_info {
358+
pub platform: cpu_platform,
359+
}
360+
361+
pub struct cpu_topology_package_info {
362+
pub vendor: cpu_vendor,
363+
pub cache_line_size: u32,
364+
}
365+
366+
pub struct cpu_topology_core_info {
367+
pub model: u32,
368+
pub default_frequency: u64,
369+
}
313370
// kernel/fs_attr.h
314371
pub struct attr_info {
315372
pub type_: u32,
@@ -412,6 +469,23 @@ s_no_extra_traits! {
412469
pub as_chars: [::c_char; 16],
413470
pub regs: __c_anonymous_regs,
414471
}
472+
473+
#[cfg(libc_union)]
474+
pub union __c_anonymous_cpu_topology_info_data {
475+
pub root: cpu_topology_root_info,
476+
pub package: cpu_topology_package_info,
477+
pub core: cpu_topology_core_info,
478+
}
479+
480+
pub struct cpu_topology_node_info {
481+
pub id: u32,
482+
pub type_: topology_level_type,
483+
pub level: u32,
484+
#[cfg(libc_union)]
485+
pub data: __c_anonymous_cpu_topology_info_data,
486+
#[cfg(not(libc_union))]
487+
pub data: cpu_topology_core_info,
488+
}
415489
}
416490

417491
cfg_if! {
@@ -446,6 +520,50 @@ cfg_if! {
446520
}
447521
}
448522
}
523+
524+
#[cfg(libc_union)]
525+
impl PartialEq for __c_anonymous_cpu_topology_info_data {
526+
fn eq(&self, other: &__c_anonymous_cpu_topology_info_data) -> bool {
527+
unsafe {
528+
self.root == other.root
529+
|| self.package == other.package
530+
|| self.core == other.core
531+
}
532+
}
533+
}
534+
#[cfg(libc_union)]
535+
impl Eq for __c_anonymous_cpu_topology_info_data {}
536+
#[cfg(libc_union)]
537+
impl ::fmt::Debug for __c_anonymous_cpu_topology_info_data {
538+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
539+
unsafe {
540+
f.debug_struct("__c_anonymous_cpu_topology_info_data")
541+
.field("root", &self.root)
542+
.field("package", &self.package)
543+
.field("core", &self.core)
544+
.finish()
545+
}
546+
}
547+
}
548+
549+
impl PartialEq for cpu_topology_node_info {
550+
fn eq(&self, other: &cpu_topology_node_info) -> bool {
551+
self.id == other.id
552+
&& self.type_ == other.type_
553+
&& self.level == other.level
554+
}
555+
}
556+
557+
impl Eq for cpu_topology_node_info {}
558+
impl ::fmt::Debug for cpu_topology_node_info {
559+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
560+
f.debug_struct("cpu_topology_node_info")
561+
.field("id", &self.id)
562+
.field("type", &self.type_)
563+
.field("level", &self.level)
564+
.finish()
565+
}
566+
}
449567
}
450568
}
451569

@@ -1026,6 +1144,10 @@ extern "C" {
10261144
info: *mut cpu_info,
10271145
size: ::size_t,
10281146
) -> status_t;
1147+
pub fn get_cpu_topology_info(
1148+
topologyInfos: *mut cpu_topology_node_info,
1149+
topologyInfoCount: *mut u32,
1150+
) -> status_t;
10291151
pub fn is_computer_on() -> i32;
10301152
pub fn is_computer_on_fire() -> ::c_double;
10311153
pub fn send_signal(threadID: thread_id, signal: ::c_uint) -> ::c_int;

0 commit comments

Comments
 (0)