GCC Code Coverage Report


Directory: ./
File: Os/Cpu.hpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 2 2 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // ======================================================================
2 // \title Os/Cpu.hpp
3 // \brief common function definitions for Os::Cpu
4 // ======================================================================
5 #include "Os/Os.hpp"
6
7 #ifndef OS_CPU_HPP_
8 #define OS_CPU_HPP_
9
10 namespace Os {
11
12 //! \brief Cpu variable handle parent
13 class CpuHandle {};
14
15 //! \brief interface for cpu implementation
16 class CpuInterface {
17 public:
18 using Status = Os::Generic::Status;
19 using Ticks = Os::Generic::UsedTotal;
20
21 //! Default constructor
22 22 CpuInterface() = default;
23 //! Default destructor
24 44 virtual ~CpuInterface() = default;
25
26 //! \brief copy constructor is forbidden
27 CpuInterface(const CpuInterface& other) = delete;
28
29 //! \brief assignment operator is forbidden
30 virtual CpuInterface& operator=(const CpuInterface& other) = delete; // NO_CODESONAR (cpp:S3657)
31
32 //! \brief Request the count of the CPUs detected by the system
33 //!
34 //! \param cpu_count: (output) filled with CPU count on system
35 //! \return: OP_OK with valid CPU count, ERROR when error occurs
36 //!
37 virtual Status _getCount(FwSizeType& cpu_count) = 0;
38
39 //! \brief Get the CPU tick information for a given CPU
40 //!
41 //! CPU ticks represent a small time slice of processor time. This will retrieve the used CPU ticks and total
42 //! ticks for a given CPU. This information in a running accumulation and thus a sample-to-sample
43 //! differencing is needed to see the 'realtime' changing load. This shall be done by the caller.
44 //!
45 //! \param ticks: (output) filled with the tick information for the given CPU
46 //! \param cpu_index: index for CPU to read. Default: 0
47 //! \return: ERROR when error occurs, OK otherwise.
48 //!
49 virtual Status _getTicks(Ticks& ticks, FwSizeType cpu_index) = 0;
50
51 //! \brief return the underlying cpu handle (implementation specific).
52 //! \return internal task handle representation
53 virtual CpuHandle* getHandle() = 0;
54
55 //! \brief provide a pointer to a Mutex delegate object
56 static CpuInterface* getDelegate(CpuHandleStorage& aligned_new_memory);
57 };
58
59 //! \brief cpu implementation
60 class Cpu final : public CpuInterface {
61 public:
62 //! \brief default constructor
63 Cpu();
64
65 //! \brief default virtual destructor
66 ~Cpu() final;
67
68 //! \brief copy constructor is forbidden
69 Cpu(const CpuInterface& other) = delete;
70
71 //! \brief copy constructor is forbidden
72 Cpu(const CpuInterface* other) = delete;
73
74 //! \brief assignment operator is forbidden
75 CpuInterface& operator=(const CpuInterface& other) override = delete;
76
77 //-----------------------------------------------------------------------------
78 // Interface methods
79 //-----------------------------------------------------------------------------
80
81 //! \brief initialize the singleton
82 static void init();
83
84 //! \brief return singleton
85 static Cpu& getSingleton();
86
87 //-----------------------------------------------------------------------------
88 // Delegating methods
89 //-----------------------------------------------------------------------------
90
91 //! \brief Request the count of the CPUs detected by the system
92 //!
93 //! This method wraps delegates to the underlying implementation.
94 //!
95 //! \param cpu_count: (output) filled with CPU count on system
96 //! \return: OP_OK with valid CPU count, ERROR when error occurs
97 //!
98 Status _getCount(FwSizeType& cpu_count) override;
99
100 //! \brief Get the CPU tick information for a given CPU
101 //!
102 //! CPU ticks represent a small time slice of processor time. This will retrieve the used CPU ticks and total
103 //! ticks for a given CPU. This information in a running accumulation and thus a sample-to-sample
104 //! differencing is needed to see the 'realtime' changing load. This shall be done by the caller. This method wraps
105 //! delegates to the underlying implementation.
106 //!
107 //! \param ticks: (output) filled with the tick information for the given CPU
108 //! \param cpu_index: index for CPU to read. Default: 0
109 //! \return: ERROR when error occurs, OK otherwise.
110 //!
111 Status _getTicks(Ticks& ticks, FwSizeType cpu_index) override;
112
113 //! \brief return the underlying cpu handle (implementation specific).
114 //! \return internal task handle representation
115 CpuHandle* getHandle() override;
116
117 //-----------------------------------------------------------------------------
118 // Static interface (singleton) methods
119 //-----------------------------------------------------------------------------
120
121 //! \brief Request the count of the CPUs detected by the system
122 //!
123 //! This method wraps a singleton implementation.
124 //!
125 //! \param cpu_count: (output) filled with CPU count on system
126 //! \return: OP_OK with valid CPU count, ERROR when error occurs
127 //!
128 static Status getCount(FwSizeType& cpu_count);
129
130 //! \brief Get the CPU tick information for a given CPU
131 //!
132 //! CPU ticks represent a small time slice of processor time. This will retrieve the used CPU ticks and total
133 //! ticks for a given CPU. This information in a running accumulation and thus a sample-to-sample
134 //! differencing is needed to see the 'realtime' changing load. This shall be done by the caller. This method wraps
135 //! a singleton implementation.
136 //!
137 //! \param ticks: (output) filled with the tick information for the given CPU
138 //! \param cpu_index: index for CPU to read. Default: 0
139 //! \return: ERROR when error occurs, OK otherwise.
140 //!
141 static Status getTicks(Ticks& ticks, FwSizeType cpu_index);
142
143 private:
144 // This section is used to store the implementation-defined file handle. To Os::File and fprime, this type is
145 // opaque and thus normal allocation cannot be done. Instead, we allow the implementor to store then handle in
146 // the byte-array here and set `handle` to that address for storage.
147 alignas(FW_HANDLE_ALIGNMENT) CpuHandleStorage m_handle_storage; //!< Storage for aligned data
148 CpuInterface& m_delegate; //!< Delegate for the real implementation
149 };
150 } // namespace Os
151 #endif // OS_CONDITION_HPP_
152