~aleteoryx/muditaos

ref: 395e99e16239630263d5892e2462f1333236ae99 muditaos/module-sys/SystemManager/CpuGovernor.hpp -rw-r--r-- 1.9 KiB
395e99e1 — Marek Niepieklo [CP-583] Update failure due to version.json on the phone 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <memory>
#include <vector>
#include "Service/CpuSentinel.hpp"

namespace sys
{
    using SentinelPointer = std::weak_ptr<CpuSentinel>;

    class GovernorSentinel
    {
      public:
        explicit GovernorSentinel(std::shared_ptr<CpuSentinel> newSentinel);
        [[nodiscard]] auto GetSentinel() const noexcept -> SentinelPointer;
        [[nodiscard]] auto GetRequestedFrequency() const noexcept -> bsp::CpuFrequencyHz;
        void SetRequestedFrequency(bsp::CpuFrequencyHz newFrequency);

      private:
        SentinelPointer sentinelPtr;
        bsp::CpuFrequencyHz requestedFrequency;
    };

    using GovernorSentinelPointer = std::unique_ptr<GovernorSentinel>;
    using GovernorSentinelsVector = std::vector<GovernorSentinelPointer>;

    /// CpuGovernor manages all sentinels in the system and has CPU frequency requests from them (e.g. eInkSentinel).
    /// It is also responsible for informing all sentinels that the CPU frequency has changed.
    class CpuGovernor
    {

      public:
        void RegisterNewSentinel(std::shared_ptr<CpuSentinel> newSentinel);
        [[nodiscard]] auto GetNumberOfRegisteredSentinels() const noexcept -> uint32_t;
        void PrintAllSentinels() const noexcept;

        void SetCpuFrequencyRequest(std::string sentinelName, bsp::CpuFrequencyHz request);
        void ResetCpuFrequencyRequest(std::string sentinelName);

        [[nodiscard]] auto GetMinimumFrequencyRequested() const noexcept -> bsp::CpuFrequencyHz;
        void InformSentinelsAboutCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency) const noexcept;

      private:
        static void PrintName(const GovernorSentinelPointer &element);

        GovernorSentinelsVector sentinels;
    };

} // namespace sys