use crate::op_class::OpClass;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum DispatchProfile {
LatencyBound,
PortBound,
MemoryBound,
Streaming,
Unspecified,
}
impl DispatchProfile {
pub fn default_ns_per_elem(self) -> Option<u32> {
match self {
Self::LatencyBound => Some(600),
Self::PortBound => Some(12),
Self::MemoryBound => Some(50),
Self::Streaming => Some(50),
Self::Unspecified => None,
}
}
pub fn default_oversubscription_log2(self) -> u8 {
match self {
Self::LatencyBound => 2,
Self::PortBound => 1,
Self::MemoryBound => 1,
Self::Streaming => 1,
Self::Unspecified => 1,
}
}
pub fn is_latency_bound(self) -> bool {
matches!(self, Self::LatencyBound | Self::MemoryBound)
}
pub fn use_mailbox_routing(self) -> bool {
false
}
pub fn deque_tier_hint(self) -> Option<crate::sched::deque_tier::DequeTier> {
None
}
}
impl OpClass for DispatchProfile {
fn is_latency_bound(&self) -> bool {
DispatchProfile::is_latency_bound(*self)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn latency_bound_profiles_activate_smt() {
assert!(DispatchProfile::LatencyBound.is_latency_bound());
assert!(DispatchProfile::MemoryBound.is_latency_bound());
assert!(!DispatchProfile::PortBound.is_latency_bound());
assert!(!DispatchProfile::Streaming.is_latency_bound());
assert!(!DispatchProfile::Unspecified.is_latency_bound());
}
#[test]
fn default_cost_estimates_are_set_for_classified_profiles() {
assert_eq!(DispatchProfile::LatencyBound.default_ns_per_elem(), Some(600));
assert_eq!(DispatchProfile::PortBound.default_ns_per_elem(), Some(12));
assert_eq!(DispatchProfile::MemoryBound.default_ns_per_elem(), Some(50));
assert_eq!(DispatchProfile::Streaming.default_ns_per_elem(), Some(50));
assert_eq!(DispatchProfile::Unspecified.default_ns_per_elem(), None);
}
#[test]
fn default_oversubscription_log2_matches_design() {
assert_eq!(DispatchProfile::LatencyBound.default_oversubscription_log2(), 2);
assert_eq!(DispatchProfile::PortBound.default_oversubscription_log2(), 1);
assert_eq!(DispatchProfile::MemoryBound.default_oversubscription_log2(), 1);
assert_eq!(DispatchProfile::Streaming.default_oversubscription_log2(), 1);
assert_eq!(DispatchProfile::Unspecified.default_oversubscription_log2(), 1);
}
#[test]
fn op_class_trait_agrees_with_inherent() {
for profile in [
DispatchProfile::LatencyBound,
DispatchProfile::PortBound,
DispatchProfile::MemoryBound,
DispatchProfile::Streaming,
DispatchProfile::Unspecified,
] {
assert_eq!(
<DispatchProfile as OpClass>::is_latency_bound(&profile),
profile.is_latency_bound(),
"trait must agree with inherent for {profile:?}",
);
}
}
}