crash.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <linux/kernel.h>
  2. #include <linux/smp.h>
  3. #include <linux/reboot.h>
  4. #include <linux/kexec.h>
  5. #include <linux/bootmem.h>
  6. #include <linux/crash_dump.h>
  7. #include <linux/delay.h>
  8. #include <linux/irq.h>
  9. #include <linux/types.h>
  10. #include <linux/sched.h>
  11. /* This keeps a track of which one is crashing cpu. */
  12. static int crashing_cpu = -1;
  13. static cpumask_t cpus_in_crash = CPU_MASK_NONE;
  14. #ifdef CONFIG_SMP
  15. static void crash_shutdown_secondary(void *ignore)
  16. {
  17. struct pt_regs *regs;
  18. int cpu = smp_processor_id();
  19. regs = task_pt_regs(current);
  20. if (!cpu_online(cpu))
  21. return;
  22. local_irq_disable();
  23. if (!cpumask_test_cpu(cpu, &cpus_in_crash))
  24. crash_save_cpu(regs, cpu);
  25. cpumask_set_cpu(cpu, &cpus_in_crash);
  26. while (!atomic_read(&kexec_ready_to_reboot))
  27. cpu_relax();
  28. relocated_kexec_smp_wait(NULL);
  29. /* NOTREACHED */
  30. }
  31. static void crash_kexec_prepare_cpus(void)
  32. {
  33. unsigned int msecs;
  34. unsigned int ncpus = num_online_cpus() - 1;/* Excluding the panic cpu */
  35. dump_send_ipi(crash_shutdown_secondary);
  36. smp_wmb();
  37. /*
  38. * The crash CPU sends an IPI and wait for other CPUs to
  39. * respond. Delay of at least 10 seconds.
  40. */
  41. pr_emerg("Sending IPI to other cpus...\n");
  42. msecs = 10000;
  43. while ((cpumask_weight(&cpus_in_crash) < ncpus) && (--msecs > 0)) {
  44. cpu_relax();
  45. mdelay(1);
  46. }
  47. }
  48. #else /* !defined(CONFIG_SMP) */
  49. static void crash_kexec_prepare_cpus(void) {}
  50. #endif /* !defined(CONFIG_SMP) */
  51. void default_machine_crash_shutdown(struct pt_regs *regs)
  52. {
  53. local_irq_disable();
  54. crashing_cpu = smp_processor_id();
  55. crash_save_cpu(regs, crashing_cpu);
  56. crash_kexec_prepare_cpus();
  57. cpumask_set_cpu(crashing_cpu, &cpus_in_crash);
  58. }