time.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 1991,1992,1995 Linus Torvalds
  3. * Copyright (c) 1994 Alan Modra
  4. * Copyright (c) 1995 Markus Kuhn
  5. * Copyright (c) 1996 Ingo Molnar
  6. * Copyright (c) 1998 Andrea Arcangeli
  7. * Copyright (c) 2002,2006 Vojtech Pavlik
  8. * Copyright (c) 2003 Andi Kleen
  9. *
  10. */
  11. #include <linux/clockchips.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/i8253.h>
  14. #include <linux/time.h>
  15. #include <linux/export.h>
  16. #include <asm/vsyscall.h>
  17. #include <asm/x86_init.h>
  18. #include <asm/i8259.h>
  19. #include <asm/timer.h>
  20. #include <asm/hpet.h>
  21. #include <asm/time.h>
  22. #ifdef CONFIG_X86_64
  23. __visible volatile unsigned long jiffies __cacheline_aligned_in_smp = INITIAL_JIFFIES;
  24. #endif
  25. unsigned long profile_pc(struct pt_regs *regs)
  26. {
  27. unsigned long pc = instruction_pointer(regs);
  28. if (!user_mode(regs) && in_lock_functions(pc)) {
  29. #ifdef CONFIG_FRAME_POINTER
  30. return *(unsigned long *)(regs->bp + sizeof(long));
  31. #else
  32. unsigned long *sp =
  33. (unsigned long *)kernel_stack_pointer(regs);
  34. /*
  35. * Return address is either directly at stack pointer
  36. * or above a saved flags. Eflags has bits 22-31 zero,
  37. * kernel addresses don't.
  38. */
  39. if (sp[0] >> 22)
  40. return sp[0];
  41. if (sp[1] >> 22)
  42. return sp[1];
  43. #endif
  44. }
  45. return pc;
  46. }
  47. EXPORT_SYMBOL(profile_pc);
  48. /*
  49. * Default timer interrupt handler for PIT/HPET
  50. */
  51. static irqreturn_t timer_interrupt(int irq, void *dev_id)
  52. {
  53. global_clock_event->event_handler(global_clock_event);
  54. return IRQ_HANDLED;
  55. }
  56. static struct irqaction irq0 = {
  57. .handler = timer_interrupt,
  58. .flags = IRQF_NOBALANCING | IRQF_IRQPOLL | IRQF_TIMER,
  59. .name = "timer"
  60. };
  61. void __init setup_default_timer_irq(void)
  62. {
  63. if (!nr_legacy_irqs())
  64. return;
  65. setup_irq(0, &irq0);
  66. }
  67. /* Default timer init function */
  68. void __init hpet_time_init(void)
  69. {
  70. if (!hpet_enable())
  71. setup_pit_timer();
  72. setup_default_timer_irq();
  73. }
  74. static __init void x86_late_time_init(void)
  75. {
  76. x86_init.timers.timer_init();
  77. tsc_init();
  78. }
  79. /*
  80. * Initialize TSC and delay the periodic timer init to
  81. * late x86_late_time_init() so ioremap works.
  82. */
  83. void __init time_init(void)
  84. {
  85. late_time_init = x86_late_time_init;
  86. }