async fn iterate_thermal_control(&self) -> Result<(), Error> {
        let raw_temperature = self.get_temperature().await?;

        // Record the timestamp for this iteration now that we have all the data we need to proceed
        let timestamp = Nanoseconds(fasync::Time::now().into_nanos());

        // We should have run the iteration at least once before proceeding
        if !self.state.state_initialized.get() {
            self.state.prev_temperature.set(raw_temperature);
            self.state.prev_timestamp.set(timestamp);
            self.state.state_initialized.set(true);
            return Ok(());
        }

        let time_delta = Seconds::from_nanos(timestamp.0 - self.state.prev_timestamp.get().0);
        self.state.prev_timestamp.set(timestamp);

        let filtered_temperature = Celsius(low_pass_filter(
            raw_temperature.0,
            self.state.prev_temperature.get().0,
            time_delta.0,
            self.config.policy_params.controller_params.filter_time_constant.0,
        ));
        self.state.prev_temperature.set(filtered_temperature);

        fx_vlog!(
            1,
            "iteration_period={}s; filtered_temperature={}C; raw_temperature={}C",
            time_delta.0,
            filtered_temperature.0,
            raw_temperature.0
        );

        // If the new temperature is above the critical threshold then shutdown the system
        log_if_error(
            self.check_critical_temperature(filtered_temperature).await,
            "Error checking critical temperature",
        );

        // Update the ThermalLimiter node with the latest thermal load
        log_if_error(
            self.update_thermal_load(filtered_temperature).await,
            "Error updating thermal load",
        );

        // Run the thermal feedback controller
        log_if_error(
            self.iterate_controller(filtered_temperature, time_delta).await,
            "Error running thermal feedback controller",
        );

        Ok(())
    }
/// This is the main body of the closed loop thermal control logic. The function is called
/// periodically by the timer started in `start_periodic_thermal_loop`. For each iteration, the
/// following steps will be taken:
///     1. Read the current temperature from the temperature driver specified in ThermalConfig
///     2. Filter the raw temperature value using a low-pass filter
///     3. Use the new filtered temperature value as input to the PID control algorithm
///     4. The PID algorithm outputs the available power limit to impose in the system
///     5. Distribute the available power to the power actors (initially this is only the CPU)
This is the main body of the closed loop thermal control logic. The function is called
periodically by the timer started in `start_periodic_thermal_loop`. For each iteration, the
following steps will be taken:
1. Read the current temperature from the temperature driver specified in ThermalConfig
2. Filter the raw temperature value using a low-pass filter
3. Use the new filtered temperature value as input to the PID control algorithm
4. The PID algorithm outputs the available power limit to impose in the system
5. Distribute the available power to the power actors (initially this is only the CPU)
This is the main body of the closed loop thermal control logic . The function is called periodically by the timer started in ` start_periodic_thermal_loop ` . For each iteration the following steps will be taken : 1 . Read the current temperature from the temperature driver specified in ThermalConfig 2 . Filter the raw temperature value using a low - pass filter 3 . Use the new filtered temperature value as input to the PID control algorithm 4 . The PID algorithm outputs the available power limit to impose in the system 5 . Distribute the available power to the power actors ( initially this is only the CPU )
async fn iterate_thermal_control(&self) -> Result<(), Error> {
        let raw_temperature = self.get_temperature().await?;
        // Record the timestamp for this iteration now that we have all the data we need to proceed
        let timestamp = Nanoseconds(fasync::Time::now().into_nanos());
        // We should have run the iteration at least once before proceeding
        if !self.state.state_initialized.get() {
            self.state.prev_temperature.set(raw_temperature);
            self.state.prev_timestamp.set(timestamp);
            self.state.state_initialized.set(true);
            return Ok(());
        }
        let time_delta = Seconds::from_nanos(timestamp.0 - self.state.prev_timestamp.get().0);
        self.state.prev_timestamp.set(timestamp);
        let filtered_temperature = Celsius(low_pass_filter(
            raw_temperature.0,
            self.state.prev_temperature.get().0,
            time_delta.0,
            self.config.policy_params.controller_params.filter_time_constant.0,
        ));
        self.state.prev_temperature.set(filtered_temperature);
        fx_vlog!(
            1,
            "iteration_period={}s; filtered_temperature={}C; raw_temperature={}C",
            time_delta.0,
            filtered_temperature.0,
            raw_temperature.0
        );
        // If the new temperature is above the critical threshold then shutdown the system
        log_if_error(
            self.check_critical_temperature(filtered_temperature).await,
            "Error checking critical temperature",
        );
        // Update the ThermalLimiter node with the latest thermal load
        log_if_error(
            self.update_thermal_load(filtered_temperature).await,
            "Error updating thermal load",
        );
        // Run the thermal feedback controller
        log_if_error(
            self.iterate_controller(filtered_temperature, time_delta).await,
            "Error running thermal feedback controller",
        );
        Ok(())
    }
async fn iterate_thermal_control ( & self ) -> Result < ( ) , Error > { let raw_temperature = self . get_temperature ( ) . await ? ; // Record the timestamp for this iteration now that we have all the data we need to proceed let timestamp = Nanoseconds ( fasync :: Time :: now ( ) . into_nanos ( ) ) ; // We should have run the iteration at least once before proceeding if ! self . state . state_initialized . get ( ) { self . state . prev_temperature . set ( raw_temperature ) ; self . state . prev_timestamp . set ( timestamp ) ; self . state . state_initialized . set ( true ) ; return Ok ( ( ) ) ; } let time_delta = Seconds :: from_nanos ( timestamp . 0 - self . state . prev_timestamp . get ( ) . 0 ) ; self . state . prev_timestamp . set ( timestamp ) ; let filtered_temperature = Celsius ( low_pass_filter ( raw_temperature . 0 , self . state . prev_temperature . get ( ) . 0 , time_delta . 0 , self . config . policy_params . controller_params . filter_time_constant . 0 , ) ) ; self . state . prev_temperature . set ( filtered_temperature ) ; fx_vlog ! ( 1 " " time_delta 0 filtered_temperature 0 raw_temperature 0 ) ; // If the new temperature is above the critical threshold then shutdown the system log_if_error ( self . check_critical_temperature ( filtered_temperature ) . await , " " , ) ; // Update the ThermalLimiter node with the latest thermal load log_if_error ( self . update_thermal_load ( filtered_temperature ) . await , " " , ) ; // Run the thermal feedback controller log_if_error ( self . iterate_controller ( filtered_temperature , time_delta ) . await , " " , ) ; Ok ( ( ) ) }
This is the main body of the closed loop thermal control logic.
This is the main body of the closed loop thermal control logic .
&self