From patchwork Thu Sep 28 02:22:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaobing Li X-Patchwork-Id: 145722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3051028vqu; Wed, 27 Sep 2023 20:41:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHy0SzA1+nvLJdzSQZdDu0cBaHkUdv7Wk68FmpVQRr2Io/o53DIYxT+YUPyCqRkc1ynzfx9 X-Received: by 2002:a05:620a:2916:b0:767:f108:a5c6 with SMTP id m22-20020a05620a291600b00767f108a5c6mr58975qkp.57.1695872494372; Wed, 27 Sep 2023 20:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695872494; cv=none; d=google.com; s=arc-20160816; b=yK7aXFtBGnCIKpyGqkAjx2+gFFmK9xfhzDu2xgHgPcdaILqK6/ivOTznncJ727RgWq lfN29FSSMifkf4h2QKKx9Wk4pKBXcmRxZosFWdi1BErid1xTa/C1Atg+zqUkRxYonbPH mxO4pOm9aUR952QrAPhQ4WrSEc2RqzaC71tqddVJnnSoDFFZzCCkXc+/Kkhmyr7dKkbD R6I/t+EqlghDTs9NuyDd0WhKALTe5peRBbC2P/Tgr9WKgHYtt8G288m/YakTH5rv/GAP YgtxTZjmFg1YE1dbcoYCPoS2xfFUrIVEHNkD6M1a4beFPvTw2CK6vPRCBR5x3S3e7aJc tdvQ== 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:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=WTFp5Vr5HivTWCAVmF3NpzIT1Lf+kl+P72Qzrl5ReU0=; fh=+eathbumsBANWBAlCe60DQPXjfrrEcO5pvOovl5t+Vs=; b=Y98SqarFA/nXn7/9rQmCrU5XpVC+wnWxyqgumcnVoMeTNFkXykb2c71ZB1c7Vh9ZjM X4p4rdr1MqM7VD6xa7hYVVCqB3uhMYfKd0aYPfv1d+XH+k3bSV+wP1yyEPCT1XYVqiBo 4sw+2TAdYyGoUNBGXhvSY5jLTtMbT68n4+malicKJFD6s7XgoHrHobFDF5ZIlxCHHhh6 9nvFWdKaFse3TqGp7AGJSdvuAbm3aoN296yoNfhNl0EU/XLklBPoHrL2lxafU0B5A4yj EZYQKs9lmBvILW1xC3Xp4CkPJza2OctsjATnIrrA9nW6t96Ye1jRqp+kpMOKDBe2/vxN jyNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=nJovRlm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id fa25-20020a056a002d1900b0068fb3451deesi18872089pfb.290.2023.09.27.20.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 20:41:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=nJovRlm9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 6DCF380C4D69; Wed, 27 Sep 2023 19:31:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229983AbjI1CbB (ORCPT + 20 others); Wed, 27 Sep 2023 22:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbjI1Ca6 (ORCPT ); Wed, 27 Sep 2023 22:30:58 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EE2A94 for ; Wed, 27 Sep 2023 19:30:56 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230928023051epoutp021ca6a9cba20d84b2e534d51d8b35d17f~I7zCcUkme1142811428epoutp02U for ; Thu, 28 Sep 2023 02:30:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230928023051epoutp021ca6a9cba20d84b2e534d51d8b35d17f~I7zCcUkme1142811428epoutp02U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1695868251; bh=WTFp5Vr5HivTWCAVmF3NpzIT1Lf+kl+P72Qzrl5ReU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nJovRlm90U27App2zIv+RwExHtWMHY58jCgaD0Y9+lF5bZjGyLqpMvd4RbdgVkHi8 m82y6WuVl0ot4lYaqMhPnvixxqHmu/WHltOWpaAjMXfvwnNJ9K+AhKYhNrtLRn6A69 KMllS4jTltpi9QO9JF6Ycn5cPFGx4EidNcmNiESI= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20230928023051epcas5p3bb33ed4fac719af1ef5da9dbde1d462a~I7zB7wbo_0480204802epcas5p3w; Thu, 28 Sep 2023 02:30:51 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.182]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4RwyBx645Wz4x9Pv; Thu, 28 Sep 2023 02:30:49 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 8C.8C.09638.955E4156; Thu, 28 Sep 2023 11:30:49 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20230928023007epcas5p276b6e029a67001a6ed8ab28c05b2be9c~I7yZllfei3125231252epcas5p25; Thu, 28 Sep 2023 02:30:07 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20230928023007epsmtrp27b4006b9f4955f51fedfe4f3bec4afa6~I7yZkeGmo1134711347epsmtrp2t; Thu, 28 Sep 2023 02:30:07 +0000 (GMT) X-AuditID: b6c32a4a-6d5ff700000025a6-af-6514e5594fc0 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id FD.9B.18916.F25E4156; Thu, 28 Sep 2023 11:30:07 +0900 (KST) Received: from AHRE124.. (unknown [109.105.118.124]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230928023005epsmtip16085199ca976dd349f984fe31ae0ee3a~I7yXilTaC1182111821epsmtip1C; Thu, 28 Sep 2023 02:30:05 +0000 (GMT) From: Xiaobing Li To: mingo@redhat.com, peterz@infradead.org, 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 Cc: 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, Xiaobing Li Subject: [PATCH 1/3] SCHEDULER: Add an interface for counting real utilization. Date: Thu, 28 Sep 2023 10:22:26 +0800 Message-Id: <20230928022228.15770-2-xiaobing.li@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928022228.15770-1-xiaobing.li@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02TfUxbVRjGPfdeLoWleFdQzkoUrKCBDWih1MOkZJnMdB8mqMnmxxQr3BVC abveVoczE8cIjI1RMYAyWCoYXAAZ30KFgnS4McKQMmR8dKNhTBgZLgzohAn2A9z++71Pnue8 ed9zDgvnLJFcVopCQ6sVUjmP9CRaTMHBoe9P+9B8w3AIKq1qAajakk8i89QwiYpnvybQtK4Z R/NZ1wnUs36fRJb8QgKtnLEA1Ly45IbaO3oJNGQoJdG383cBMnfpMXS3wwNdyevCkDFnEkOL Jps7yrm8jKPmHjsVNrViKOfUENj1vKTmQg2QtJVY3CWnjGPuEn2DVtJ4MUQy1K+VTPzZTkr+ Ng6TknNNVUDS2Hdc8rDhxfgtH6TGJNPSJFodQCsSlUkpCpmYt//dhDcSokR8QaggGr3GC1BI 02gxL+5AfOibKXL7qLyAz6RyrV2KlzIMLzw2Rq3UauiAZCWjEfNoVZJcJVSFMdI0RquQhSlo zU4Bnx8RZTd+kpp89ncTpmr3P3azxURmgJltuYDFgpQQdtkic4Eni0P9CmBm/pibq1gA8Lvx 2SeFac5IbCbaFt9y6W0A5tTfI3OBh72YBbBaL3MwSW2HI7W5zrAPdRqDhorbzgKnCjBY0zTg 5nB5U29DXVMZ7mCCCoLzt0fdHcymYqCx5wcnQ8ofdv7W7/R4UGLYueDqxqa2wt7v7xAOxu2e zObzuKMBpB6xYFllC+4Kx8HR9dYN9ob3rjRtHMqFD+c7SBcz8PJZm5srnAFg8fjwhul1uHaj 3TkzTgXDS4Zwl/wCLLxWi7kae8G81TuYS2fD1gubHASrzVbCxX5wLmN1Q5fAgq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YEcIQRUc2SlO0S5oMTJmU9YQGxmoPLmrbOZJzAKzEKSmoUktYCRaRWjaGpBcW56bnKBoV5x Ym5xaV66XnJ+7iZGcExqBe1gXLb+r94hRiYOxkOMEhzMSiK8D28LpQrxpiRWVqUW5ccXleak Fh9ilOZgURLnVc7pTBESSE8sSc1OTS1ILYLJMnFwSjUwya/1EHQUdczbk1/obSQtXKcdVflS l135xNtJ/A4CL1eb563qOegYELrujh3Xj6fLjrVe7VkjfHtm45snIsocYdNPtffFPEv0qlu0 v/1p2u3WeUdLz9ctr2c1bDOYspP5SdIZh6kbLeszp22bHCj6X7vt47ZjS4zP8b52M+l7dFHX bId/4dHGbZUL/zJenxPWHqbedm7HwjkudhmMi6q3vjn1N/N+y0HOpWkTPf6fYBFM5rglsvWW i2H1ZdfAnIMXK+a933n39wnnyM/h63NXhd+sqfm+JD+tQadkY1bypR3aMuZ5/aFOhy7uV1m1 O+5IaFW3YWf6cyNNzb9Vi9xvXpN4vni1jc4Pu4DY0C9MSizFGYmGWsxFxYkAWRRgXjgDAAA= X-CMS-MailID: 20230928023007epcas5p276b6e029a67001a6ed8ab28c05b2be9c X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230928023007epcas5p276b6e029a67001a6ed8ab28c05b2be9c References: <20230928022228.15770-1-xiaobing.li@samsung.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 19:31:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778251196822719090 X-GMAIL-MSGID: 1778251196822719090 Since pelt takes the running time of the thread as utilization, and for some threads, although they are running, they are not actually processing any transactions and are in an idling state. our goal is to count the effective working time of the thread, so as to Calculate the true utilization of threads. Signed-off-by: Xiaobing Li --- include/linux/kernel.h | 7 ++++++- include/linux/sched.h | 1 + kernel/sched/cputime.c | 36 +++++++++++++++++++++++++++++++++++- kernel/sched/pelt.c | 14 ++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index cee8fe87e9f4..c1557fa9cbbe 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -37,7 +37,8 @@ #include #define STACK_MAGIC 0xdeadbeef - +struct cfs_rq; +struct sched_entity; /** * REPEAT_BYTE - repeat the value @x multiple times as an unsigned long value * @x: value to repeat @@ -103,6 +104,10 @@ extern int __cond_resched(void); #elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL) +extern void __update_sq_avg_block(u64 now, struct sched_entity *se); + +extern void __update_sq_avg(u64 now, struct sched_entity *se); + extern int __cond_resched(void); DECLARE_STATIC_CALL(might_resched, __cond_resched); diff --git a/include/linux/sched.h b/include/linux/sched.h index 77f01ac385f7..403ccb456c9a 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -583,6 +583,7 @@ struct sched_entity { * collide with read-mostly values above. */ struct sched_avg avg; + struct sched_avg sq_avg; #endif }; diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index af7952f12e6c..824203293fd9 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -479,6 +479,40 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st) #else /* !CONFIG_VIRT_CPU_ACCOUNTING_NATIVE: */ +void get_sqthread_util(struct task_struct *p) +{ + struct task_struct **sqstat = kcpustat_this_cpu->sq_util; + + for (int i = 0; i < MAX_SQ_NUM; i++) { + if (sqstat[i] && (task_cpu(sqstat[i]) != task_cpu(p) + || sqstat[i]->__state == TASK_DEAD)) + sqstat[i] = NULL; + } + + if (strncmp(p->comm, "iou-sqp", 7)) + return; + + if (!kcpustat_this_cpu->flag) { + for (int j = 0; j < MAX_SQ_NUM; j++) + kcpustat_this_cpu->sq_util[j] = NULL; + kcpustat_this_cpu->flag = true; + } + int index = MAX_SQ_NUM; + bool flag = true; + + for (int i = 0; i < MAX_SQ_NUM; i++) { + if (sqstat[i] == p) + flag = false; + if (!sqstat[i] || task_cpu(sqstat[i]) != task_cpu(p)) { + sqstat[i] = NULL; + if (i < index) + index = i; + } + } + if (flag && index < MAX_SQ_NUM) + sqstat[index] = p; +} + /* * Account a single tick of CPU time. * @p: the process that the CPU time gets accounted to @@ -487,7 +521,7 @@ void thread_group_cputime_adjusted(struct task_struct *p, u64 *ut, u64 *st) void account_process_tick(struct task_struct *p, int user_tick) { u64 cputime, steal; - + get_sqthread_util(p); if (vtime_accounting_enabled_this_cpu()) return; diff --git a/kernel/sched/pelt.c b/kernel/sched/pelt.c index 0f310768260c..945efe80e08c 100644 --- a/kernel/sched/pelt.c +++ b/kernel/sched/pelt.c @@ -266,6 +266,20 @@ ___update_load_avg(struct sched_avg *sa, unsigned long load) WRITE_ONCE(sa->util_avg, sa->util_sum / divider); } +void __update_sq_avg_block(u64 now, struct sched_entity *se) +{ + if (___update_load_sum(now, &se->sq_avg, 0, 0, 0)) + ___update_load_avg(&se->sq_avg, se_weight(se)); +} + +void __update_sq_avg(u64 now, struct sched_entity *se) +{ + struct cfs_rq *qcfs_rq = cfs_rq_of(se); + + if (___update_load_sum(now, &se->sq_avg, !!se->on_rq, se_runnable(se), qcfs_rq->curr == se)) + ___update_load_avg(&se->sq_avg, se_weight(se)); +} + /* * sched_entity: * From patchwork Thu Sep 28 02:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaobing Li X-Patchwork-Id: 145743 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3076755vqu; Wed, 27 Sep 2023 22:01:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSoawuwz7B4QrksXRLJV6zlinFZbMEhCZAu3BQBZzfHMDGX9hEBVl85unMSGVjOxjNLQ6t X-Received: by 2002:a05:6870:1686:b0:1bf:df47:7b5d with SMTP id j6-20020a056870168600b001bfdf477b5dmr213520oae.24.1695877297681; Wed, 27 Sep 2023 22:01:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695877297; cv=none; d=google.com; s=arc-20160816; b=xMIXH0dG7JdBEJ0NSbzQn+U9Lmn335DJAu+iNMotZrcs/H/ELaUfijPzZq8cdWMOgS bnipuxelvnQ6BKX5CJpofV/AOZU2W+Phlb3vaw2Me72XTIrFZ1tDy0WJBR/Q/JLlwjLL 0YgWC8A0rbdVn7a3XaxC9iw8FdVO8JfJAAszAXhXAQioqELmQ/S8wLUwS/0VEIv1Ohho wONl1DTFS2vUOUUxS53CyqlgxFE6vJA73z/7f0dx7qGrkwWeHe+jvlVoinF8TCw+xcos saC6kfadw592/XAjd/xZZeTmHrnsn+vi6HaPS+HHLhtVU+M3Bg9/4ED2i5hETVjWsezX o4GA== 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:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=IPFMkhvUhh2Nbce6Uqs8Hy4irIy4VWJBDhiYhVwQ2kI=; fh=+eathbumsBANWBAlCe60DQPXjfrrEcO5pvOovl5t+Vs=; b=ogKZAWYNnFjTzOx9cVQms7+tEluAAsFjplN1tBa4ltzN+lAKzacUGcZy2opHiVI63e IjxTab4MK4vt0Yqs6156q2ug35XRKRePgE9iGgNWUgEuXhuvCEhGpOl8F+i1u+Itg22P tE8vrf/doaH2/Ns9DROI9/QAzTOrDErVuKO3yJM0buXLgZNgZux76rxYeDhz44y1uWOT PZjknZ+JHkytK/xjIkkzyJ2mE29teMYhiuiyY0vBXUeH2DrtDPor9bm7/klkCExBM6CK Id5mcKqtgA05woPWpUPhdGRXQ1N73lbJ+Vlutbh4oeAQtpvxSVmaJ27ZVjcV8/rG4Sd2 5B5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=qs9Ux3U7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id x4-20020a63db44000000b005849fe1d3aesi7039135pgi.458.2023.09.27.22.01.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 22:01:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=qs9Ux3U7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id CF35E81A05B4; Wed, 27 Sep 2023 19:31:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230074AbjI1CbD (ORCPT + 20 others); Wed, 27 Sep 2023 22:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230052AbjI1CbB (ORCPT ); Wed, 27 Sep 2023 22:31:01 -0400 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D33018F for ; Wed, 27 Sep 2023 19:30:59 -0700 (PDT) Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20230928023055epoutp024c6af1765b88fcd65080b4675198f300~I7zFxtaVt1695016950epoutp02E for ; Thu, 28 Sep 2023 02:30:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20230928023055epoutp024c6af1765b88fcd65080b4675198f300~I7zFxtaVt1695016950epoutp02E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1695868255; bh=IPFMkhvUhh2Nbce6Uqs8Hy4irIy4VWJBDhiYhVwQ2kI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qs9Ux3U7LyzvYXOG/cNX98M1PG5ui1nrhd1zpuitIwRCNnv+7deA3fNcuH0Qwy8ul eJ93Kmk0kFIS+KsW2G8ydSeqIJTPEbKNJL7GVwxT+lmTvvyl5EsSowbblCwgnrKRpO NS27q9RVAH1H8dvAztn1U0wbXssmIRKbX09nPin0= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20230928023054epcas5p415ca6b1d7463b9c2a135b47edd2030a3~I7zFFNtnQ0071000710epcas5p43; Thu, 28 Sep 2023 02:30:54 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.181]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4RwyC12sqZz4x9Q1; Thu, 28 Sep 2023 02:30:53 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id BA.FB.09023.D55E4156; Thu, 28 Sep 2023 11:30:53 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20230928023011epcas5p32668b193b447f1cd6bf78035f4894c42~I7ydaBPLU2327723277epcas5p3z; Thu, 28 Sep 2023 02:30:11 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230928023011epsmtrp10b18654ae936abd952c42aa65696781a~I7ydY1_vL1037210372epsmtrp1J; Thu, 28 Sep 2023 02:30:11 +0000 (GMT) X-AuditID: b6c32a44-a21ff7000000233f-28-6514e55d9751 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id EB.49.08788.335E4156; Thu, 28 Sep 2023 11:30:11 +0900 (KST) Received: from AHRE124.. (unknown [109.105.118.124]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230928023009epsmtip18196df64eb77d978dfc95071ab3bc7d8~I7ybU1qZW1182111821epsmtip1F; Thu, 28 Sep 2023 02:30:09 +0000 (GMT) From: Xiaobing Li To: mingo@redhat.com, peterz@infradead.org, 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 Cc: 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, Xiaobing Li Subject: [PATCH 2/3] PROC FILESYSTEM: Add real utilization data of sq thread. Date: Thu, 28 Sep 2023 10:22:27 +0800 Message-Id: <20230928022228.15770-3-xiaobing.li@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928022228.15770-1-xiaobing.li@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA01Te0xbZRT3u/f2toCd11K3D9DZ1PAHdDw62vJ1A10c6sUniWYxZNo19FqQ vtLbytBFS9wECxvoJJOOVzY1Bgooj8lYeayAezCEUGFzg0zCYwGyuQeMZGxgyy26/36/c87v +51zvhwBLlomIwU5JhtjNWkNUjKUONUbExP3wYyYSXRfDEeVdacAqp8oJdHI1CiJjs0VEGim rA1Htw79QaD+tZskmigtJ9CD4gmA2haXeMjTeYFAvo5KEh29NQvQSE8thmY7Q9C5wz0Y6ir6 G0OLvct8VNR3H0dt/X5U3tqOoaKDPrBrM+2udgP6tGuCTx/susqna5vtdMvPsbRv0E6Pj3lI +p+uUZI+0loH6JaBz+h7zVszwjJzU7IZrY6xShhTllmXY9KnSt94V7Nbo1QlyuPkapQslZi0 RiZVmvZmRtyrOQb/qFLJJ1qD3R/K0LKsNOHFFKvZbmMk2WbWliplLDqDRWGJZ7VG1m7Sx5sY 2w55YuJ2pb9wX252Q/F3wPITtd9X4gAOUCh0ghABpBTwr5JWzAlCBSLqDIDO0SXAkbsANpx/ SHLkvp9MloANSUHbEM4lOgFsHPARHJkD8EbvUSxQRVIyeLnRyQskxNTXGOw4eX2d4NS3GHS3 DvmJQBBOvQO7josDAoKKhtN9Y2QAC6kU+Kh7jc/ZPQ+7zw7iARxCpcLuu/PBmqfhhYppIoBx f82XbcfXW4LUmgCOPxzFOHEa9AwukRwOh/PnWoOPRsK50q+CmIV9Jcs8TuwA8Ni10WBiJ1z9 00MEGsWpGNjUkcCFn4PlFxsxzngTPLwyHfQSwvbqDRwN60cmCQ5HwQXHSjBOw8X6MT63rjIA Lw3f4ZUBieuxgVyPDeT637oW4HUggrGwRj2TpbTITUzefx+dZT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qeV6xYm5xaV56XrJ+bmbGMGxqaW1g3HPqg96hxiZOBgPMUpwMCuJ8D68LZQqxJuSWFmVWpQf X1Sak1p8iFGag0VJnPfb694UIYH0xJLU7NTUgtQimCwTB6dUA1Nf9V+2Ct3oueydIt91Ahea nqoRNbwe/qCFf2WcZNgDm2/nz925fMH/6eFL7P5bG/yMQ+62yvefyhQomcdqHrOL+fO1u8k7 b1/udDy5YFq3c84Op+C3egtn+csGyJU3rZ8vp1TH8vJB2aLA8EQ+Y4v3z6fdDbovnDx/e/w0 3omeKeeTBfbV6kfJdp7Sij2x1ojhHbu/2DQf9uOpzgoffm97I2DEkrVVruHq3a0fK+fJlnkG 7WlaMoHHULyUPb5LSf9Ap/oWX6b5V/Y/9frXENZavM6S5zHH5a0Cchzuov/XHeqd6nBw6q6D lQ03o8RfmH7i3nDgvJ2zt/3jbRyOJ3oz0to9Dkdeq6pg0jlir8RSnJFoqMVcVJwIAO4Q/SI8 AwAA X-CMS-MailID: 20230928023011epcas5p32668b193b447f1cd6bf78035f4894c42 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230928023011epcas5p32668b193b447f1cd6bf78035f4894c42 References: <20230928022228.15770-1-xiaobing.li@samsung.com> 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.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 (agentk.vger.email [0.0.0.0]); Wed, 27 Sep 2023 19:31:49 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778256233039900168 X-GMAIL-MSGID: 1778256233039900168 Since it is necessary to count and record the real utilization of the sq thread, it is recorded in the /proc/stat file. Signed-off-by: Xiaobing Li --- fs/proc/stat.c | 25 ++++++++++++++++++++++++- include/linux/kernel_stat.h | 3 +++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/fs/proc/stat.c b/fs/proc/stat.c index da60956b2915..bd86c0657874 100644 --- a/fs/proc/stat.c +++ b/fs/proc/stat.c @@ -79,6 +79,29 @@ static void show_all_irqs(struct seq_file *p) show_irq_gap(p, nr_irqs - next); } +static void show_sqthread_util(struct seq_file *p) +{ + int i, j; + + for_each_online_cpu(i) { + struct kernel_cpustat kcpustat; + + kcpustat_cpu_fetch(&kcpustat, i); + struct task_struct **sqstat = kcpustat.sq_util; + + for (j = 0; j < MAX_SQ_NUM; j++) { + if (sqstat[j]) { + seq_printf(p, "%d %s", sqstat[j]->pid, sqstat[j]->comm); + seq_put_decimal_ull(p, " pelt ", + (unsigned long long)sqstat[j]->se.avg.util_avg); + seq_put_decimal_ull(p, " real ", + (unsigned long long)sqstat[j]->se.sq_avg.util_avg); + seq_putc(p, '\n'); + } + } + } +} + static int show_stat(struct seq_file *p, void *v) { int i, j; @@ -187,7 +210,7 @@ static int show_stat(struct seq_file *p, void *v) for (i = 0; i < NR_SOFTIRQS; i++) seq_put_decimal_ull(p, " ", per_softirq_sums[i]); seq_putc(p, '\n'); - + show_sqthread_util(p); return 0; } diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h index 9935f7ecbfb9..722703da681e 100644 --- a/include/linux/kernel_stat.h +++ b/include/linux/kernel_stat.h @@ -11,6 +11,7 @@ #include #include +#define MAX_SQ_NUM 16 /* * 'kernel_stat.h' contains the definitions needed for doing * some kernel statistics (CPU usage, context switches ...), @@ -36,6 +37,8 @@ enum cpu_usage_stat { struct kernel_cpustat { u64 cpustat[NR_STATS]; + bool flag; + struct task_struct *sq_util[MAX_SQ_NUM]; }; struct kernel_stat { From patchwork Thu Sep 28 02:22:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaobing Li X-Patchwork-Id: 145790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3114077vqu; Wed, 27 Sep 2023 23:43:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEnHvVTBYLHdh1UscqgdtrdCoZU9FAZko7zlTfYw+ul9afVKX/MezN0z/auyxjpfEQHVQQm X-Received: by 2002:a05:6a20:3d0a:b0:161:3120:e840 with SMTP id y10-20020a056a203d0a00b001613120e840mr466204pzi.2.1695883384205; Wed, 27 Sep 2023 23:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695883384; cv=none; d=google.com; s=arc-20160816; b=IGd55BT2kIVELQBDeCJ3FCTJzlVDFSCxr5sQFn63Ww/TFjJuS9+5wozhn4WijsK6vt 1vxZok1tXWZW3zdZbaG8dAM5aOdiHajVHmGuJajTHk44bT3wU8e/ibxgDwstyg9C/Q5E mZXLHUzAf3wh/ywLOHQMGZz+wZYDiGpuZOFe07XCpdRWd/wAVSHtrSvjGbr4QrJ13vFq 5mniqaAU4ITUdZqd9UOWXm0ONSpYWLXAJqxchkPObZN1Ar8HNBBB+VhkyvuDcnsK1meR EAZOCg29PSPO9cYOXsAjsXl3Fi9Zpfnf6qCBJvGX//YteUhrJvurVR6X8r+zq89U8nUd PEAA== 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:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=phR98v9y8l1Bi3dNmiWC+zZrMiNiEm3JGyrCS7t+Eok=; fh=+eathbumsBANWBAlCe60DQPXjfrrEcO5pvOovl5t+Vs=; b=KcvH26RDE80nMr24jMr4XL1YSk/GZeEmGQdAFe8ZDRrssRZtzYU302BmjkzZkLWb7H 9RbA9EYruKiZ38xh/9qFEej2O1CFZIRcEUGwKOORI+e87AiZItZ6vr5IGjrAwksA5dD8 XSJXmAWLtfKVFnqlNeEwmjt6oYzU4y/LuiCZ0dcH9kl24Dkv3C89qESNYP14btDD/8cr hNpk0aZ2vBGlDgfyKOvAABDHQxZHvjwkqLj1+OPIlnQLeUrhGCv0Owj54Mcx7wo9hX3C 9JqKtMCnrffHAnIilplt6/95bOfYqnk7S5jvZjUHBXNzZgo//YgQccqKbWic32vWaiAX aClg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=XVqyCjSf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id bg7-20020a17090b0d8700b0026839b09526si17247473pjb.96.2023.09.27.23.43.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 23:43:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=XVqyCjSf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 56FF7802C932; Wed, 27 Sep 2023 19:32:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbjI1CbL (ORCPT + 20 others); Wed, 27 Sep 2023 22:31:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbjI1CbI (ORCPT ); Wed, 27 Sep 2023 22:31:08 -0400 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DDF218F for ; Wed, 27 Sep 2023 19:31:02 -0700 (PDT) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20230928023057epoutp034723d8e18846fe83122b7616137da5b6~I7zIL1wTB1997519975epoutp03X for ; Thu, 28 Sep 2023 02:30:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20230928023057epoutp034723d8e18846fe83122b7616137da5b6~I7zIL1wTB1997519975epoutp03X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1695868257; bh=phR98v9y8l1Bi3dNmiWC+zZrMiNiEm3JGyrCS7t+Eok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVqyCjSfVkpXkZtNLYrxJ+uKezwBblPMudywJ24y5fU5AbIySzy6rYRbjenHUXgjR VYgHS76D+LlWY3GnXA8hF6ppB+ZZuIXTnlFuQMOUqLR8iomIf5PInQouFMhkhZVKlU W+Ydtvu/UZjGloqcsb9J88lh3A3dl16NGe0gq0tQ= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p3.samsung.com (KnoxPortal) with ESMTP id 20230928023056epcas5p32063873a28ff1bc19c778e0760db6d76~I7zHOssCf2816728167epcas5p3q; Thu, 28 Sep 2023 02:30:56 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.179]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4RwyC33Ty0z4x9Pw; Thu, 28 Sep 2023 02:30:55 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 6B.E8.09949.F55E4156; Thu, 28 Sep 2023 11:30:55 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20230928023015epcas5p273b3eaebf3759790c278b03c7f0341c8~I7ygcFF7M1568415684epcas5p2I; Thu, 28 Sep 2023 02:30:15 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20230928023015epsmtrp17ca3517f88f3ddab7dfa50ab843be849~I7ygbGHI91037210372epsmtrp1c; Thu, 28 Sep 2023 02:30:15 +0000 (GMT) X-AuditID: b6c32a49-bd9f8700000026dd-c2-6514e55f29fb Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 12.AB.18916.735E4156; Thu, 28 Sep 2023 11:30:15 +0900 (KST) Received: from AHRE124.. (unknown [109.105.118.124]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20230928023013epsmtip1eab11b66930a2274adf827fb2e468e3e~I7yedTBhZ1192811928epsmtip1u; Thu, 28 Sep 2023 02:30:13 +0000 (GMT) From: Xiaobing Li To: mingo@redhat.com, peterz@infradead.org, 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 Cc: 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, Xiaobing Li Subject: [PATCH 3/3] IO_URING: Statistics of the true utilization of sq threads. Date: Thu, 28 Sep 2023 10:22:28 +0800 Message-Id: <20230928022228.15770-4-xiaobing.li@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928022228.15770-1-xiaobing.li@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Te0xTVxzHPffe3hZc9VoYHJlo0+mmEB51bTkoGJeZ7aJsYyPLsodgQ+8o obRdb7sJmK0bYhjYgRhwMGQYIpkImhXqABGRwipbUFLEZUBV5LHxUAYDVFRcy8XN/z7n+/t9 83uccwS4aI4MEKRojYxBq9RISG/inH3L5pDEEV8mfN7ij8qqzwF02pVPIudQL4mOjX1FoJEC G47uZl8hUMeTOyRy5RcRaCHPBZBtdo6Hmi90EqinqYxER++OAuRsrcDQ6AUv5LC0Yqgl5xaG Zu33+CinfR5Htg43FdU3YCjnYA/Y6UfXlNcAurHUxacPtvTx6Qqria77MYju6TLRA9ebSXqq pZekv62vBnTdb5n0P9b1cSs/TI1SM0oVYxAz2iSdKkWbHC3ZE5/4WqJcES4NkUaiCIlYq0xj oiW7YuNCXk/RuEeViD9TakxuKU7JspKwHVEGncnIiNU61hgtYfQqjV6mD2WVaaxJmxyqZYzb pOHhW+XuxH2p6hMjl3n6J6L9VyfO4mZQvToXeAkgJYMdtacID4uo8wCWPH6T4xkA7Tm7c4E3 xwuzTiwXCJYMNos/pzcCuFgyALjDGIDWWRfmcZNUMPz9TC7PE/ClvsFgU+XNpQNOFWKwpv4q z5PlQ70LR06aSQ8T1CY4Yx1bcgupKPho5ATJ9bcBXrzUhXvYi4qGF2fGSS5nDewsGV7qG3fn ZNm+xz0FIHVfALOy53DOvAvWzxXyOfaB4476ZQ6AY/mHlpmF7Yfv8TizGcBj/b3Lge1w8Voz 4Rkap7bAs01hnBwIi349g3GFV0HLw2GM04Wwofwpb4KnnYMExy/ACfPDZZ2Gx+fzMG5fBQCe /GmIKADi0mcGKn1moNL/S1cAvBqsZfRsWjLDyvVSLfP5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z03ucBQrzgx t7g0L10vOT93EyM4JrWCdjAuW/9X7xAjEwfjIUYJDmYlEd6Ht4VShXhTEiurUovy44tKc1KL DzFKc7AoifMq53SmCAmkJ5akZqemFqQWwWSZODilGpi2Xvr/WOVFk6fihfnXdgk/2sc3k5+9 dc4p32NdoTekLLX7/V+3TBf9ZGXR9qLsFp9J/Z7+NA6DNK6FiaccT4e0ntCJuhL+fL5pevDK qgx+z4o5/UbrNvw+uCzYi/fXwTh+c63k7816t3s0b26wzLj6TMHUurX10IKNEoemb930xzX9 7M7gPXv6TK6yZ0XmMu/8N2Oj6c5Mxo8RHzLWqLjtlZrxUMjupFBWMFd8Y2KuwiULw29c0paa eZUPrlo/N7Iq3D5D/DvfqtqpVh8qVfb6MUhUP07Ive8133mKzbKnJS81H6zrnOusm7/7dvIS 0z+3nru6eF18pdp9tN/e69HCjQKKe5w2nshZ8S1TMk+JpTgj0VCLuag4EQAFHibMOAMAAA== X-CMS-MailID: 20230928023015epcas5p273b3eaebf3759790c278b03c7f0341c8 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20230928023015epcas5p273b3eaebf3759790c278b03c7f0341c8 References: <20230928022228.15770-1-xiaobing.li@samsung.com> 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 19:32:22 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778262615551586430 X-GMAIL-MSGID: 1778262615551586430 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;