Flutter Engine
 
Loading...
Searching...
No Matches
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.
 
const std::vector< size_t > & GetIndices (CpuAffinity affinity) const
 Return the set of CPU indices for the requested CPU affinity.
 

Detailed Description

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

Note
This is visible for testing.

Definition at line 64 of file cpu_affinity.h.

Constructor & Destructor Documentation

◆ CPUSpeedTracker()

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

Definition at line 35 of file cpu_affinity.cc.

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

References data.

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 74 of file cpu_affinity.cc.

75 {
76 switch (affinity) {
78 return performance_;
80 return efficiency_;
82 return not_performance_;
84 return not_efficiency_;
85 }
86}
@ kNotEfficiency
Request affinity for all non-efficiency cores.
@ kPerformance
Request CPU affinity for the performance cores.
@ kEfficiency
Request CPU affinity for the efficiency cores.
@ kNotPerformance
Request affinity for all non-performance cores.

References fml::kEfficiency, fml::kNotEfficiency, fml::kNotPerformance, and fml::kPerformance.

Referenced by fml::AndroidEfficiencyCoreCount(), and fml::AndroidRequestAffinity().

◆ 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 70 of file cpu_affinity.cc.

70 {
71 return valid_;
72}

Referenced by fml::SetUpCPUTracker().


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