linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] per-cpu patch 2/3
@ 2002-07-18  3:48 Rusty Russell
  2002-07-18 17:05 ` Robert Love
  0 siblings, 1 reply; 4+ messages in thread
From: Rusty Russell @ 2002-07-18  3:48 UTC (permalink / raw)
  To: torvalds; +Cc: linux-kernel

Given the ongoing races with smp_processor_id() and preempt, this
makes sense to me.  this_cpu() was too generic a name anyway.

Name: get_cpu_var patch
Author: Rusty Russell
Status: Cleanup

D: This makes introduces get_cpu_var() which gets a per-cpu variable
D: and disables preemption, and renames the (unsafe under preemption)
D: "this_cpu()" macro to __get_cpu_var().  It also deletes the
D: redundant definitions in linux/smp.h.

diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/include/linux/percpu.h working-2.5.25-getcpu/include/linux/percpu.h
--- linux-2.5.25/include/linux/percpu.h	Mon Jun 24 00:53:24 2002
+++ working-2.5.25-getcpu/include/linux/percpu.h	Thu Jul 11 13:32:30 2002
@@ -8,7 +8,9 @@
 #else
 #define __per_cpu_data
 #define per_cpu(var, cpu)			var
-#define this_cpu(var)				var
+#define __get_cpu_var(var)			var
 #endif
 
+#define get_cpu_var(var) ({ preempt_disable(); __get_cpu_var(var); })
+#define put_cpu_var(var) preempt_enable()
 #endif /* __LINUX_PERCPU_H */
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/include/linux/smp.h working-2.5.25-getcpu/include/linux/smp.h
--- linux-2.5.25/include/linux/smp.h	Fri Jun 21 09:41:55 2002
+++ working-2.5.25-getcpu/include/linux/smp.h	Thu Jul 11 13:32:07 2002
@@ -89,10 +89,6 @@
 #define cpu_online_map				1
 #define cpu_online(cpu)				1
 #define num_online_cpus()			1
-#define __per_cpu_data
-#define per_cpu(var, cpu)			var
-#define this_cpu(var)				var
-
 #endif /* !SMP */
 
 #define get_cpu()	({ preempt_disable(); smp_processor_id(); })
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/include/asm-ia64/percpu.h working-2.5.25-getcpu/include/asm-ia64/percpu.h
--- linux-2.5.25/include/asm-ia64/percpu.h	Tue Apr 23 11:39:38 2002
+++ working-2.5.25-getcpu/include/asm-ia64/percpu.h	Thu Jul 11 13:34:05 2002
@@ -17,7 +17,7 @@
 extern unsigned long __per_cpu_offset[NR_CPUS];
 
 #define per_cpu(var, cpu)	(*(__typeof__(&(var))) ((void *) &(var) + __per_cpu_offset[cpu]))
-#define this_cpu(var)		(var)
+#define __get_cpu_var(var)	(var)
 
 #endif /* !__ASSEMBLY__ */
 
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/include/asm-ia64/processor.h working-2.5.25-getcpu/include/asm-ia64/processor.h
--- linux-2.5.25/include/asm-ia64/processor.h	Fri Jun 21 09:41:55 2002
+++ working-2.5.25-getcpu/include/asm-ia64/processor.h	Thu Jul 11 13:33:26 2002
@@ -181,7 +181,7 @@
  * The "local" data pointer.  It points to the per-CPU data of the currently executing
  * CPU, much like "current" points to the per-task data of the currently executing task.
  */
-#define local_cpu_data		(&this_cpu(cpu_info))
+#define local_cpu_data		(&__get_cpu_var(cpu_info))
 #define cpu_data(cpu)		(&per_cpu(cpu_info, cpu))
 
 extern void identify_cpu (struct cpuinfo_ia64 *);
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/include/asm-x86_64/percpu.h working-2.5.25-getcpu/include/asm-x86_64/percpu.h
--- linux-2.5.25/include/asm-x86_64/percpu.h	Mon Jun 17 23:19:25 2002
+++ working-2.5.25-getcpu/include/asm-x86_64/percpu.h	Thu Jul 11 13:34:17 2002
@@ -4,7 +4,7 @@
 #include <asm/pda.h>
 
 /* var is in discarded region: offset to particular copy we want */
-#define this_cpu(var)     (*RELOC_HIDE(&var, read_pda(cpudata_offset)))
+#define __get_cpu_var(var)     (*RELOC_HIDE(&var, read_pda(cpudata_offset)))
 #define per_cpu(var, cpu) (*RELOC_HIDE(&var, per_cpu_pda[cpu]))
 
 void setup_per_cpu_areas(void);
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/arch/ia64/kernel/perfmon.c working-2.5.25-getcpu/arch/ia64/kernel/perfmon.c
--- linux-2.5.25/arch/ia64/kernel/perfmon.c	Thu Jun 20 01:28:47 2002
+++ working-2.5.25-getcpu/arch/ia64/kernel/perfmon.c	Thu Jul 11 13:35:08 2002
@@ -1762,7 +1762,7 @@
 		ia64_srlz_i();
 
 #ifdef CONFIG_SMP
-		this_cpu(pfm_dcr_pp)  = 0;
+		__get_cpu_var(pfm_dcr_pp)  = 0;
 #else
 		pfm_tasklist_toggle_pp(0);
 #endif
@@ -2163,7 +2163,7 @@
 	if (ctx->ctx_fl_system) {
 		
 #ifdef CONFIG_SMP
-		this_cpu(pfm_dcr_pp)  = 1;
+		__get_cpu_var(pfm_dcr_pp)  = 1;
 #else
 		pfm_tasklist_toggle_pp(1);
 #endif
@@ -2218,8 +2218,8 @@
 		ia64_srlz_i();
 
 #ifdef CONFIG_SMP
-		this_cpu(pfm_syst_wide) = 1;
-		this_cpu(pfm_dcr_pp)    = 0;
+		__get_cpu_var(pfm_syst_wide) = 1;
+		__get_cpu_var(pfm_dcr_pp)    = 0;
 #endif
 	} else {
 		/*
@@ -2973,9 +2973,9 @@
 	p += sprintf(p, "CPU%d syst_wide   : %d\n"
 			"CPU%d dcr_pp      : %d\n", 
 			smp_processor_id(), 
-			this_cpu(pfm_syst_wide), 
+			__get_cpu_var(pfm_syst_wide), 
 			smp_processor_id(), 
-			this_cpu(pfm_dcr_pp));
+			__get_cpu_var(pfm_dcr_pp));
 #endif
 
 	LOCK_PFS();
@@ -3045,7 +3045,7 @@
 	/*
 	 * propagate the value of the dcr_pp bit to the psr
 	 */
-	ia64_psr(regs)->pp = mode ? this_cpu(pfm_dcr_pp) : 0;
+	ia64_psr(regs)->pp = mode ? __get_cpu_var(pfm_dcr_pp) : 0;
 }
 #endif
 
@@ -3539,8 +3539,8 @@
 		ia64_srlz_i();
 
 #ifdef CONFIG_SMP
-		this_cpu(pfm_syst_wide) = 0;
-		this_cpu(pfm_dcr_pp)    = 0;
+		__get_cpu_var(pfm_syst_wide) = 0;
+		__get_cpu_var(pfm_dcr_pp)    = 0;
 #else
 		pfm_tasklist_toggle_pp(0);
 #endif
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/arch/ia64/kernel/process.c working-2.5.25-getcpu/arch/ia64/kernel/process.c
--- linux-2.5.25/arch/ia64/kernel/process.c	Thu May 30 10:00:47 2002
+++ working-2.5.25-getcpu/arch/ia64/kernel/process.c	Thu Jul 11 13:35:21 2002
@@ -194,7 +194,7 @@
 		pfm_save_regs(task);
 
 # ifdef CONFIG_SMP
-	if (this_cpu(pfm_syst_wide))
+	if (__get_cpu_var(pfm_syst_wide))
 		pfm_syst_wide_update_task(task, 0);
 # endif
 #endif
@@ -216,7 +216,7 @@
 		pfm_load_regs(task);
 
 # ifdef CONFIG_SMP
-	if (this_cpu(pfm_syst_wide)) pfm_syst_wide_update_task(task, 1);
+	if (__get_cpu_var(pfm_syst_wide)) pfm_syst_wide_update_task(task, 1);
 # endif
 #endif
 
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/arch/ia64/kernel/smp.c working-2.5.25-getcpu/arch/ia64/kernel/smp.c
--- linux-2.5.25/arch/ia64/kernel/smp.c	Thu Jun 20 01:28:47 2002
+++ working-2.5.25-getcpu/arch/ia64/kernel/smp.c	Thu Jul 11 13:35:39 2002
@@ -99,7 +99,7 @@
 handle_IPI (int irq, void *dev_id, struct pt_regs *regs)
 {
 	int this_cpu = smp_processor_id();
-	unsigned long *pending_ipis = &this_cpu(ipi_operation);
+	unsigned long *pending_ipis = &__get_cpu_var(ipi_operation);
 	unsigned long ops;
 
 	/* Count this now; we may make a call that never returns. */
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/include/asm-generic/percpu.h working-2.5.25-getcpu/include/asm-generic/percpu.h
--- linux-2.5.25/include/asm-generic/percpu.h	Mon Apr 15 11:47:44 2002
+++ working-2.5.25-getcpu/include/asm-generic/percpu.h	Thu Jul 11 13:32:42 2002
@@ -8,6 +8,6 @@
 
 /* var is in discarded region: offset to particular copy we want */
 #define per_cpu(var, cpu) (*RELOC_HIDE(&var, __per_cpu_offset[cpu]))
-#define this_cpu(var) per_cpu(var, smp_processor_id())
+#define __get_cpu_var(var) per_cpu(var, smp_processor_id())
 
 #endif /* _ASM_GENERIC_PERCPU_H_ */
diff -urN -I \$.*\$ --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.25/kernel/softirq.c working-2.5.25-getcpu/kernel/softirq.c
--- linux-2.5.25/kernel/softirq.c	Sun Jul  7 02:12:24 2002
+++ working-2.5.25-getcpu/kernel/softirq.c	Thu Jul 11 13:31:26 2002
@@ -162,8 +162,8 @@
 	unsigned long flags;
 
 	local_irq_save(flags);
-	t->next = this_cpu(tasklet_vec).list;
-	this_cpu(tasklet_vec).list = t;
+	t->next = __get_cpu_var(tasklet_vec).list;
+	__get_cpu_var(tasklet_vec).list = t;
 	cpu_raise_softirq(smp_processor_id(), TASKLET_SOFTIRQ);
 	local_irq_restore(flags);
 }
@@ -173,8 +173,8 @@
 	unsigned long flags;
 
 	local_irq_save(flags);
-	t->next = this_cpu(tasklet_hi_vec).list;
-	this_cpu(tasklet_hi_vec).list = t;
+	t->next = __get_cpu_var(tasklet_hi_vec).list;
+	__get_cpu_var(tasklet_hi_vec).list = t;
 	cpu_raise_softirq(smp_processor_id(), HI_SOFTIRQ);
 	local_irq_restore(flags);
 }
@@ -184,8 +184,8 @@
 	struct tasklet_struct *list;
 
 	local_irq_disable();
-	list = this_cpu(tasklet_vec).list;
-	this_cpu(tasklet_vec).list = NULL;
+	list = __get_cpu_var(tasklet_vec).list;
+	__get_cpu_var(tasklet_vec).list = NULL;
 	local_irq_enable();
 
 	while (list) {
@@ -205,8 +205,8 @@
 		}
 
 		local_irq_disable();
-		t->next = this_cpu(tasklet_vec).list;
-		this_cpu(tasklet_vec).list = t;
+		t->next = __get_cpu_var(tasklet_vec).list;
+		__get_cpu_var(tasklet_vec).list = t;
 		__cpu_raise_softirq(smp_processor_id(), TASKLET_SOFTIRQ);
 		local_irq_enable();
 	}
@@ -217,8 +217,8 @@
 	struct tasklet_struct *list;
 
 	local_irq_disable();
-	list = this_cpu(tasklet_hi_vec).list;
-	this_cpu(tasklet_hi_vec).list = NULL;
+	list = __get_cpu_var(tasklet_hi_vec).list;
+	__get_cpu_var(tasklet_hi_vec).list = NULL;
 	local_irq_enable();
 
 	while (list) {
@@ -238,8 +238,8 @@
 		}
 
 		local_irq_disable();
-		t->next = this_cpu(tasklet_hi_vec).list;
-		this_cpu(tasklet_hi_vec).list = t;
+		t->next = __get_cpu_var(tasklet_hi_vec).list;
+		__get_cpu_var(tasklet_hi_vec).list = t;
 		__cpu_raise_softirq(smp_processor_id(), HI_SOFTIRQ);
 		local_irq_enable();
 	}

--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] per-cpu patch 2/3
  2002-07-18  3:48 [PATCH] per-cpu patch 2/3 Rusty Russell
@ 2002-07-18 17:05 ` Robert Love
  2002-07-19  1:36   ` Rusty Russell
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Love @ 2002-07-18 17:05 UTC (permalink / raw)
  To: Rusty Russell; +Cc: torvalds, linux-kernel

On Wed, 2002-07-17 at 20:48, Rusty Russell wrote:
> Given the ongoing races with smp_processor_id() and preempt, this
> makes sense to me.  this_cpu() was too generic a name anyway.

Very nice, although:

How do you reenable preemption?

We already have get_cpu() and put_cpu() which do pretty much what you
are suggesting (and put_cpu() enables preemption) and are used by code
today.  If you want to make changes to them, that is fine, but we should
keep the interface...

	Robert Love



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] per-cpu patch 2/3
  2002-07-18 17:05 ` Robert Love
@ 2002-07-19  1:36   ` Rusty Russell
  2002-07-19 17:49     ` Robert Love
  0 siblings, 1 reply; 4+ messages in thread
From: Rusty Russell @ 2002-07-19  1:36 UTC (permalink / raw)
  To: Robert Love; +Cc: torvalds, linux-kernel

In message <1027011926.1086.118.camel@sinai> you write:
> On Wed, 2002-07-17 at 20:48, Rusty Russell wrote:
> > Given the ongoing races with smp_processor_id() and preempt, this
> > makes sense to me.  this_cpu() was too generic a name anyway.
> 
> Very nice, although:
> 
> How do you reenable preemption?

I think you are confused: this patch is an enhancement of the per-cpu
variable infrastructure.  I was making an analogy with
smp_processor_id().

+#define get_cpu_var(var) ({ preempt_disable(); __get_cpu_var(var); })
+#define put_cpu_var(var) preempt_enable()

Clear?
Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] per-cpu patch 2/3
  2002-07-19  1:36   ` Rusty Russell
@ 2002-07-19 17:49     ` Robert Love
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Love @ 2002-07-19 17:49 UTC (permalink / raw)
  To: Rusty Russell; +Cc: torvalds, linux-kernel

On Thu, 2002-07-18 at 18:36, Rusty Russell wrote:

> I think you are confused: this patch is an enhancement of the per-cpu
> variable infrastructure.  I was making an analogy with
> smp_processor_id().
> 
> +#define get_cpu_var(var) ({ preempt_disable(); __get_cpu_var(var); })
> +#define put_cpu_var(var) preempt_enable()
> 
> Clear?

as day.

sorry,

	Robert Love


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-07-19 17:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-18  3:48 [PATCH] per-cpu patch 2/3 Rusty Russell
2002-07-18 17:05 ` Robert Love
2002-07-19  1:36   ` Rusty Russell
2002-07-19 17:49     ` Robert Love

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).