2 * linux/arch/alpha/kernel/smp.c
5 #include <linux/errno.h>
6 #include <linux/kernel.h>
7 #include <linux/kernel_stat.h>
8 #include <linux/sched.h>
10 #include <linux/tasks.h>
11 #include <linux/smp.h>
12 #include <linux/smp_lock.h>
13 #include <linux/interrupt.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
17 #include <asm/hwrpb.h>
18 #include <asm/ptrace.h>
19 #include <asm/atomic.h>
23 #include <asm/bitops.h>
24 #include <asm/pgtable.h>
25 #include <asm/spinlock.h>
26 #include <asm/hardirq.h>
27 #include <asm/softirq.h>
29 #define __KERNEL_SYSCALLS__
30 #include <asm/unistd.h>
38 #define DBGS(args) printk args
43 /* A collection of per-processor data. */
44 struct cpuinfo_alpha cpu_data
[NR_CPUS
];
46 /* A collection of single bit ipi messages. */
48 unsigned long bits __cacheline_aligned
;
51 enum ipi_message_type
{
57 spinlock_t kernel_flag __cacheline_aligned
= SPIN_LOCK_UNLOCKED
;
59 /* Set to a secondary's cpuid when it comes online. */
60 static unsigned long smp_secondary_alive
;
62 unsigned long cpu_present_mask
; /* Which cpus ids came online. */
64 static int max_cpus
= -1; /* Command-line limitation. */
65 int smp_boot_cpuid
; /* Which processor we booted from. */
66 int smp_num_probed
; /* Internal processor count */
67 int smp_num_cpus
= 1; /* Number that came online. */
68 int smp_threads_ready
; /* True once the per process idle is forked. */
69 cycles_t cacheflush_time
;
71 int cpu_number_map
[NR_CPUS
];
72 int __cpu_logical_map
[NR_CPUS
];
74 extern void calibrate_delay(void);
75 extern asmlinkage
void entInt(void);
79 * Process bootcommand SMP options, like "nosmp" and "maxcpus=".
82 smp_setup(char *str
, int *ints
)
84 if (ints
&& ints
[0] > 0)
91 * Called by both boot and secondaries to move global data into
92 * per-processor storage.
94 static inline void __init
95 smp_store_cpu_info(int cpuid
)
97 cpu_data
[cpuid
].loops_per_sec
= loops_per_sec
;
98 cpu_data
[cpuid
].last_asn
99 = (cpuid
<< WIDTH_HARDWARE_ASN
) + ASN_FIRST_VERSION
;
103 * Ideally sets up per-cpu profiling hooks. Doesn't do much now...
105 static inline void __init
106 smp_setup_percpu_timer(int cpuid
)
108 cpu_data
[cpuid
].prof_counter
= 1;
109 cpu_data
[cpuid
].prof_multiplier
= 1;
111 #ifdef NOT_YET_PROFILING
112 load_profile_irq(mid_xlate
[cpu
], lvl14_resolution
);
113 if (cpu
== smp_boot_cpuid
)
119 * Where secondaries begin a life of C.
124 int cpuid
= hard_smp_processor_id();
126 DBGS(("CALLIN %d state 0x%lx\n", cpuid
, current
->state
));
128 /* Turn on machine checks. */
131 /* Set trap vectors. */
134 /* Set interrupt vector. */
137 /* Setup the scheduler for this processor. */
140 /* Get our local ticker going. */
141 smp_setup_percpu_timer(cpuid
);
143 /* Must have completely accurate bogos. */
146 smp_store_cpu_info(cpuid
);
148 /* Allow master to continue. */
150 smp_secondary_alive
= cpuid
;
152 /* Wait for the go code. */
153 while (!smp_threads_ready
)
156 DBGS(("smp_callin: commencing CPU %d current %p\n",
165 * Rough estimation for SMP scheduling, this is the number of cycles it
166 * takes for a fully memory-limited process to flush the SMP-local cache.
168 * We are not told how much cache there is, so we have to guess.
171 smp_tune_scheduling (void)
173 struct percpu_struct
*cpu
;
174 unsigned long on_chip_cache
;
177 cpu
= (struct percpu_struct
*)((char*)hwrpb
+ hwrpb
->processor_offset
);
181 on_chip_cache
= 16 + 16;
186 on_chip_cache
= 8 + 8 + 96;
190 on_chip_cache
= 16 + 8;
194 on_chip_cache
= 64 + 64;
198 on_chip_cache
= 8 + 8;
202 freq
= hwrpb
->cycle_freq
? : est_cycle_freq
;
204 /* Magic estimation stolen from x86 port. */
205 cacheflush_time
= freq
/ 1024 * on_chip_cache
/ 5000;
209 * Send a message to a secondary's console. "START" is one such
210 * interesting message. ;-)
213 send_secondary_console_msg(char *str
, int cpuid
)
215 struct percpu_struct
*cpu
;
216 register char *cp1
, *cp2
;
217 unsigned long cpumask
;
221 cpu
= (struct percpu_struct
*)
223 + hwrpb
->processor_offset
224 + cpuid
* hwrpb
->processor_size
);
226 cpumask
= (1L << cpuid
);
227 if (hwrpb
->txrdy
& cpumask
)
233 *(unsigned int *)&cpu
->ipc_buffer
[0] = len
;
234 cp1
= (char *) &cpu
->ipc_buffer
[1];
235 memcpy(cp1
, cp2
, len
);
237 /* atomic test and set */
239 set_bit(cpuid
, &hwrpb
->rxrdy
);
241 if (hwrpb
->txrdy
& cpumask
)
247 /* Wait one second. Note that jiffies aren't ticking yet. */
248 for (timeout
= 100000; timeout
> 0; --timeout
) {
249 if (!(hwrpb
->txrdy
& cpumask
))
257 /* Wait one second. */
258 for (timeout
= 100000; timeout
> 0; --timeout
) {
259 if (!(hwrpb
->txrdy
& cpumask
))
267 printk("Processor %x not ready\n", cpuid
);
272 * A secondary console wants to send a message. Receive it.
275 recv_secondary_console_msg(void)
278 unsigned long txrdy
= hwrpb
->txrdy
;
279 char *cp1
, *cp2
, buf
[80];
280 struct percpu_struct
*cpu
;
282 DBGS(("recv_secondary_console_msg: TXRDY 0x%lx.\n", txrdy
));
284 mycpu
= hard_smp_processor_id();
286 for (i
= 0; i
< NR_CPUS
; i
++) {
287 if (!(txrdy
& (1L << i
)))
290 DBGS(("recv_secondary_console_msg: "
291 "TXRDY contains CPU %d.\n", i
));
293 cpu
= (struct percpu_struct
*)
295 + hwrpb
->processor_offset
296 + i
* hwrpb
->processor_size
);
298 DBGS(("recv_secondary_console_msg: on %d from %d"
299 " HALT_REASON 0x%lx FLAGS 0x%lx\n",
300 mycpu
, i
, cpu
->halt_reason
, cpu
->flags
));
302 cnt
= cpu
->ipc_buffer
[0] >> 32;
303 if (cnt
<= 0 || cnt
>= 80)
304 strcpy(buf
, "<<< BOGUS MSG >>>");
306 cp1
= (char *) &cpu
->ipc_buffer
[11];
310 while ((cp2
= strchr(cp2
, '\r')) != 0) {
317 printk(KERN_INFO
"recv_secondary_console_msg: on %d "
318 "message is '%s'\n", mycpu
, buf
);
325 * Convince the console to have a secondary cpu begin execution.
328 secondary_cpu_start(int cpuid
, struct task_struct
*idle
)
330 struct percpu_struct
*cpu
;
331 struct pcb_struct
*hwpcb
;
334 cpu
= (struct percpu_struct
*)
336 + hwrpb
->processor_offset
337 + cpuid
* hwrpb
->processor_size
);
338 hwpcb
= (struct pcb_struct
*) cpu
->hwpcb
;
340 /* Initialize the CPU's HWPCB to something just good enough for
341 us to get started. Immediately after starting, we'll swpctx
342 to the target idle task's tss. Reuse the stack in the mean
343 time. Precalculate the target PCBB. */
344 hwpcb
->ksp
= (unsigned long) idle
+ sizeof(union task_union
) - 16;
346 hwpcb
->ptbr
= idle
->tss
.ptbr
;
349 hwpcb
->unique
= virt_to_phys(&idle
->tss
);
350 hwpcb
->flags
= idle
->tss
.pal_flags
;
351 hwpcb
->res1
= hwpcb
->res2
= 0;
353 DBGS(("KSP 0x%lx PTBR 0x%lx VPTBR 0x%lx UNIQUE 0x%lx\n",
354 hwpcb
->ksp
, hwpcb
->ptbr
, hwrpb
->vptb
, hwcpb
->unique
));
355 DBGS(("Starting secondary cpu %d: state 0x%lx pal_flags 0x%lx\n",
356 cpuid
, idle
->state
, idle
->tss
.pal_flags
));
358 /* Setup HWRPB fields that SRM uses to activate secondary CPU */
359 hwrpb
->CPU_restart
= __smp_callin
;
360 hwrpb
->CPU_restart_data
= (unsigned long) __smp_callin
;
362 /* Recalculate and update the HWRPB checksum */
363 hwrpb_update_checksum(hwrpb
);
366 * Send a "start" command to the specified processor.
369 /* SRM III 3.4.1.3 */
370 cpu
->flags
|= 0x22; /* turn on Context Valid and Restart Capable */
371 cpu
->flags
&= ~1; /* turn off Bootstrap In Progress */
374 send_secondary_console_msg("START\r\n", cpuid
);
376 /* Wait 1 second for an ACK from the console. Note that jiffies
377 aren't ticking yet. */
378 for (timeout
= 100000; timeout
> 0; timeout
--) {
384 printk(KERN_ERR
"SMP: Processor %d failed to start.\n", cpuid
);
388 DBGS(("secondary_cpu_start: SUCCESS for CPU %d!!!\n", cpuid
));
393 * Bring one cpu online.
396 smp_boot_one_cpu(int cpuid
, int cpunum
)
398 struct task_struct
*idle
;
401 /* Cook up an idler for this guy. Note that the address we give
402 to kernel_thread is irrelevant -- it's going to start where
403 HWRPB.CPU_restart says to start. But this gets all the other
404 task-y sort of data structures set up like we wish. */
405 kernel_thread((void *)__smp_callin
, NULL
, CLONE_PID
|CLONE_VM
);
408 panic("No idle process for CPU %d", cpuid
);
409 idle
->processor
= cpuid
;
411 /* Schedule the first task manually. */
412 /* ??? Ingo, what is this? */
415 DBGS(("smp_boot_one_cpu: CPU %d state 0x%lx flags 0x%lx\n",
416 cpuid
, idle
->state
, idle
->flags
));
418 /* The secondary will change this once it is happy. Note that
419 secondary_cpu_start contains the necessary memory barrier. */
420 smp_secondary_alive
= -1;
422 /* Whirrr, whirrr, whirrrrrrrrr... */
423 if (secondary_cpu_start(cpuid
, idle
))
426 /* We've been acked by the console; wait one second for the task
427 to start up for real. Note that jiffies aren't ticking yet. */
428 for (timeout
= 0; timeout
< 100000; timeout
++) {
429 if (smp_secondary_alive
!= -1)
435 printk(KERN_ERR
"SMP: Processor %d is stuck.\n", cpuid
);
439 /* Another "Red Snapper". */
440 cpu_number_map
[cpuid
] = cpunum
;
441 __cpu_logical_map
[cpunum
] = cpuid
;
446 * Called from setup_arch. Detect an SMP system and which processors
452 struct percpu_struct
*cpubase
, *cpu
;
455 smp_boot_cpuid
= hard_smp_processor_id();
456 if (smp_boot_cpuid
!= 0) {
457 printk(KERN_WARNING
"SMP: Booting off cpu %d instead of 0?\n",
461 if (hwrpb
->nr_processors
> 1) {
464 DBGS(("setup_smp: nr_processors %ld\n",
465 hwrpb
->nr_processors
));
467 cpubase
= (struct percpu_struct
*)
468 ((char*)hwrpb
+ hwrpb
->processor_offset
);
469 boot_cpu_palrev
= cpubase
->pal_revision
;
471 for (i
= 0; i
< hwrpb
->nr_processors
; i
++ ) {
472 cpu
= (struct percpu_struct
*)
473 ((char *)cpubase
+ i
*hwrpb
->processor_size
);
474 if ((cpu
->flags
& 0x1cc) == 0x1cc) {
476 /* Assume here that "whami" == index */
477 cpu_present_mask
|= (1L << i
);
478 cpu
->pal_revision
= boot_cpu_palrev
;
481 DBGS(("setup_smp: CPU %d: flags 0x%lx type 0x%lx\n",
482 i
, cpu
->flags
, cpu
->type
));
483 DBGS(("setup_smp: CPU %d: PAL rev 0x%lx\n",
484 i
, cpu
->pal_revision
));
488 cpu_present_mask
= (1L << smp_boot_cpuid
);
491 printk(KERN_INFO
"SMP: %d CPUs probed -- cpu_present_mask = %lx\n",
492 smp_num_probed
, cpu_present_mask
);
496 * Called by smp_init bring all the secondaries online and hold them.
502 unsigned long bogosum
;
504 /* Take care of some initial bookkeeping. */
505 memset(cpu_number_map
, -1, sizeof(cpu_number_map
));
506 memset(__cpu_logical_map
, -1, sizeof(__cpu_logical_map
));
507 memset(ipi_data
, 0, sizeof(ipi_data
));
509 cpu_number_map
[smp_boot_cpuid
] = 0;
510 __cpu_logical_map
[0] = smp_boot_cpuid
;
511 current
->processor
= smp_boot_cpuid
;
513 smp_store_cpu_info(smp_boot_cpuid
);
514 smp_tune_scheduling();
515 smp_setup_percpu_timer(smp_boot_cpuid
);
519 /* Nothing to do on a UP box, or when told not to. */
520 if (smp_num_probed
== 1 || max_cpus
== 0) {
521 printk(KERN_INFO
"SMP mode deactivated.\n");
525 printk(KERN_INFO
"SMP starting up secondaries.\n");
528 for (i
= 0; i
< NR_CPUS
; i
++) {
529 if (i
== smp_boot_cpuid
)
532 if (((cpu_present_mask
>> i
) & 1) == 0)
535 if (smp_boot_one_cpu(i
, cpu_count
))
541 if (cpu_count
== 1) {
542 printk(KERN_ERR
"SMP: Only one lonely processor alive.\n");
547 for (i
= 0; i
< NR_CPUS
; i
++) {
548 if (cpu_present_mask
& (1L << i
))
549 bogosum
+= cpu_data
[i
].loops_per_sec
;
551 printk(KERN_INFO
"SMP: Total of %d processors activated "
552 "(%lu.%02lu BogoMIPS).\n",
553 cpu_count
, (bogosum
+ 2500) / 500000,
554 ((bogosum
+ 2500) / 5000) % 100);
556 smp_num_cpus
= cpu_count
;
560 * Called by smp_init to release the blocking online cpus once they
566 /* smp_init sets smp_threads_ready -- that's enough. */
571 * Only broken Intel needs this, thus it should not even be
572 * referenced globally.
576 initialize_secondary(void)
581 extern void update_one_process(struct task_struct
*p
, unsigned long ticks
,
582 unsigned long user
, unsigned long system
,
586 smp_percpu_timer_interrupt(struct pt_regs
*regs
)
588 int cpu
= smp_processor_id();
589 int user
= user_mode(regs
);
590 struct cpuinfo_alpha
*data
= &cpu_data
[cpu
];
592 #ifdef NOT_YET_PROFILING
593 clear_profile_irq(mid_xlate
[cpu
]);
595 alpha_do_profile(regs
->pc
);
598 if (!--data
->prof_counter
) {
599 /* We need to make like a normal interrupt -- otherwise
600 timer interrupts ignore the global interrupt lock,
601 which would be a Bad Thing. */
602 irq_enter(cpu
, TIMER_IRQ
);
604 update_one_process(current
, 1, user
, !user
, cpu
);
606 if (--current
->counter
< 0) {
607 current
->counter
= 0;
608 current
->need_resched
= 1;
612 if (current
->priority
< DEF_PRIORITY
) {
614 kstat
.per_cpu_nice
[cpu
]++;
617 kstat
.per_cpu_user
[cpu
]++;
621 kstat
.per_cpu_system
[cpu
]++;
625 data
->prof_counter
= data
->prof_multiplier
;
626 irq_exit(cpu
, TIMER_IRQ
);
631 setup_profiling_timer(unsigned int multiplier
)
633 #ifdef NOT_YET_PROFILING
637 /* Prevent level14 ticker IRQ flooding. */
638 if((!multiplier
) || (lvl14_resolution
/ multiplier
) < 500)
642 for (i
= 0; i
< NR_CPUS
; i
++) {
643 if (cpu_present_mask
& (1L << i
)) {
644 load_profile_irq(mid_xlate
[i
],
645 lvl14_resolution
/ multiplier
);
646 prof_multiplier
[i
] = multiplier
;
649 restore_flags(flags
);
659 send_ipi_message(unsigned long to_whom
, enum ipi_message_type operation
)
663 /* Reduce the number of memory barriers by doing two loops,
664 one to set the bits, one to invoke the interrupts. */
666 mb(); /* Order out-of-band data and bit setting. */
668 for (i
= 0, j
= 1; i
< NR_CPUS
; ++i
, j
<<= 1) {
670 set_bit(operation
, &ipi_data
[i
].bits
);
673 mb(); /* Order bit setting and interrupt. */
675 for (i
= 0, j
= 1; i
< NR_CPUS
; ++i
, j
<<= 1) {
681 /* Structure and data for smp_call_function. This is designed to
682 minimize static memory requirements. Plus it looks cleaner. */
684 struct smp_call_struct
{
685 void (*func
) (void *info
);
688 atomic_t unstarted_count
;
689 atomic_t unfinished_count
;
692 static struct smp_call_struct
*smp_call_function_data
;
694 /* Atomicly drop data into a shared pointer. The pointer is free if
695 it is initially locked. If retry, spin until free. */
698 pointer_lock (void *lock
, void *data
, int retry
)
704 /* Compare and swap with zero. */
712 : "=&r"(old
), "=m"(*(void **)lock
), "=&r"(tmp
)
721 while (*(void **)lock
)
727 handle_ipi(struct pt_regs
*regs
)
729 int this_cpu
= smp_processor_id();
730 unsigned long *pending_ipis
= &ipi_data
[this_cpu
].bits
;
733 DBGS(("handle_ipi: on CPU %d ops 0x%x PC 0x%lx\n",
734 this_cpu
, *pending_ipis
, regs
->pc
));
736 mb(); /* Order interrupt and bit testing. */
737 while ((ops
= xchg(pending_ipis
, 0)) != 0) {
738 mb(); /* Order bit clearing and data access. */
746 if (which
== IPI_RESCHEDULE
) {
747 /* Reschedule callback. Everything to be done
748 is done by the interrupt return path. */
750 else if (which
== IPI_CALL_FUNC
) {
751 struct smp_call_struct
*data
;
752 void (*func
)(void *info
);
756 data
= smp_call_function_data
;
761 /* Notify the sending CPU that the data has been
762 received, and execution is about to begin. */
764 atomic_dec (&data
->unstarted_count
);
766 /* At this point the structure may be gone unless
770 /* Notify the sending CPU that the task is done. */
772 if (wait
) atomic_dec (&data
->unfinished_count
);
774 else if (which
== IPI_CPU_STOP
) {
778 printk(KERN_CRIT
"Unknown IPI on CPU %d: %lu\n",
783 mb(); /* Order data access and bit testing. */
786 cpu_data
[this_cpu
].ipi_count
++;
789 recv_secondary_console_msg();
793 smp_send_reschedule(int cpu
)
796 if (cpu
== hard_smp_processor_id())
798 "smp_send_reschedule: Sending IPI to self.\n");
800 send_ipi_message(1L << cpu
, IPI_RESCHEDULE
);
806 unsigned long to_whom
= cpu_present_mask
^ (1L << smp_processor_id());
808 if (hard_smp_processor_id() != boot_cpu_id
)
809 printk(KERN_WARNING
"smp_send_stop: Not on boot cpu.\n");
811 send_ipi_message(to_whom
, IPI_CPU_STOP
);
815 * Run a function on all other CPUs.
816 * <func> The function to run. This must be fast and non-blocking.
817 * <info> An arbitrary pointer to pass to the function.
818 * <retry> If true, keep retrying until ready.
819 * <wait> If true, wait until function has completed on other CPUs.
820 * [RETURNS] 0 on success, else a negative status code.
822 * Does not return until remote CPUs are nearly ready to execute <func>
823 * or are or have executed.
827 smp_call_function (void (*func
) (void *info
), void *info
, int retry
, int wait
)
829 unsigned long to_whom
= cpu_present_mask
^ (1L << smp_processor_id());
830 struct smp_call_struct data
;
836 atomic_set(&data
.unstarted_count
, smp_num_cpus
- 1);
837 atomic_set(&data
.unfinished_count
, smp_num_cpus
- 1);
839 /* Aquire the smp_call_function_data mutex. */
840 if (pointer_lock(&smp_call_function_data
, &data
, retry
))
843 /* Send a message to all other CPUs. */
844 send_ipi_message(to_whom
, IPI_CALL_FUNC
);
846 /* Wait for a minimal response. */
847 timeout
= jiffies
+ HZ
;
848 while (atomic_read (&data
.unstarted_count
) > 0
849 && time_before (jiffies
, timeout
))
852 /* We either got one or timed out -- clear the lock. */
854 smp_call_function_data
= 0;
855 if (atomic_read (&data
.unstarted_count
) > 0)
858 /* Wait for a complete response, if needed. */
860 while (atomic_read (&data
.unfinished_count
) > 0)
868 ipi_flush_tlb_all(void *ignored
)
876 /* Although we don't have any data to pass, we do want to
877 synchronize with the other processors. */
878 if (smp_call_function(ipi_flush_tlb_all
, NULL
, 1, 1)) {
879 printk(KERN_CRIT
"flush_tlb_all: timed out\n");
886 ipi_flush_tlb_mm(void *x
)
888 struct mm_struct
*mm
= (struct mm_struct
*) x
;
889 if (mm
== current
->mm
)
890 flush_tlb_current(mm
);
894 flush_tlb_mm(struct mm_struct
*mm
)
896 if (mm
== current
->mm
)
897 flush_tlb_current(mm
);
901 if (smp_call_function(ipi_flush_tlb_mm
, mm
, 1, 1)) {
902 printk(KERN_CRIT
"flush_tlb_mm: timed out\n");
906 struct flush_tlb_page_struct
{
907 struct vm_area_struct
*vma
;
908 struct mm_struct
*mm
;
913 ipi_flush_tlb_page(void *x
)
915 struct flush_tlb_page_struct
*data
= (struct flush_tlb_page_struct
*)x
;
916 if (data
->mm
== current
->mm
)
917 flush_tlb_current_page(data
->mm
, data
->vma
, data
->addr
);
921 flush_tlb_page(struct vm_area_struct
*vma
, unsigned long addr
)
923 struct flush_tlb_page_struct data
;
924 struct mm_struct
*mm
= vma
->vm_mm
;
930 if (mm
== current
->mm
)
931 flush_tlb_current_page(mm
, vma
, addr
);
935 if (smp_call_function(ipi_flush_tlb_page
, &data
, 1, 1)) {
936 printk(KERN_CRIT
"flush_tlb_page: timed out\n");
941 flush_tlb_range(struct mm_struct
*mm
, unsigned long start
, unsigned long end
)
943 /* On the Alpha we always flush the whole user tlb. */
949 smp_info(char *buffer
)
952 unsigned long sum
= 0;
953 for (i
= 0; i
< NR_CPUS
; i
++)
954 sum
+= cpu_data
[i
].ipi_count
;
956 return sprintf(buffer
, "CPUs probed %d active %d map 0x%lx IPIs %ld\n",
957 smp_num_probed
, smp_num_cpus
, cpu_present_mask
, sum
);
963 spin_unlock(spinlock_t
* lock
)
969 lock
->previous
= NULL
;
971 lock
->base_file
= "none";
976 debug_spin_lock(spinlock_t
* lock
, const char *base_file
, int line_no
)
980 void *inline_pc
= __builtin_return_address(0);
981 unsigned long started
= jiffies
;
983 int cpu
= smp_processor_id();
988 /* Use sub-sections to put the actual loop at the end
989 of this object file's text section so as to perfect
990 branch prediction. */
991 __asm__
__volatile__(
999 ".section .text2,\"ax\"\n"
1006 : "=r" (tmp
), "=m" (__dummy_lock(lock
)), "=r" (stuck
)
1007 : "1" (__dummy_lock(lock
)), "2" (stuck
));
1011 "%s:%d spinlock stuck in %s at %p(%d)"
1012 " owner %s at %p(%d) %s:%d\n",
1014 current
->comm
, inline_pc
, cpu
,
1015 lock
->task
->comm
, lock
->previous
,
1016 lock
->on_cpu
, lock
->base_file
, lock
->line_no
);
1022 /* Exiting. Got the lock. */
1024 lock
->previous
= inline_pc
;
1025 lock
->task
= current
;
1026 lock
->base_file
= base_file
;
1027 lock
->line_no
= line_no
;
1031 "%s:%d spinlock grabbed in %s at %p(%d) %ld ticks\n",
1032 base_file
, line_no
, current
->comm
, inline_pc
,
1033 cpu
, jiffies
- started
);
1038 debug_spin_trylock(spinlock_t
* lock
, const char *base_file
, int line_no
)
1041 if ((ret
= !test_and_set_bit(0, lock
))) {
1042 lock
->on_cpu
= smp_processor_id();
1043 lock
->previous
= __builtin_return_address(0);
1044 lock
->task
= current
;
1046 lock
->base_file
= base_file
;
1047 lock
->line_no
= line_no
;
1051 #endif /* DEBUG_SPINLOCK */
1054 void write_lock(rwlock_t
* lock
)
1057 int stuck_lock
, stuck_reader
;
1058 void *inline_pc
= __builtin_return_address(0);
1063 stuck_reader
= 1<<26;
1065 __asm__
__volatile__(
1073 ".section .text2,\"ax\"\n"
1074 "6: blt %3,4b # debug\n"
1075 " subl %3,1,%3 # debug\n"
1078 "8: blt %4,4b # debug\n"
1079 " subl %4,1,%4 # debug\n"
1084 : "=m" (__dummy_lock(lock
)), "=&r" (regx
), "=&r" (regy
),
1085 "=&r" (stuck_lock
), "=&r" (stuck_reader
)
1086 : "0" (__dummy_lock(lock
)), "3" (stuck_lock
), "4" (stuck_reader
));
1088 if (stuck_lock
< 0) {
1089 printk(KERN_WARNING
"write_lock stuck at %p\n", inline_pc
);
1092 if (stuck_reader
< 0) {
1093 printk(KERN_WARNING
"write_lock stuck on readers at %p\n",
1099 void read_lock(rwlock_t
* lock
)
1103 void *inline_pc
= __builtin_return_address(0);
1109 __asm__
__volatile__(
1116 ".section .text2,\"ax\"\n"
1118 " blt %2,4b # debug\n"
1119 " subl %2,1,%2 # debug\n"
1123 : "=m" (__dummy_lock(lock
)), "=&r" (regx
), "=&r" (stuck_lock
)
1124 : "0" (__dummy_lock(lock
)), "2" (stuck_lock
));
1126 if (stuck_lock
< 0) {
1127 printk(KERN_WARNING
"read_lock stuck at %p\n", inline_pc
);
1131 #endif /* DEBUG_RWLOCK */