Debian Codegraph @

runtime/linux/common_session_state.h

raw
1 // Will be included once by runtime/common_session_state.h, which is included
2 // once by translate.cxx c_unparser::emit_common_header ().
3
4 #define DEFINE_SESSION_ATOMIC(name, init) \
5 static atomic_t g_##name = ATOMIC_INIT (init); \
6 static inline atomic_t *name(void) { \
7 return &g_##name; \
8 }
9
10 DEFINE_SESSION_ATOMIC(session_state, STAP_SESSION_UNINITIALIZED);
11
12 DEFINE_SESSION_ATOMIC(error_count, 0);
13 DEFINE_SESSION_ATOMIC(skipped_count, 0);
14 DEFINE_SESSION_ATOMIC(skipped_count_lowstack, 0);
15 DEFINE_SESSION_ATOMIC(skipped_count_reentrant, 0);
16 DEFINE_SESSION_ATOMIC(skipped_count_uprobe_reg, 0);
17 DEFINE_SESSION_ATOMIC(skipped_count_uprobe_unreg, 0);
18
19 #undef DEFINE_SESSION_ATOMIC
20
21
22 #ifdef STP_ALIBI
23 atomic_t g_probe_alibi[STP_PROBE_COUNT];
24 static inline atomic_t *probe_alibi(size_t index)
25 {
26 // Do some simple bounds-checking. Translator-generated code
27 // should never get this wrong, but better to be safe.
28 index = clamp_t(size_t, index, 0, STP_PROBE_COUNT - 1);
29 return &g_probe_alibi[index];
30 }
31 #endif
32
33
34 #ifdef STP_TIMING
35 Stat g_probe_timing[STP_PROBE_COUNT];
36 static inline Stat probe_timing(size_t index)
37 {
38 // Do some simple bounds-checking. Translator-generated code
39 // should never get this wrong, but better to be safe.
40 index = clamp_t(size_t, index, 0, STP_PROBE_COUNT - 1);
41 return g_probe_timing[index];
42 }
43 Stat g_refresh_timing;
44 Stat g_module_init_timing;
45 #endif
46
47
48 // Globals are declared and initialized in the translator.
49 static struct stp_globals stp_global;
50
51 #define global(name) (stp_global.name)
52 #define global_set(name, val) (global(name) = (val))
53 #define global_lock(name) (&global(name ## _lock))
54 #define global_lock_init(name) stp_rwlock_init(global_lock(name))
55 #ifdef STP_TIMING
56 #define global_skipped(name) (&global(name ## _lock_skip_count))
57 #define global_contended(name) (&global(name ## _lock_contention_count))
58 #endif
59
60
61 static int stp_session_init(void)
62 {
63 size_t i;
64
65 // The session_state and error/skip counts have static initialization.
66
67 #ifdef STP_ALIBI
68 // Initialize all the alibi counters
69 for (i = 0; i < STP_PROBE_COUNT; ++i)
70 atomic_set(probe_alibi(i), 0);
71 #endif
72
73 #ifdef STP_TIMING
74 // Initialize each Stat used for timing information
75 for (i = 0; i < STP_PROBE_COUNT; ++i)
76 // NB: we don't check for null return here, but instead at
77 // passage to probe handlers and at final printing.
78 g_probe_timing[i] = _stp_stat_init(STAT_OP_MIN, STAT_OP_MAX, STAT_OP_AVG, STAT_OP_VARIANCE, 0, NULL);
79 g_refresh_timing = _stp_stat_init(STAT_OP_MIN, STAT_OP_MAX, STAT_OP_AVG, STAT_OP_VARIANCE, 0, NULL);
80 g_module_init_timing = _stp_stat_init(STAT_OP_MIN, STAT_OP_MAX, STAT_OP_AVG, STAT_OP_VARIANCE, 0, NULL);
81 #endif
82
83 #if defined(STAPCONF_UDELAY_SIMPLE) && !defined(STAPCONF_UDELAY_SIMPLE_EXPORTED)
84 // PR20516: Some s390 kernels that have udelay_simple() don't
85 // have it exported. Note that we have to do this early since
86 // other init routines could call udelay().
87 kallsyms_udelay_simple = (void *)kallsyms_lookup_name("udelay_simple");
88 if (kallsyms_udelay_simple == NULL) {
89 _stp_error("couldn't find udelay_simple");
90 return 1;
91 }
92 #endif
93 return 0;
94 }
95
96 static void stp_session_exit(void)
97 {
98 #ifdef STP_TIMING
99 size_t i;
100
101 // Free each Stat on error in systemtap_module_init()
102 for (i = 0; i < STP_PROBE_COUNT; ++i)
103 _stp_stat_del(g_probe_timing[i]);
104 _stp_stat_del(g_refresh_timing);
105 _stp_stat_del(g_module_init_timing);
106 #endif
107 }