Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3325078rdh; Thu, 28 Sep 2023 08:32:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiEJ0Ph5iYbClSHdnfURW7XwbNLn6O9o7hv5IgkCErB/pXA74ywC6ipKrHRSOnySWPe6tM X-Received: by 2002:a05:6a00:1396:b0:690:2ad9:1436 with SMTP id t22-20020a056a00139600b006902ad91436mr1995409pfg.7.1695915170928; Thu, 28 Sep 2023 08:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695915170; cv=none; d=google.com; s=arc-20160816; b=TzN73Ox0E1+E0SydwARMwXpfH5fXTFyE4WikUnYpoKzgYDfGvjmK/ebv02f4UZ3DES 4Rh8dDgn4gjJHDrfLYUz6DBfQE4+GTuOO1hQAht7azX1J8qr2/XKUfcHla9kn4bJS5oA ToOFmNe1NSOz73ZLDThpid64p8sZZHjPmAkxSaMOfh4Dkc+7stk769s4apWqjcztb4va iHGAKmUoFi9/39p0TXLPiyLXE5pvdtDAReYaNSTdVL9O4WsDNgkASx3X5oZQ5CNK1YSK GYokGfC4IqQ9HShxKCTB16RgsP7IeF517tm+/cQ6HAUHbBrx2dfGlsZRWKi7BvHl3grj dT0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Pse9Z+N4XlTYomnLZ/c/AzQ6F1EPTLngwTiS8AhkwVM=; fh=ieUoaKiSzKVBHFUU67WiEsvOKASQGdzAnrUqVqhkpN4=; b=WtJZBblzKA17aqfOLYgWUr8cmZzoSJlhpIwNw3eyuL4PFX0p+uNMJo0lwKsTCFdqgB FLU6ke65tBw4HoK9KAzJnbC55jv3U3rgkwyMSuIFznHHoqgM3lLpMftyrsbH2b64ZDBA t+6q3AueV5nP/hw5YC4KDL+lYrjzoh3qnl5Wjw2MwewPR5YDqPZkx2XbzUMFoAXDKOE3 P0hzxscaCJ7xLhS5XDv61VEAf19Uq2wrMqWqGTFWs73AgkrImaCYcXtkRGwjO3REZgiW Go87JZKcPEp6l2ZKWrfTk9QTf5Tp1C/012AtNBcvb+GEcnzXGL4qNLjdYrF4kTm3CFpE Smdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wAea2Si1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id y21-20020a056a00191500b0068fbbef7909si20234234pfi.256.2023.09.28.08.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 08:32:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=wAea2Si1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E3CD180C1113; Thu, 28 Sep 2023 01:01:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbjI1IBe (ORCPT + 99 others); Thu, 28 Sep 2023 04:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbjI1IBc (ORCPT ); Thu, 28 Sep 2023 04:01:32 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A49997; Thu, 28 Sep 2023 01:01:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Pse9Z+N4XlTYomnLZ/c/AzQ6F1EPTLngwTiS8AhkwVM=; b=wAea2Si11Soip4KcRtIzGqAym/ /tII41chyhGhRkmeymXBGGA79r6ggZ6FiRM5sZi3yEQuxT0/VCG1pyKlQxtAKr+nsc9+Yeiwb4/rk zc8zQyFsKDAHncUYF1HLwWDC0QpFA33umWWPNBER8Z0G6gzQcK9kMLPpW9kriXZcKn/8ou1qQGjwu xAiNPX/iBKDkvrTRauG96nxrN1FS5E5etSgN3kMp+LKka82LXi3mHvbp5WAhqHmXlQITypoJV8R2P gdwRPNK63l2nT+Rt62o/XFoToIctA4lzj8SzlekHfG8A3P8I+0DuwWltfEQRUG84P9b0UX4CUSEZg D1HSIn6w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qllxS-001Jhm-TW; Thu, 28 Sep 2023 08:01:15 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 9202E3002E3; Thu, 28 Sep 2023 10:01:14 +0200 (CEST) Date: Thu, 28 Sep 2023 10:01:14 +0200 From: Peter Zijlstra To: Xiaobing Li Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, axboe@kernel.dk, asml.silence@gmail.com, linux-kernel@vger.kernel.org, linux-fsdevel@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 Subject: Re: [PATCH 3/3] IO_URING: Statistics of the true utilization of sq threads. Message-ID: <20230928080114.GC9829@noisy.programming.kicks-ass.net> References: <20230928022228.15770-1-xiaobing.li@samsung.com> <20230928022228.15770-4-xiaobing.li@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230928022228.15770-4-xiaobing.li@samsung.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 28 Sep 2023 01:01:48 -0700 (PDT) On Thu, Sep 28, 2023 at 10:22:28AM +0800, Xiaobing Li wrote: > 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 | 26 +++++++++++++++++++++++++- > 1 file changed, 25 insertions(+), 1 deletion(-) > > diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c > index bd6c2c7959a5..2c5fc4d95fa8 100644 > --- a/io_uring/sqpoll.c > +++ b/io_uring/sqpoll.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > > #include > > @@ -235,6 +236,10 @@ static int io_sq_thread(void *data) > set_cpus_allowed_ptr(current, cpu_online_mask); > > mutex_lock(&sqd->lock); > + bool first = true; > + struct timespec64 ts_start, ts_end; > + struct timespec64 ts_delta; > + struct sched_entity *se = &sqd->thread->se; > while (1) { > bool cap_entries, sqt_spin = false; > > @@ -243,7 +248,16 @@ static int io_sq_thread(void *data) > break; > timeout = jiffies + sqd->sq_thread_idle; > } > - > + ktime_get_boottime_ts64(&ts_start); > + ts_delta = timespec64_sub(ts_start, ts_end); > + unsigned long long now = ts_delta.tv_sec * NSEC_PER_SEC + ts_delta.tv_nsec + > + se->sq_avg.last_update_time; > + > + if (first) { > + now = 0; > + first = false; > + } > + __update_sq_avg_block(now, se); > cap_entries = !list_is_singular(&sqd->ctx_list); > list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { > int ret = __io_sq_thread(ctx, cap_entries); > @@ -251,6 +265,16 @@ static int io_sq_thread(void *data) > if (!sqt_spin && (ret > 0 || !wq_list_empty(&ctx->iopoll_list))) > sqt_spin = true; > } > + > + ktime_get_boottime_ts64(&ts_end); > + ts_delta = timespec64_sub(ts_end, ts_start); > + now = ts_delta.tv_sec * NSEC_PER_SEC + ts_delta.tv_nsec + > + se->sq_avg.last_update_time; > + > + if (sqt_spin) > + __update_sq_avg(now, se); > + else > + __update_sq_avg_block(now, se); > if (io_run_task_work()) > sqt_spin = true; > All of this is quite insane, but the above is actually broken. You're using wall-time to measure runtime of a preemptible thread. On top of that, for extra insanity, you're using the frigging insane timespec interface, because clearly the _ns() interfaces are too complicated or something? And that whole first thing is daft too, pull now out of the loop and set it before, then all that goes away. Now, I see what you're trying to do, but who actually uses this data? Finally, please don't scream in the subject :/