// K2276-K2280: compositor.limits — UI CPU ve yüzey sınırları // Invariant: Sonsuz redraw diğer uygulamayı aç bırakmaz // Positive: Üç farklı redraw hızı // Counterexample: Bir client frame fırtınası // Acceptance: Throttle drop ve ilerleme raporu pub const COMPOSITOR_LIMITS_SCHEMA: &str = "turkos.os.compositor.limits.v1"; pub const COMPOSITOR_LIMITS_INVARIANT: &str = "Sonsuz redraw diğer uygulamayı aç bırakmaz"; pub const COMPOSITOR_LIMITS_POSITIVE: &str = "Üç farklı redraw hızı"; pub const COMPOSITOR_LIMITS_COUNTEREXAMPLE: &str = "Bir client frame fırtınası"; pub const COMPOSITOR_LIMITS_ACCEPTANCE: &str = "Throttle drop ve ilerleme raporu"; pub const EXPECTED_REDRAW_RATE_CLIENTS: u32 = 3; pub const EXPECTED_THROTTLED_DROPPED_FRAMES: u32 = 12; pub const EXPECTED_HEALTHY_CLIENT_PROGRESS: u32 = 60; pub const EXPECTED_STARVED_CLIENTS: u32 = 0; #[repr(u8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum CompositorLimitsError { UnthrottledClientFrameStorm = 1, InfiniteRedrawStarvedPeerApp = 2, MissingThrottleProgressReport = 3, RedrawRateClientCountMismatch = 4, ThrottledDroppedFramesMismatch = 5, HealthyClientProgressMismatch = 6, ZeroLimitsEpoch = 7, NonMonotonicLimitsEpoch = 8, ZeroLimitsBudgetDigest = 9, UnboundCompositorLimitsDigest = 10, AlreadyCommitted = 11, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct CompositorLimitsRequest { pub unthrottled_client_frame_storm: bool, pub starved_clients: u32, pub throttle_progress_reported: bool, pub redraw_rate_clients: u32, pub throttled_dropped_frames: u32, pub healthy_client_progress: u32, pub limits_epoch: u64, pub previous_limits_epoch: u64, pub limits_budget_digest: u64, pub limits_binding_digest: u64, } #[repr(C)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct CompositorLimitsReceipt { pub redraw_rate_clients: u32, pub throttled_dropped_frames: u32, pub healthy_client_progress: u32, pub starved_clients: u32, pub throttle_progress_reported: bool, pub limits_epoch: u64, pub limits_budget_digest: u64, pub receipt_digest: u64, } pub const fn compute_compositor_limits_binding_digest( redraw_rate_clients: u32, throttled_dropped_frames: u32, healthy_client_progress: u32, starved_clients: u32, limits_epoch: u64, limits_budget_digest: u64, ) -> u64 { let mut h: u64 = 0xcbf2_9ce4_8422_2325; h = (h ^ 0x2280_434f_4d50_4c4d).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (redraw_rate_clients as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (throttled_dropped_frames as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (healthy_client_progress as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ (starved_clients as u64)).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ limits_epoch).wrapping_mul(0x0000_0100_0000_01b3); h = (h ^ limits_budget_digest).wrapping_mul(0x0000_0100_0000_01b3); h } pub struct CompositorLimitsCoordinator { committed: bool, committed_total: u64, rejected_total: u64, storm_starvation_refusals: u64, rate_budget_refusals: u64, committed_receipt: Option, } impl CompositorLimitsCoordinator { pub const fn new() -> Self { Self { committed: false, committed_total: 0, rejected_total: 0, storm_starvation_refusals: 0, rate_budget_refusals: 0, committed_receipt: None, } } pub fn is_committed(&self) -> bool { self.committed } pub fn committed_total(&self) -> u64 { self.committed_total } pub fn rejected_total(&self) -> u64 { self.rejected_total } pub fn storm_starvation_refusals(&self) -> u64 { self.storm_starvation_refusals } pub fn rate_budget_refusals(&self) -> u64 { self.rate_budget_refusals } pub fn committed_receipt(&self) -> Option { self.committed_receipt } pub fn commit_redraw_limits( &mut self, req: &CompositorLimitsRequest, ) -> Result { if self.committed { self.rejected_total += 1; return Err(CompositorLimitsError::AlreadyCommitted); } if req.unthrottled_client_frame_storm { self.rejected_total += 1; self.storm_starvation_refusals += 1; return Err(CompositorLimitsError::UnthrottledClientFrameStorm); } if req.starved_clients != EXPECTED_STARVED_CLIENTS { self.rejected_total += 1; self.storm_starvation_refusals += 1; return Err(CompositorLimitsError::InfiniteRedrawStarvedPeerApp); } if !req.throttle_progress_reported { self.rejected_total += 1; self.storm_starvation_refusals += 1; return Err(CompositorLimitsError::MissingThrottleProgressReport); } if req.redraw_rate_clients != EXPECTED_REDRAW_RATE_CLIENTS { self.rejected_total += 1; self.rate_budget_refusals += 1; return Err(CompositorLimitsError::RedrawRateClientCountMismatch); } if req.throttled_dropped_frames != EXPECTED_THROTTLED_DROPPED_FRAMES { self.rejected_total += 1; self.rate_budget_refusals += 1; return Err(CompositorLimitsError::ThrottledDroppedFramesMismatch); } if req.healthy_client_progress != EXPECTED_HEALTHY_CLIENT_PROGRESS { self.rejected_total += 1; self.rate_budget_refusals += 1; return Err(CompositorLimitsError::HealthyClientProgressMismatch); } if req.limits_epoch == 0 { self.rejected_total += 1; return Err(CompositorLimitsError::ZeroLimitsEpoch); } if req.limits_epoch <= req.previous_limits_epoch { self.rejected_total += 1; return Err(CompositorLimitsError::NonMonotonicLimitsEpoch); } if req.limits_budget_digest == 0 { self.rejected_total += 1; return Err(CompositorLimitsError::ZeroLimitsBudgetDigest); } let expected_binding = compute_compositor_limits_binding_digest( req.redraw_rate_clients, req.throttled_dropped_frames, req.healthy_client_progress, req.starved_clients, req.limits_epoch, req.limits_budget_digest, ); if req.limits_binding_digest != expected_binding { self.rejected_total += 1; self.rate_budget_refusals += 1; return Err(CompositorLimitsError::UnboundCompositorLimitsDigest); } self.committed = true; self.committed_total += 1; let receipt = CompositorLimitsReceipt { redraw_rate_clients: req.redraw_rate_clients, throttled_dropped_frames: req.throttled_dropped_frames, healthy_client_progress: req.healthy_client_progress, starved_clients: req.starved_clients, throttle_progress_reported: true, limits_epoch: req.limits_epoch, limits_budget_digest: req.limits_budget_digest, receipt_digest: expected_binding ^ 0x2280_ACE0_4c49_4d54, }; self.committed_receipt = Some(receipt); Ok(receipt) } }