Skip to main content

ExternalCpuDomain

Struct ExternalCpuDomain 

Source
pub struct ExternalCpuDomain { /* private fields */ }
Expand description

Caller-supplied descriptor for one externally managed CPU resource domain.

The descriptor retains the supplied executor without replacing its pool or changing its affinity claim. Registration and process-CPU-set validation are performed later by crate::CpuBackend.

§Examples

use std::num::NonZeroUsize;
use std::sync::Arc;
use tenferro_cpu::{
    CpuContext, CpuDomainOwnership, CpuId, CpuSet,
    ExternalCpuDomain, ResolvedCpuPlacement,
};
use tenferro_tensor::CpuDomainId;

let domain = ExternalCpuDomain::new(
    CpuDomainId::new(7),
    ResolvedCpuPlacement::AllAllowed {
        cpus: CpuSet::new([CpuId::new(0)])?,
    },
    Arc::new(CpuContext::with_threads(1)?),
    NonZeroUsize::new(1).unwrap(),
)?;
assert_eq!(domain.ownership(), CpuDomainOwnership::ExternalManaged);

Implementations§

Source§

impl ExternalCpuDomain

Source

pub fn new( id: CpuDomainId, placement: ResolvedCpuPlacement, executor: Arc<dyn CpuDomainExecutor>, thread_budget: NonZeroUsize, ) -> Result<Self, ExternalCpuDomainError>

Construct one externally managed CPU resource-domain descriptor.

The executor is retained for the complete descriptor lifetime. The placement’s CPU set is the domain’s identity for resource exclusion: two domains whose sets overlap never execute at the same time. It does not alter the executor’s affinity capability, and tenferro makes no promise about where threads created by an external provider run.

§Examples
use std::num::NonZeroUsize;
use std::sync::Arc;
use tenferro_cpu::{
    CpuContext, CpuId, CpuSet, ExternalCpuDomain,
    ResolvedCpuPlacement,
};
use tenferro_tensor::CpuDomainId;

let domain = ExternalCpuDomain::new(
    CpuDomainId::new(3),
    ResolvedCpuPlacement::AllAllowed {
        cpus: CpuSet::new([CpuId::new(0)])?,
    },
    Arc::new(CpuContext::with_threads(1)?),
    NonZeroUsize::new(1).unwrap(),
)?;
assert_eq!(domain.id(), CpuDomainId::new(3));
§Errors

Returns ExternalCpuDomainError::EmptyPlacementCpuSet for an empty resolved CPU set, ExternalCpuDomainError::ZeroExecutorWorkers when the executor reports no workers, or ExternalCpuDomainError::ThreadBudgetExceedsWorkerCount when thread_budget is greater than the executor’s worker count.

Source

pub fn new_caller_managed( id: CpuDomainId, executor: Arc<dyn CpuDomainExecutor>, thread_budget: NonZeroUsize, ) -> Result<Self, ExternalCpuDomainError>

Construct a caller-managed domain without declaring a CPU set.

The caller owns admission between distinct caller-managed domains. tenferro retains executor, rejects concurrent public entry into this domain, and never constructs or shuts down another executor.

§Examples
use std::num::NonZeroUsize;
use std::sync::Arc;
use tenferro_cpu::{
    CpuAdmissionMode, ExternalCpuDomain, RayonCpuDomainExecutor,
};
use tenferro_tensor::CpuDomainId;

let pool = Arc::new(rayon::ThreadPoolBuilder::new().num_threads(2).build()?);
let executor = Arc::new(RayonCpuDomainExecutor::new(Arc::clone(&pool)));
let domain = ExternalCpuDomain::new_caller_managed(
    CpuDomainId::new(9),
    executor,
    NonZeroUsize::new(2).unwrap(),
)?;
assert_eq!(domain.admission_mode(), CpuAdmissionMode::CallerManaged);
assert!(domain.placement().is_none());
§Errors

Returns ExternalCpuDomainError::ZeroExecutorWorkers when the executor reports no workers, or ExternalCpuDomainError::ThreadBudgetExceedsWorkerCount when thread_budget exceeds the executor worker count.

Source

pub fn id(&self) -> CpuDomainId

Return the caller-stable identity of this CPU domain.

§Examples
use tenferro_cpu::ExternalCpuDomain;
use tenferro_tensor::CpuDomainId;

let _id: fn(&ExternalCpuDomain) -> CpuDomainId = ExternalCpuDomain::id;
Source

pub fn placement(&self) -> Option<&ResolvedCpuPlacement>

Return the declared resolved placement, if this domain uses CPU-set admission.

§Examples
use std::num::NonZeroUsize;
use std::sync::Arc;
use tenferro_cpu::{CpuContext, ExternalCpuDomain};
use tenferro_tensor::CpuDomainId;

let domain = ExternalCpuDomain::new_caller_managed(
    CpuDomainId::new(1),
    Arc::new(CpuContext::with_threads(1)?),
    NonZeroUsize::MIN,
)?;
assert!(domain.placement().is_none());
Source

pub fn cpus(&self) -> Option<&CpuSet>

Return the logical CPUs declared for CPU-set admission.

§Examples
use std::num::NonZeroUsize;
use std::sync::Arc;
use tenferro_cpu::{CpuContext, ExternalCpuDomain};
use tenferro_tensor::CpuDomainId;

let domain = ExternalCpuDomain::new_caller_managed(
    CpuDomainId::new(1),
    Arc::new(CpuContext::with_threads(1)?),
    NonZeroUsize::MIN,
)?;
assert!(domain.cpus().is_none());
Source

pub fn admission_mode(&self) -> CpuAdmissionMode

Return this domain’s admission contract.

§Examples
use std::num::NonZeroUsize;
use std::sync::Arc;
use tenferro_cpu::{CpuAdmissionMode, CpuContext, ExternalCpuDomain};
use tenferro_tensor::CpuDomainId;

let domain = ExternalCpuDomain::new_caller_managed(
    CpuDomainId::new(1),
    Arc::new(CpuContext::with_threads(1)?),
    NonZeroUsize::MIN,
)?;
assert_eq!(domain.admission_mode(), CpuAdmissionMode::CallerManaged);
Source

pub fn thread_budget(&self) -> NonZeroUsize

Return the nonzero thread budget requested for tenferro work.

§Examples
use std::num::NonZeroUsize;
use tenferro_cpu::ExternalCpuDomain;

let _budget: fn(&ExternalCpuDomain) -> NonZeroUsize =
    ExternalCpuDomain::thread_budget;
Source

pub fn ownership(&self) -> CpuDomainOwnership

Return the external ownership diagnostic.

§Examples
use tenferro_cpu::{CpuDomainOwnership, ExternalCpuDomain};

let _ownership: fn(&ExternalCpuDomain) -> CpuDomainOwnership =
    ExternalCpuDomain::ownership;
Source

pub fn executor_capabilities(&self) -> CpuDomainExecutorCapabilities

Return the supplied executor’s immutable capability descriptor.

§Examples
use tenferro_cpu::{CpuDomainExecutorCapabilities, ExternalCpuDomain};

let _capabilities: fn(&ExternalCpuDomain) -> CpuDomainExecutorCapabilities =
    ExternalCpuDomain::executor_capabilities;

Trait Implementations§

Source§

impl Debug for ExternalCpuDomain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.