Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1967287rdf; Sun, 5 Nov 2023 23:56:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7EbyAtFjGpv9Etlt2NFFo1kedzg3tKR3TQb5ej2GqiSJ5y9ThzrHvC+wNRbdCrDR5hF2l X-Received: by 2002:a05:6808:4d3:b0:3b2:f431:e029 with SMTP id a19-20020a05680804d300b003b2f431e029mr29645897oie.26.1699257363548; Sun, 05 Nov 2023 23:56:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699257363; cv=none; d=google.com; s=arc-20160816; b=i4uwvj1/33w6GmLHMbMHqKDeRTX5zm6qqVcF92vQECt0ILiz9TRFdi4vdCBIoixbb3 jn0MYmZi49Ro9ZZ06lpt1VnRmDxwP2y/92rpOBJMZczB89KwvVHTPfQTNkzp9WuAWqZE 0jjarZ9VutZ7l4hJ7jNipDzntoTTgTNOlTbsaOaYa4O7UPbkvRz4f3/WGWyFQd83wpPE JdEY6XqMXfVYOQ1LdGzZLNSIPkSWGNCauzWl7bfh+KnHBmL4UiiBuQc0svuT6Lt/PNP0 HeZ4LRXgEKdYpNgDflmUWhngCoA2sYffGBdUg1Ga7OkvUO/MXRkXfndX/mKKtHmbGZAY VkTw== 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=6NYx99oCWyMXAuJQC3OusH2vT6lJSfTjX8zw5hfAzvE=; fh=IHLCUkI0smA/KkEh3ghm8DmX2p5E3xbVcV7ILYZjlzw=; b=fWp00jCzAjHuPWfV2yTYVxZO4oCMs35rP0SkbRrc2lC1vmuqy/jMC8MzpOOXBum1gv iFgS8mg0JOGGhg+hQL2IMUoZtRTrftmCC1QdEOVzLQVX5R724Ph5HimvN4gtypF2/w21 Ecm4PCXu9L5DqvFVPJGICJwmaA+dUiQzPoGX30lWnWhTqCgOJkPTs/O6LdsKQoOvc/k1 NY+xTTmhY7pDL2XAHDM+l7DT5O9yd0nLB5sulf6OVn55K9HFM9TR2m68u5IeUzueI2hi /vOlvb6TTlnXfz98jhYa/Fjh4Seak2Smv4XvossgV/waYokt6vUwA/jRW9KeLssudxBM okqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=MZvj4vrY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id p56-20020a056a0026f800b006c3212b57aasi6855703pfw.325.2023.11.05.23.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 23:56:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=MZvj4vrY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id D5CC7805B045; Sun, 5 Nov 2023 23:56:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbjKFHzs (ORCPT + 99 others); Mon, 6 Nov 2023 02:55:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbjKFHzr (ORCPT ); Mon, 6 Nov 2023 02:55:47 -0500 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E751DB3 for ; Sun, 5 Nov 2023 23:55:41 -0800 (PST) Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20231106075539epoutp0183eea43b3cd34e6cf0cabe6c40f29fee~U_YwyPM4K2757527575epoutp01d for ; Mon, 6 Nov 2023 07:55:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20231106075539epoutp0183eea43b3cd34e6cf0cabe6c40f29fee~U_YwyPM4K2757527575epoutp01d DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1699257339; bh=6NYx99oCWyMXAuJQC3OusH2vT6lJSfTjX8zw5hfAzvE=; h=From:To:Cc:Subject:Date:References:From; b=MZvj4vrYJaJDHxSB/4lg3rCf56rZuQ94fJdIuOW/7hzLCpUD2sf7NQlq81YQJ5Uj1 S5kCxauinNACzNIu4sthRMGPJFjoVCWs/5iN1MCJg3N+/TFOlfd5zJFuvuVDl7Uopo OMmE35zKoCW784VFy5ypfu2ZM+pVRFY/CeHb5tt0= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20231106075539epcas5p3b7b48b19d7968bacebe62918775115b4~U_YwY_dFe2090520905epcas5p3h; Mon, 6 Nov 2023 07:55:39 +0000 (GMT) Received: from epsmgec5p1-new.samsung.com (unknown [182.195.38.182]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SP3Yk1zLXz4x9Q9; Mon, 6 Nov 2023 07:55:38 +0000 (GMT) Received: from epcas5p4.samsung.com ( [182.195.41.42]) by epsmgec5p1-new.samsung.com (Symantec Messaging Gateway) with SMTP id 67.CB.19369.AFB98456; Mon, 6 Nov 2023 16:55:38 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20231106074844epcas5p252beb2aa7925de34aea33d5c64d1d72e~U_StddITd2058820588epcas5p2n; Mon, 6 Nov 2023 07:48:44 +0000 (GMT) Received: from epsmgmc1p1new.samsung.com (unknown [182.195.42.40]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231106074844epsmtrp20f47fa419814ea03c209a3b9c4d9dc19~U_StctKF91829318293epsmtrp2c; Mon, 6 Nov 2023 07:48:44 +0000 (GMT) X-AuditID: b6c32a50-9e1ff70000004ba9-ea-65489bfaa706 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmc1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 7E.6E.07368.B5A98456; Mon, 6 Nov 2023 16:48:43 +0900 (KST) Received: from AHRE124.. (unknown [109.105.118.124]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231106074842epsmtip29fbba4a4dd6ccb175ec68b965e03fa4b~U_SsQtdsB1909319093epsmtip2Z; Mon, 6 Nov 2023 07:48:42 +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, Xiaobing Li Subject: [PATCH] IO_URING: Statistics of the true utilization of sq threads. Date: Mon, 6 Nov 2023 15:40:55 +0800 Message-Id: <20231106074055.1248629-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+NgFprEJsWRmVeSWpSXmKPExsWy7bCmlu6v2R6pBt0dXBZzVm1jtFh9t5/N 4l3rORaLo//fsln86r7L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: 20231106074844epcas5p252beb2aa7925de34aea33d5c64d1d72e 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: 20231106074844epcas5p252beb2aa7925de34aea33d5c64d1d72e References: X-Spam-Status: No, score=-1.4 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 groat.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 (groat.vger.email [0.0.0.0]); Sun, 05 Nov 2023 23:56:01 -0800 (PST) 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. Signed-off-by: Xiaobing Li --- io_uring/sqpoll.c | 8 ++++++++ io_uring/sqpoll.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index bd6c2c7959a5..27b01ad42678 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -224,6 +224,7 @@ static int io_sq_thread(void *data) struct io_ring_ctx *ctx; unsigned long timeout = 0; char buf[TASK_COMM_LEN]; + unsigned long long start, begin, end; DEFINE_WAIT(wait); snprintf(buf, sizeof(buf), "iou-sqp-%d", sqd->task_pid); @@ -235,6 +236,7 @@ static int io_sq_thread(void *data) set_cpus_allowed_ptr(current, cpu_online_mask); mutex_lock(&sqd->lock); + start = jiffies; while (1) { bool cap_entries, sqt_spin = false; @@ -245,12 +247,18 @@ static int io_sq_thread(void *data) } cap_entries = !list_is_singular(&sqd->ctx_list); + begin = jiffies; list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { int ret = __io_sq_thread(ctx, cap_entries); if (!sqt_spin && (ret > 0 || !wq_list_empty(&ctx->iopoll_list))) sqt_spin = true; } + end = jiffies; + sqd->total = end - start; + if (sqt_spin == true) + sqd->work += end - begin; + if (io_run_task_work()) sqt_spin = true; diff --git a/io_uring/sqpoll.h b/io_uring/sqpoll.h index 8df37e8c9149..c6b2ecb654fd 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 long work; + unsigned long long total; unsigned long state; struct completion exited; }; -- 2.34.1