]>
sourceware.org Git - systemtap.git/blob - runtime/linux/runtime_context.h
2 * Context Runtime Functions
3 * Copyright (C) 2014 Red Hat Inc.
5 * This file is part of systemtap, and is free software. You can
6 * redistribute it and/or modify it under the terms of the GNU General
7 * Public License (GPL); either version 2, or (at your option) any
11 #ifndef _LINUX_RUNTIME_CONTEXT_H_
12 #define _LINUX_RUNTIME_CONTEXT_H_
14 static struct context
*contexts
[NR_CPUS
] = { NULL
};
16 static int _stp_runtime_contexts_alloc(void)
20 for_each_possible_cpu(cpu
) {
21 /* Module init, so in user context, safe to use
22 * "sleeping" allocation. */
23 contexts
[cpu
] = _stp_kzalloc_gfp(sizeof(struct context
),
24 STP_ALLOC_SLEEP_FLAGS
);
25 if (contexts
[cpu
] == NULL
) {
26 _stp_error ("context (size %lu) allocation failed",
27 (unsigned long) sizeof (struct context
));
34 static void _stp_runtime_contexts_free(void)
38 for_each_possible_cpu(cpu
) {
39 if (contexts
[cpu
] != NULL
) {
40 _stp_kfree(contexts
[cpu
]);
46 static struct context
* _stp_runtime_entryfn_get_context(void)
48 struct context
* __restrict__ c
= NULL
;
50 c
= contexts
[smp_processor_id()];
52 if (atomic_inc_return(&c
->busy
) == 1)
56 preempt_enable_no_resched();
60 static inline void _stp_runtime_entryfn_put_context(struct context
*c
)
62 if (c
&& c
== contexts
[smp_processor_id()]) {
64 preempt_enable_no_resched();
66 /* else, warn about bad state? */
70 static inline struct context
* _stp_runtime_get_context(void)
72 return contexts
[smp_processor_id()];
75 static void _stp_runtime_context_wait(void)
78 unsigned long hold_start
;
87 for_each_possible_cpu(i
) {
88 if (contexts
[i
] != NULL
89 && atomic_read (& contexts
[i
]->busy
)) {
92 /* Just in case things are really
93 * stuck, let's print some diagnostics. */
94 if (time_after(jiffies
, hold_start
+ HZ
) // > 1 second
95 && (i
> hold_index
)) { // not already printed
97 printk(KERN_ERR
"%s context[%d] stuck: %s\n", THIS_MODULE
->name
, i
, contexts
[i
]->probe_point
);
103 * Just in case things are really really stuck, a
104 * handler probably suffered a fault, and the kernel
105 * probably killed a task/thread already. We can't be
106 * quite sure in what state everything is in, however
107 * auxiliary stuff like kprobes / uprobes / locks have
108 * already been unregistered. So it's *probably* safe
109 * to pretend/assume/hope everything is OK, and let
110 * the cleanup finish.
112 * In the worst case, there may occur a fault, as a
113 * genuinely running probe handler tries to access
114 * script globals (about to be freed), or something
115 * accesses module memory (about to be unloaded).
116 * This is sometimes stinky, so the alternative
117 * (default) is to change from a livelock to a
118 * livelock that sleeps awhile.
120 #ifdef STAP_OVERRIDE_STUCK_CONTEXT
121 if (time_after(jiffies
, hold_start
+ HZ
*10)) { // > 10 seconds
122 printk(KERN_ERR
"%s overriding stuck context to allow module shutdown.", THIS_MODULE
->name
);
123 holdon
= 0; // allow loop to exit
126 /* at least stop sucking down the staprun cpu */
130 /* NB: we run at least one of these during the
131 * shutdown sequence: */
132 yield(); /* aka schedule() and then some */
136 #endif /* _LINUX_RUNTIME_CONTEXT_H_ */
This page took 0.040697 seconds and 5 git commands to generate.