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: <BANLkTi=ybwWg9z6tKaAL-BfeSmsq6EL-=Q@mail.gmail.com>
Date:	Wed, 25 May 2011 20:48:26 +0800
From:	Hillf Danton <dhillf@...il.com>
To:	LKML <linux-kernel@...r.kernel.org>
Cc:	Ingo Molnar <mingo@...e.hu>, Peter Zijlstra <peterz@...radead.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Mike Galbraith <efault@....de>,
	Yong Zhang <yong.zhang0@...il.com>
Subject: [PATCH] sched: deduplicate atomic operations in select_nohz_load_balancer()

Two atomic-related operations, atomic_read and atomic_cmpxchg, are
used here to do the job. Since comparison is already included in the
later, the former is folded in the later, and operation is shorter.

Signed-off-by: Hillf Danton <dhillf@...il.com>
---

--- tip-git/kernel/sched_fair.c	Sat May 14 15:21:56 2011
+++ sched_fair.c	Wed May 25 20:15:34 2011
@@ -3806,35 +3806,25 @@ void select_nohz_load_balancer(int stop_

 	if (stop_tick) {
 		if (!cpu_active(cpu)) {
-			if (atomic_read(&nohz.load_balancer) != cpu)
-				return;
-
 			/*
 			 * If we are going offline and still the leader,
 			 * give up!
 			 */
-			if (atomic_cmpxchg(&nohz.load_balancer, cpu,
-					   nr_cpu_ids) != cpu)
-				BUG();
+			atomic_cmpxchg(&nohz.load_balancer, cpu, nr_cpu_ids);

 			return;
 		}

 		cpumask_set_cpu(cpu, nohz.idle_cpus_mask);

-		if (atomic_read(&nohz.first_pick_cpu) == cpu)
-			atomic_cmpxchg(&nohz.first_pick_cpu, cpu, nr_cpu_ids);
-		if (atomic_read(&nohz.second_pick_cpu) == cpu)
-			atomic_cmpxchg(&nohz.second_pick_cpu, cpu, nr_cpu_ids);
+		atomic_cmpxchg(&nohz.first_pick_cpu, cpu, nr_cpu_ids);
+		atomic_cmpxchg(&nohz.second_pick_cpu, cpu, nr_cpu_ids);

-		if (atomic_read(&nohz.load_balancer) >= nr_cpu_ids) {
+		/* make me the ilb owner */
+		if (nr_cpu_ids ==
+		    atomic_cmpxchg(&nohz.load_balancer, nr_cpu_ids, cpu)) {
 			int new_ilb;

-			/* make me the ilb owner */
-			if (atomic_cmpxchg(&nohz.load_balancer, nr_cpu_ids,
-					   cpu) != nr_cpu_ids)
-				return;
-
 			/*
 			 * Check to see if there is a more power-efficient
 			 * ilb.
@@ -3853,10 +3843,7 @@ void select_nohz_load_balancer(int stop_

 		cpumask_clear_cpu(cpu, nohz.idle_cpus_mask);

-		if (atomic_read(&nohz.load_balancer) == cpu)
-			if (atomic_cmpxchg(&nohz.load_balancer, cpu,
-					   nr_cpu_ids) != cpu)
-				BUG();
+		atomic_cmpxchg(&nohz.load_balancer, cpu, nr_cpu_ids);
 	}
 	return;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ