1 /*
2  * Copyright (c) 2012-2014 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include <lk/compiler.h>
11 
12 __BEGIN_CDECLS
13 
14 #include <lk/debug.h>
15 
16 /* kernel event log */
17 #if WITH_KERNEL_EVLOG
18 
19 #include <lib/evlog.h>
20 
21 #ifndef KERNEL_EVLOG_LEN
22 #define KERNEL_EVLOG_LEN 1024
23 #endif
24 
25 void kernel_evlog_init(void);
26 
27 void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1);
28 void kernel_evlog_dump(void);
29 
30 #else // !WITH_KERNEL_EVLOG
31 
32 /* do nothing versions */
33 static inline void kernel_evlog_init(void) {}
34 static inline void kernel_evlog_add(uintptr_t id, uintptr_t arg0, uintptr_t arg1) {}
35 static inline void kernel_evlog_dump(void) {}
36 
37 #endif
38 
39 enum {
40     KERNEL_EVLOG_NULL = 0,
41     KERNEL_EVLOG_CONTEXT_SWITCH,
42     KERNEL_EVLOG_PREEMPT,
43     KERNEL_EVLOG_TIMER_TICK,
44     KERNEL_EVLOG_TIMER_CALL,
45     KERNEL_EVLOG_IRQ_ENTER,
46     KERNEL_EVLOG_IRQ_EXIT,
47 };
48 
49 #define KEVLOG_THREAD_SWITCH(from, to) kernel_evlog_add(KERNEL_EVLOG_CONTEXT_SWITCH, (uintptr_t)from, (uintptr_t)to)
50 #define KEVLOG_THREAD_PREEMPT(thread) kernel_evlog_add(KERNEL_EVLOG_PREEMPT, (uintptr_t)thread, 0)
51 #define KEVLOG_TIMER_TICK() kernel_evlog_add(KERNEL_EVLOG_TIMER_TICK, 0, 0)
52 #define KEVLOG_TIMER_CALL(ptr, arg) kernel_evlog_add(KERNEL_EVLOG_TIMER_CALL, (uintptr_t)ptr, (uintptr_t)arg)
53 #define KEVLOG_IRQ_ENTER(irqn) kernel_evlog_add(KERNEL_EVLOG_IRQ_ENTER, (uintptr_t)irqn, 0)
54 #define KEVLOG_IRQ_EXIT(irqn) kernel_evlog_add(KERNEL_EVLOG_IRQ_EXIT, (uintptr_t)irqn, 0)
55 
56 __END_CDECLS
57