Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/build_qnx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
-//score/memory/shared:shared_memory_resource_open_test
-//score/os/test:asil_qm_test
-//score/os/test:grp_test
-//src/containers:tests
- bazel-config: bl-aarch64-qnx
bazel-test-target: >-
//score/...
Expand All @@ -48,9 +47,6 @@ jobs:
-//score/memory/shared:shared_memory_factory_test
-//score/memory/shared:shared_memory_resource_open_test
-//score/os/utils/inotify:unit_test
-//src/containers:tests
-//src/pal:tests
-//src/thread:tests
extra-bazel-test-flags: "--test_timeout=120,600,1800,7200" # Increase test timeout due to QEMU emulation
uses: eclipse-score/cicd-workflows/.github/workflows/qnx-build.yml@af347722c7ae3ed85518895c11268d96ac728f62
permissions:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ examples/integration/bazel-*
user.bazelrc
.cache
compile_commands.json
target/

# docs build artifacts
_build
Expand Down
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ license-file = "LICENSE.md"
authors = ["S-CORE Contributors"]

[workspace.dependencies]
libc = "0.2.177"

containers = { path = "src/containers" }
score_log = { path = "src/log/score_log" }
score_log_fmt = { path = "src/log/score_log_fmt" }
Expand Down
23 changes: 11 additions & 12 deletions src/containers/storage/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ mod tests {
use super::*;
use elementary::{HeapAllocator, GLOBAL_ALLOCATOR};

// Type used by all tests.
type T = u64;
// Equals to 1GB. Tests might fail for runners with <1GB.
const LARGE_CAP: u32 = (i32::MAX as u32 / size_of::<T>() as u32) / 2;
// Capacity test cases.
const CAP_CASES: [u32; 7] = [0, 1, 2, 3, 4, 5, LARGE_CAP];

#[test]
fn subslice() {
type T = u64;

fn run_test(capacity: u32) {
let instance = Heap::<T, _>::new(capacity, &GLOBAL_ALLOCATOR);

Expand All @@ -171,15 +176,13 @@ mod tests {
}
}

for cap in [0, 1, 2, 3, 4, 5, i32::MAX as u32 / size_of::<T>() as u32] {
for cap in CAP_CASES {
run_test(cap);
}
}

#[test]
fn subslice_mut() {
type T = u64;

fn run_test(capacity: u32) {
let mut instance = Heap::<T, HeapAllocator>::new(capacity, &GLOBAL_ALLOCATOR);

Expand All @@ -205,15 +208,13 @@ mod tests {
}
}

for cap in [0, 1, 2, 3, 4, 5, i32::MAX as u32 / size_of::<T>() as u32] {
for cap in CAP_CASES {
run_test(cap);
}
}

#[test]
fn element() {
type T = u64;

fn run_test(capacity: u32) {
let instance = Heap::<T, HeapAllocator>::new(capacity, &GLOBAL_ALLOCATOR);

Expand All @@ -240,15 +241,13 @@ mod tests {
}
}

for cap in [0, 1, 2, 3, 4, 5, i32::MAX as u32 / size_of::<T>() as u32] {
for cap in CAP_CASES {
run_test(cap);
}
}

#[test]
fn element_mut() {
type T = u64;

fn run_test(capacity: u32) {
let mut instance = Heap::<T, HeapAllocator>::new(capacity, &GLOBAL_ALLOCATOR);

Expand All @@ -275,7 +274,7 @@ mod tests {
}
}

for cap in [0, 1, 2, 3, 4, 5, i32::MAX as u32 / size_of::<T>() as u32] {
for cap in CAP_CASES {
run_test(cap);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/pal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ rust_library(
deps = [
"//src/containers",
"//src/log/score_log",
"@score_crates//:libc",
],
)

Expand Down
1 change: 0 additions & 1 deletion src/pal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ edition.workspace = true
path = "lib.rs"

[dependencies]
libc.workspace = true
containers.workspace = true
score_log.workspace = true
90 changes: 70 additions & 20 deletions src/pal/affinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,34 @@
//! Affinity handling differs between Linux and QNX.
//! Module ensures similar behavior between both OSes.

use crate::errno;
use crate::{c_int, errno};
use containers::fixed_capacity::FixedCapacityVec;
use score_log::ScoreDebug;

#[cfg(target_os = "linux")]
use libc::{cpu_set_t, sched_getaffinity, sched_setaffinity};
#[repr(C)]
pub struct cpu_set_t {
#[cfg(all(target_pointer_width = "32", not(target_arch = "x86_64")))]
bits: [u32; 32],
#[cfg(not(all(target_pointer_width = "32", not(target_arch = "x86_64"))))]
bits: [u64; 16],
}

#[cfg(target_os = "linux")]
extern "C" {
pub fn sched_getaffinity(pid: crate::pid_t, cpusetsize: crate::size_t, cpuset: *mut cpu_set_t) -> c_int;
pub fn sched_setaffinity(pid: crate::pid_t, cpusetsize: crate::size_t, cpuset: *const cpu_set_t) -> c_int;
}

#[cfg(target_os = "nto")]
const _NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT: u32 = 10;
#[cfg(target_os = "nto")]
use libc::{ThreadCtl, _NTO_TCTL_RUNMASK_GET_AND_SET_INHERIT};
extern "C" {
pub fn ThreadCtl(__cmd: c_int, __data: *mut crate::c_void) -> c_int;
}

#[cfg(target_os = "nto")]
pub const _SC_NPROCESSORS_ONLN: c_int = 91;

const MAX_CPU_NUM: usize = 1024;
const CPU_MASK_SIZE: usize = MAX_CPU_NUM / (u8::BITS as usize);
Expand Down Expand Up @@ -126,39 +145,70 @@ impl From<CpuSet> for cpu_set_t {
#[repr(C)]
#[derive(Clone, Copy)]
struct NtoCpuSet {
// Expected to always be set to `32` - see comment above.
size: i32,
run_mask: [u32; 32],
// Expected to always be zeroed - left unaltered.
inherit_mask: [u32; 32],
// `ThreadCtl` data internal representation.
// `size` must be determined based on number of CPU, with max allowed value equal to 32.
// [ size: i32 | run_mask: size * u32 | inherit_mask: size * u32 ]
data: [u32; 1 + 32 + 32],
}

#[cfg(target_os = "nto")]
impl NtoCpuSet {
fn new(mask: [u32; 32]) -> Self {
Self {
size: 32,
run_mask: mask,
inherit_mask: [0; 32],
}
fn new() -> Self {
// Get number of CPUs.
let num_cpus = unsafe { crate::sysconf(_SC_NPROCESSORS_ONLN) } as u32;
assert!(
num_cpus >= 1 && num_cpus <= MAX_CPU_NUM as u32,
"number of CPUs in the system out of expected range: {num_cpus}"
);

// Get number of elements and set it at 0.
let size = (num_cpus - 1) / u32::BITS + 1;
let mut data = [0; _];
data[0] = size;

Self { data }
}

fn run_mask(&self) -> &[u32] {
let size = self.data[0] as usize;
&self.data[1..1 + size]
}

fn run_mask_mut(&mut self) -> &mut [u32] {
let size = self.data[0] as usize;
&mut self.data[1..1 + size]
}
}

#[cfg(target_os = "nto")]
impl From<NtoCpuSet> for CpuSet {
fn from(value: NtoCpuSet) -> Self {
// SAFETY: CPU mask layout and size is ensured.
let mask = unsafe { core::mem::transmute(value.run_mask) };
// Reorient data from array of u32 to array of u8.
let mut mask = [0u8; CPU_MASK_SIZE];
for (i, &word) in value.run_mask().iter().enumerate() {
const CHUNK_SIZE: usize = i32::BITS as usize / 8;
mask[i * CHUNK_SIZE..i * CHUNK_SIZE + CHUNK_SIZE].copy_from_slice(&word.to_le_bytes());
}
Self { mask }
}
}

#[cfg(target_os = "nto")]
impl From<CpuSet> for NtoCpuSet {
fn from(value: CpuSet) -> Self {
// SAFETY: CPU mask layout and size is ensured.
let run_mask = unsafe { core::mem::transmute(value.mask) };
Self::new(run_mask)
// Reorient data from array of u8 to array of u32.
let mut nto_cpu_set = Self::new();
let size = nto_cpu_set.data[0] as usize;
let used_bytes = size * (u32::BITS as usize / 8);
assert!(
value.mask[used_bytes..].iter().all(|&b| b == 0),
"provided CpuSet contains CPU IDs out of range for NtoCpuSet in this configuration"
);

for (i, chunk) in value.mask[..used_bytes].chunks_exact(4).enumerate() {
nto_cpu_set.run_mask_mut()[i] = u32::from_le_bytes(chunk.try_into().expect("chunk is 4 bytes"));
}
nto_cpu_set
}
}

Expand Down Expand Up @@ -220,7 +270,7 @@ pub fn get_affinity() -> FixedCapacityVec<usize> {

#[cfg(target_os = "nto")]
{
let mut native_cpu_set = NtoCpuSet::new([0; _]);
let mut native_cpu_set = NtoCpuSet::new();
// SAFETY:
// Native CPU set is properly initialized.
// `NtoCpuSet` layout must be as expected by `ThreadCtl`.
Expand Down
16 changes: 14 additions & 2 deletions src/pal/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@

//! Unified `errno` access.

use crate::c_int;

#[cfg(target_os = "linux")]
extern "C" {
pub fn __errno_location() -> *mut c_int;
}

#[cfg(target_os = "nto")]
extern "C" {
pub fn __get_errno_ptr() -> *mut c_int;
}

#[cfg(target_os = "linux")]
use libc::__errno_location as errno_ptr;
use __errno_location as errno_ptr;

#[cfg(target_os = "nto")]
use libc::__get_errno_ptr as errno_ptr;
use __get_errno_ptr as errno_ptr;

/// Current errno value.
pub fn errno() -> crate::c_int {
Expand Down
Loading
Loading