From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout10.his.huawei.com (canpmsgout10.his.huawei.com [113.46.200.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 000034071FF for ; Mon, 20 Jul 2026 11:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.225 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784548591; cv=none; b=i9jzjoyLMmg3WsIoO3MXRIBaQxuSiu+5pgfz6QcIUavezzA4Ae/GdSa1xZsw/dYOcmX3+yjJpQN8jzL5ue+/761zXPEKxvd9PZDYxFrb6Diy4UJRe6fEBNZ/TbfYCmrCw2iBxMMyF2wZ5XERZKp6f6mCgAPl/9Zzq/AK2/g0exQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784548591; c=relaxed/simple; bh=L1s1WisQ9wJVHzpyMRtnkrBdgmNkw6CA/WHp77ZJ0eI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iVFsZWRQSIVO+n+LMdo0/ckyO4gNS9wfhamMXiVjv3pcFA91D7tKCPTI05J6JbBS1g+4M8TH70TTtXOuzKAZMjGVEwkNNgOl9Fv1dkhHDQ59gu3zTaoyQp3guGetbWhtUl07qy67tHmGwFeDU3mz9asAumUTuq4NqXQ77UReKGE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=zS+MsSr0; arc=none smtp.client-ip=113.46.200.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="zS+MsSr0" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=nNAWtovndmTdWm440E8eliORNMrF6Bfnh/PuzosPtxU=; b=zS+MsSr0C02/dHF2q+YU/A+3/ON7B2dTGS591yhlg4LsWhboSjP+Eua7dOQbmcbSgHrwbgkSS 0MmplPcSq6jb9zV4VopxziAHCkx676NEQVlgY/7ZvP8vI2y6bCFf6QAG/OIx6gcuYLtqlFp+Eya 8ZFxWOliue6eHQZnP156AIA= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4h3dzC0nWZz1K96b; Mon, 20 Jul 2026 19:47:03 +0800 (CST) Received: from kwepemj100017.china.huawei.com (unknown [7.202.194.11]) by mail.maildlp.com (Postfix) with ESMTPS id 5AE5940563; Mon, 20 Jul 2026 19:56:23 +0800 (CST) Received: from huawei.com (10.67.174.193) by kwepemj100017.china.huawei.com (7.202.194.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Mon, 20 Jul 2026 19:56:22 +0800 From: Luo Gengkun To: , , , , , CC: , , , , , , Subject: [PATCH v7 linux 2/2] -- DO NOT APPLY!!! -- sched/cache/debug: Add trace event and sched feature to track scan cost Date: Mon, 20 Jul 2026 12:22:14 +0000 Message-ID: <20260720122214.3977092-3-luogengkun2@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260720122214.3977092-1-luogengkun2@huawei.com> References: <20260720122214.3977092-1-luogengkun2@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems200001.china.huawei.com (7.221.188.67) To kwepemj100017.china.huawei.com (7.202.194.11) To evaluate the effectiveness of the previous patch, this debug patch introduces feature SC_VISIT as well as trace events to facilitate testing. Signed-off-by: Luo Gengkun --- include/trace/events/sched.h | 21 +++++++++++++++++++++ kernel/sched/fair.c | 26 +++++++++++++++++++++----- kernel/sched/features.h | 1 + 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 535860581f15..aced624f198d 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -10,6 +10,27 @@ #include #include +TRACE_EVENT(sched_cache_scan, + + TP_PROTO(struct task_struct *t, int scan), + + TP_ARGS(t, scan), + + TP_STRUCT__entry( + __string( comm, t->comm ) + __field( pid_t, pid ) + __field( int, scan ) + ), + + TP_fast_assign( + __assign_str(comm); + __entry->pid = t->pid; + __entry->scan = scan; + ), + + TP_printk("comm=%s pid=%d scan=%d", __get_str(comm), __entry->pid, + __entry->scan) +); /* * Tracepoint for calling kthread_stop, performed to end a kthread: */ diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c56b2df66de8..e5a2dd241f3e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1648,7 +1648,8 @@ static unsigned long fraction_mm_sched(int cpu, __update_mm_sched(rq, pcpu_sched); /* Skip the rq that has not been hit for a long time */ - if ((rq->cpu_epoch - pcpu_sched->epoch_last_visit) > llc_epoch_affinity_timeout) { + if (sched_feat(SC_VISIT) && + (rq->cpu_epoch - pcpu_sched->epoch_last_visit) > llc_epoch_affinity_timeout) { cpumask_clear_cpu(cpu, mm->sc_stat.visited_cpus); return 0; } @@ -1723,7 +1724,8 @@ void account_mm_sched(struct rq *rq, struct task_struct *p, s64 delta_exec) rq->cpu_runtime += delta_exec; epoch = rq->cpu_epoch; pcpu_sched->epoch_last_visit = epoch; - if (!cpumask_test_cpu(cpu_of(rq), mm->sc_stat.visited_cpus)) + if (sched_feat(SC_VISIT) && + !cpumask_test_cpu(cpu_of(rq), mm->sc_stat.visited_cpus)) cpumask_set_cpu(cpu_of(rq), mm->sc_stat.visited_cpus); } @@ -1846,7 +1848,8 @@ static void task_cache_work(struct callback_head *work) unsigned long curr_m_a_occ = 0; struct mm_struct *mm = p->mm; unsigned long m_a_occ = 0; - cpumask_var_t cpus; + cpumask_var_t cpus, scan_cpus; + int scanned = 0; WARN_ON_ONCE(work != &p->cache_work); @@ -1877,6 +1880,11 @@ static void task_cache_work(struct callback_head *work) if (!zalloc_cpumask_var(&cpus, GFP_KERNEL)) return; + if (!zalloc_cpumask_var(&scan_cpus, GFP_KERNEL)) { + free_cpumask_var(cpus); + return; + } + scoped_guard (cpus_read_lock) { guard(rcu)(); @@ -1892,7 +1900,8 @@ static void task_cache_work(struct callback_head *work) * implies this process hasn't run on that CPU for a long * time, and will be captured in the next cycle. */ - cpumask_and(cpus, cpus, mm->sc_stat.visited_cpus); + if (sched_feat(SC_VISIT)) + cpumask_and(cpus, cpus, mm->sc_stat.visited_cpus); for_each_cpu(cpu, cpus) { /* XXX sched_cluster_active */ @@ -1903,12 +1912,17 @@ static void task_cache_work(struct callback_head *work) if (!sd) continue; - for_each_cpu_and(i, sched_domain_span(sd), mm->sc_stat.visited_cpus) { + cpumask_copy(scan_cpus, sched_domain_span(sd)); + if (sched_feat(SC_VISIT)) + cpumask_and(scan_cpus, scan_cpus, mm->sc_stat.visited_cpus); + + for_each_cpu(i, scan_cpus) { cur = rcu_dereference_all(cpu_rq(i)->curr); if (cur && !(cur->flags & (PF_EXITING | PF_KTHREAD)) && cur->mm == mm) nr_running++; + scanned++; occ = fraction_mm_sched(i, mm); if (occ == 0) continue; @@ -1963,6 +1977,8 @@ static void task_cache_work(struct callback_head *work) update_avg_scale(&mm->sc_stat.nr_running_avg, nr_running); free_cpumask_var(cpus); + free_cpumask_var(scan_cpus); + trace_sched_cache_scan(p, scanned); } void init_sched_mm(struct task_struct *p) diff --git a/kernel/sched/features.h b/kernel/sched/features.h index 8f0dee8fc475..990714ebabfd 100644 --- a/kernel/sched/features.h +++ b/kernel/sched/features.h @@ -142,3 +142,4 @@ SCHED_FEAT(LATENCY_WARN, false) */ SCHED_FEAT(NI_RANDOM, true) SCHED_FEAT(NI_RATE, true) +SCHED_FEAT(SC_VISIT, false) -- 2.34.1