Skip to contentSkip to conversation

Kill ipipe_processor_id completely

RFC PATCH New Jan Kiszka 1 participant 1 message May 13, 2007

Subsystems (2)
lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

RFC PATCH 1/1 Kill ipipe_processor_id completely

Hi Philippe,

you have been warned, here it is: my radical janitor work to remove any trace of ipipe_processor_id from the I-pipe patch. =8)

It's still RFC, comes in big blobs, and most probably leaves a few corner cases behind, but it already survived light testing on qemu smp boxes. Features:

- Far less reasons to handle smp_processor_id() calls special when being used also over non-root domains -- thus less patch hunks.
- (Almost) fully functional debug_smp_processor_id() for all I-pipe domains. The only restriction comes from the fact that domain- internal preempt_disable variants are not known to the generic code and still require special handling (raw_smp_processor_id()).
- Micro-optimisations for UP (killed a few cpuid parameter passings).
- Remove also ipipe_safe_current(), we should demand non-stack-based current for all archs now. As ipipe-kdgb is still stalled for recent kernels (I wonder if kgdb will EVER make it into mainline - a pity), no damage is caused.

To-do:
- Review and test for more corner cases in which debug_smp_processor_id may give false positives.
- Check if xntimer_init is actually fine.
- Port to other archs.

Here is the patch list:
[I-pipe 1.8-01, dependencies: trace_panic-only-once.patch]
1. remove-safe-current.patch
2. remove-ipipe_processor_id.patch
3. remove-ipipe_processor_id-i386.patch

[Xenomai trunk]
4. xeno-kill-ipipe_processor_id.patch

Comments welcome!

Jan

---
 include/linux/ipipe.h |   11 -----------
 1 file changed, 11 deletions(-)
include/linux/ipipe.h +0 -11
Index: linux-2.6.20/include/linux/ipipe.h
===================================================================
@@ -588,16 +588,6 @@ static inline void ipipe_clear_foreign_s
 	__clear_bit(IPIPE_NOSTACK_FLAG, &ipd->cpudata[cpuid].status);
 }
 
-#define ipipe_safe_current()					\
-({								\
-	ipipe_declare_cpuid;					\
-	struct task_struct *p;					\
-	ipipe_load_cpuid();					\
-	p = test_bit(IPIPE_NOSTACK_FLAG,			\
-		     &per_cpu(ipipe_percpu_domain, cpuid)->cpudata[cpuid].status) ? &init_task : current; \
-	p; \
-})
-
 ipipe_event_handler_t ipipe_catch_event(struct ipipe_domain *ipd,
 					unsigned event,
 					ipipe_event_handler_t handler);
@@ -686,7 +676,6 @@ int ipipe_disable_ondemand_mappings(stru
 #define ipipe_irq_unlock(irq)		do { } while(0)
 
 #define ipipe_root_domain_p		1
-#define ipipe_safe_current		current
 
 #define local_irq_disable_head()	local_irq_disable()
 
---
 include/linux/ipipe.h      |   17 +++-----
 include/linux/smp.h        |    8 ---
 kernel/ipipe/Kconfig.debug |   11 ++++-
 kernel/ipipe/core.c        |   16 ++++---
 kernel/ipipe/tracer.c      |   91 +++++++++++++++++++++++----------------------
 lib/smp_processor_id.c     |   17 +++++++-
 6 files changed, 90 insertions(+), 70 deletions(-)
include/linux/ipipe.h +7 -10
Index: linux-2.6.20/include/linux/ipipe.h
===================================================================
@@ -96,16 +96,17 @@
 #define IPIPE_NR_CPUS		NR_CPUS
 #define ipipe_declare_cpuid	int cpuid
 #define ipipe_load_cpuid()	do { \
-					cpuid = ipipe_processor_id();	\
+					cpuid = smp_processor_id();	\
 				} while(0)
 #define ipipe_lock_cpu(flags)	do { \
 					local_irq_save_hw(flags); \
-					cpuid = ipipe_processor_id(); \
+					cpuid = smp_processor_id(); \
 				} while(0)
 #define ipipe_unlock_cpu(flags)	local_irq_restore_hw(flags)
 #define ipipe_get_cpu(flags)	ipipe_lock_cpu(flags)
 #define ipipe_put_cpu(flags)	ipipe_unlock_cpu(flags)
-#define ipipe_current_domain	per_cpu(ipipe_percpu_domain, ipipe_processor_id())
+#define ipipe_current_domain \
+	per_cpu(ipipe_percpu_domain, raw_smp_processor_id())
 
 #else /* !CONFIG_SMP */
 
@@ -304,7 +305,7 @@ void __ipipe_remove_domain_proc(struct i
 
 void __ipipe_flush_printk(unsigned irq, void *cookie);
 
-void fastcall __ipipe_walk_pipeline(struct list_head *pos, int cpuid);
+void __ipipe_walk_pipeline(struct list_head *pos);
 
 int fastcall __ipipe_schedule_irq(unsigned irq, struct list_head *head);
 
@@ -402,9 +403,8 @@ do {									\
 
 #define ipipe_trap_notify(ex, regs)		\
 ({						\
-	ipipe_declare_cpuid;			\
+	int cpuid = raw_smp_processor_id();	\
 	int ret = 0;				\
-	ipipe_load_cpuid();			\
 	if ((test_bit(IPIPE_NOSTACK_FLAG, &ipipe_current_domain->cpudata[cpuid].status) || \
 	     ((current)->flags & PF_EVNOTIFY)) &&			\
 	    __ipipe_event_monitored_p(ex))				\
@@ -529,7 +529,7 @@ static inline void ipipe_restore_pipelin
 	 * the truth value (if this is wrong, the failed optimization will
 	 * be caught in __ipipe_restore_pipeline_head() if
 	 * CONFIG_DEBUG_KERNEL is set). */
-	if ((x ^ test_bit(IPIPE_STALL_FLAG, &head->cpudata[ipipe_processor_id()].status)) & 1)
+	if ((x ^ test_bit(IPIPE_STALL_FLAG, &head->cpudata[smp_processor_id()].status)) & 1)
 		__ipipe_restore_pipeline_head(head,x);
 }
 
@@ -635,8 +635,6 @@ int ipipe_disable_ondemand_mappings(stru
 			local_irq_disable_hw();		\
 	} while(0)
 
-#define smp_processor_id_hw()				ipipe_processor_id()
-
 #define ipipe_irq_lock(irq)						\
 	do {								\
 		ipipe_declare_cpuid;					\
@@ -670,7 +668,6 @@ int ipipe_disable_ondemand_mappings(stru
 #define local_irq_disable_hw_cond()		do { } while(0)
 #define local_irq_save_hw_cond(flags)	do { (void)(flags); } while(0)
 #define local_irq_restore_hw_cond(flags)	do { } while(0)
-#define smp_processor_id_hw()			smp_processor_id()
 
 #define ipipe_irq_lock(irq)		do { } while(0)
 #define ipipe_irq_unlock(irq)		do { } while(0)
kernel/ipipe/core.c +10 -6
Index: linux-2.6.20/kernel/ipipe/core.c
===================================================================
@@ -272,7 +272,7 @@ void fastcall ipipe_unstall_pipeline_fro
 	else
 		pos = __ipipe_pipeline.next;
 
-	__ipipe_walk_pipeline(pos, cpuid);
+	__ipipe_walk_pipeline(pos);
 
 	if (__ipipe_pipeline_head_p(ipd))
 		local_irq_enable_hw();
@@ -316,7 +316,7 @@ void ipipe_unstall_pipeline_head(void)
 		if (likely(head == per_cpu(ipipe_percpu_domain, cpuid)))
 			__ipipe_sync_pipeline(IPIPE_IRQMASK_ANY);
 		else
-			__ipipe_walk_pipeline(&head->p_link, cpuid);
+			__ipipe_walk_pipeline(&head->p_link);
         }
 
 	local_irq_enable_hw();
@@ -352,7 +352,7 @@ void fastcall __ipipe_restore_pipeline_h
 			if (likely(head == per_cpu(ipipe_percpu_domain, cpuid)))
 				__ipipe_sync_pipeline(IPIPE_IRQMASK_ANY);
 			else
-				__ipipe_walk_pipeline(&head->p_link, cpuid);
+				__ipipe_walk_pipeline(&head->p_link);
 		}
 		local_irq_enable_hw();
 	}
@@ -361,9 +361,13 @@ void fastcall __ipipe_restore_pipeline_h
 /* __ipipe_walk_pipeline(): Plays interrupts pending in the log. Must
    be called with local hw interrupts disabled. */
 
-void fastcall __ipipe_walk_pipeline(struct list_head *pos, int cpuid)
+void __ipipe_walk_pipeline(struct list_head *pos)
 {
-	struct ipipe_domain *this_domain = per_cpu(ipipe_percpu_domain, cpuid);
+	struct ipipe_domain *this_domain;
+	ipipe_declare_cpuid;
+
+	ipipe_load_cpuid();
+	this_domain = per_cpu(ipipe_percpu_domain, cpuid);
 
 	while (pos != &__ipipe_pipeline) {
 		struct ipipe_domain *next_domain =
@@ -810,7 +814,7 @@ void fastcall __ipipe_sync_stage(unsigne
 			__ipipe_run_isr(ipd, irq, cpuid);
 #ifdef CONFIG_SMP
 			{
-				int _cpuid = ipipe_processor_id();
+				int _cpuid = smp_processor_id();
 
 				if (_cpuid != cpuid) {	/* Handle CPU migration. */
 					/*
kernel/ipipe/tracer.c +47 -44

275 lines not on this page · raw message

include/linux/smp.h +1 -7
Index: linux-2.6.20/include/linux/smp.h
===================================================================
@@ -109,8 +109,6 @@ static inline int smp_call_function_sing
 
 #endif /* !SMP */
 
-#include <linux/ipipe_base.h>
-
 /*
  * smp_processor_id(): get the current CPU ID.
  *
@@ -130,11 +128,7 @@ static inline int smp_call_function_sing
   extern unsigned int debug_smp_processor_id(void);
 # define smp_processor_id() debug_smp_processor_id()
 #else
-# define smp_processor_id()				\
-	({						\
-		ipipe_check_context(ipipe_root_domain);	\
-		raw_smp_processor_id();			\
-	})
+# define smp_processor_id() raw_smp_processor_id()
 #endif
 
 #define get_cpu()		({ preempt_disable(); smp_processor_id(); })
lib/smp_processor_id.c +16 -1
Index: linux-2.6.20/lib/smp_processor_id.c
===================================================================
@@ -13,7 +13,22 @@ unsigned int debug_smp_processor_id(void
 	int this_cpu = raw_smp_processor_id();
 	cpumask_t this_mask;
 
-	ipipe_check_context(ipipe_root_domain);
+#ifdef CONFIG_IPIPE
+	if (irqs_disabled_hw())
+		goto out;
+
+	if (unlikely(!ipipe_root_domain_p && !ipipe_test_pipeline())) {
+		ipipe_trace_panic_freeze();
+		printk(KERN_ERR "BUG: using smp_processor_id() in non-atomic "
+			"context. I-pipe domain: %s\n",
+			ipipe_current_domain->name);
+		print_symbol("caller is %s\n",
+			(long)__builtin_return_address(0));
+		dump_stack();
+		ipipe_trace_panic_dump();
+		goto out;
+	}
+#endif /* CONFIG_IPIPE */
 
 	if (likely(preempt_count))
 		goto out;
kernel/ipipe/Kconfig.debug +9 -2
Index: linux-2.6.20/kernel/ipipe/Kconfig.debug
===================================================================
@@ -2,9 +2,15 @@ config IPIPE_DEBUG
 	bool "I-pipe debugging"
 	depends on IPIPE
 
+if IPIPE_DEBUG
+
+comment "HINT: Switch on DEBUG_PREEMPT in order to detect broken"
+	depends on !DEBUG_PREEMPT
+comment "usages of smp_processor_id() also over non-root domains."
+	depends on !DEBUG_PREEMPT
+
 config IPIPE_DEBUG_CONTEXT
 	bool "Check for illicit cross-domain calls"
-	depends on IPIPE_DEBUG
 	default y
 	---help---
 	  Enable this feature to arm checkpoints in the kernel that
@@ -14,7 +20,6 @@ config IPIPE_DEBUG_CONTEXT
 
 config IPIPE_TRACE
 	bool "Latency tracing"
-	depends on IPIPE_DEBUG
 	select FRAME_POINTER
 	select KALLSYMS
 	select PROC_FS
@@ -78,3 +83,5 @@ config IPIPE_TRACE_ENABLE_VALUE
 	int
 	default 0 if !IPIPE_TRACE_ENABLE
 	default 1 if IPIPE_TRACE_ENABLE
+
+endif
---
 arch/i386/kernel/ipipe.c                 |    2 +-
 arch/i386/kernel/nmi.c                   |    2 +-
 arch/i386/kernel/process.c               |    2 +-
 arch/i386/kernel/traps.c                 |    6 +-----
 include/asm-i386/desc.h                  |    2 +-
 include/asm-i386/ipipe.h                 |    2 --
 include/asm-i386/mach-bigsmp/mach_ipi.h  |    2 +-
 include/asm-i386/mach-default/mach_ipi.h |    2 +-
 include/asm-i386/mach-es7000/mach_apic.h |    2 +-
 include/asm-i386/mach-es7000/mach_ipi.h  |    2 +-
 include/asm-i386/mach-numaq/mach_ipi.h   |    2 +-
 include/asm-i386/mach-summit/mach_ipi.h  |    2 +-
 include/asm-i386/mmu_context.h           |    4 ++--
 include/asm-i386/processor.h             |    2 +-
 14 files changed, 14 insertions(+), 20 deletions(-)
arch/i386/kernel/ipipe.c +1 -1
Index: linux-2.6.20/arch/i386/kernel/ipipe.c
===================================================================
@@ -834,7 +834,7 @@ finalize:
 	 * current domain in the pipeline.
 	 */
 
-	__ipipe_walk_pipeline(head, cpuid);
+	__ipipe_walk_pipeline(head);
 
 	ipipe_load_cpuid();
 
include/asm-i386/ipipe.h +0 -2
Index: linux-2.6.20/include/asm-i386/ipipe.h
===================================================================
@@ -86,8 +86,6 @@
 #include <linux/threads.h>
 #include <asm/ptrace.h>
 
-#define ipipe_processor_id()   raw_smp_processor_id()
-
 #define prepare_arch_switch(next)		\
 do {						\
 	ipipe_schedule_notify(current, next);	\
arch/i386/kernel/nmi.c +1 -1
Index: linux-2.6.20/arch/i386/kernel/nmi.c
===================================================================
@@ -896,7 +896,7 @@ static __kprobes int default_nmi_watchdo
 	 */
 	unsigned int sum;
 	int touched = 0;
-	int cpu = smp_processor_id_hw();
+	int cpu = smp_processor_id();
 	struct nmi_watchdog_ctlblk *wd = &__get_cpu_var(nmi_watchdog_ctlblk);
 	u64 dummy;
 	int rc=0;
arch/i386/kernel/process.c +1 -1
Index: linux-2.6.20/arch/i386/kernel/process.c
===================================================================
@@ -636,7 +636,7 @@ struct task_struct fastcall * __switch_t
 {
 	struct thread_struct *prev = &prev_p->thread,
 				 *next = &next_p->thread;
-	int cpu = raw_smp_processor_id();
+	int cpu = smp_processor_id();
 	struct tss_struct *tss = &per_cpu(init_tss, cpu);
 
 	/* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
arch/i386/kernel/traps.c +1 -5
Index: linux-2.6.20/arch/i386/kernel/traps.c
===================================================================
@@ -725,7 +725,7 @@ static __kprobes void default_do_nmi(str
 	unsigned char reason = 0;
 
 	/* Only the BSP gets external NMIs from the system.  */
-	if (!smp_processor_id_hw())
+	if (!smp_processor_id())
 		reason = get_nmi_reason();
  
 	if (!(reason & 0xc0)) {
@@ -764,11 +764,7 @@ fastcall __kprobes void do_nmi(struct pt
 
 	nmi_enter();
 
-#ifdef CONFIG_IPIPE
-	cpu = ipipe_processor_id();
-#else /* !CONFIG_IPIPE */
 	cpu = smp_processor_id();
-#endif /* !CONFIG_IPIPE */
 
 	++nmi_count(cpu);
 
include/asm-i386/mach-bigsmp/mach_ipi.h +1 -1
Index: linux-2.6.20/include/asm-i386/mach-bigsmp/mach_ipi.h
===================================================================
@@ -11,7 +11,7 @@ static inline void send_IPI_mask(cpumask
 static inline void send_IPI_allbutself(int vector)
 {
 	cpumask_t mask = cpu_online_map;
-	cpu_clear(smp_processor_id_hw(), mask);
+	cpu_clear(smp_processor_id(), mask);
 
 	if (!cpus_empty(mask))
 		send_IPI_mask(mask, vector);
include/asm-i386/mach-default/mach_ipi.h +1 -1
Index: linux-2.6.20/include/asm-i386/mach-default/mach_ipi.h
===================================================================
@@ -19,7 +19,7 @@ static inline void __local_send_IPI_allb
 	if (no_broadcast || vector == NMI_VECTOR) {
 		cpumask_t mask = cpu_online_map;
 
-		cpu_clear(smp_processor_id_hw(), mask);
+		cpu_clear(smp_processor_id(), mask);
 		send_IPI_mask(mask, vector);
 	} else
 		__send_IPI_shortcut(APIC_DEST_ALLBUT, vector);
include/asm-i386/mach-es7000/mach_apic.h +1 -1
Index: linux-2.6.20/include/asm-i386/mach-es7000/mach_apic.h
===================================================================
@@ -16,7 +16,7 @@ static inline cpumask_t target_cpus(void
 #if defined CONFIG_ES7000_CLUSTERED_APIC
 	return CPU_MASK_ALL;
 #else
-	return cpumask_of_cpu(smp_processor_id_hw());
+	return cpumask_of_cpu(smp_processor_id());
 #endif
 }
 #define TARGET_CPUS	(target_cpus())
include/asm-i386/mach-es7000/mach_ipi.h +1 -1
Index: linux-2.6.20/include/asm-i386/mach-es7000/mach_ipi.h
===================================================================
@@ -11,7 +11,7 @@ static inline void send_IPI_mask(cpumask
 static inline void send_IPI_allbutself(int vector)
 {
 	cpumask_t mask = cpu_online_map;
-	cpu_clear(smp_processor_id_hw(), mask);
+	cpu_clear(smp_processor_id(), mask);
 	if (!cpus_empty(mask))
 		send_IPI_mask(mask, vector);
 }
include/asm-i386/mach-numaq/mach_ipi.h +1 -1
Index: linux-2.6.20/include/asm-i386/mach-numaq/mach_ipi.h
===================================================================
@@ -11,7 +11,7 @@ static inline void send_IPI_mask(cpumask
 static inline void send_IPI_allbutself(int vector)
 {
 	cpumask_t mask = cpu_online_map;
-	cpu_clear(smp_processor_id_hw(), mask);
+	cpu_clear(smp_processor_id(), mask);
 
 	if (!cpus_empty(mask))
 		send_IPI_mask(mask, vector);
include/asm-i386/mach-summit/mach_ipi.h +1 -1
Index: linux-2.6.20/include/asm-i386/mach-summit/mach_ipi.h
===================================================================
@@ -11,7 +11,7 @@ static inline void send_IPI_mask(cpumask
 static inline void send_IPI_allbutself(int vector)
 {
 	cpumask_t mask = cpu_online_map;
-	cpu_clear(smp_processor_id_hw(), mask);
+	cpu_clear(smp_processor_id(), mask);
 
 	if (!cpus_empty(mask))
 		send_IPI_mask(mask, vector);
include/asm-i386/mmu_context.h +2 -2
Index: linux-2.6.20/include/asm-i386/mmu_context.h
===================================================================
@@ -16,7 +16,7 @@ void destroy_context(struct mm_struct *m
 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
 {
 #ifdef CONFIG_SMP
-	unsigned cpu = smp_processor_id_hw();
+	unsigned cpu = smp_processor_id();
 	if (per_cpu(cpu_tlbstate, cpu).state == TLBSTATE_OK)
 		per_cpu(cpu_tlbstate, cpu).state = TLBSTATE_LAZY;
 #endif
@@ -26,7 +26,7 @@ static inline void switch_mm(struct mm_s
 			     struct mm_struct *next,
 			     struct task_struct *tsk)
 {
-	int cpu = smp_processor_id_hw();
+	int cpu = smp_processor_id();
 
 	if (likely(prev != next)) {
 		/* stop flush ipis for the previous mm */
include/asm-i386/desc.h +1 -1
Index: linux-2.6.20/include/asm-i386/desc.h
===================================================================
@@ -101,7 +101,7 @@ static inline fastcall void native_set_l
 	if (likely(entries == 0))
 		__asm__ __volatile__("lldt %w0"::"q" (0));
 	else {
-		unsigned cpu = smp_processor_id_hw();
+		unsigned cpu = smp_processor_id();
 		__u32 a, b;
 
 		pack_descriptor(&a, &b, (unsigned long)addr,
include/asm-i386/processor.h +1 -1
Index: linux-2.6.20/include/asm-i386/processor.h
===================================================================
@@ -104,7 +104,7 @@ DECLARE_PER_CPU(struct tss_struct, init_
 
 #ifdef CONFIG_SMP
 extern struct cpuinfo_x86 cpu_data[];
-#define current_cpu_data cpu_data[smp_processor_id_hw()]
+#define current_cpu_data cpu_data[smp_processor_id()]
 #else
 #define cpu_data (&boot_cpu_data)
 #define current_cpu_data boot_cpu_data
---
 include/asm-generic/hal.h    |   18 ++++++++++++------
 include/asm-generic/system.h |    5 +++++
 include/asm-sim/system.h     |    1 +
 include/nucleus/pod.h        |   15 +++++++++------
 ksrc/nucleus/shadow.c        |   14 ++++++--------
 ksrc/nucleus/timer.c         |    3 ++-
 6 files changed, 35 insertions(+), 21 deletions(-)
include/asm-generic/hal.h +12 -6
Index: xenomai/include/asm-generic/hal.h
===================================================================
@@ -151,7 +151,7 @@ typedef rwlock_t rthal_rwlock_t;
 #define rthal_declare_cpuid		ipipe_declare_cpuid
 
 #define rthal_load_cpuid()		ipipe_load_cpuid()
-#define rthal_suspend_domain()	ipipe_suspend_domain()
+#define rthal_suspend_domain()		ipipe_suspend_domain()
 #define rthal_grab_superlock(syncfn)	ipipe_critical_enter(syncfn)
 #define rthal_release_superlock(x)	ipipe_critical_exit(x)
 #define rthal_propagate_irq(irq)	ipipe_propagate_irq(irq)
@@ -160,10 +160,10 @@ typedef rwlock_t rthal_rwlock_t;
 #define rthal_virtualize_irq(dom,irq,isr,cookie,ackfn,mode) ipipe_virtualize_irq(dom,irq,isr,cookie,ackfn,mode)
 #define rthal_alloc_virq()		ipipe_alloc_virq()
 #define rthal_free_virq(irq)		ipipe_free_virq(irq)
-#define rthal_trigger_irq(irq)	ipipe_trigger_irq(irq)
-#define rthal_get_sysinfo(ibuf)	ipipe_get_sysinfo(ibuf)
+#define rthal_trigger_irq(irq)		ipipe_trigger_irq(irq)
+#define rthal_get_sysinfo(ibuf)		ipipe_get_sysinfo(ibuf)
 #define rthal_alloc_ptdkey()		ipipe_alloc_ptdkey()
-#define rthal_free_ptdkey(key)	ipipe_free_ptdkey(key)
+#define rthal_free_ptdkey(key)		ipipe_free_ptdkey(key)
 #define rthal_send_ipi(irq,cpus)	ipipe_send_ipi(irq,cpus)
 #define rthal_lock_irq(dom,cpu,irq)	__ipipe_lock_irq(dom,cpu,irq)
 #define rthal_unlock_irq(dom,irq)	__ipipe_unlock_irq(dom,irq)
@@ -174,12 +174,18 @@ typedef rwlock_t rthal_rwlock_t;
 #define rthal_unlock_cpu(x)		ipipe_unlock_cpu(x)
 #define rthal_get_cpu(x)		ipipe_get_cpu(x)
 #define rthal_put_cpu(x)		ipipe_put_cpu(x)
+#ifdef ipipe_processor_id
 #define rthal_processor_id()		ipipe_processor_id()
+#define rthal_raw_processor_id()	ipipe_processor_id()
+#else
+#define rthal_processor_id()		smp_processor_id()
+#define rthal_raw_processor_id()	raw_smp_processor_id()
+#endif
 
 #define rthal_setsched_root(t,pol,prio)	ipipe_setscheduler_root(t,pol,prio)
 #define rthal_reenter_root(t,pol,prio)	ipipe_reenter_root(t,pol,prio)
-#define rthal_emergency_console()		ipipe_set_printk_sync(ipipe_current_domain)
-#define rthal_read_tsc(v)			ipipe_read_tsc(v)
+#define rthal_emergency_console()	ipipe_set_printk_sync(ipipe_current_domain)
+#define rthal_read_tsc(v)		ipipe_read_tsc(v)
 
 static inline unsigned long rthal_get_cpufreq(void)
 {
include/asm-generic/system.h +5 -0
Index: xenomai/include/asm-generic/system.h
===================================================================
@@ -205,6 +205,11 @@ static inline unsigned xnarch_current_cp
     return rthal_processor_id();
 }
 
+static inline unsigned xnarch_raw_current_cpu(void)
+{
+    return rthal_raw_processor_id();
+}
+
 #define xnarch_declare_cpuid  rthal_declare_cpuid
 #define xnarch_get_cpu(flags) rthal_get_cpu(flags)
 #define xnarch_put_cpu(flags) rthal_put_cpu(flags)
include/asm-sim/system.h +1 -0
Index: xenomai/include/asm-sim/system.h
===================================================================
@@ -420,6 +420,7 @@ static inline void xnarch_sysfree (void 
 }
 
 #define xnarch_current_cpu()  0
+#define xnarch_raw_current_cpu() 0
 #define xnarch_declare_cpuid  const int cpuid = 0
 #define xnarch_get_cpu(x)     do  { (x) = (x); } while(0)
 #define xnarch_put_cpu(x)     do { } while(0)
include/nucleus/pod.h +9 -6
Index: xenomai/include/nucleus/pod.h
===================================================================
@@ -153,7 +153,7 @@ typedef struct xnsched {
 #endif /* CONFIG_SMP */
 
 #define xnsched_resched_mask() \
-    (xnpod_current_sched()->resched)
+    (xnpod_raw_current_sched()->resched)
 
 #define xnsched_resched_p()                     \
     (!xnarch_cpus_empty(xnsched_resched_mask()))
@@ -261,17 +261,20 @@ static inline void xnpod_reset_watchdog(
 #define xnpod_current_sched() \
     xnpod_sched_slot(xnarch_current_cpu())
 
+#define xnpod_raw_current_sched() \
+    xnpod_sched_slot(xnarch_raw_current_cpu())
+
 #define xnpod_interrupt_p() \
-    (xnpod_current_sched()->inesting > 0)
+    (xnpod_raw_current_sched()->inesting > 0)
 
 #define xnpod_callout_p() \
-    (!!testbits(xnpod_current_sched()->status,XNKCOUT))
+    (!!testbits(xnpod_raw_current_sched()->status,XNKCOUT))
 
 #define xnpod_asynch_p() \
     (xnpod_interrupt_p() || xnpod_callout_p())
 
 #define xnpod_current_thread() \
-    (xnpod_current_sched()->runthread)
+    (xnpod_raw_current_sched()->runthread)
 
 #define xnpod_current_root() \
     (&xnpod_current_sched()->rootcb)
@@ -412,7 +415,7 @@ void xnpod_dispatch_signals(void);
 
 static inline void xnpod_lock_sched(void)
 {
-	xnthread_t *runthread = xnpod_current_sched()->runthread;
+	xnthread_t *runthread = xnpod_current_thread();
 	spl_t s;
 
 	xnlock_get_irqsave(&nklock, s);
@@ -425,7 +428,7 @@ static inline void xnpod_lock_sched(void
 
 static inline void xnpod_unlock_sched(void)
 {
-	xnthread_t *runthread = xnpod_current_sched()->runthread;
+	xnthread_t *runthread = xnpod_current_thread();
 	spl_t s;
 
 	xnlock_get_irqsave(&nklock, s);
ksrc/nucleus/timer.c +2 -1
Index: xenomai/ksrc/nucleus/timer.c
===================================================================
@@ -532,7 +532,8 @@ void xntimer_init(xntimer_t *timer, xntb
 	timer->status = XNTIMER_DEQUEUED;
 	timer->handler = handler;
 	timer->interval = 0;
-	timer->sched = xnpod_current_sched();
+	/*FIXME: Do we care about the correct initial sched or not? */
+	timer->sched = xnpod_raw_current_sched();
 
 	xnarch_init_display_context(timer);
 }
ksrc/nucleus/shadow.c +6 -8
Index: xenomai/ksrc/nucleus/shadow.c
===================================================================
@@ -201,7 +201,7 @@ static void rpi_push(xnthread_t *thread)
 	int prio;
 	spl_t s;
 
-	gk = &gatekeeper[rthal_processor_id()];
+	gk = &gatekeeper[smp_processor_id()];
 
 	/* non-RT shadows and RT shadows which disabled RPI cause the
 	   root priority to be lowered to its base level. The purpose
@@ -235,7 +235,7 @@ static void rpi_pop(xnthread_t *thread)
 	int prio;
 	spl_t s;
 
-	gk = &gatekeeper[rthal_processor_id()];
+	gk = &gatekeeper[smp_processor_id()];
 
 	xnlock_get_irqsave(&rpilock, s);
 
@@ -300,7 +300,7 @@ static inline void rpi_update(xnthread_t
 
 	if (sched_emptypq_p(&thread->rpi->threadq)) {
 		int rcpu = container_of(thread->rpi, struct __gatekeeper, rpislot) - gatekeeper;
-		if (rcpu != rthal_processor_id()) {
+		if (rcpu != smp_processor_id()) {
 			xnsched_t *rsched = xnpod_sched_slot(rcpu);
 			if (!testbits(rsched->status, XNRPICK)) {
 				xnarch_cpumask_t cpumask;
@@ -327,7 +327,7 @@ static inline void rpi_switch(struct tas
 
 	threadout = xnshadow_thread(current);
 	threadin = xnshadow_thread(next);
-	gk = &gatekeeper[rthal_processor_id()];
+	gk = &gatekeeper[smp_processor_id()];
 	oldprio = xnthread_current_priority(xnpod_current_root());
 
 	if (threadout &&
@@ -421,7 +421,7 @@ void xnshadow_rpi_check(void)
 	struct __gatekeeper *gk;
 	spl_t s;
 
-	gk = &gatekeeper[rthal_processor_id()];
+	gk = &gatekeeper[smp_processor_id()];
 
 	xnlock_get_irqsave(&rpilock, s);
 
@@ -848,9 +848,7 @@ static void lostage_handler(void *cookie
 
 static void schedule_linux_call(int type, struct task_struct *p, int arg)
 {
-	/* Do _not_ use smp_processor_id() here so we don't trigger Linux
-	   preemption debug traps inadvertently (see lib/smp_processor_id.c). */
-	int cpuid = rthal_processor_id(), reqnum;
+	int cpuid = smp_processor_id(), reqnum;
 	struct __lostagerq *rq = &lostagerq[cpuid];
 	spl_t s;