Skip to content

Commit 07416af

Browse files
Villemoestorvalds
authored andcommitted
kernel/async.c: stop guarding pr_debug() statements
It's currently nigh impossible to get these pr_debug()s to print something. Being guarded by initcall_debug means one has to enable tons of other debug output during boot, and the system_state condition further means it's impossible to get them when loading modules later. Also, the compiler can't know that these global conditions do not change, so there are W=2 warnings kernel/async.c:125:9: warning: `calltime' may be used uninitialized in this function [-Wmaybe-uninitialized] kernel/async.c:300:9: warning: `starttime' may be used uninitialized in this function [-Wmaybe-uninitialized] Make it possible, for a DYNAMIC_DEBUG kernel, to get these to print their messages by booting with appropriate 'dyndbg="file async.c +p"' command line argument. For a non-DYNAMIC_DEBUG kernel, pr_debug() compiles to nothing. This does cost doing an unconditional ktime_get() for the starttime value, but the corresponding ktime_get for the end time can be elided by factoring it into a function which only gets called if the printk() arguments end up being evaluated. Link: https://lkml.kernel.org/r/20210309151723.1907838-1-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9c39c6f commit 07416af

1 file changed

Lines changed: 20 additions & 28 deletions

File tree

‎kernel/async.c‎

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ static DECLARE_WAIT_QUEUE_HEAD(async_done);
7878

7979
static atomic_t entry_count;
8080

81+
static long long microseconds_since(ktime_t start)
82+
{
83+
ktime_t now = ktime_get();
84+
return ktime_to_ns(ktime_sub(now, start)) >> 10;
85+
}
86+
8187
static async_cookie_t lowest_in_progress(struct async_domain *domain)
8288
{
8389
struct async_entry *first = NULL;
@@ -111,24 +117,18 @@ static void async_run_entry_fn(struct work_struct *work)
111117
struct async_entry *entry =
112118
container_of(work, struct async_entry, work);
113119
unsigned long flags;
114-
ktime_t calltime, delta, rettime;
120+
ktime_t calltime;
115121

116122
/* 1) run (and print duration) */
117-
if (initcall_debug && system_state < SYSTEM_RUNNING) {
118-
pr_debug("calling %lli_%pS @ %i\n",
119-
(long long)entry->cookie,
120-
entry->func, task_pid_nr(current));
121-
calltime = ktime_get();
122-
}
123+
pr_debug("calling %lli_%pS @ %i\n", (long long)entry->cookie,
124+
entry->func, task_pid_nr(current));
125+
calltime = ktime_get();
126+
123127
entry->func(entry->data, entry->cookie);
124-
if (initcall_debug && system_state < SYSTEM_RUNNING) {
125-
rettime = ktime_get();
126-
delta = ktime_sub(rettime, calltime);
127-
pr_debug("initcall %lli_%pS returned after %lld usecs\n",
128-
(long long)entry->cookie,
129-
entry->func,
130-
(long long)ktime_to_ns(delta) >> 10);
131-
}
128+
129+
pr_debug("initcall %lli_%pS returned after %lld usecs\n",
130+
(long long)entry->cookie, entry->func,
131+
microseconds_since(calltime));
132132

133133
/* 2) remove self from the pending queues */
134134
spin_lock_irqsave(&async_lock, flags);
@@ -287,23 +287,15 @@ EXPORT_SYMBOL_GPL(async_synchronize_full_domain);
287287
*/
288288
void async_synchronize_cookie_domain(async_cookie_t cookie, struct async_domain *domain)
289289
{
290-
ktime_t starttime, delta, endtime;
290+
ktime_t starttime;
291291

292-
if (initcall_debug && system_state < SYSTEM_RUNNING) {
293-
pr_debug("async_waiting @ %i\n", task_pid_nr(current));
294-
starttime = ktime_get();
295-
}
292+
pr_debug("async_waiting @ %i\n", task_pid_nr(current));
293+
starttime = ktime_get();
296294

297295
wait_event(async_done, lowest_in_progress(domain) >= cookie);
298296

299-
if (initcall_debug && system_state < SYSTEM_RUNNING) {
300-
endtime = ktime_get();
301-
delta = ktime_sub(endtime, starttime);
302-
303-
pr_debug("async_continuing @ %i after %lli usec\n",
304-
task_pid_nr(current),
305-
(long long)ktime_to_ns(delta) >> 10);
306-
}
297+
pr_debug("async_continuing @ %i after %lli usec\n", task_pid_nr(current),
298+
microseconds_since(starttime));
307299
}
308300
EXPORT_SYMBOL_GPL(async_synchronize_cookie_domain);
309301

0 commit comments

Comments
 (0)