~aleteoryx/muditaos

muditaos/module-os/prof/prof.h -rw-r--r-- 1.5 KiB
a405cad6Aleteoryx trim readme 6 days 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
53
54
55
56
57
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>
#include <stdint.h>

/// just store what's interesting
/// 1. do not store TaskHandle_t, id is better - we normally have up to 32 id's as we do not
///    as we tend to keep up to ~30 threads alive
/// 2. execution time, the better granulation, the better result
struct task_prof_data {
    uint32_t task_TCB_id; /// task TCB id
    uint32_t exec_time;   /// single task switch execution time summed up in TS
    uint32_t switches;    /// count how many times it was switched out
};

/// initialization structure
struct prof_pool_init_data
{
    size_t size;                /// size of the pool, use should have linear eficiency
};

#if PROF_ON

/// initialization of pool to store switch data
void prof_pool_init(struct prof_pool_init_data init);
void prof_pool_deinit();
struct prof_pool_init_data prof_pool_get_data();

/// get next available slot from the pool
/// struct task_prof_data* prof_pool_get_next();
/// set the element
void prof_pool_data_set(uint8_t ts, uint32_t id);

/// mark if overflow happened
unsigned int prof_pool_overflow();

/// to `mem` flush up to `cap` data - then clean
/// if passed:
/// - set used count: how much data was used
/// - returns overflow count
/// requires sched lock before running
unsigned int prof_pool_flush(struct task_prof_data *mem, size_t cap);

#else
#define prof_pool_data_set(...)
#endif

#ifdef __cplusplus
}
#endif