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, CpuPlacementGuarantee, 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(),
CpuPlacementGuarantee::AdvisoryDeclared,
)?;
assert_eq!(domain.ownership(), CpuDomainOwnership::ExternalManaged);Implementations§
Source§impl ExternalCpuDomain
impl ExternalCpuDomain
Sourcepub fn new(
id: CpuDomainId,
placement: ResolvedCpuPlacement,
executor: Arc<dyn CpuDomainExecutor>,
thread_budget: NonZeroUsize,
placement_guarantee: CpuPlacementGuarantee,
) -> Result<Self, ExternalCpuDomainError>
pub fn new( id: CpuDomainId, placement: ResolvedCpuPlacement, executor: Arc<dyn CpuDomainExecutor>, thread_budget: NonZeroUsize, placement_guarantee: CpuPlacementGuarantee, ) -> Result<Self, ExternalCpuDomainError>
Construct one externally managed CPU resource-domain descriptor.
The executor is retained for the complete descriptor lifetime. Exact and advisory placement values remain caller declarations and do not alter the executor’s affinity capability.
§Examples
use std::num::NonZeroUsize;
use std::sync::Arc;
use tenferro_cpu::{
CpuContext, CpuId, CpuPlacementGuarantee, 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(),
CpuPlacementGuarantee::ExactDeclared,
)?;
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.
Sourcepub fn new_caller_managed(
id: CpuDomainId,
executor: Arc<dyn CpuDomainExecutor>,
thread_budget: NonZeroUsize,
) -> Result<Self, ExternalCpuDomainError>
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.
Sourcepub fn id(&self) -> CpuDomainId
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;Sourcepub fn placement(&self) -> Option<&ResolvedCpuPlacement>
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());Sourcepub fn cpus(&self) -> Option<&CpuSet>
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());Sourcepub fn admission_mode(&self) -> CpuAdmissionMode
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);Sourcepub fn thread_budget(&self) -> NonZeroUsize
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;Sourcepub fn placement_guarantee(&self) -> Option<CpuPlacementGuarantee>
pub fn placement_guarantee(&self) -> Option<CpuPlacementGuarantee>
Return whether cooperative placement is an exact or advisory declaration.
§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_guarantee().is_none());Sourcepub fn ownership(&self) -> CpuDomainOwnership
pub fn ownership(&self) -> CpuDomainOwnership
Return the external ownership diagnostic.
§Examples
use tenferro_cpu::{CpuDomainOwnership, ExternalCpuDomain};
let _ownership: fn(&ExternalCpuDomain) -> CpuDomainOwnership =
ExternalCpuDomain::ownership;Sourcepub fn executor_capabilities(&self) -> CpuDomainExecutorCapabilities
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§
Auto Trait Implementations§
impl !RefUnwindSafe for ExternalCpuDomain
impl !UnwindSafe for ExternalCpuDomain
impl Freeze for ExternalCpuDomain
impl Send for ExternalCpuDomain
impl Sync for ExternalCpuDomain
impl Unpin for ExternalCpuDomain
impl UnsafeUnpin for ExternalCpuDomain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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