Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
fml::CPUSpeedTracker Class Reference

A class that computes the correct CPU indices for a requested CPU affinity. More...

#include <cpu_affinity.h>

Public Member Functions

 CPUSpeedTracker (std::vector< CpuIndexAndSpeed > data)
 
bool IsValid () const
 The class is valid if it has more than one CPU index and a distinct set of efficiency or performance CPUs. More...
 
const std::vector< size_t > & GetIndices (CpuAffinity affinity) const
 Return the set of CPU indices for the requested CPU affinity. More...
 

Detailed Description

A class that computes the correct CPU indices for a requested CPU affinity.

Note
This is visible for testing.

Definition at line 60 of file cpu_affinity.h.

Constructor & Destructor Documentation

◆ CPUSpeedTracker()

fml::CPUSpeedTracker::CPUSpeedTracker ( std::vector< CpuIndexAndSpeed data)
explicit

Definition at line 34 of file cpu_affinity.cc.

35 : cpu_speeds_(std::move(data)) {
36 std::optional<int64_t> max_speed = std::nullopt;
37 std::optional<int64_t> min_speed = std::nullopt;
38 for (const auto& data : cpu_speeds_) {
39 if (!max_speed.has_value() || data.speed > max_speed.value()) {
40 max_speed = data.speed;
41 }
42 if (!min_speed.has_value() || data.speed < min_speed.value()) {
43 min_speed = data.speed;
44 }
45 }
46 if (!max_speed.has_value() || !min_speed.has_value() ||
47 min_speed.value() == max_speed.value()) {
48 return;
49 }
50 const int64_t max_speed_value = max_speed.value();
51 const int64_t min_speed_value = min_speed.value();
52
53 for (const auto& data : cpu_speeds_) {
54 if (data.speed == max_speed_value) {
55 performance_.push_back(data.index);
56 } else {
57 not_performance_.push_back(data.index);
58 }
59 if (data.speed == min_speed_value) {
60 efficiency_.push_back(data.index);
61 }
62 }
63
64 valid_ = true;
65}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

Member Function Documentation

◆ GetIndices()

const std::vector< size_t > & fml::CPUSpeedTracker::GetIndices ( CpuAffinity  affinity) const

Return the set of CPU indices for the requested CPU affinity.

   If the tracker is valid, this will always return a non-empty set. 

Definition at line 71 of file cpu_affinity.cc.

72 {
73 switch (affinity) {
75 return performance_;
77 return efficiency_;
79 return not_performance_;
80 }
81}
@ kPerformance
Request CPU affinity for the performance cores.
@ kEfficiency
Request CPU affinity for the efficiency cores.
@ kNotPerformance
Request affinity for all non-performance cores.

◆ IsValid()

bool fml::CPUSpeedTracker::IsValid ( ) const

The class is valid if it has more than one CPU index and a distinct set of efficiency or performance CPUs.

If all CPUs are the same speed this returns false, and all requests to set affinity are ignored.

Definition at line 67 of file cpu_affinity.cc.

67 {
68 return valid_;
69}

The documentation for this class was generated from the following files: