Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp211665rdf; Mon, 20 Nov 2023 23:44:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi7qpeg4ZDLNvjCa/LdK+yilcKS+LZq0Op0OJxYz4QwlfxtgEbrgji6foAnlqUtaUEzkB7 X-Received: by 2002:a05:6870:d289:b0:1f4:dac9:75a8 with SMTP id d9-20020a056870d28900b001f4dac975a8mr10957058oae.10.1700552674472; Mon, 20 Nov 2023 23:44:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700552674; cv=none; d=google.com; s=arc-20160816; b=R7GAHRbFWMJMo+m/pstOIWl0mZJ4jhLGAVNQANxpWOcavXIhq4JNu/usApWzHKjTHb LY84OfTrdTsMm95pULKbFrS93vSOhwI0KyrotpHJdrqI4W5FBpxcCuDE2OJrdEaAqQzv HPA2mzeyy2KxHVpCvXQcYTqUA9jxnVjgtj+NsRJpE/1Xc3oFOpE1toq0SVS8RnAgnQ9/ 30ryxQ+/twz3gZEmAOj+qLpJLP0Z0mE4ew9emCOXylo9yTBi9ksk+kX0FCiaNgeRWvgu vNckvkegrQnkyetNmPv2TTzVKpb78gh06Gdhzl16rTcB1WFsscPsyInCyA+I4E3dgf0w YQRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Oy4Ju1WL2mVGG2QrypFriwR5F4jz+aV0nOVNhDl8a0k=; fh=0dOHTwLhZRcSeL1cn2LfAx4yZf5ptHxTdWpvFvnOHEs=; b=Ysz0THFFdm/xqrA775iDRDqwIMgG95aSxLw7IV+oGWjT2+uwnC4Y6wvEA/CVHRobfi iCk5yXPeacB86mY+0SGy5x6KsjABxFFqLBn0/yz+mNXpLhEk3k1DkXuKWv9YV4kzNHeZ o2iMfkjduE39wPlWSSZwcz7Ioind2emBGI1DIY7Akmsg3gdkrXl3xAdJEJu0+/p1mjKg /wUQ+1Z2eYa1Nv/YOpLQQkhO9ARb/Fzz/D14NSNirDECdG/mOI8NeDmasP0AKfiEc6kC RU80QzkXTq66HKFQYv/bUuqLnCjNI2grenS9/yTKOeDepaT0hxr+ZYrVAKZVkZg0qtwd EDiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EIh9LpPq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f189-20020a6251c6000000b0069342aef90bsi9522853pfb.3.2023.11.20.23.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 23:44:34 -0800 (PST) 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=@intel.com header.s=Intel header.b=EIh9LpPq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 851AE80713DC; Mon, 20 Nov 2023 23:41:02 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229486AbjKUHk7 (ORCPT + 99 others); Tue, 21 Nov 2023 02:40:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjKUHk6 (ORCPT ); Tue, 21 Nov 2023 02:40:58 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 745B497 for ; Mon, 20 Nov 2023 23:40:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700552454; x=1732088454; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kDE9oNZ7PjL2CqLOzbBkD7BOUp0VBCVrH28Nu10oP9c=; b=EIh9LpPqo14pZR/q4qYTKUGmDwHxejQX/57dKeEjJBuxmlNLD4ZoUVPO DeqoewJunhpyHnV9GflEpz5UHbkDhJa+bEx5RqUfZ06+ypbTjnl1BtlIK tFAbbcl5VLTFFSZZwjFG7SQTMVy67DWAUhNETn4ozPGOGc1ZFxBH5xd4F T2ZLM0Zb7knlpF5hkKPPIAGSS2SlFbfn1rHjZ2SlXKcH1PCS1E648AOep 4rK03qSXKudicczEf+X3J6pJetQdLCTU7eALB2gaIIoI5J7QHJhyPgG4C s+cGZagOJimnRHeJ9lgcy7FT5V4WOPrDXevsKeLdZ3FQMfFXF6G3zVCPX A==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="376821688" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="376821688" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 23:40:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="884101994" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="884101994" Received: from chenyu-dev.sh.intel.com ([10.239.62.164]) by fmsmga002.fm.intel.com with ESMTP; 20 Nov 2023 23:40:39 -0800 From: Chen Yu To: Peter Zijlstra , Mathieu Desnoyers , Ingo Molnar , Vincent Guittot , Juri Lelli Cc: Tim Chen , Aaron Lu , Dietmar Eggemann , Steven Rostedt , Mel Gorman , K Prateek Nayak , "Gautham R . Shenoy" , Chen Yu , linux-kernel@vger.kernel.org, Chen Yu Subject: [PATCH v2 1/3] sched/fair: Record the task sleeping time as the cache hot duration Date: Tue, 21 Nov 2023 15:39:40 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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]); Mon, 20 Nov 2023 23:41:02 -0800 (PST) The cache hot duration is calculated by the average sleeping time of a task, which is the time delta between the task being dequeued and enqueued. The cache hot duration of a task is introduced to describe how soon this dequeue task could be woken up. During this cache hot period, the task's previous CPU is regarded as still cache-hot for the task. This information will be used by SIS_CACHE to improve cache locality for short-sleeping tasks. Suggested-by: Mathieu Desnoyers Suggested-by: Aaron Lu Reviewed-by: Mathieu Desnoyers Signed-off-by: Chen Yu --- include/linux/sched.h | 4 ++++ kernel/sched/fair.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 8d258162deb0..7d0fafd29345 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1347,6 +1347,10 @@ struct task_struct { struct callback_head cid_work; #endif + u64 last_dequeue_time; + u64 avg_hot_dur; /* Average cache hot duration */ + int last_dequeue_cpu; + struct tlbflush_unmap_batch tlb_ubc; /* Cache last used pipe for splice(): */ diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 53e7bf2ccc44..672616503e35 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6667,6 +6667,36 @@ 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->last_dequeue_time; + + if ((flags & ENQUEUE_WAKEUP) && last_dequeue && + cpu_online(p->last_dequeue_cpu)) { + /* + * The enqueue task_cpu(p) has already been assigned + * with a new one. Need to calculate the task's sleeping + * time based on its previous running CPU. + */ + u64 now = sched_clock_cpu(p->last_dequeue_cpu); + + /* + * Record the task's short sleep time. This sleep time + * indicates how soon this task might be woken up again. + * The task's previous running CPU is regarded as cache-hot + * in the sleep time. So, define the average sleep time of + * the task as its cache-hot duration. The SIS could leverage + * the cache-hot duration for better idle CPU selection. + * This improves cache locality for short-sleeping tasks. + * + * If the sleep time is longer than sysctl_sched_migration_cost, + * give the cache hot duration a penalty by cutting it to half. + */ + if (now > last_dequeue) { + if (now - last_dequeue < sysctl_sched_migration_cost) + update_avg(&p->avg_hot_dur, now - last_dequeue); + else + p->avg_hot_dur >>= 1; + } + } /* * The code below (indirectly) updates schedutil which looks at @@ -6821,6 +6851,15 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) dequeue_throttle: util_est_update(&rq->cfs, p, task_sleep); + + if (task_sleep) { + p->last_dequeue_time = sched_clock_cpu(cpu_of(rq)); + p->last_dequeue_cpu = cpu_of(rq); + } else { + /* 0 indicates the dequeue is not caused by sleep */ + p->last_dequeue_time = 0; + } + hrtick_update(rq); } -- 2.25.1