PatchworkOS  dbbdc99
A non-POSIX operating system.
Loading...
Searching...
No Matches
perf.h
Go to the documentation of this file.
1#pragma once
2
4#include <kernel/sync/lock.h>
5
6#include <time.h>
7
8typedef struct cpu cpu_t;
9typedef struct thread thread_t;
10
11/**
12 * @brief Performance driver.
13 * @defgroup kernel_drivers_performance Performance Driver
14 * @ingroup kernel_drivers
15 *
16 * The Performance driver is exposed in the `/dev/perf` directory. Below is an overview of the files in this
17 * directory.
18 *
19 * ## Cpu performance
20 *
21 * The `/dev/perf/cpu` file contains per-CPU performance data in the following format:
22 * ```
23 * cpu idle_clocks active_clocks interrupt_clocks
24 * %lu %lu %lu %lu
25 * %lu %lu %lu %lu
26 * ...
27 * %lu %lu %lu %lu
28 * ```
29 *
30 * ## Memory performance
31 *
32 * The `/dev/perf/mem` file contains memory performance data in the following format:
33 * ```
34 * total_pages %lu
35 * free_pages %lu
36 * used_pages %lu
37 * ```
38 *
39 * @see @ref kernel_proc "Process" for per-process performance data.
40 *
41 * @{
42 */
43
44/**
45 * @brief Per-Process performance context.
46 * @struct stat_process_ctx_t
47 */
48typedef struct
49{
50 _Atomic(clock_t) userClocks; ///< Total user mode CPU time used by this process.
52 kernelClocks; ///< Total kernel mode CPU time used by this process, does not include interrupt time.
53 clock_t startTime; ///< The time when the process was started.
55
56/**
57 * @brief Per-Thread performance context.
58 * @struct perf_thread_ctx_t
59 *
60 * The thread context tracks tracks the time it spends in and outside of system calls, this is then accumulated into the
61 * process performance context.
62 */
63typedef struct
64{
65 clock_t syscallBegin; ///< The time the current syscall began. Also used to "skip" time spent in interrupts.
68
69/**
70 * @brief Initializes a per-process performance context.
71 *
72 * @param ctx The context to initialize.
73 */
75
76/**
77 * @brief Initializes a per-thread performance context.
78 *
79 * @param ctx The context to initialize.
80 */
82
83/**
84 * @brief Initializes the performance driver.
85 */
86void perf_init(void);
87
88/**
89 * @brief Called at the beginning of an interrupt to update cpu performance data.
90 *
91 * Must be called with interrupts disabled.
92 */
93void perf_interrupt_begin(void);
94
95/**
96 * @brief Called at the end of an interrupt to update cpu performance data.
97 *
98 * Must be called with interrupts disabled.
99 */
100void perf_interrupt_end(void);
101
102/**
103 * @brief Called at the beginning of a syscall to update process performance data.
104 */
105void perf_syscall_begin(void);
106
107/**
108 * @brief Called at the end of a syscall to update process performance data.
109 */
110void perf_syscall_end(void);
111
112/** @} */
void perf_interrupt_end(void)
Called at the end of an interrupt to update cpu performance data.
Definition perf.c:206
void perf_interrupt_begin(void)
Called at the beginning of an interrupt to update cpu performance data.
Definition perf.c:170
void perf_syscall_end(void)
Called at the end of a syscall to update process performance data.
Definition perf.c:248
void perf_syscall_begin(void)
Called at the beginning of a syscall to update process performance data.
Definition perf.c:226
void perf_process_ctx_init(perf_process_ctx_t *ctx)
Initializes a per-process performance context.
Definition perf.c:137
void perf_thread_ctx_init(perf_thread_ctx_t *ctx)
Initializes a per-thread performance context.
Definition perf.c:144
void perf_init(void)
Initializes the performance driver.
Definition perf.c:150
__UINT64_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
CPU structure.
Definition cpu.h:84
_Atomic(clock_t) kernelClocks
Total kernel mode CPU time used by this process, does not include interrupt time.
clock_t startTime
The time when the process was started.
Definition perf.h:53
_Atomic(clock_t) userClocks
Total user mode CPU time used by this process.
Per-Thread performance context.
Definition perf.h:64
clock_t syscallBegin
The time the current syscall began. Also used to "skip" time spent in interrupts.
Definition perf.h:65
clock_t syscallEnd
Definition perf.h:66
Thread of execution structure.
Definition thread.h:61