sparc32 SMP for 2.6
I've been poking at the sparc32 SMP code and I have it to the point where it will run a minimal userland. It is still far from being stable though.
For reference, I started with the SMP patch [0] that wli sent to the list last July. To go along with the attached SMP patch, it needs the spinlock fix [1] from Art Haas, and the attached DEBUGSPINLOCK patch from Tom Callaway.
Here's a list of problems I have seen with it so far:
- the scsi driver must be compiled in or it has problems.
- when I compiled with gcc 3.3.4, it drops back to the prom with a level 15 interrupt.
- from a serial console, init hangs
- /proc/interrupts shows 0 interrupts for the 2nd cpu
- sun4d still needs fixing
Testing with gcc 3.2.2 and 2 150 MHz HyperSPARCs, if I compile in scsi and leave out all of the networking, I am able to pass "init=/bin/bash" and get a shell everytime.
I am sure there are still areas of bitrot and neglect that remain, so if anyone has any ideas, feel free to share them.
Bob
[0] http://marc.theaimsgroup.com/?l=linux-sparc&m=109105275025491
[1] http://marc.theaimsgroup.com/?l=linux-sparc&m=110806229008323
arch/sparc/kernel/sparc_ksyms.c renamed from arch/sparc/kernel/sparc_ksyms.c.BAD +2 -1
@@ -118,11 +118,12 @@ EXPORT_SYMBOL(kernel_thread);#ifdef CONFIG_SMP EXPORT_SYMBOL (_do_spin_lock);EXPORT_SYMBOL (_do_spin_unlock); -EXPORT_SYMBOL (_spin_trylock); +EXPORT_SYMBOL (_do_spin_trylock);EXPORT_SYMBOL (_do_read_lock);EXPORT_SYMBOL (_do_read_unlock);EXPORT_SYMBOL (_do_write_lock);EXPORT_SYMBOL (_do_write_unlock); +EXPORT_SYMBOL (_do_write_trylock);#endif #else // XXX find what uses (or used) these.
arch/sparc/lib/debuglocks.c renamed from arch/sparc/lib/debuglocks.c.BAD +24 -1
@@ -82,7 +82,7 @@ again: lock->owner_pc = (cpu &3 ) | (caller & ~3 ); } -int _spin_trylock (spinlock_t *lock) +int _do_spin_trylock (spinlock_t *lock) {unsigned long val;unsigned long caller;
@@ -199,4 +199,27 @@ void _do_write_unlock(rwlock_t *rw) rw->lock =0 ; } +int _do_write_trylock (rwlock_t *rw,char *str) +{ +unsigned long caller; +unsigned long val; +int cpu =smp_processor_id (); + +STORE_CALLER (caller); + + __asm__ __volatile__("ldstub [%1 + 3], %0" :"=r" (val) :"r" (&(rw->lock))); +if (val) { +barrier (); +return 0 ; + } +if (rw->lock & ~0xff ) { + *(((unsigned char *)&rw->lock)+3 ) =0 ; +barrier (); +return 0 ; + } +barrier (); + rw->owner_pc = (cpu &3 ) | (caller & ~3 ); +return 1 ; +} +#endif /* SMP */
arch/sparc/Kconfig renamed from arch/sparc/Kconfig.BAD +0 -1
@@ -83,7 +83,6 @@ config HW_CONSOLE config SMP bool "Symmetric multi-processing support (does not work on sun4/sun4c)" - depends on BROKEN ---help--- This enables support for systems with more than one CPU. If you have a system with only one CPU, say N. If you have a system with more
include/asm-sparc/spinlock.h renamed from include/asm-sparc/spinlock.h.BAD +12 -2
@@ -25,10 +25,10 @@ typedef struct _spinlock_debug spinlock_#define spin_unlock_wait (lp) do { barrier(); } while(*(volatile unsigned char *)(&(lp)->lock))extern void _do_spin_lock (spinlock_t *lock,char *str); -extern int _spin_trylock (spinlock_t *lock); +extern int _do_spin_trylock (spinlock_t *lock);extern void _do_spin_unlock (spinlock_t *lock); -#define _raw_spin_trylock (lp) _spin_trylock(lp) +#define _raw_spin_trylock (lp) _do_spin_trylock(lp)#define _raw_spin_lock (lock) _do_spin_lock(lock, "spin_lock")#define _raw_spin_unlock (lock) _do_spin_unlock(lock)
@@ -48,6 +48,7 @@ extern void _do_read_lock(rwlock_t *rw,extern void _do_read_unlock (rwlock_t *rw,char *str);extern void _do_write_lock (rwlock_t *rw,char *str);extern void _do_write_unlock (rwlock_t *rw); +extern int _do_write_trylock (rwlock_t *rw,char *str);#define _raw_read_lock (lock) \ do { unsigned long flags; \
@@ -77,6 +78,15 @@ do { unsigned long flags; \local_irq_restore (flags); \ } while(0) +#define _raw_write_trylock (lock) \ +({ unsigned long flags; \ + int val; \ + local_irq_save(flags); \ + val = _do_write_trylock(lock, "write_trylock"); \ + local_irq_restore(flags); \ + val; \ +}) +#else /* !CONFIG_DEBUG_SPINLOCK */ typedef unsigned char spinlock_t ;
include/asm-sparc/smp.h +1 -8
@@ -81,16 +81,9 @@return 0 ; } -extern __volatile__ int __cpu_number_map[NR_CPUS]; -extern __volatile__ int __cpu_logical_map[NR_CPUS]; -extern __inline__int cpu_logical_map (int cpu) { -return __cpu_logical_map[cpu]; -} -extern __inline__int cpu_number_map (int cpu) -{ -return __cpu_number_map[cpu]; +return cpu; }extern __inline__int hard_smp4m_processor_id (void )
include/asm-sparc/spinlock.h +30 -8
@@ -101,7 +101,7 @@barrier (); \ }while (*((volatile unsigned char *)lock)) -extern __inline__ void _raw_spin_lock(spinlock_t *lock) +static inline void _raw_spin_lock(spinlock_t *lock) { __asm__ __volatile__( "\n1:\n\t"
@@ -121,7 +121,7 @@ : "g2", "memory", "cc"); } -extern __inline__int _raw_spin_trylock (spinlock_t *lock) +static inline int _raw_spin_trylock (spinlock_t *lock) {unsigned int result; __asm__ __volatile__("ldstub [%1], %0"
@@ -131,7 +131,7 @@return (result ==0 ); } -extern __inline__void _raw_spin_unlock (spinlock_t *lock) +static inline void _raw_spin_unlock (spinlock_t *lock) { __asm__ __volatile__("stb %%g0, [%0]" : :"r" (lock) :"memory" ); }
@@ -174,7 +174,7 @@* * Unfortunately this scheme limits us to ~16,000,000 cpus. */ -extern __inline__void _read_lock (rwlock_t *rw) +static inline void __read_lock (rwlock_t *rw) { registerrwlock_t *lp asm("g1" ); lp = rw;
@@ -190,11 +190,11 @@#define _raw_read_lock (lock) \ do { unsigned long flags; \ local_irq_save(flags); \ - _read_lock(lock); \ + __read_lock(lock); \ local_irq_restore(flags); \ } while(0) -extern __inline__void _read_unlock (rwlock_t *rw) +static inline void __read_unlock (rwlock_t *rw) { registerrwlock_t *lp asm("g1" ); lp = rw;
@@ -210,11 +210,11 @@#define _raw_read_unlock (lock) \ do { unsigned long flags; \ local_irq_save(flags); \ - _read_unlock(lock); \ + __read_unlock(lock); \ local_irq_restore(flags); \ } while(0) -extern __inline__void _raw_write_lock (rwlock_t *rw) +static inline void _raw_write_lock (rwlock_t *rw) { registerrwlock_t *lp asm("g1" ); lp = rw;
@@ -227,11 +227,33 @@ : "g2", "g4", "memory", "cc"); } +static inline int _raw_write_trylock (rwlock_t *rw) +{ +int val; + __asm__ __volatile__( +"ldstub [%1 + 3], %0\n\t" +"orcc %0, 0x0, %%g0\n\t" +"bne 1f\n\t" +" nop\n\t" +"ld [%1], %0\n\t" +"andncc %0, 0xff, %0\n\t" +"bne,a 1f\n\t" +" stb %%g0, [%1 + 3]\n" +"1:" + :"=&r" (val) + :"r" (rw) + :"memory" ,"cc" ); + +/* on success, val is zero and return true */ +return (val ==0 ); +} +#define _raw_write_unlock (rw) do { (rw)->lock = 0; } while(0)#endif /* CONFIG_DEBUG_SPINLOCK */ #define _raw_spin_lock_flags (lock, flags) _raw_spin_lock(lock) +#define _raw_read_trylock (lock) generic_raw_read_trylock(lock)#endif /* !(__ASSEMBLY__) */
Only in linux-2.6.11-rc3/arch/sparc/boot: btfix.S
Only in linux-2.6.11-rc3/arch/sparc/boot: image
arch/sparc/kernel/irq.c +21 -15
@@ -21,6 +21,7 @@#include <linux/signal.h> #include <linux/sched.h> #include <linux/interrupt.h> +#include <linux/irq.h> #include <linux/slab.h> #include <linux/random.h> #include <linux/init.h>
@@ -154,8 +155,11 @@ void (*sparc_init_timers)(irqreturn_t (*struct irqaction static_irqaction[MAX_STATIC_ALLOC ];int static_irq_count; -struct irqaction *irq_action[NR_IRQS ] = { - [0 ... (NR_IRQS -1 )] =NULL +struct { +struct irqaction *action; +int flags; +} sparc_irq[NR_IRQS ] = { + [0 ... (NR_IRQS -1 )] = {NULL ,0 } };/* Used to protect the IRQ action lists */
@@ -177,7 +181,7 @@ int show_interrupts(struct seq_file *p, }spin_lock_irqsave (&irq_action_lock, flags);if (i <NR_IRQS ) { - action = *(i + irq_action); + action = sparc_irq[i].action;if (!action) goto out_unlock;seq_printf (p,"%3d: " , i);
@@ -187,7 +191,7 @@ int show_interrupts(struct seq_file *p,for (j =0 ; j <NR_CPUS ; j++) {if (cpu_online (j))seq_printf (p,"%10u " , -kstat_cpu (cpu_logical_map (j)).irqs[i]); +kstat_cpu (j).irqs[i]); }#endif seq_printf(p, " %c %s",
@@ -226,7 +230,7 @@ void free_irq(unsigned int irq, void *despin_lock_irqsave (&irq_action_lock, flags); - action = *(cpu_irq + irq_action); + action = sparc_irq[cpu_irq].action;if (!action->handler) {printk ("Trying to free free IRQ%d\n" ,irq);
@@ -259,7 +263,7 @@ void free_irq(unsigned int irq, void *deif (action && tmp) tmp->next = action->next;else - *(cpu_irq + irq_action) = action->next; + sparc_irq[cpu_irq].action = action->next;spin_unlock_irqrestore (&irq_action_lock, flags);
@@ -269,7 +273,7 @@ void free_irq(unsigned int irq, void *dekfree (action); -if (!(*(cpu_irq + irq_action))) +if (!sparc_irq[cpu_irq].action)disable_irq (irq); out_unlock:
@@ -288,8 +292,8 @@ EXPORT_SYMBOL(free_irq);#ifdef CONFIG_SMP void synchronize_irq (unsigned int irq) { -printk ("synchronize_irq says: implement me!\n" ); -BUG (); +while (sparc_irq[irq].flags &IRQ_INPROGRESS ) +cpu_relax (); }#endif /* SMP */
@@ -300,7 +304,7 @@ void unexpected_irq(int irq, void *dev_iunsigned int cpu_irq; cpu_irq = irq & (NR_IRQS -1 ); - action = *(cpu_irq + irq_action); + action = sparc_irq[cpu_irq].action;printk ("IO device interrupt, irq = %d\n" , irq); printk("PC = %08lx NPC = %08lx FP=%08lx\n", regs->pc,
@@ -326,12 +330,13 @@ void handler_irq(int irq, struct pt_regsirq_enter ();disable_pil_irq (irq); + sparc_irq[irq].flags |=IRQ_INPROGRESS ;#ifdef CONFIG_SMP /* Only rotate on lower priority IRQ's (scsi, ethernet, etc.). */ if (irq <10 )smp4m_irq_rotate (cpu);#endif - action = *(irq + irq_action); + action = sparc_irq[irq].action;kstat_cpu (cpu).irqs[irq]++; do { if (!action || !action->handler)
@@ -339,6 +344,7 @@ void handler_irq(int irq, struct pt_regs action->handler (irq, action->dev_id, regs); action = action->next; }while (action); + sparc_irq[irq].flags &= ~IRQ_INPROGRESS ;enable_pil_irq (irq);irq_exit (); }
@@ -390,7 +396,7 @@ int request_fast_irq(unsigned int irq,spin_lock_irqsave (&irq_action_lock, flags); - action = *(cpu_irq + irq_action); + action = sparc_irq[cpu_irq].action;if (action) {if (action->flags &SA_SHIRQ )panic ("Trying to register fast irq when already shared.\n" );
@@ -453,7 +459,7 @@ int request_fast_irq(unsigned int irq, action->dev_id =NULL ; action->next =NULL ; - *(cpu_irq + irq_action) = action; + sparc_irq[cpu_irq].action = action;enable_irq (irq);
@@ -491,7 +497,7 @@ int request_irq(unsigned int irq,spin_lock_irqsave (&irq_action_lock, flags); - action = *(cpu_irq + irq_action); + action = sparc_irq[cpu_irq].action;if (action) {if ((action->flags &SA_SHIRQ ) && (irqflags &SA_SHIRQ )) {for (tmp = action; tmp->next; tmp = tmp->next);
@@ -536,7 +542,7 @@ int request_irq(unsigned int irq,if (tmp) tmp->next = action;else - *(cpu_irq + irq_action) = action; + sparc_irq[cpu_irq].action = action;enable_irq (irq);
arch/sparc/kernel/smp.c +65 -21
125 lines not on this page · raw message
arch/sparc/kernel/sparc_ksyms.c +6 -3
@@ -90,6 +90,9 @@ extern void ___set_bit(void);extern void ___clear_bit (void );extern void ___change_bit (void ); +/* Per-CPU information table */ +EXPORT_PER_CPU_SYMBOL (__cpu_data); +/* Alias functions whose names begin with "." and export the aliases. * The module references will be fixed up by module_frob_arch_sections. */
@@ -148,9 +151,9 @@ EXPORT_SYMBOL(___change_bit);/* IRQ implementation. */ EXPORT_SYMBOL (synchronize_irq); -/* Misc SMP information */ -EXPORT_SYMBOL (__cpu_number_map); -EXPORT_SYMBOL (__cpu_logical_map); +/* CPU online map and active count. */ +EXPORT_SYMBOL (cpu_online_map); +EXPORT_SYMBOL (phys_cpu_present_map);#endif EXPORT_SYMBOL (__udelay);
arch/sparc/kernel/sun4d_irq.c +9 -5
@@ -14,6 +14,7 @@#include <linux/sched.h> #include <linux/ptrace.h> #include <linux/interrupt.h> +#include <linux/irq.h> #include <linux/slab.h> #include <linux/random.h> #include <linux/init.h>
@@ -54,7 +55,8 @@ unsigned char cpu_leds[32];unsigned char sbus_tid[32 ];#endif -extern struct irqaction *irq_action[]; +//extern struct irqaction *irq_action[]; +extern struct {struct irqaction *action;int flags; } sparc_irq[];extern spinlock_t irq_action_lock;struct sbus_action {
@@ -88,7 +90,7 @@ int show_sun4d_interrupts(struct seq_filif (i <NR_IRQS ) { sbusl = pil_to_sbus[i];if (!sbusl) { - action = *(i + irq_action); + action = sparc_irq[i].action;if (!action) goto out_unlock; }else {
@@ -145,7 +147,7 @@ void sun4d_free_irq(unsigned int irq, vospin_lock_irqsave (&irq_action_lock, flags);if (irq <15 ) - actionp = irq + irq_action; + actionp = &(sparc_irq[irq].action);else actionp = &(sbus_actions[irq - (1 <<5 )].action); action = *actionp;
@@ -212,9 +214,10 @@ void sun4d_handler_irq(int irq, struct pcc_set_iclr (1 << irq);irq_enter (); + sparc_irq[irq].flags |=IRQ_INPROGRESS ;kstat_cpu (cpu).irqs[irq]++;if (!sbusl) { - action = *(irq + irq_action); + action = sparc_irq[irq].action;if (!action)unexpected_irq (irq,NULL , regs); do {
@@ -252,6 +255,7 @@ void sun4d_handler_irq(int irq, struct p } } } + sparc_irq[irq].flags &= ~IRQ_INPROGRESS ;irq_exit (); }
@@ -297,7 +301,7 @@ int sun4d_request_irq(unsigned int irq,if (irq >= (1 <<5 )) actionp = &(sbus_actions[irq - (1 <<5 )].action);else - actionp = irq + irq_action; + actionp = &(sparc_irq[irq].action); action = *actionp;if (action) {
arch/sparc/kernel/sun4d_smp.c +4 -2
@@ -54,7 +54,9 @@ extern volatile int __cpu_number_map[NR_extern volatile int __cpu_logical_map[NR_CPUS ];extern volatile unsigned long ipi_count;extern volatile int smp_process_available; -extern volatile int smp_commenced; + +extern cpumask_t smp_commenced_mask; +extern int __smp4d_processor_id (void );/* #define SMP_DEBUG */
@@ -137,7 +139,7 @@ void __init smp4d_callin(void)local_irq_enable ();/* We don't allow PIL 14 yet */ -while (!smp_commenced) +while (!cpu_isset (cpuid, smp_commenced_mask))barrier ();spin_lock_irqsave (&sun4d_imsk_lock, flags);
arch/sparc/kernel/sun4m_smp.c +28 -79
185 lines not on this page · raw message
Only in linux-2.6.11-rc3/arch/sparc/kernel: vmlinux.lds
arch/sparc/mm/srmmu.c +1 -0
@@ -1417,6 +1417,7 @@ static void __init init_vac_layout(void) max_size = vac_cache_size;if (vac_line_size < min_line_size) min_line_size = vac_line_size; +// FIXME: cpus not contiguous!! cpu++;if (cpu >=NR_CPUS || !cpu_online (cpu))break ;
We are currently investigating how to add linux SMP support for the leon sparc processor, so your patches are appreciated! I will report back in case we find/solve other issues. We have both a behavioural simulator and a FPGA system with on-chip debug support, so tracing and debugging SMP software should be a bit easier than on Sun hardware ...
Jiri Gaisler.
Quoted 8 lines · Bob Breuer
I've been poking at the sparc32 SMP code and I have it to the point where it will run a minimal userland. It is still far from being stable though.
For reference, I started with the SMP patch [0] that wli sent to the list last July. To go along with the attached SMP patch, it needs the spinlock fix [1] from Art Haas, and the attached DEBUGSPINLOCK patch from Tom Callaway.
Quoted 11 lines · Bob Breuer
I've been poking at the sparc32 SMP code and I have it to the point where it will run a minimal userland. It is still far from being stable though.
For reference, I started with the SMP patch [0] that wli sent to the list last July. To go along with the attached SMP patch, it needs the spinlock fix [1] from Art Haas, and the attached DEBUGSPINLOCK patch from Tom Callaway.
Here's a list of problems I have seen with it so far:
- the scsi driver must be compiled in or it has problems.
- when I compiled with gcc 3.3.4, it drops back to the prom with a level 15 interrupt.
Quoted 8 lines
- from a serial console, init hangs
-/proc/interruptsshows 0 interrupts for the 2nd cpu
- sun4d still needs fixing
Testing with gcc 3.2.2 and 2 150 MHz HyperSPARCs, if I compile in scsi and leave out all of the networking, I am able to pass "init=/bin/bash" and get a shell everytime.
I am sure there are still areas of bitrot and neglect that remain, so if anyone has any ideas, feel free to share them.
Between networking and serial it sounds as if this is a partial explanation as to why I'm having trouble here.
-- wli
Quoted 2 lines · William Lee Irwin III
Between networking and serial it sounds as if this is a partial explanation as to why I'm having trouble here.
The networking may be a red herring. I only mentioned it because it was an easy option to remove to get the kernel size back down to a point where silo would boot it.
And for the serial, bash ran fine on the serial port, it was just init that had problems so far.
Bob
Do not forget about the patch for FPU context switching in SMP I posted last month.
Without the patch, I am able to reproduce unexpected FP exceptions in linker (ld) during the SMP compilation (make -j3 on 2-way SS20). With the patch they are gone. I found it in the 2.4 kernel, but the buggy code is the same in 2.4 and 2.6 so I suspect that 2.6 needs it too.
It is maybe not so critical now, but it definitely adds to stability of 32-bit SPARC SMP.
Regards,
Krzysztof
I was able to narrow down a couple problems.
- scsi problems
also exists with a UP kernel, seems to be CONFIG_SCSI=m and CONFIG_SCSI_MULTI_LUN=y that causes it.
- init hangs from serial console
I had a bug in synchronize_irq, drop this version in instead:
void synchronize_irq(unsigned int irq)
{
unsigned int cpu_irq;
cpu_irq = irq & (NR_IRQS - 1);
while (sparc_irq[cpu_irq].flags & IRQ_INPROGRESS)
cpu_relax();
}- only cpu #0 handles interrupts
Need to implement smp4m_irq_rotate().
Bob