Skip to content

Commit

Permalink
Add PmPowerPolicy to simplify implementation of power policies
Browse files Browse the repository at this point in the history
In the future, this may also be useful if any classes outside of power policies need to access the PowerManager instance.
  • Loading branch information
MatejKafka committed Sep 9, 2021
1 parent c47f6b8 commit 3ed200f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/power_policy/_power_policy.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

#include <memory>
#include <power_manager.hpp>
#include <process.hpp>

// forward declaration to avoid circular dependency between PowerPolicy and Window
class Window;

/**
Expand Down Expand Up @@ -39,3 +41,13 @@ class PowerPolicy
*/
static std::unique_ptr<PowerPolicy> setup_power_policy(const std::string &policy_str);
};

/**
* Subclass of PowerPolicy, which is extended by power policy implementations
* which use PowerManager. In the rest of the codebase, you should accept
* the more general PowerPolicy interface instead of this one.
*/
class PmPowerPolicy : public PowerPolicy {
protected:
PowerManager pm{};
};
5 changes: 1 addition & 4 deletions src/power_policy/high.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#include "_power_policy.hpp"
#include "power_manager.hpp"

class PowerPolicy_FixedHigh : public PowerPolicy
class PowerPolicy_FixedHigh : public PmPowerPolicy
{
private:
PowerManager pm{};

public:
PowerPolicy_FixedHigh()
{
Expand Down
3 changes: 1 addition & 2 deletions src/power_policy/imx8_alternating.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
*
* NOTE: this is a test power policy, the error messages are not very helpful
*/
class PowerPolicy_Imx8_Alternating : public PowerPolicy
class PowerPolicy_Imx8_Alternating : public PmPowerPolicy
{
private:
PowerManager pm{};
CpufreqPolicy &a53_pol = pm.get_policy("policy0");
CpufreqPolicy &a72_pol = pm.get_policy("policy4");
CpuFrequencyHz f1_a53 = 0;
Expand Down
5 changes: 1 addition & 4 deletions src/power_policy/imx8_fixed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
*
* NOTE: this is a test power policy, the error messages are not very helpful
*/
class PowerPolicy_Imx8_Fixed : public PowerPolicy
class PowerPolicy_Imx8_Fixed : public PmPowerPolicy
{
private:
PowerManager pm{};

public:
/** *_freq_i - integer, range <0,3> */
PowerPolicy_Imx8_Fixed(const std::string& a53_freq_i, const std::string& a72_freq_i)
Expand Down
3 changes: 1 addition & 2 deletions src/power_policy/imx8_per_process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
*
* NOTE: this is a test power policy, the error messages are not very helpful
*/
class PowerPolicy_Imx8_PerProcess : public PowerPolicy
class PowerPolicy_Imx8_PerProcess : public PmPowerPolicy
{
private:
PowerManager pm{};
CpufreqPolicy &a53_pol;
CpufreqPolicy &a72_pol;
const cpu_set a53_cpus{0b001111};
Expand Down
5 changes: 1 addition & 4 deletions src/power_policy/low.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#include "_power_policy.hpp"
#include "power_manager.hpp"

class PowerPolicy_FixedLow : public PowerPolicy
class PowerPolicy_FixedLow : public PmPowerPolicy
{
private:
PowerManager pm{};

public:
PowerPolicy_FixedLow()
{
Expand Down
5 changes: 1 addition & 4 deletions src/power_policy/minbe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
#include "_power_policy.hpp"
#include "power_manager.hpp"

class PowerPolicy_MinBE : public PowerPolicy
class PowerPolicy_MinBE : public PmPowerPolicy
{
private:
PowerManager pm{};

public:
PowerPolicy_MinBE()
{
Expand Down

0 comments on commit 3ed200f

Please sign in to comment.