Skip to contentSkip to conversation

Remove useless test during exchanging values

PATCH In review Minfei Huang 2 participants 2 messages Apr 21, 2016 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove useless test during exchanging values

The value delta is correct as well, although calc_load_idle[idx] is equal to 0. Remove this useless test to improve performance, since this function is called more frequently.

---
 kernel/sched/loadavg.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/loadavg.c +2 -3
index ef71590..5a5d7ae 100644
@@ -216,10 +216,9 @@ void calc_load_exit_idle(void)
 static long calc_load_fold_idle(void)
 {
 	int idx = calc_load_read_idx();
-	long delta = 0;
+	long delta;
 
-	if (atomic_long_read(&calc_load_idle[idx]))
-		delta = atomic_long_xchg(&calc_load_idle[idx], 0);
+	delta = atomic_long_xchg(&calc_load_idle[idx], 0);
 
 	return delta;
 }
Signature · 1 line
2.6.3
maintainer
#1 lore raw
Quoted 14 lines · Minfei Huang

The value delta is correct as well, although calc_load_idle[idx] is equal to 0. Remove this useless test to improve performance, since this function is called more frequently.

---
 kernel/sched/loadavg.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/loadavg.c +0 -0
index ef71590..5a5d7ae 100644

kernel/sched/loadavg.c void calc_load_exit_idle(void) · line 221

Quoted 9 lines
kernel/sched/loadavg.c +2 -3
@@ -216,10 +216,9 @@ void calc_load_exit_idle(void)
 static long calc_load_fold_idle(void)
 {
 	int idx = calc_load_read_idx();
-	long delta = 0;
+	long delta;
 
-	if (atomic_long_read(&calc_load_idle[idx]))
-		delta = atomic_long_xchg(&calc_load_idle[idx], 0);
+	delta = atomic_long_xchg(&calc_load_idle[idx], 0);

This will actually degrade performance.

The read can have the cacheline in shared mode, while the xchg will force it into exclusive mode. Also, the xchg atomic operation is a really expensive instruction.