Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2232631rdh; Tue, 26 Sep 2023 17:37:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGaTWLIUcwEr3c245e9tpWRIG35Ck8afd89b7hRmuBwF7pljOWqLy3EfE65gTwjVOKmm8vw X-Received: by 2002:a05:6a20:4410:b0:12d:23ea:9ccc with SMTP id ce16-20020a056a20441000b0012d23ea9cccmr560160pzb.39.1695775022840; Tue, 26 Sep 2023 17:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695775022; cv=none; d=google.com; s=arc-20160816; b=0DBXVb8tSHgT+RFqEz34t8kdzQdkp6P82UFbLP/7GJ/rVlxHBb0frNVta8pkL0LIVK tKmK8arqVPFYvh1jgvfSiKScvQI8zJ3xDJ5FBe5x+6k79cOcaHk4PG3B3Ak0YtWJr5+t myAT1UD/mxNf2ZMQ7wbYagKToPs+q2+1ZVYPzoDU2WNtnTRlRCuf/JltYDYVM3wjSBLe HYVCfGFuptpznkMMx5b9qO/tCU9tb2GGW3lSSWPNc0vz+e/e74lrNrWWBBVRSPW7EUnB tWqWjQyChLS2p93eCSqMqfqtwetEvMoQc2MruhODDpfndDO9Xmiiw/ObNdnFBf3HQ5tw IlZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=rwj/Ok5dXgeZB0n7/sBptca+Y0QQ+xzMPk2MNSkpYAM=; fh=ftij8aZyYWcEY99kO4R5Yj41pSNFIYi4Zsf56wDIUkc=; b=aSvMlgXs/A/tvDPTWgY6MF8itBNJun3mE5rLsDA5w+iPUM+wN8lL41sf8/GGDRorXp vpg2EtEEJfwedb3pD0x2SOm7a2iYykCSuBb46FOxpMqRRnAVEqAWUQw7Ei86GZusB52r ZLK0LfoY75Mtv8YOPuOPZ47LKiHofKtFF/FjIENIh7qm4QmV5X7Chr5e3d160YBthTIO Jb+DEhJnpjL/2u9n21AdbToGaggWPQIgj8c1Pb+2+G4gwMUKi4Ng9k6cp6h5tMqPtSBV FWGc1JMoQ9q3xsdizrE6NXJ3w0nppJP8T3GdEwmUhcqDv/uNpGen2CY+v/FZ5m69+7VW PbHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=BA1Aa3rO; 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=efficios.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id q3-20020a170902dac300b001b82a4d3ea7si15146498plx.249.2023.09.26.17.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 17:37:02 -0700 (PDT) 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=@efficios.com header.s=smtpout1 header.b=BA1Aa3rO; 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=efficios.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1D65480752BF; Tue, 26 Sep 2023 08:30:59 -0700 (PDT) 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 S235090AbjIZPaz (ORCPT + 99 others); Tue, 26 Sep 2023 11:30:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233309AbjIZPay (ORCPT ); Tue, 26 Sep 2023 11:30:54 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B01010A for ; Tue, 26 Sep 2023 08:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1695742244; bh=OnohBIbzxshPyEmMWAh4gOX+hda/cp3tuqHCS6jOsUI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=BA1Aa3rOB6wid579Ks59TXZr7TnH8DbyKrk50K4zQAtEx1peEQ/AHSyTlyPz8bh1S Vy51Ppme5FxAxdI7z4vUnrwVGQmjmdyqq1cUG5PAosyoB4SKNJbVR6WRIxZHUZrDL5 XKEpaVaBLVhqq+YGdfG7xreNvbGfSXm3IcbSdMyiGsKz3zanRcgC2hcbycSMBs3WuQ oq7kM+/fwXMIFGQisrnyFjYIAIqR/5v6amZnxN5VnH6uF6wI6mevBne8jvwIXqBztW 96+plrvTcleIs2Y0fsdOtNb/YJd6o5zwag2DSwV05qoCZVSq6mXQc4iYmqzHSoh+GF WIOCQm+p4TLHQ== Received: from [172.16.0.134] (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4Rw3bm0Nrkz1R9H; Tue, 26 Sep 2023 11:30:44 -0400 (EDT) Message-ID: <677cd7ab-4347-ed09-bf56-4c2a9833ae50@efficios.com> Date: Tue, 26 Sep 2023 06:29:40 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH 1/2] sched/fair: Record the short sleeping time of a task Content-Language: en-US To: Chen Yu , Peter Zijlstra , Ingo Molnar , Vincent Guittot , Juri Lelli Cc: Tim Chen , Aaron Lu , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , K Prateek Nayak , "Gautham R . Shenoy" , linux-kernel@vger.kernel.org, Chen Yu References: From: Mathieu Desnoyers In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DATE_IN_PAST_03_06, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 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]); Tue, 26 Sep 2023 08:30:59 -0700 (PDT) On 9/26/23 06:11, Chen Yu wrote: > During task wakeup, the wakee firstly checks if its previous > running CPU is idle. If yes, choose that CPU as its first > choice. However, in most cases, the wakee's previous CPU > could be chosen by someone else, which breaks the cache > locality. > > Proposes a mechanism to reserve the task's previous > CPU for a short while. In this reservation period, other > tasks are not allowed to pick that CPU until a timeout. > The reservation period is defined as the average short > sleep time of the task. To be more specific, it is the > time delta between this task being dequeued and enqueued. > Only the sleep time shorter than sysctl_sched_migration_cost > will be recorded. If the sleep time is longer than > sysctl_sched_migration_cost, give the reservation period > a penalty by shrinking it to half. In this way, the 'burst' > sleeping time of the task is honored, meanwhile, if that > task becomes a long-sleeper, the reservation time of that > task is shrunk to reduce the impact on task wakeup. > > Suggested-by: Mathieu Desnoyers > Signed-off-by: Chen Yu > --- > include/linux/sched.h | 3 +++ > kernel/sched/fair.c | 21 +++++++++++++++++++++ > 2 files changed, 24 insertions(+) > > diff --git a/include/linux/sched.h b/include/linux/sched.h > index dc37ae787e33..4a0ac0276384 100644 > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -561,6 +561,9 @@ struct sched_entity { > u64 vruntime; > s64 vlag; > u64 slice; > + u64 prev_dequeue_time; > + /* the reservation period of this task during wakeup */ > + u64 sis_rsv_avg; > > u64 nr_migrations; > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index d0877878bcdb..297b9470829c 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -6456,6 +6456,24 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags) > struct sched_entity *se = &p->se; > int idle_h_nr_running = task_has_idle_policy(p); > int task_new = !(flags & ENQUEUE_WAKEUP); > + u64 last_dequeue = p->se.prev_dequeue_time; > + u64 now = sched_clock_cpu(task_cpu(p)); > + > + /* > + * If the task is a short-sleepting task, there is no need > + * to migrate it to other CPUs. Estimate the average short sleeping > + * time of the wakee. This sleep time is used as a hint to reserve > + * the dequeued task's previous CPU for a short while. During this > + * reservation period, select_idle_cpu() prevents other wakees from > + * choosing this CPU. This could bring a better cache locality. "This could bring a better cache locality." could be rephrased as "This improves cache locality for short-sleeping tasks." Please add my: Reviewed-by: Mathieu Desnoyers > + */ > + if ((flags & ENQUEUE_WAKEUP) && last_dequeue && cpu_online(task_cpu(p)) && > + now > last_dequeue) { > + if (now - last_dequeue < sysctl_sched_migration_cost) > + update_avg(&p->se.sis_rsv_avg, now - last_dequeue); > + else > + p->se.sis_rsv_avg >>= 1; > + } > > /* > * The code below (indirectly) updates schedutil which looks at > @@ -6550,6 +6568,7 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) > int task_sleep = flags & DEQUEUE_SLEEP; > int idle_h_nr_running = task_has_idle_policy(p); > bool was_sched_idle = sched_idle_rq(rq); > + u64 now; > > util_est_dequeue(&rq->cfs, p); > > @@ -6611,6 +6630,8 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) > dequeue_throttle: > util_est_update(&rq->cfs, p, task_sleep); > hrtick_update(rq); > + now = sched_clock_cpu(cpu_of(rq)); > + p->se.prev_dequeue_time = task_sleep ? now : 0; > } > > #ifdef CONFIG_SMP -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com