time.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Based on arch/arm/kernel/time.c
  3. *
  4. * Copyright (C) 1991, 1992, 1995 Linus Torvalds
  5. * Modifications for ARM (C) 1994-2001 Russell King
  6. * Copyright (C) 2012 ARM Ltd.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/export.h>
  21. #include <linux/kernel.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/time.h>
  24. #include <linux/init.h>
  25. #include <linux/sched.h>
  26. #include <linux/smp.h>
  27. #include <linux/timex.h>
  28. #include <linux/errno.h>
  29. #include <linux/profile.h>
  30. #include <linux/syscore_ops.h>
  31. #include <linux/timer.h>
  32. #include <linux/irq.h>
  33. #include <linux/delay.h>
  34. #include <linux/clocksource.h>
  35. #include <clocksource/arm_arch_timer.h>
  36. #include <asm/thread_info.h>
  37. #include <asm/stacktrace.h>
  38. #ifdef CONFIG_SMP
  39. unsigned long profile_pc(struct pt_regs *regs)
  40. {
  41. struct stackframe frame;
  42. if (!in_lock_functions(regs->pc))
  43. return regs->pc;
  44. frame.fp = regs->regs[29];
  45. frame.sp = regs->sp;
  46. frame.pc = regs->pc;
  47. do {
  48. int ret = unwind_frame(&frame);
  49. if (ret < 0)
  50. return 0;
  51. } while (in_lock_functions(frame.pc));
  52. return frame.pc;
  53. }
  54. EXPORT_SYMBOL(profile_pc);
  55. #endif
  56. static u64 sched_clock_mult __read_mostly;
  57. unsigned long long notrace sched_clock(void)
  58. {
  59. return arch_timer_read_counter() * sched_clock_mult;
  60. }
  61. int read_current_timer(unsigned long *timer_value)
  62. {
  63. *timer_value = arch_timer_read_counter();
  64. return 0;
  65. }
  66. void __init time_init(void)
  67. {
  68. u32 arch_timer_rate;
  69. clocksource_of_init();
  70. arch_timer_rate = arch_timer_get_rate();
  71. if (!arch_timer_rate)
  72. panic("Unable to initialise architected timer.\n");
  73. /* Cache the sched_clock multiplier to save a divide in the hot path. */
  74. sched_clock_mult = NSEC_PER_SEC / arch_timer_rate;
  75. /* Calibrate the delay loop directly */
  76. lpj_fine = arch_timer_rate / HZ;
  77. }