lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220126152222.5429-1-carlos.bilbao@amd.com>
Date:   Wed, 26 Jan 2022 09:22:23 -0600
From:   Carlos Bilbao <carlos.bilbao@....com>
To:     <peterz@...radead.org>, <juri.lelli@...hat.com>
CC:     <vincent.guittot@...aro.org>, <mingo@...hat.com>,
        <dietmar.eggemann@....com>, <rostedt@...dmis.org>,
        <bsegall@...gle.com>, <mgorman@...e.de>, <bristot@...hat.com>,
        <linux-kernel@...r.kernel.org>,
        Carlos Bilbao <carlos.bilbao@....com>
Subject: [PATCH] kernel/sched: Update schedstats when migrating threads

The kernel manages per-task scheduler statistics or schedstats. Such
counters should be reinitialized when the thread is migrated to a
different core rq, except for the values recording number of migrations.

Signed-off-by: Carlos Bilbao <carlos.bilbao@....com>
---
 kernel/sched/core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fe53e510e711..d64c2a290176 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8757,6 +8757,7 @@ bool sched_smp_initialized __read_mostly;
 int migrate_task_to(struct task_struct *p, int target_cpu)
 {
 	struct migration_arg arg = { p, target_cpu };
+	uint64_t forced_migrations, migrations_cold;
 	int curr_cpu = task_cpu(p);
 
 	if (curr_cpu == target_cpu)
@@ -8765,7 +8766,14 @@ int migrate_task_to(struct task_struct *p, int target_cpu)
 	if (!cpumask_test_cpu(target_cpu, p->cpus_ptr))
 		return -EINVAL;
 
-	/* TODO: This is not properly updating schedstats */
+	if (schedstat_enabled()) {
+		forced_migrations = schedstat_val(p->stats.nr_forced_migrations);
+		migrations_cold = schedstat_val(p->stats.nr_migrations_cold);
+		memset(&p->stats, 0, sizeof(p->stats));
+		schedstat_set(p->stats.nr_forced_migrations, forced_migrations);
+		schedstat_set(p->stats.nr_migrations_cold, migrations_cold);
+		schedstat_inc(p->stats.nr_migrations_cold);
+	}
 
 	trace_sched_move_numa(p, curr_cpu, target_cpu);
 	return stop_one_cpu(curr_cpu, migration_cpu_stop, &arg);
-- 
2.27.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ