From patchwork Sat Jan 7 00:10:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. McKenney" X-Patchwork-Id: 40280 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1088906wrt; Fri, 6 Jan 2023 16:13:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXtDZurPh/Ab3vJ7ceX2u32C/tNgJk+I8VLfZNIwxippE4BS2F5j3OmBbDB9Utiw+gfnvIsp X-Received: by 2002:a05:6a20:c78d:b0:a4:b615:2239 with SMTP id hk13-20020a056a20c78d00b000a4b6152239mr74018517pzb.24.1673050424262; Fri, 06 Jan 2023 16:13:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673050424; cv=none; d=google.com; s=arc-20160816; b=dxlR55UVAK+8R3QhUS0TFZen9f3mL9S2FXTvR82xqPSDUDf7IKGLUoxFjChH+DZAOS 7hhbuLoD8zUWCxtHTXaNYoXGTWJy7cvbP1FPY5801zlBZiR/ZJLtDH6ouLLqfnY8Iseb rq4ol0htu1uM1GJYxp1Y/bt5Gr7Ush0mwMLNcn0GGjw+1XgFIqBx617TN3p+uSpPTFaM rxCan1KaPyShrbrTrC4JIRsnWRvA49Vm5v1Mi8dTIWlEqH6AWmViuUvdQXU6kdEgoWF3 iAYv7CiFrXYC33ivceY/7kh1KG4GsJhQo5bIu6tE4sVJ1n7y6IWAy10mZ1kE7V++VweS JusQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:reply-to :message-id:subject:cc:to:from:date:dkim-signature; bh=H8R/5BDAfLuORWzYxg9yAk/5CXuFZUQyb7TNVMIqqoE=; b=Z204yfMm4DYnxxle7ga2MRhrAsY4LKtq+GKxz7VlXuMLGGa6eGEjwDiRCW34yCcwXO VL325dfEeZjRPpyh741IrpGdJjG0dh1Y/hRM7EbnUG3zqhG8koEreKXJxxX2RsXQZ/av +MzQgKxftcUOHWauG65w/23gA/0KXYn5g9/MGvq53FTcj0QsYS9Sa9rNrgDVI5rI1e2y oL0o8IKGo7wbvKl/Ny2yh8mA8tDVY2nWwYfc7+nYJX5xDI2WvpQjO3Noj+5hkTwYuzLm oQFsZfbBHcw3C8y4a1u++MR6HKsSgaDib0oc5Gxv2uPVG428lXY5buGqMAMMdjXDIRlp 75Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o1GoimRm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 19-20020a170902c21300b00186b287bd57si2294190pll.190.2023.01.06.16.13.31; Fri, 06 Jan 2023 16:13:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o1GoimRm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235069AbjAGAKa (ORCPT + 99 others); Fri, 6 Jan 2023 19:10:30 -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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754320521505375682?= X-GMAIL-MSGID: =?utf-8?q?1754320521505375682?= 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=0x0 pwq 0: cpus=0 node=0 flags=0x1 nice=0 active=10/256 refcnt=11 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_func1, 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=0x0 pwq 0: cpus=0 node=0 flags=0x1 nice=0 active=10/256 refcnt=11 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 *pool) pr_cont(" flags=0x%x nice=%d", pool->flags, pool->attrs->nice); } -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_cont_work_struct *pcwsp) +{ + if (!pcwsp->ctr) + goto out_record; + if (func == pcwsp->func) { + pcwsp->ctr++; + return; + } + if (pcwsp->ctr == 1) + pr_cont("%s %ps", pcwsp->comma ? "," : "", pcwsp->func); + else + pr_cont("%s %ld*%ps", pcwsp->comma ? "," : "", pcwsp->ctr, pcwsp->func); + pcwsp->ctr = 0; +out_record: + if ((long)func == -1L) + return; + pcwsp->comma = comma; + pcwsp->func = func; + pcwsp->ctr = 1; +} + +static void pr_cont_work(bool comma, struct work_struct *work, struct pr_cont_work_struct *pcwsp) { if (work->func == wq_barrier_func) { struct wq_barrier *barr; barr = container_of(work, struct wq_barrier, work); + 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); } } static void show_pwq(struct pool_workqueue *pwq) { + struct pr_cont_work_struct pcws = { .ctr = 0, }; struct worker_pool *pool = 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 = true; } pr_cont("\n"); @@ -4777,9 +4809,10 @@ static void show_pwq(struct pool_workqueue *pwq) if (get_work_pwq(work) != pwq) continue; - pr_cont_work(comma, work); + pr_cont_work(comma, work, &pcws); comma = !(*work_data_bits(work) & WORK_STRUCT_LINKED); } + pr_cont_work_flush(comma, (work_func_t)-1L, &pcws); pr_cont("\n"); } @@ -4788,9 +4821,10 @@ static void show_pwq(struct pool_workqueue *pwq) pr_info(" inactive:"); list_for_each_entry(work, &pwq->inactive_works, entry) { - pr_cont_work(comma, work); + pr_cont_work(comma, work, &pcws); comma = !(*work_data_bits(work) & WORK_STRUCT_LINKED); } + pr_cont_work_flush(comma, (work_func_t)-1L, &pcws); pr_cont("\n"); } }