From nobody Tue Sep 16 02:22:10 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A42DDC54EBD for ; Sat, 7 Jan 2023 00:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235821AbjAGAKb (ORCPT ); Fri, 6 Jan 2023 19:10:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230269AbjAGAK2 (ORCPT ); Fri, 6 Jan 2023 19:10:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28AC873E13 for ; Fri, 6 Jan 2023 16:10:27 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D4F1EB81F39 for ; Sat, 7 Jan 2023 00:10:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 827B7C433EF; Sat, 7 Jan 2023 00:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673050224; bh=K2/PuTmRX9viLkgdMX73R6LPBfGmXCCrjVqdGlYZbu4=; h=Date:From:To:Cc:Subject:Reply-To:From; b=o1GoimRmZQIpITHQq4+zXq1XcNzS0ZjbEt0NxvdjqRg6LXuI6dbecNnqtPCpDA1uT BmQ/YZ+4loKyWi1i0PEb8xqpAQoEYG2INFN0hnmL5i+V5VoudDF5cvUaQT6MYDlq75 uxtiDeJfEIeVnQQZTNwAcuoSoAUMl69KxJMGnGdEI5lOlGUFtjoO3npqNT1eBE1rwJ OvpIE1oTItPRjUera700bomPgu0RhTRVk51sM1vsMzyExfakXo9gIje14MI/OqmZkG HMxIjS3I5rWyCUHoEdzL8ui/VzcB+orZsIa6Iyiw3ojEGoQiKSFKXq0Y+R1ZjWeywg A1Su1tLFfWQww== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 0FF745C0A2D; Fri, 6 Jan 2023 16:10:24 -0800 (PST) Date: Fri, 6 Jan 2023 16:10:24 -0800 From: "Paul E. McKenney" To: Tejun Heo , Lai Jiangshan Cc: Dave Jones , Rik van Riel , linux-kernel@vger.kernel.org Subject: [PATCH RFC] workqueue: Make show_pwq() use run-length encoding Message-ID: <20230107001024.GA3893528@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The show_pwq() function dumps out a pool_workqueue structure's activity, including the pending work-queue handlers: Showing busy workqueues and worker pools: workqueue events: flags=3D0x0 pwq 0: cpus=3D0 node=3D0 flags=3D0x1 nice=3D0 active=3D10/256 refcnt=3D11 in-flight: 7:test_work_func, 64:test_work_func, 249:test_work_func pending: test_work_func, test_work_func, test_work_func1, test_work_fu= nc1, test_work_func1, test_work_func1, test_work_func1 When large systems are facing certain types of hang conditions, it is not unusual for this "pending" list to contain runs of hundreds of identical function names. This "wall of text" is difficult to read, and worse yet, it can be interleaved with other output such as stack traces. Therefore, make show_pwq() use run-length encoding so that the above printout instead looks like this: Showing busy workqueues and worker pools: workqueue events: flags=3D0x0 pwq 0: cpus=3D0 node=3D0 flags=3D0x1 nice=3D0 active=3D10/256 refcnt=3D11 in-flight: 7:test_work_func, 64:test_work_func, 249:test_work_func pending: 2*test_work_func, 5*test_work_func1 When no comma would be printed, including the WORK_STRUCT_LINKED case, a new run is started unconditionally. This output is more readable, places less stress on the hardware, firmware, and software on the console-log path, and reduces interference with other output. Signed-off-by: Paul E. McKenney Cc: Tejun Heo Cc: Lai Jiangshan Cc: Dave Jones Cc: Rik van Riel diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 07895deca2711..73c4291776ab4 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -4709,22 +4709,53 @@ static void pr_cont_pool_info(struct worker_pool *p= ool) pr_cont(" flags=3D0x%x nice=3D%d", pool->flags, pool->attrs->nice); } =20 -static void pr_cont_work(bool comma, struct work_struct *work) +struct pr_cont_work_struct { + bool comma; + work_func_t func; + long ctr; +}; + +static void pr_cont_work_flush(bool comma, work_func_t func, struct pr_con= t_work_struct *pcwsp) +{ + if (!pcwsp->ctr) + goto out_record; + if (func =3D=3D pcwsp->func) { + pcwsp->ctr++; + return; + } + if (pcwsp->ctr =3D=3D 1) + pr_cont("%s %ps", pcwsp->comma ? "," : "", pcwsp->func); + else + pr_cont("%s %ld*%ps", pcwsp->comma ? "," : "", pcwsp->ctr, pcwsp->func); + pcwsp->ctr =3D 0; +out_record: + if ((long)func =3D=3D -1L) + return; + pcwsp->comma =3D comma; + pcwsp->func =3D func; + pcwsp->ctr =3D 1; +} + +static void pr_cont_work(bool comma, struct work_struct *work, struct pr_c= ont_work_struct *pcwsp) { if (work->func =3D=3D wq_barrier_func) { struct wq_barrier *barr; =20 barr =3D container_of(work, struct wq_barrier, work); =20 + pr_cont_work_flush(comma, (work_func_t)-1, pcwsp); pr_cont("%s BAR(%d)", comma ? "," : "", task_pid_nr(barr->task)); } else { - pr_cont("%s %ps", comma ? "," : "", work->func); + if (!comma) + pr_cont_work_flush(comma, (work_func_t)-1, pcwsp); + pr_cont_work_flush(comma, work->func, pcwsp); } } =20 static void show_pwq(struct pool_workqueue *pwq) { + struct pr_cont_work_struct pcws =3D { .ctr =3D 0, }; struct worker_pool *pool =3D pwq->pool; struct work_struct *work; struct worker *worker; @@ -4757,7 +4788,8 @@ static void show_pwq(struct pool_workqueue *pwq) worker->rescue_wq ? "(RESCUER)" : "", worker->current_func); list_for_each_entry(work, &worker->scheduled, entry) - pr_cont_work(false, work); + pr_cont_work(false, work, &pcws); + pr_cont_work_flush(comma, (work_func_t)-1L, &pcws); comma =3D true; } pr_cont("\n"); @@ -4777,9 +4809,10 @@ static void show_pwq(struct pool_workqueue *pwq) if (get_work_pwq(work) !=3D pwq) continue; =20 - pr_cont_work(comma, work); + pr_cont_work(comma, work, &pcws); comma =3D !(*work_data_bits(work) & WORK_STRUCT_LINKED); } + pr_cont_work_flush(comma, (work_func_t)-1L, &pcws); pr_cont("\n"); } =20 @@ -4788,9 +4821,10 @@ static void show_pwq(struct pool_workqueue *pwq) =20 pr_info(" inactive:"); list_for_each_entry(work, &pwq->inactive_works, entry) { - pr_cont_work(comma, work); + pr_cont_work(comma, work, &pcws); comma =3D !(*work_data_bits(work) & WORK_STRUCT_LINKED); } + pr_cont_work_flush(comma, (work_func_t)-1L, &pcws); pr_cont("\n"); } }