1 /*
2  * Copyright 2014, General Dynamics C4 Systems
3  *
4  * SPDX-License-Identifier: GPL-2.0-only
5  */
6 
7 /*
8  * Profiler Interface
9  *
10  * 2006 - 2007  David Greenaway
11  * 2007 Ported to seL4 C kernel by Philip Derrin
12  */
13 
14 #pragma once
15 
16 #include <machine/registerset.h>
17 #include <machine/hardware.h>
18 
19 #ifdef PROFILER
20 
21 /* Approximate number of unique addresses that we can record.
22  *
23  * This value corresponds to the size of a hash table, and needs
24  * to be a prime number to ensure correctness.
25  */
26 //#define MAX_UNIQUE_INSTRUCTIONS ((256 * 1024) + 3)  /* 262147 is prime */
27 /* Downsized to fit in the default 1M kernel section - davec */
28 #define MAX_UNIQUE_INSTRUCTIONS 94349
29 
30 #define MAX_UNIQUE_CHECKPOINTS 2000
31 
32 /* Record the given program counter */
33 void profiler_record_sample(word_t pc) VISIBLE;
34 
35 /* Reset all counters */
36 void profiler_reset(void);
37 
38 /* List the recorded values to stdout */
39 void profiler_list(void);
40 
41 /* Should we be profiling the system? */
42 extern bool_t profiler_enabled;
43 
44 /* Set the current status of the profiler */
profiler_set_enabled(bool_t enabled)45 static inline void profiler_set_enabled(bool_t enabled)
46 {
47     profiler_enabled = enabled;
48 }
49 
50 /* Get the current status of the profiler */
profiler_is_enabled(void)51 static inline bool_t profiler_is_enabled(void)
52 {
53     return profiler_enabled;
54 }
55 
56 /* Number of entries the profiler currently keeps track of */
57 extern int profiler_num_entries;
58 
59 /* Number of instructions the profiler could not record */
60 extern long long profiler_dropped_instructions;
61 
62 /* The instructions recorded by the profiler */
63 typedef struct {
64     word_t pc;
65     word_t count;
66 } profiler_entry_t;
67 
68 #ifdef CHECKPOINT_PROFILER
69 extern volatile unsigned int checkpoint;
70 extern profiler_entry_t profiler_entries[MAX_UNIQUE_CHECKPOINTS];
71 #else
72 extern profiler_entry_t profiler_entries[MAX_UNIQUE_INSTRUCTIONS];
73 #endif
74 
75 #endif /* PROFILER */
76 
77 
78