|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +// |
| 6 | +// If you are cutting-and-pasting this code into another kernel (and that |
| 7 | +// kernel is armv6m), it is hoped that you will cut-and-paste this compile |
| 8 | +// error along with it and take heed of its admonition! |
| 9 | +// |
| 10 | +#[cfg(not(any(armv7m, armv8m)))] |
| 11 | +compile_error!("ringbuf is unsound in the kernel on armv6m"); |
| 12 | + |
| 13 | +use ringbuf::*; |
| 14 | + |
| 15 | +#[derive(Copy, Clone, PartialEq)] |
| 16 | +enum Event { |
| 17 | + SyscallEnter(u32), |
| 18 | + SyscallExit, |
| 19 | + SecondarySyscallEnter, |
| 20 | + SecondarySyscallExit, |
| 21 | + IsrEnter, |
| 22 | + IsrExit, |
| 23 | + TimerIsrEnter, |
| 24 | + TimerIsrExit, |
| 25 | + ContextSwitch(usize), |
| 26 | +} |
| 27 | + |
| 28 | +#[derive(Copy, Clone, PartialEq)] |
| 29 | +enum Trace { |
| 30 | + None, |
| 31 | + Event(Event), |
| 32 | +} |
| 33 | + |
| 34 | +ringbuf!(Trace, 128, Trace::None); |
| 35 | + |
| 36 | +fn trace(event: Event) { |
| 37 | + ringbuf_entry!(Trace::Event(event)); |
| 38 | +} |
| 39 | + |
| 40 | +fn syscall_enter(nr: u32) { |
| 41 | + trace(Event::SyscallEnter(nr)); |
| 42 | +} |
| 43 | + |
| 44 | +fn syscall_exit() { |
| 45 | + trace(Event::SyscallExit); |
| 46 | +} |
| 47 | + |
| 48 | +fn secondary_syscall_enter() { |
| 49 | + trace(Event::SecondarySyscallEnter); |
| 50 | +} |
| 51 | + |
| 52 | +fn secondary_syscall_exit() { |
| 53 | + trace(Event::SecondarySyscallExit); |
| 54 | +} |
| 55 | + |
| 56 | +fn isr_enter() { |
| 57 | + trace(Event::IsrEnter); |
| 58 | +} |
| 59 | + |
| 60 | +fn isr_exit() { |
| 61 | + trace(Event::IsrExit); |
| 62 | +} |
| 63 | + |
| 64 | +fn timer_isr_enter() { |
| 65 | + trace(Event::TimerIsrEnter); |
| 66 | +} |
| 67 | + |
| 68 | +fn timer_isr_exit() { |
| 69 | + trace(Event::TimerIsrExit); |
| 70 | +} |
| 71 | + |
| 72 | +fn context_switch(addr: usize) { |
| 73 | + trace(Event::ContextSwitch(addr)); |
| 74 | +} |
| 75 | + |
| 76 | +static TRACING: kern::profiling::EventsTable = kern::profiling::EventsTable { |
| 77 | + syscall_enter, |
| 78 | + syscall_exit, |
| 79 | + secondary_syscall_enter, |
| 80 | + secondary_syscall_exit, |
| 81 | + isr_enter, |
| 82 | + isr_exit, |
| 83 | + timer_isr_enter, |
| 84 | + timer_isr_exit, |
| 85 | + context_switch, |
| 86 | +}; |
| 87 | + |
| 88 | +pub fn table() -> &'static kern::profiling::EventsTable { |
| 89 | + &TRACING |
| 90 | +} |
0 commit comments