Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5099286rdb; Tue, 12 Dec 2023 20:55:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHmHhhst+PgS+/cHFcPnlMLevDKutyBN+2/0PkVObBTolNQZYOOHoAkQVbFng9x3hfLEleG X-Received: by 2002:a05:6a00:1487:b0:6ce:46ba:9c2 with SMTP id v7-20020a056a00148700b006ce46ba09c2mr10201498pfu.28.1702443314817; Tue, 12 Dec 2023 20:55:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702443314; cv=none; d=google.com; s=arc-20160816; b=z14qgR+yzGqcoKstOamkNGIDJohHMoyfzsZvOEPUVv+CflyxvYfkvPPvifxcWDfHUp kczlPQ33vEdv4DYpEkZECmvXob3q7KuyeDBHZBeV9olYo2jd5Jy1060PsBEdbOk1Av/j ppnLNdu/cSrNQP3fb4s69ci33HixNWPidh6ClB1kuasJKB1djzXEPkd9ov0aSlomyktj w2VRCpf9n13CbGWFsJICP7Mq51HwpTXeiStdbOSQqDDaTRi9ozqIE+lrVZZqT6G3q7Hv 1lh37PZLL3yO64MtuRePpHuu5JeWEPN8PO3vr9EYIbRWXkIEJyWKv0qVPTPY8vebzNKC nWgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=MgcKzc1IORHWtSSPzD4YL1p/LjIGorkzaZhtW/BEzRA=; fh=IygsB5GgLdzsVreQ0nCe0Ur8GRjuWj89mJu7Jt+ig78=; b=Nk3s6FB130pTksAAl+ExU+qx2XfEJHYpEL73/DJs0zptYiyJu8hnb9LCzdLK9/KoAX UsiXRlgafAjlWeENi9RtFgacXwF8tvWadDlCjLHdSyUyi2iDTlbp+6iBi17Qppy/W1C2 OQsYlYiNXp95Dj8FWRXyZf6madwMVZUaXefFkz1v2VitOIWIM3az22o43G7uMkXS3l3/ SAx8XqKnKayZyNApnko6DykUZ5x2JjhQt52xEhePfEVprJK3mQktOwhR5xAnbnA/FFwg fq3yiwFp5P9tOQy4u53uDqRiT02hwNLvrcuWFxDOXB5jhhEpE/ovLsqyMxOtHsQYyPDS mkWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=gyP1rZVH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id j20-20020a635954000000b005b42f4443b7si9068465pgm.653.2023.12.12.20.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 20:55:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=gyP1rZVH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3E9A0806501E; Tue, 12 Dec 2023 20:55:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378510AbjLMEy4 (ORCPT + 99 others); Tue, 12 Dec 2023 23:54:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378466AbjLMEyy (ORCPT ); Tue, 12 Dec 2023 23:54:54 -0500 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97D6FAD for ; Tue, 12 Dec 2023 20:54:58 -0800 (PST) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231213045456epoutp0383c4b86e95579a8e6ef7b679543c21e3~gSyiHLuzO1688816888epoutp033 for ; Wed, 13 Dec 2023 04:54:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231213045456epoutp0383c4b86e95579a8e6ef7b679543c21e3~gSyiHLuzO1688816888epoutp033 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1702443296; bh=MgcKzc1IORHWtSSPzD4YL1p/LjIGorkzaZhtW/BEzRA=; h=From:To:Cc:Subject:Date:References:From; b=gyP1rZVH3zLLn9LJDMETLZneVwxvOoFTMgQ9zP+ylgGqObbV09PhKIIJBQA64RJf8 Bt67DpBJHz0grJnpBVe/Y8xMtPknyDMdMqe/jlDQ2tdFd0gAyZjvgVdGdjDpr5VbKc O4qyiYITdjplVrAYDfpI/8E5NvTZLA6btBsCr8AU= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20231213045455epcas5p2867e0f6682429d8d7929c20000d18693~gSyhF0gZM2683426834epcas5p2H; Wed, 13 Dec 2023 04:54:55 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.179]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4Sqjp437cPz4x9Px; Wed, 13 Dec 2023 04:54:52 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id D7.91.09634.B1939756; Wed, 13 Dec 2023 13:54:51 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20231213033309epcas5p4a312be32080125bfe62bf5353abadd74~gRrIRE6l51492114921epcas5p44; Wed, 13 Dec 2023 03:33:09 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231213033309epsmtrp236608f0b4346b2c27d0dff9145953263~gRrIQMiCF2684726847epsmtrp2M; Wed, 13 Dec 2023 03:33:09 +0000 (GMT) X-AuditID: b6c32a49-159fd700000025a2-a7-6579391bc399 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 59.48.08755.5F529756; Wed, 13 Dec 2023 12:33:09 +0900 (KST) Received: from AHRE124.. (unknown [109.105.118.124]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20231213033308epsmtip1679095a847f903ea9f7e7d97cb1a9565~gRrG4SE7m2763727637epsmtip1a; Wed, 13 Dec 2023 03:33:08 +0000 (GMT) From: Xiaobing Li To: axboe@kernel.dk, asml.silence@gmail.com Cc: linux-kernel@vger.kernel.org, io-uring@vger.kernel.org, kun.dou@samsung.com, peiwei.li@samsung.com, joshi.k@samsung.com, kundan.kumar@samsung.com, wenwen.chen@samsung.com, ruyi.zhang@samsung.com, cliang01.li@samsung.com, xue01.he@samsung.com, Xiaobing Li Subject: [PATCH v4] io_uring: Statistics of the true utilization of sq threads. Date: Wed, 13 Dec 2023 11:25:13 +0800 Message-Id: <20231213032513.12591-1-xiaobing.li@samsung.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNJsWRmVeSWpSXmKPExsWy7bCmhq60ZWWqwf4HshZzVm1jtFh9t5/N 4vTfxywW71rPsVgc/f+WzeJX911Gi61fvrJaXN41h83i2V5Oiy+Hv7NbT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S-MailID: 20231213033309epcas5p4a312be32080125bfe62bf5353abadd74 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231213033309epcas5p4a312be32080125bfe62bf5353abadd74 References: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 20:55:12 -0800 (PST) v4: 1.Since the sq thread has a while(1) structure, during this process, there may be a lot of time that is not processing IO but does not exceed the timeout period, therefore, the sqpoll thread will keep running and will keep occupying the CPU. Obviously, the CPU is wasted at this time;Our goal is to count the part of the time that the sqpoll thread actually processes IO, so as to reflect the part of the CPU it uses to process IO, which can be used to help improve the actual utilization of the CPU in the future. 2."work_time" in the code represents the sum of the jiffies of the sq thread actually processing IO, that is, how many milliseconds it actually takes to process IO. "total_time" represents the total time that the sq thread has elapsed from the beginning of the loop to the current time point, that is, how many milliseconds it has spent in total. The output "SqBusy" represents the percentage of time utilization that the sq thread actually uses to process IO. Signed-off-by: Xiaobing Li The test results are as follows: Every 0.5s: cat /proc/23112/fdinfo/6 | grep Sq SqMask: 0x3 SqHead: 1168417 SqTail: 1168418 CachedSqHead: 1168418 SqThread: 23112 SqThreadCpu: 55 SqBusy: 97% --- io_uring/fdinfo.c | 4 ++++ io_uring/sqpoll.c | 8 ++++++++ io_uring/sqpoll.h | 2 ++ 3 files changed, 14 insertions(+) diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c index 976e9500f651..b0f9d296c5aa 100644 --- a/io_uring/fdinfo.c +++ b/io_uring/fdinfo.c @@ -64,6 +64,7 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) unsigned int sq_shift = 0; unsigned int sq_entries, cq_entries; int sq_pid = -1, sq_cpu = -1; + int sq_busy = 0; bool has_lock; unsigned int i; @@ -147,10 +148,13 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f) sq_pid = sq->task_pid; sq_cpu = sq->sq_cpu; + if (sq->total_time != 0) + sq_busy = (int)(sq->work_time * 100 / sq->total_time); } seq_printf(m, "SqThread:\t%d\n", sq_pid); seq_printf(m, "SqThreadCpu:\t%d\n", sq_cpu); + seq_printf(m, "SqBusy:\t%d%%\n", sq_busy); seq_printf(m, "UserFiles:\t%u\n", ctx->nr_user_files); for (i = 0; has_lock && i < ctx->nr_user_files; i++) { struct file *f = io_file_from_index(&ctx->file_table, i); diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index 65b5dbe3c850..9b74e344c52a 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -225,6 +225,7 @@ static int io_sq_thread(void *data) struct io_ring_ctx *ctx; unsigned long timeout = 0; char buf[TASK_COMM_LEN]; + unsigned long sq_start, sq_work_begin, sq_work_end; DEFINE_WAIT(wait); snprintf(buf, sizeof(buf), "iou-sqp-%d", sqd->task_pid); @@ -241,6 +242,7 @@ static int io_sq_thread(void *data) } mutex_lock(&sqd->lock); + sq_start = jiffies; while (1) { bool cap_entries, sqt_spin = false; @@ -251,6 +253,7 @@ static int io_sq_thread(void *data) } cap_entries = !list_is_singular(&sqd->ctx_list); + sq_work_begin = jiffies; list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { int ret = __io_sq_thread(ctx, cap_entries); @@ -260,6 +263,11 @@ static int io_sq_thread(void *data) if (io_run_task_work()) sqt_spin = true; + sq_work_end = jiffies; + sqd->total_time = sq_work_end - sq_start; + if (sqt_spin == true) + sqd->work_time += sq_work_end - sq_work_begin; + if (sqt_spin || !time_after(jiffies, timeout)) { if (sqt_spin) timeout = jiffies + sqd->sq_thread_idle; diff --git a/io_uring/sqpoll.h b/io_uring/sqpoll.h index 8df37e8c9149..92b4b07220fa 100644 --- a/io_uring/sqpoll.h +++ b/io_uring/sqpoll.h @@ -16,6 +16,8 @@ struct io_sq_data { pid_t task_pid; pid_t task_tgid; + unsigned long work_time; + unsigned long total_time; unsigned long state; struct completion exited; }; -- 2.34.1