Skip to main content

kernel/
stats.rs

1// Copyright 2026 The Fuchsia Authors
2//
3// Use of this source code is governed by a MIT-style
4// license that can be found in the LICENSE file or at
5// https://opensource.org/licenses/MIT
6
7unsafe extern "C" {
8    fn cpp_cpu_stats_inc_reschedules();
9    fn cpp_cpu_stats_inc_context_switches();
10    fn cpp_cpu_stats_inc_preempts();
11    fn cpp_cpu_stats_inc_yields();
12    fn cpp_cpu_stats_inc_interrupts();
13    fn cpp_cpu_stats_inc_timer_ints();
14    fn cpp_cpu_stats_inc_timers();
15    fn cpp_cpu_stats_inc_perf_ints();
16    fn cpp_cpu_stats_inc_syscalls();
17    fn cpp_cpu_stats_inc_page_faults();
18    fn cpp_cpu_stats_inc_reschedule_ipis();
19    fn cpp_cpu_stats_inc_generic_ipis();
20}
21
22/// Increment the reschedule counter for the current CPU.
23#[inline(always)]
24pub fn inc_reschedules() {
25    // SAFETY: cpp_cpu_stats_inc_reschedules increments the per-CPU reschedule counter
26    // for the currently executing CPU and is safe to call from any context.
27    unsafe { cpp_cpu_stats_inc_reschedules() }
28}
29
30/// Increment the context switch counter for the current CPU.
31#[inline(always)]
32pub fn inc_context_switches() {
33    // SAFETY: cpp_cpu_stats_inc_context_switches increments the per-CPU context switch counter
34    // for the currently executing CPU and is safe to call from any context.
35    unsafe { cpp_cpu_stats_inc_context_switches() }
36}
37
38/// Increment the preempt counter for the current CPU.
39#[inline(always)]
40pub fn inc_preempts() {
41    // SAFETY: cpp_cpu_stats_inc_preempts increments the per-CPU preempt counter
42    // for the currently executing CPU and is safe to call from any context.
43    unsafe { cpp_cpu_stats_inc_preempts() }
44}
45
46/// Increment the yield counter for the current CPU.
47#[inline(always)]
48pub fn inc_yields() {
49    // SAFETY: cpp_cpu_stats_inc_yields increments the per-CPU yield counter
50    // for the currently executing CPU and is safe to call from any context.
51    unsafe { cpp_cpu_stats_inc_yields() }
52}
53
54/// Increment the interrupt counter for the current CPU.
55#[inline(always)]
56pub fn inc_interrupts() {
57    // SAFETY: cpp_cpu_stats_inc_interrupts increments the per-CPU interrupt counter
58    // for the currently executing CPU and is safe to call from any context.
59    unsafe { cpp_cpu_stats_inc_interrupts() }
60}
61
62/// Increment the timer interrupt counter for the current CPU.
63#[inline(always)]
64pub fn inc_timer_ints() {
65    // SAFETY: cpp_cpu_stats_inc_timer_ints increments the per-CPU timer interrupt counter
66    // for the currently executing CPU and is safe to call from any context.
67    unsafe { cpp_cpu_stats_inc_timer_ints() }
68}
69
70/// Increment the timer callback counter for the current CPU.
71#[inline(always)]
72pub fn inc_timers() {
73    // SAFETY: cpp_cpu_stats_inc_timers increments the per-CPU timer callback counter
74    // for the currently executing CPU and is safe to call from any context.
75    unsafe { cpp_cpu_stats_inc_timers() }
76}
77
78/// Increment the performance monitor interrupt counter for the current CPU.
79#[inline(always)]
80pub fn inc_perf_ints() {
81    // SAFETY: cpp_cpu_stats_inc_perf_ints increments the per-CPU performance interrupt counter
82    // for the currently executing CPU and is safe to call from any context.
83    unsafe { cpp_cpu_stats_inc_perf_ints() }
84}
85
86/// Increment the syscall counter for the current CPU.
87#[inline(always)]
88pub fn inc_syscalls() {
89    // SAFETY: cpp_cpu_stats_inc_syscalls increments the per-CPU syscall counter
90    // for the currently executing CPU and is safe to call from any context.
91    unsafe { cpp_cpu_stats_inc_syscalls() }
92}
93
94/// Increment the page fault counter for the current CPU.
95#[inline(always)]
96pub fn inc_page_faults() {
97    // SAFETY: cpp_cpu_stats_inc_page_faults increments the per-CPU page fault counter
98    // for the currently executing CPU and is safe to call from any context.
99    unsafe { cpp_cpu_stats_inc_page_faults() }
100}
101
102/// Increment the reschedule IPI counter for the current CPU.
103#[inline(always)]
104pub fn inc_reschedule_ipis() {
105    // SAFETY: cpp_cpu_stats_inc_reschedule_ipis increments the per-CPU reschedule IPI counter
106    // for the currently executing CPU and is safe to call from any context.
107    unsafe { cpp_cpu_stats_inc_reschedule_ipis() }
108}
109
110/// Increment the generic IPI counter for the current CPU.
111#[inline(always)]
112pub fn inc_generic_ipis() {
113    // SAFETY: cpp_cpu_stats_inc_generic_ipis increments the per-CPU generic IPI counter
114    // for the currently executing CPU and is safe to call from any context.
115    unsafe { cpp_cpu_stats_inc_generic_ipis() }
116}