Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3131920rdh; Thu, 28 Sep 2023 03:46:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8j+1laHb94kqRLcs1wK1yQDmPQYt0pwZBt464AEKjco9hwhDg3RvAn8huS/0PYh4umfjB X-Received: by 2002:a17:90a:43a3:b0:277:2d2d:9a37 with SMTP id r32-20020a17090a43a300b002772d2d9a37mr748224pjg.4.1695898013968; Thu, 28 Sep 2023 03:46:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695898013; cv=none; d=google.com; s=arc-20160816; b=krk0sf8g7eu6qI8l2KSrSc257z3ts46MqbOC8AkoFq6ujVTH17ubSGmmDiRFSsJEUf Vw+xlrLd2EDgSLZ/j7/AaGQjC/zABJ83Wal1tp7m3tHtZ2ZQGfPut8XYA1POFYeTO/yR /VbmMWg0C0vqRnazCKcy4fD/NK8H/H1kv2sXDAHtkVDf/clUqe/i0QoPhmh1bytN3kyI 2DeC0qkIyo+Nio2V53c4uMKAkVSnaLWxMmU5SO1cv94hNPNe7+o+m73tDNkVP3XqGgzt N4Bg2SPNVcHAjDr/7C7kSebrPeEIgwG5rjodl1AV0/aL5DciUxxfA2YBakfMIHAtXMoP o8LQ== 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:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id gf16-20020a17090ac7d000b00274e5b20e65si2842664pjb.50.2023.09.28.03.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 03:46:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; 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:6 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 DD931803DAD6; Wed, 27 Sep 2023 19:31:40 -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 S230038AbjI1CbA (ORCPT + 99 others); Wed, 27 Sep 2023 22:31:00 -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 Content-Transfer-Encoding: 8bit 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/wCLLxWi7kae8G81TuYS2fD1gubHASrzVbCxX5wLmN1Q5fAgqUOwrU7HYCN Q9OEDgSUPDVQyVMDlTxprQd4FdhGq5g0Gc1EqSIU9Of/X3OiMq0BON9/yL5WYJ18ENYNMBbo BpCF83zY1nEOzWEnSdO/oNXKBLV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EhzMSiK8D28LpQrxpiRWVqUW5ccXleak 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 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: 20230928023007epcas5p276b6e029a67001a6ed8ab28c05b2be9c 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:31:41 -0700 (PDT) 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: * -- 2.34.1