Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp95571lqs; Thu, 13 Jun 2024 05:08:19 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXuQwKRGDjWaWryeJFM6kLpQbhfSZTYHdHQf+HUAt/yb7d2Oq6RFLbrsxPWg/q1SJZs8eK+64gnv+SF0Ci0wCUUYGXX5zcaJOHHrruHKw== X-Google-Smtp-Source: AGHT+IEBbpRN/OPlUIJDnuANY5YQ/qwSzruxKfU1wjrcUF8w3HYOYM/BdelBxa3+M5jxkZwA0HSs X-Received: by 2002:a05:620a:3729:b0:792:93cf:b91d with SMTP id af79cd13be357-797f603fc63mr509294885a.40.1718280498902; Thu, 13 Jun 2024 05:08:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718280498; cv=pass; d=google.com; s=arc-20160816; b=S2kaMF1x7yv9gmOWt7invlV927PMKJSS2fLjEqOvij0PYcn7dSc9LAX2c5A6eY6A7A +e6LXnZiQnIDfBg7pvj0kbhsMeckZJNEmf0hg4jAww552PCDTjk+hhEzQNlkKm7ltPEM 5c9my06aFbAx4EG19GuwlIJ/XoTF+rlY6R8j8Vc7YO/ERxlcKFu7ct+b2zTqg1CxDvXj Vu2nHuFzmSm2OL5jxGiBCiVwmJcjwqMYKt1QSpxz9nwoGNNhsyq2DzkTg7nUCWez2nRx kMvJc3nyD3O2gNp08tYkExsbh+8j6hMLhsLT5LGPH+CHa5dHrgfVdkEAHYB+02RA5S9m KTow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=RKA/VUM/a9F8ecl/GN0yeGv3buwPv6S6vu54++YIlkQ=; fh=1fy+vQDDCKx3rea82+IglQ6QwdzrAZBAFDdxZWyGyWk=; b=QtkoNwOqg8edIegIp2efil8fvJzSd+/i5RPmAzn56c2zOJML05kqmweSNuLkjLPyog SHMD8CuBSmS8i216YdUc+Wx2PNdieWZEdgZm6lDMfregpt09got3NGxhiSyP8HvDYYhT vAf1NmcDLW12OyDOPwI3cGkiRLgcWbSJ+hCnqRoAGOfHljYYxMhJYSrNpFiXE03mmMl0 +sYqxKbAmM1zsGRCuMgebutuRKmPA4Oj51CXoz3rxAKI/J0xs/nd9uRXd2LNkbeOOGxW Yq0GLojt/SccMcMzhH8EGrvvsfrIWJPpHbuDR8XFVricMHSHmHUoaAOd0Fuv2/rhYSvE jE+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UlFvmOx9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-213167-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213167-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-798aac9cca1si118220185a.89.2024.06.13.05.08.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 05:08:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213167-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UlFvmOx9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-213167-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213167-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 82A8E1C21975 for ; Thu, 13 Jun 2024 12:08:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AAF8146010; Thu, 13 Jun 2024 12:03:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UlFvmOx9" Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4D8314600C for ; Thu, 13 Jun 2024 12:03:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718280185; cv=none; b=NiR3Jv44Xk6XcJAcKhO0f11IfA8GSXdNY2cf8ofZjmM3J37jzw3BaXMmpx4/x2eq2Qap5XOPp2yyRrKevo7sWAWBa2K5G0oREr3QoZ5dY3Mvp4TMVbNQzuBhMCSNbq3nvCBEDz91GFUV2QZ7rcbqGW10PwUHfOJN1o9AOvzIv4o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718280185; c=relaxed/simple; bh=BOQnWw+R6xqgs1kCZYtL4uxwTR527cu00+c0814eQK0=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=TH74v9em+ZSoDdljobrfbaB71yi54hkilfQ//McgzRW+fSNWPH3ANeDZgXHr3LxWIT0bJrLccsi742bOoH7Uk02dQw9KYpcOXcLPWCP4acoE1zFY9PeWYo4CR0+eHaYfIR9kcVOMC+ir5g9uIiuWCQAnLE8qnlSthApXbgyMwtM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UlFvmOx9; arc=none smtp.client-ip=209.85.160.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-4403bb543a4so5276491cf.1 for ; Thu, 13 Jun 2024 05:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718280183; x=1718884983; darn=vger.kernel.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RKA/VUM/a9F8ecl/GN0yeGv3buwPv6S6vu54++YIlkQ=; b=UlFvmOx9KwgsQlV06OgyyiD1Znh9Nfjzy1U2enBGNT2MFGkKZ0kyLC0jffkKH3RjZi H0oQpeerDWMAeleMZNnS+x5S2QB2Hac4F8XLfEgoj4cb/t8smI6087zt4OF0taEeMDeb X96EliEUhf58ch63WpiKA0n6edaT3jAedj7NCHiOeTv4eoTjgpugNnHA4q4uD/k2HmwW im1ko980MFk7YIJ4hTnDi6GU1xkDRxCfmqla9UBP0wuiyP5Cx/SduOWFVAXq9h8QkV3h pwIc2NUXv0hmMH8u+zhVNizy4fMTxZTNV2qz7TziFLGZ1H7CIfgp1Im+tOEqphQ5Aq+O JASw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718280183; x=1718884983; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RKA/VUM/a9F8ecl/GN0yeGv3buwPv6S6vu54++YIlkQ=; b=dPFTZUkbl0HpwZj23Ek0bju3cf2DpWE+ekNQbi9Lmays6H+2Wl2hFy/H/KAV3VsBV7 04OjPbvqhMrvgHvuB2JJnTa4psh3i2UjFQMddjQxmr3W2gpwkFbH3Gw5zJHfgWk5TxRK WOCufiCUbtKQz9qpIYI03Md72sbjClQs13cqqSDRcXYjLS3d0Ax3vX6JuW32bZA4YJAY 4QjKEaWfsLzMc4hEdYj3fkApqnR5r9hlCCvKnzfmXnhBvS88ekQfl+F0qBE13LuSVTHx Q2eKQ6jx3qgtkP85TQGmVz1j6Dt+qzznUpudoK0PO2xq+XqNJUnC1Szr3VRE8VmcYno5 77lg== X-Forwarded-Encrypted: i=1; AJvYcCVQwdVBYvNnZjyjfDduhbBI+5IIDgNJMN89WlK7+NA4LG9XDXDnZoKETO+HrpzBiMYJTxdkvK0n6IJW6dd4VxutuD+QnpUdXh+tsFFW X-Gm-Message-State: AOJu0YwFzpTZar7A+OWetz41r/qmqG7nA4FwE0KK5LWWWZkQyhLmRw11 aExMTeqp4da4VNtohAmmVRJLmo6TIYThg7GcaNDFZZpDIERmvtBR X-Received: by 2002:a05:622a:188f:b0:441:322:af74 with SMTP id d75a77b69052e-4415ac61d20mr46974021cf.41.1718280182579; Thu, 13 Jun 2024 05:03:02 -0700 (PDT) Received: from smtpclient.apple (174.137.59.200.16clouds.com. [174.137.59.200]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798abe6b4d4sm45580485a.129.2024.06.13.05.02.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2024 05:03:02 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: [PATCH v2] sched/fair: Reschedule the cfs_rq when current is ineligible From: Chunxin Zang In-Reply-To: Date: Thu, 13 Jun 2024 20:02:37 +0800 Cc: Honglei Wang , mingo@redhat.com, Peter Zijlstra , 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, Mike Galbraith , K Prateek Nayak , linux-kernel@vger.kernel.org, yangchen11@lixiang.com, Jerry Zhou , Chunxin Zang Content-Transfer-Encoding: quoted-printable Message-Id: <112FECA8-5D21-406F-814C-ACBE63351CBB@gmail.com> References: <20240529141806.16029-1-spring.cxz@gmail.com> <2E6EB0D6-D913-4205-B7DD-35EF4FA25667@gmail.com> To: Chen Yu X-Mailer: Apple Mail (2.3731.700.6) > On Jun 13, 2024, at 19:54, Chen Yu wrote: >=20 > On 2024-06-12 at 18:39:11 +0800, Chunxin Zang wrote: >>=20 >>=20 >>> On Jun 7, 2024, at 13:07, Chen Yu wrote: >>>=20 >>> On 2024-05-29 at 22:18:06 +0800, Chunxin Zang wrote: >>>> I found that some tasks have been running for a long enough time = and >>>> have become illegal, but they are still not releasing the CPU. This >>>> will increase the scheduling delay of other processes. Therefore, I >>>> tried checking the current process in wakeup_preempt and = entity_tick, >>>> and if it is illegal, reschedule that cfs queue. >>>>=20 >>>> When RUN_TO_PARITY is enabled, its behavior essentially remains >>>> consistent with the original process. When NO_RUN_TO_PARITY is = enabled, >>>> some additional preemptions will be introduced, but not too many. >>>>=20 >>>> I have pasted some test results below. >>>> I isolated four cores for testing and ran hackbench in the = background, >>>> and observed the test results of cyclictest. >>>>=20 >>>> hackbench -g 4 -l 100000000 & >>>> cyclictest --mlockall -D 5m -q >>>>=20 >>>> EEVDF PATCH EEVDF-NO_PARITY = PATCH-NO_PARITY >>>>=20 >>>> # Min Latencies: 00006 00006 00006 = 00006 >>>> LNICE(-19) # Avg Latencies: 00191 00133 00089 = 00066 >>>> # Max Latencies: 15442 08466 14133 = 07713 >>>>=20 >>>> # Min Latencies: 00006 00010 00006 = 00006 >>>> LNICE(0) # Avg Latencies: 00466 00326 00289 = 00257 >>>> # Max Latencies: 38917 13945 32665 = 17710 >>>>=20 >>>> # Min Latencies: 00019 00053 00010 = 00013 >>>> LNICE(19) # Avg Latencies: 37151 25852 18293 = 23035 >>>> # Max Latencies: 2688299 4643635 426196 = 425708 >>>>=20 >>>> I captured and compared the number of preempt occurrences in = wakeup_preempt >>>> to see if it introduced any additional overhead. >>>>=20 >>>> Similarly, hackbench is used to stress the utilization of four = cores to >>>> 100%, and the method for capturing the number of PREEMPT = occurrences is >>>> referenced from [1]. >>>>=20 >>>> schedstats EEVDF PATCH = EEVDF-NO_PARITY PATCH-NO_PARITY CFS(6.5) >>>> .stats.check_preempt_count 5053054 5045388 5018589 = 5029585 >>>> .stats.patch_preempt_count ------- 0020495 ------- = 0700670 ------- >>>> .stats.need_preempt_count 0570520 0458947 3380513 = 3116966 1140821 >>>>=20 >>>> =46rom the above test results, there is a slight increase in the = number of >>>> preempt occurrences in wakeup_preempt. However, the results vary = with each >>>> test, and sometimes the difference is not that significant. >>>>=20 >>>> [1]: = https://lore.kernel.org/all/20230816134059.GC982867@hirez.programming.kick= s-ass.net/T/#m52057282ceb6203318be1ce9f835363de3bef5cb >>>>=20 >>>> Signed-off-by: Chunxin Zang >>>> Reviewed-by: Chen Yang >>>>=20 >>>> ------ >>>> Changes in v2: >>>> - Make the logic that determines the current process as ineligible = and >>>> triggers preemption effective only when NO_RUN_TO_PARITY is = enabled. >>>> - Update the commit message >>>> --- >>>> kernel/sched/fair.c | 17 +++++++++++++++++ >>>> 1 file changed, 17 insertions(+) >>>>=20 >>>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >>>> index 03be0d1330a6..fa2c512139e5 100644 >>>> --- a/kernel/sched/fair.c >>>> +++ b/kernel/sched/fair.c >>>> @@ -745,6 +745,17 @@ int entity_eligible(struct cfs_rq *cfs_rq, = struct sched_entity *se) >>>> return vruntime_eligible(cfs_rq, se->vruntime); >>>> } >>>>=20 >>>> +static bool check_entity_need_preempt(struct cfs_rq *cfs_rq, = struct sched_entity *se) >>>> +{ >>>> + if (sched_feat(RUN_TO_PARITY) && se->vlag !=3D se->deadline) >>>> + return true; >>>=20 >>> If I understand correctly, here it intends to check if the current = se >>> has consumed its 1st slice after been picked at set_next_entity(), = and if yes do a reschedule. >>> check_entity_need_preempt() is added at the end of entity_tick(), = which could overwrite >>> the police to reschedule current: = (entity_tick()->update_curr()->update_deadline()), only there >>> are more than 1 runnable tasks will the current be preempted, even = if it has expired the 1st >>> requested slice. >>>=20 >>=20 >> The purpose of the modification is to increase preemption = opportunities without breaking the >> RUN_TO_PARITY rule. However, it clearly introduces some additional = preemptions, or perhaps >> there should be a check for the eligibility of the se. Also, to avoid = overwriting the scheduling >> strategy in entity_tick, would a modification like the following be = more appropriate? >>=20 >=20 > I wonder if we can only take care of the NO_RUN_TO_PARITY case? = Something like this, >=20 >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 03be0d1330a6..5e49a15bbdd3 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -745,6 +745,21 @@ int entity_eligible(struct cfs_rq *cfs_rq, = struct sched_entity *se) >> return vruntime_eligible(cfs_rq, se->vruntime); >> } >>=20 >> +static bool check_entity_need_preempt(struct cfs_rq *cfs_rq, struct = sched_entity *se) >> +{ > if (sched_feat(RUN_TO_PARITY) || cfs_rq->nr_running <=3D 1 || > !entity_eligible(cfs_rq, se)) > return false; >=20 > return true; >=20 > Thoughts? >=20 This does indeed look better. In that case, do I need to make the = changes this way and send out a version 3? thanks=20 Chunxin > thanks, > Chenyu >=20 >> + if (cfs_rq->nr_running <=3D 1) >> + return false; >> + >> + if (sched_feat(RUN_TO_PARITY) && se->vlag !=3D se->deadline >> + && !entity_eligible(cfs_rq, = se)) >> + return true; >> + >> + if (!sched_feat(RUN_TO_PARITY) && !entity_eligible(cfs_rq, = se)) >> + return true; >> + >> + return false; >> +} >> +