Skyward boardcore
Loading...
Searching...
No Matches
CpuMeter.h
Go to the documentation of this file.
1/* Copyright (c) 2017 Skyward Experimental Rocketry
2 * Author: Federico Terraneo
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <utils/Stats/Stats.h>
26
27#include "CpuMeterData.h"
28
29namespace Boardcore
30{
31
32namespace CpuMeter
33{
34
35/*
36 * This CPU meter works like this.
37 * It creates a thread with the minimum priority that is (almost) always active
38 * Since the Miosix priority scheduler always runs the thread with the highest
39 * priority, every time other threads (or interrupts) have work to do, they
40 * preempt this thread. By measuring the amount of actual time this thread
41 * takes to perform a busy wait delay it is possible to compute an average CPU
42 * utilization.
43 *
44 * The advantage of this technique is that it can account for the CPU time
45 * of everything, including interrupts and task context switch overhead.
46 * The disadvantage is that by being (almost) always running it prevents the
47 * idle thread from running and thus it prevents the CPU from going into deep
48 * sleep.
49 *
50 * NOTE: For this to work, no other thread with the lowest priority has to be
51 * created, otherwise its time will not be accounted.
52 */
53
55#define ENABLE_CPU_METER
56
60CpuMeterData getCpuStats();
61
65void resetCpuStats();
66
67} // namespace CpuMeter
68
69} // namespace Boardcore
void resetCpuStats()
Resets the cpu utilization statistics.
Definition CpuMeter.cpp:55
CpuMeterData getCpuStats()
Definition CpuMeter.cpp:45
This file includes all the types the logdecoder script will decode.