/// Determines the current thermal load. If there is a change from the cached thermal_load,
/// then the new value is sent out to the ThermalLimiter node.
Determines the current thermal load. If there is a change from the cached thermal_load,
then the new value is sent out to the ThermalLimiter node.
Determines the current thermal load . If there is a change from the cached thermal_load then the new value is sent out to the ThermalLimiter node .
async fn update_thermal_load(
        &self,
        timestamp: Nanoseconds,
        temperature: Celsius,
    ) -> Result<(), Error> {
        fuchsia_trace::duration!(
            "power_manager",
            "ThermalPolicy::update_thermal_load",
            "temperature" => temperature.0
        );
        let mut return_val = Ok(());
        let thermal_load = Self::calculate_thermal_load(
            temperature,
            &self.config.policy_params.thermal_limiting_range,
        );
        fuchsia_trace::counter!(
            "power_manager",
            "ThermalPolicy thermal_load",
            0,
            "thermal_load" => thermal_load.0
        );
        if thermal_load != self.state.thermal_load.get() {
            fuchsia_trace::instant!(
                "power_manager",
                "ThermalPolicy::thermal_load_changed",
                fuchsia_trace::Scope::Thread,
                "old_load" => self.state.thermal_load.get().0,
                "new_load" => thermal_load.0
            );
            if self.state.thermal_load.get().0 == 0 {
                // We've just entered thermal limiting
                fx_log_info!("Begin thermal mitigation");
                self.thermal_metrics.borrow_mut().log_throttle_start(timestamp);
                self.inspect.throttle_history().mark_throttling_active(timestamp);
                self.state.throttle_end_deadline.set(None);
            } else if thermal_load.0 == 0 {
                // We've just exited thermal limiting. Set the deadline time that we may consider
                // the throttle event officially complete.
                fx_log_info!("End thermal mitigation");
                let throttle_end_deadline = timestamp
                    + Nanoseconds(self.config.policy_params.throttle_end_delay.into_nanos());
                self.state.throttle_end_deadline.set(Some(throttle_end_deadline));
            }
            self.state.thermal_load.set(thermal_load);
            // Record any errors here, but don't return early from the function in case we have a
            // pending throttle_end_deadline to deal with
            return_val = match self
                .send_message(
                    &self.config.thermal_limiter_node,
                    &Message::UpdateThermalLoad(thermal_load),
                )
                .await
            {
                Ok(_) => Ok(()),
                Err(e) => Err(Error::from(e)),
            };
        }
        // If a throttle end deadline time was set and the deadline has been passed, then declare
        // the throttle event complete and clear the deadline
        if self.state.throttle_end_deadline.get().is_some()
            && timestamp >= self.state.throttle_end_deadline.get().unwrap()
        {
            self.state.throttle_end_deadline.set(None);
            self.thermal_metrics.borrow_mut().log_throttle_end_mitigated(timestamp);
            self.inspect.throttle_history().mark_throttling_inactive(timestamp);
        }
        self.inspect.throttle_history().record_thermal_load(thermal_load);
        return_val
    }
async fn update_thermal_load ( & self , timestamp : Nanoseconds , temperature : Celsius , ) -> Result < ( ) , Error > { fuchsia_trace :: duration ! ( " " " " " " temperature 0 ) ; let mut return_val = Ok ( ( ) ) ; let thermal_load = Self :: calculate_thermal_load ( temperature , & self . config . policy_params . thermal_limiting_range , ) ; fuchsia_trace :: counter ! ( " " " " 0 " " thermal_load 0 ) ; if thermal_load != self . state . thermal_load . get ( ) { fuchsia_trace :: instant ! ( " " " " fuchsia_trace Scope Thread " " self state thermal_load get ( ) 0 " " thermal_load 0 ) ; if self . state . thermal_load . get ( ) . 0 == 0 { // We've just entered thermal limiting fx_log_info ! ( " " ) ; self . thermal_metrics . borrow_mut ( ) . log_throttle_start ( timestamp ) ; self . inspect . throttle_history ( ) . mark_throttling_active ( timestamp ) ; self . state . throttle_end_deadline . set ( None ) ; } else if thermal_load . 0 == 0 { // We've just exited thermal limiting. Set the deadline time that we may consider // the throttle event officially complete. fx_log_info ! ( " " ) ; let throttle_end_deadline = timestamp + Nanoseconds ( self . config . policy_params . throttle_end_delay . into_nanos ( ) ) ; self . state . throttle_end_deadline . set ( Some ( throttle_end_deadline ) ) ; } self . state . thermal_load . set ( thermal_load ) ; // Record any errors here, but don't return early from the function in case we have a // pending throttle_end_deadline to deal with return_val = match self . send_message ( & self . config . thermal_limiter_node , & Message :: UpdateThermalLoad ( thermal_load ) , ) . await { Ok ( _ ) => Ok ( ( ) ) , Err ( e ) => Err ( Error :: from ( e ) ) , } ; } // If a throttle end deadline time was set and the deadline has been passed, then declare // the throttle event complete and clear the deadline if self . state . throttle_end_deadline . get ( ) . is_some ( ) && timestamp >= self . state . throttle_end_deadline . get ( ) . unwrap ( ) { self . state . throttle_end_deadline . set ( None ) ; self . thermal_metrics . borrow_mut ( ) . log_throttle_end_mitigated ( timestamp ) ; self . inspect . throttle_history ( ) . mark_throttling_inactive ( timestamp ) ; } self . inspect . throttle_history ( ) . record_thermal_load ( thermal_load ) ; return_val }
Determines the current thermal load.
Determines the current thermal load .
&self
timestamp
Nanoseconds
temperature
Celsius