Re: [PATCH] rtnetlink: add rtnl_lock debug log
From: Tetsuo Handa
Date: Fri Apr 30 2021 - 07:49:37 EST
On 2021/04/29 16:02, Rocco Yue wrote:
> +static void rtnl_print_btrace(struct timer_list *unused)
> +{
> + pr_info("----------- %s start -----------\n", __func__);
> + pr_info("%s[%d][%c] hold rtnl_lock more than 2 sec, start time: %llu\n",
> + rtnl_instance.task->comm,
> + rtnl_instance.pid,
> + task_state_to_char(rtnl_instance.task),
> + rtnl_instance.start_time);
> + stack_trace_print(rtnl_instance.addrs, rtnl_instance.nr_entries, 0);
Do we want to print same traces every 2 seconds?
Since it is possible to stall for e.g. 30 seconds, printing either only upon
first call to rtnl_print_btrace() for each stalling duration or only upon
end of stalling duration (i.e. from rtnl_relase_btrace()) is better?
> + show_stack(rtnl_instance.task, NULL, KERN_DEBUG);
Why KERN_DEBUG ?
If you retrieve the output via dmesg, KERN_DEBUG would be fine.
But for syzkaller (which counts on printk() messages being printed to
consoles), KERN_INFO (or default) is expected.
> + pr_info("------------ %s end -----------\n", __func__);
> +}
> +
> +static void rtnl_relase_btrace(void)
> +{
> + rtnl_instance.end_time = sched_clock();
> +
You should del_timer_sync() here than
> + if (rtnl_instance.end_time - rtnl_instance.start_time > 2000000000ULL) {
> + pr_info("rtnl_lock is held by [%d] from [%llu] to [%llu]\n",
> + rtnl_instance.pid,
> + rtnl_instance.start_time,
> + rtnl_instance.end_time);
> + }
> +
> + del_timer(&rtnl_chk_timer);
here in order to make sure that end message is printed only after
rtnl_print_btrace() messages are printed.
> +}
> +#endif
> +