tick-oneshot.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * linux/kernel/time/tick-oneshot.c
  3. *
  4. * This file contains functions which manage high resolution tick
  5. * related events.
  6. *
  7. * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
  8. * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
  9. * Copyright(C) 2006-2007, Timesys Corp., Thomas Gleixner
  10. *
  11. * This code is licenced under the GPL version 2. For details see
  12. * kernel-base/COPYING.
  13. */
  14. #include <linux/cpu.h>
  15. #include <linux/err.h>
  16. #include <linux/hrtimer.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/percpu.h>
  19. #include <linux/profile.h>
  20. #include <linux/sched.h>
  21. #include "tick-internal.h"
  22. /**
  23. * tick_program_event
  24. */
  25. int tick_program_event(ktime_t expires, int force)
  26. {
  27. struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
  28. return clockevents_program_event(dev, expires, force);
  29. }
  30. /**
  31. * tick_resume_onshot - resume oneshot mode
  32. */
  33. void tick_resume_oneshot(void)
  34. {
  35. struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev);
  36. clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
  37. clockevents_program_event(dev, ktime_get(), true);
  38. }
  39. /**
  40. * tick_setup_oneshot - setup the event device for oneshot mode (hres or nohz)
  41. */
  42. void tick_setup_oneshot(struct clock_event_device *newdev,
  43. void (*handler)(struct clock_event_device *),
  44. ktime_t next_event)
  45. {
  46. newdev->event_handler = handler;
  47. clockevents_set_mode(newdev, CLOCK_EVT_MODE_ONESHOT);
  48. clockevents_program_event(newdev, next_event, true);
  49. }
  50. /**
  51. * tick_switch_to_oneshot - switch to oneshot mode
  52. */
  53. int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *))
  54. {
  55. struct tick_device *td = &__get_cpu_var(tick_cpu_device);
  56. struct clock_event_device *dev = td->evtdev;
  57. if (!dev || !(dev->features & CLOCK_EVT_FEAT_ONESHOT) ||
  58. !tick_device_is_functional(dev)) {
  59. printk(KERN_INFO "Clockevents: "
  60. "could not switch to one-shot mode:");
  61. if (!dev) {
  62. printk(" no tick device\n");
  63. } else {
  64. if (!tick_device_is_functional(dev))
  65. printk(" %s is not functional.\n", dev->name);
  66. else
  67. printk(" %s does not support one-shot mode.\n",
  68. dev->name);
  69. }
  70. return -EINVAL;
  71. }
  72. td->mode = TICKDEV_MODE_ONESHOT;
  73. dev->event_handler = handler;
  74. clockevents_set_mode(dev, CLOCK_EVT_MODE_ONESHOT);
  75. tick_broadcast_switch_to_oneshot();
  76. return 0;
  77. }
  78. /**
  79. * tick_check_oneshot_mode - check whether the system is in oneshot mode
  80. *
  81. * returns 1 when either nohz or highres are enabled. otherwise 0.
  82. */
  83. int tick_oneshot_mode_active(void)
  84. {
  85. unsigned long flags;
  86. int ret;
  87. local_irq_save(flags);
  88. ret = __this_cpu_read(tick_cpu_device.mode) == TICKDEV_MODE_ONESHOT;
  89. local_irq_restore(flags);
  90. return ret;
  91. }
  92. #ifdef CONFIG_HIGH_RES_TIMERS
  93. /**
  94. * tick_init_highres - switch to high resolution mode
  95. *
  96. * Called with interrupts disabled.
  97. */
  98. int tick_init_highres(void)
  99. {
  100. return tick_switch_to_oneshot(hrtimer_interrupt);
  101. }
  102. #endif