Skip to contentSkip to conversation

UP optimizations ..

DISCUSSION Herbert Pötzl 4 participants 5 messages Aug 27, 2003 – Aug 29, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Mikael!
Hi Marcelo!

stumbled repeatedly over the patches (or what remained of them) from Mikael?, replacing task->processor and friends by inline functions task_cpu(task), to eliminate them on UP systems ...

my questions:
- is there an up to date patchset?
- is it planned to include this into 2.4.23?

TIA,
Herbert

#1 lore raw
Quoted 10 lines · Herbert =?iso-8859-1?Q?P=F6tzl?= writes:

Hi Mikael!
Hi Marcelo!

stumbled repeatedly over the patches (or what remained of them) from Mikael?, replacing task->processor and friends by inline functions task_cpu(task), to eliminate them on UP systems ...

my questions:
- is there an up to date patchset?

Yes, I've kept it up to date. In fact I've been using it in every single 2.4 kernel I've built for the last 18+ months. Lately also on ppc32 and x86-64.

Below is the current UP micro-optimisation patch set for 2.4.22. It changes p->processor, p->cpus_allowed, and p->cpus_runnable accesses (reads and writes) to use inline functions. In UP kernels these reduce to doing nothing or returning a constant.

To keep the patch small, it doesn't change accesses in SMP-only code. (This is also the reason why p->cpus_runnable only has a wrapper for updates, since all reads are in SMP-only code.)

/Mikael

fs/proc/array.c +1 -1
diff -ruN linux-2.4.22/fs/proc/array.c linux-2.4.22.up-opt/fs/proc/array.c
@@ -390,7 +390,7 @@
 		task->nswap,
 		task->cnswap,
 		task->exit_signal,
-		task->processor);
+		task_cpu(task));
 	if(mm)
 		mmput(mm);
 	return res;
include/linux/sched.h +63 -3

80 lines not on this page · raw message

kernel/sched.c +4 -4
diff -ruN linux-2.4.22/kernel/sched.c linux-2.4.22.up-opt/kernel/sched.c
@@ -359,7 +359,7 @@
 	if (task_on_runqueue(p))
 		goto out;
 	add_to_runqueue(p);
-	if (!synchronous || !(p->cpus_allowed & (1UL << smp_processor_id())))
+	if (!synchronous || !(task_cpus_allowed(p) & (1UL << smp_processor_id())))
 		reschedule_idle(p);
 	success = 1;
 out:
@@ -557,7 +557,7 @@
 	BUG_ON(!current->active_mm);
 need_resched_back:
 	prev = current;
-	this_cpu = prev->processor;
+	this_cpu = task_cpu(prev);
 
 	if (unlikely(in_interrupt())) {
 		printk("Scheduling in interrupt\n");
@@ -1364,7 +1364,7 @@
 	}
 	sched_data->curr = current;
 	sched_data->last_schedule = get_cycles();
-	clear_bit(current->processor, &wait_init_idle);
+	clear_bit(task_cpu(current), &wait_init_idle);
 }
 
 extern void init_timervecs (void);
@@ -1378,7 +1378,7 @@
 	int cpu = smp_processor_id();
 	int nr;
 
-	init_task.processor = cpu;
+	set_task_cpu(&init_task, cpu);
 
 	for(nr = 0; nr < PIDHASH_SZ; nr++)
 		pidhash[nr] = NULL;
kernel/softirq.c +1 -1
diff -ruN linux-2.4.22/kernel/softirq.c linux-2.4.22.up-opt/kernel/softirq.c
@@ -368,7 +368,7 @@
 	sigfillset(&current->blocked);
 
 	/* Migrate to the right CPU */
-	current->cpus_allowed = 1UL << cpu;
+	set_task_cpus_allowed(current, 1UL << cpu);
 	while (smp_processor_id() != cpu)
 		schedule();
 
#2 lore raw
Quoted 16 lines · Mikael Pettersson
Quoted 10 lines · Herbert =?iso-8859-1?Q?P=F6tzl?= writes:

Hi Mikael!
Hi Marcelo!

stumbled repeatedly over the patches (or what remained of them) from Mikael?, replacing task->processor and friends by inline functions task_cpu(task), to eliminate them on UP systems ...

my questions:
- is there an up to date patchset?

Yes, I've kept it up to date. In fact I've been using it in every single 2.4 kernel I've built for the last 18+ months. Lately also on ppc32 and x86-64.

Quoted 8 lines

Below is the current UP micro-optimisation patch set for 2.4.22. It changes p->processor, p->cpus_allowed, and p->cpus_runnable accesses (reads and writes) to use inline functions. In UP kernels these reduce to doing nothing or returning a constant.

To keep the patch small, it doesn't change accesses in SMP-only code. (This is also the reason why p->cpus_runnable only has a wrapper for updates, since all reads are in SMP-only code.)

good to know ... will use it in my patchset (now with reference ;) let me know if you add/fix something ...

thanks for the patch,
Herbert

Quoted 1 line

/Mikael

#3 lore raw
In reply to Mikael Pettersson

Am Mit, 2003-08-27 um 20.17 schrieb Mikael Pettersson:

Quoted 17 lines
include/linux/sched.h +17 -0
+#else
+
+static inline int task_cpu(const struct task_struct *p)
+{
+	return 0;
+}
+
+static inline void set_task_cpu(struct task_struct *p, int cpu)
+{
+}
+
+static inline unsigned long task_cpus_allowed(const struct task_struct *p)
+{
+	return ~0UL;
+}
+
+static inline void set_task_cpus_allowed(struct task_struct *p,

include/linux/sched.h line 620

Quoted 10 lines
include/linux/sched.h +10 -0
+					 unsigned long cpus_allowed)
+{
+}
+
+static inline void set_task_cpus_runnable(struct task_struct *p,
+					  unsigned long cpus_runnable)
+{
+}
+
+#endif /* CONFIG_SMP */

Shouldn't these be marked const?

Signature · 2 lines
Servus,
       Daniel
#4 lore raw
Quoted 1 line · Daniel Egger

Shouldn't these be marked const?

1. There's no need, because they are inline and simple enough to optimise.

2. GCC seems to ignore const and pure attributes on inline functions, even when that would enable optimisation that it cannot see from the function body.

-- Jamie