• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018 Google, Inc.
3  *
4  * SPDX-License-Identifier: GPL-2.0-or-later
5  */
6 
7 #ifndef _LTP_TRACE_PARSE_H_
8 #define _LTP_TRACE_PARSE_H_
9 
10 /*
11  * It is necessary to define TRACE_EVENTS to communicate the events to trace. */
12 #define TRACING_DIR "/sys/kernel/debug/tracing/"
13 
14 enum {
15 	TRACE_RECORD_OTHER = 0,
16 	TRACE_RECORD_SCHED_PROCESS_EXIT,
17 	TRACE_RECORD_SCHED_PROCESS_FORK,
18 	TRACE_RECORD_SCHED_SWITCH,
19 	TRACE_RECORD_SCHED_WAKEUP,
20 	TRACE_RECORD_SUGOV_UTIL_UPDATE,
21 	TRACE_RECORD_SUGOV_NEXT_FREQ,
22 	TRACE_RECORD_CPU_FREQUENCY,
23 	TRACE_RECORD_TRACING_MARK_WRITE,
24 };
25 
26 #define IRQ_CONTEXT_NORMAL '.'
27 #define IRQ_CONTEXT_SOFT 's'
28 #define IRQ_CONTEXT_HARD 'h'
29 #define IRQ_CONTEXT_HARD_IN_SOFT 'H'
30 #define IRQ_CONTEXT_NMI 'z'
31 #define IRQ_CONTEXT_NMI_IN_HARD 'Z'
32 
33 struct timestamp {
34 	unsigned int sec;
35 	unsigned int usec;
36 };
37 
38 struct trace_cpu_frequency {
39 	unsigned int state;
40 	unsigned short cpu;
41 };
42 
43 struct trace_sched_switch {
44 	char prev_comm[17];
45 	unsigned short prev_pid;
46 	unsigned short prev_prio;
47 	char prev_state;
48 	char next_comm[17];
49 	unsigned short next_pid;
50 	unsigned short next_prio;
51 };
52 
53 struct trace_sched_wakeup {
54 	char comm[17];
55 	unsigned short pid;
56 	unsigned short prio;
57 	unsigned short cpu;
58 };
59 
60 struct trace_sugov_util_update {
61 	int cpu;
62 	int util;
63 	int avg_cap;
64 	int max_cap;
65 };
66 
67 struct trace_sugov_next_freq {
68 	int cpu;
69 	int util;
70 	int max;
71 	int freq;
72 };
73 
74 struct trace_record {
75 	char task[17];
76 	unsigned short pid;
77 	unsigned short cpu;
78 
79 #define TRACE_RECORD_IRQS_OFF 0x1
80 #define TRACE_RECORD_TIF_NEED_RESCHED 0x2
81 #define TRACE_RECORD_PREEMPT_NEED_RESCHED 0x4
82 	unsigned short flags;
83 	unsigned char irq_context;
84 	unsigned short preempt_depth;
85 
86 	struct timestamp ts;
87 
88 	unsigned int event_type;
89 	void *event_data;
90 };
91 
92 extern int num_trace_records;
93 extern struct trace_record *trace;
94 
95 void trace_cleanup(void);
96 void print_trace_record(struct trace_record *tr);
97 struct trace_record *load_trace(void);
98 
99 #define LOAD_TRACE() \
100 	if (!load_trace()) \
101 		tst_brk(TBROK, "Failed to load trace.\n");
102 
103 #endif /* _LTP_TRACE_PARSE_H_ */
104