Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp211705rdf; Mon, 20 Nov 2023 23:44:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3NN0RsR0k+OZd10p+R5mwjllIwR29YGqJo+XOUMV4QxuuMdsnTW1+5bvbn3/4XawUKuKp X-Received: by 2002:a17:90b:3144:b0:27d:3439:c141 with SMTP id ip4-20020a17090b314400b0027d3439c141mr7326386pjb.39.1700552681627; Mon, 20 Nov 2023 23:44:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700552681; cv=none; d=google.com; s=arc-20160816; b=ZANq/OC2SAelI/vDhgOyfVXGmdjfdzUFd37h4bQ0rCFHqV3M3AmTZHHIfSaAgjwgdr TU19pRjNtM0OAGdOduM1ozWrsT74a0FUgk993In8d4Wqfgx5MR0K3cNIAki3mqSNB6Lh h3h5IANo7O9X8Ns7KE8S+mk1mMvwxT/msn+PDsSvgejTcL3WZvIATHKczAOp0xWSxCbm 2t3tA3nSo9Igrtou4D70xe/4VwDjR6/qupJT07hbiWvKA0oxO7bGWiGO1S/wQjZWAucz zxcFAVZP9AbLNUthWmjUPkyK7Sec27xZAdGrwsLHgRK14b1t5DAvS9/O8x/ul/fL6GBc h0lw== 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=t/0xTkFLTlI0rZ/Sv9CHrNtOfm2Q6OWeTxSifa+2Bks=; fh=0dOHTwLhZRcSeL1cn2LfAx4yZf5ptHxTdWpvFvnOHEs=; b=KY9ASBQU1Ke7qBhvMAVzpQo6prZsDPsHayFRzeoDMvtSiheo1kKOrYXar/aIP4PQH4 fhYpXXhlJItjpT+ugFima6sCVel5TBAVIkgvdh9UAPEJEQo8DQVAmzg0jr3zvTx6SeJW OaU+8OCQnalWGGSGeUE399Rrym6BSu3qk5Tp4TIEW3zXvTIR+oykRkJCDonfbSfYtT8e kvBQ29ABNvM7SvSU/Xd0bb9M4k5nMCrCueQKQ+HlY3ur6OTmp6HqU8i2FThCGDbXaebD d2iBhKmNZck4mgnLFD3Z8CYsgK8wPggb0jZPBiKCngEFmNKAhd5joEW3K3d7K5eP2rBi sXew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mN4XMyMy; 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 z9-20020a17090ad78900b002850e97e25esi6914066pju.2.2023.11.20.23.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 23:44:41 -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=mN4XMyMy; 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 9FA87808E660; Mon, 20 Nov 2023 23:41:16 -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 S229935AbjKUHlK (ORCPT + 99 others); Tue, 21 Nov 2023 02:41:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230417AbjKUHlH (ORCPT ); Tue, 21 Nov 2023 02:41:07 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E13C121 for ; Mon, 20 Nov 2023 23:41:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700552464; x=1732088464; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KjPJrAVxXZh2V7iwRKhLhm1MJKfGXzVaYnYYF6gMzhg=; b=mN4XMyMyr0/FtqZ9tllMoXVAby60n9EJ7zHwRnSbZwS1GJyuJoCZ+6mv oExDxf5bPL5t7IQk+W3R9wy+eAELogtzTGRUwi+bMazCOuqO1ZplOZTKP qsoUXa3N2Xkcs4THVw5Pwek+gUYEifa7PxD0N2wxHFFfUEbKcFBcygqSG O5csuxszB+2LvkgZQ/8CQObveHU56fbpz54Xrz0oBRHGTN2/JSlv+6FKh Uj3DBGC8VPnFjaEnO51/pi96qev+gOPfs/ljfZgxKVLBT8O8NiEeCpyKo ikjzt5GG3DM1Z/pOwVYfkY7sCwZxbtVFqXO2YS0gTsyrZ/L+lLvpQXU4w g==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="4978256" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="4978256" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 23:41:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="836972249" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="836972249" Received: from chenyu-dev.sh.intel.com ([10.239.62.164]) by fmsmga004.fm.intel.com with ESMTP; 20 Nov 2023 23:40:59 -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 2/3] sched/fair: Calculate the cache-hot time of the idle CPU Date: Tue, 21 Nov 2023 15:39:54 +0800 Message-Id: <6dccbf0f54cc4ee068a157b9eebfb4b5fa3cc4af.1700548379.git.yu.c.chen@intel.com> 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:16 -0800 (PST) When a CPU is about to become idle due to task dequeue, uses the dequeued task's average sleep time to set the cache hot timeout of this idle CPU. This information can facilitate SIS to skip the cache-hot idle CPU and scan for the next cache-cold one. When that task is woken up again, it can choose its previous CPU and reuses its hot-cache. This is a preparation for the next patch to introduce SIS_CACHE based task wakeup. Signed-off-by: Chen Yu --- kernel/sched/fair.c | 30 +++++++++++++++++++++++++++++- kernel/sched/features.h | 1 + kernel/sched/sched.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 672616503e35..c309b3d203c0 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6853,8 +6853,17 @@ static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags) util_est_update(&rq->cfs, p, task_sleep); if (task_sleep) { - p->last_dequeue_time = sched_clock_cpu(cpu_of(rq)); + u64 now = sched_clock_cpu(cpu_of(rq)); + + p->last_dequeue_time = now; p->last_dequeue_cpu = cpu_of(rq); + +#ifdef CONFIG_SMP + /* this rq becomes idle, update its cache hot timeout */ + if (sched_feat(SIS_CACHE) && !rq->nr_running && + p->avg_hot_dur) + rq->cache_hot_timeout = max(rq->cache_hot_timeout, now + p->avg_hot_dur); +#endif } else { /* 0 indicates the dequeue is not caused by sleep */ p->last_dequeue_time = 0; @@ -7347,6 +7356,25 @@ static inline int select_idle_smt(struct task_struct *p, int target) #endif /* CONFIG_SCHED_SMT */ +/* + * Return true if the idle CPU is cache-hot for someone, + * return false otherwise. + */ +static __maybe_unused bool cache_hot_cpu(int cpu, int *hot_cpu) +{ + if (!sched_feat(SIS_CACHE)) + return false; + + if (sched_clock_cpu(cpu) >= cpu_rq(cpu)->cache_hot_timeout) + return false; + + /* record the first cache hot idle cpu as the backup */ + if (*hot_cpu == -1) + *hot_cpu = cpu; + + return true; +} + /* * Scan the LLC domain for idle CPUs; this is dynamically regulated by * comparing the average scan cost (tracked in sd->avg_scan_cost) against the diff --git a/kernel/sched/features.h b/kernel/sched/features.h index a3ddf84de430..0af282712cd1 100644 --- a/kernel/sched/features.h +++ b/kernel/sched/features.h @@ -50,6 +50,7 @@ SCHED_FEAT(TTWU_QUEUE, true) * When doing wakeups, attempt to limit superfluous scans of the LLC domain. */ SCHED_FEAT(SIS_UTIL, true) +SCHED_FEAT(SIS_CACHE, true) /* * Issue a WARN when we do multiple update_rq_clock() calls diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e58a54bda77d..191ed62ef06d 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1083,6 +1083,7 @@ struct rq { #endif u64 idle_stamp; u64 avg_idle; + u64 cache_hot_timeout; /* This is used to determine avg_idle's max value */ u64 max_idle_balance_cost; -- 2.25.1