Re: [RFC 2/5] workqueue: Warn when a new worker could not be created

From: Tejun Heo
Date: Thu Feb 02 2023 - 18:30:48 EST


Hello,

On Wed, Feb 01, 2023 at 02:45:40PM +0100, Petr Mladek wrote:
> +static __printf(2, 3) __cold
> +void __print_create_worker_failure(long err, const char *fmt, ...)
> +{
> + spin_lock_irq(&create_worker_failed_lock);
> +
> + /*
> + * Report potentially repeated failures only once during a stall.
> + * Otherwise, it might be noisy. Also slow serial console drivers
> + * touch watchdogs so that more frequent messages would prevent
> + * reaching the watchdog thresh.
> + */
> + if (!create_worker_failed) {
> + va_list args;
> +
> + va_start(args, fmt);
> + vprintk(fmt, args);
> + va_end(args);
> + }
> +
> + create_worker_failed++;
> +
> + spin_unlock_irq(&create_worker_failed_lock);
> +}

That's pretty elaborate. Why not just use printk_ratelimited()?

> @@ -1931,12 +1992,16 @@ static struct worker *create_worker(struct worker_pool *pool)
>
> /* ID is needed to determine kthread name */
> id = ida_alloc(&pool->worker_ida, GFP_KERNEL);
> - if (id < 0)
> + if (id < 0) {
> + print_create_worker_failure("workqueue: Failed to allocate a pool ID", id);
^
worker ID?

> @@ -5880,8 +5950,10 @@ static void wq_watchdog_timer_fn(struct timer_list *unused)
>
> rcu_read_unlock();
>
> - if (lockup_detected)
> + if (lockup_detected) {
> + print_create_worker_failed_num();
> show_all_workqueues();
> + }

I'd just use printk_ratelimited() and leave it at that.

Thanks.

--
tejun