tick-sched.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * linux/kernel/time/tick-sched.c
  3. *
  4. * Copyright(C) 2005-2006, Thomas Gleixner <tglx@linutronix.de>
  5. * Copyright(C) 2005-2007, Red Hat, Inc., Ingo Molnar
  6. * Copyright(C) 2006-2007 Timesys Corp., Thomas Gleixner
  7. *
  8. * No idle tick implementation for low and high resolution timers
  9. *
  10. * Started by: Thomas Gleixner and Ingo Molnar
  11. *
  12. * Distribute under GPLv2.
  13. */
  14. #include <linux/cpu.h>
  15. #include <linux/err.h>
  16. #include <linux/hrtimer.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/kernel_stat.h>
  19. #include <linux/percpu.h>
  20. #include <linux/profile.h>
  21. #include <linux/sched.h>
  22. #include <linux/tick.h>
  23. #include <asm/irq_regs.h>
  24. #include "tick-internal.h"
  25. /*
  26. * Per cpu nohz control structure
  27. */
  28. static DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
  29. /*
  30. * The time, when the last jiffy update happened. Protected by xtime_lock.
  31. */
  32. static ktime_t last_jiffies_update;
  33. struct tick_sched *tick_get_tick_sched(int cpu)
  34. {
  35. return &per_cpu(tick_cpu_sched, cpu);
  36. }
  37. /*
  38. * Must be called with interrupts disabled !
  39. */
  40. static void tick_do_update_jiffies64(ktime_t now)
  41. {
  42. unsigned long ticks = 0;
  43. ktime_t delta;
  44. /* Reevalute with xtime_lock held */
  45. write_seqlock(&xtime_lock);
  46. delta = ktime_sub(now, last_jiffies_update);
  47. if (delta.tv64 >= tick_period.tv64) {
  48. delta = ktime_sub(delta, tick_period);
  49. last_jiffies_update = ktime_add(last_jiffies_update,
  50. tick_period);
  51. /* Slow path for long timeouts */
  52. if (unlikely(delta.tv64 >= tick_period.tv64)) {
  53. s64 incr = ktime_to_ns(tick_period);
  54. ticks = ktime_divns(delta, incr);
  55. last_jiffies_update = ktime_add_ns(last_jiffies_update,
  56. incr * ticks);
  57. }
  58. do_timer(++ticks);
  59. }
  60. write_sequnlock(&xtime_lock);
  61. }
  62. /*
  63. * Initialize and return retrieve the jiffies update.
  64. */
  65. static ktime_t tick_init_jiffy_update(void)
  66. {
  67. ktime_t period;
  68. write_seqlock(&xtime_lock);
  69. /* Did we start the jiffies update yet ? */
  70. if (last_jiffies_update.tv64 == 0)
  71. last_jiffies_update = tick_next_period;
  72. period = last_jiffies_update;
  73. write_sequnlock(&xtime_lock);
  74. return period;
  75. }
  76. /*
  77. * NOHZ - aka dynamic tick functionality
  78. */
  79. #ifdef CONFIG_NO_HZ
  80. /*
  81. * NO HZ enabled ?
  82. */
  83. static int tick_nohz_enabled __read_mostly = 1;
  84. /*
  85. * Enable / Disable tickless mode
  86. */
  87. static int __init setup_tick_nohz(char *str)
  88. {
  89. if (!strcmp(str, "off"))
  90. tick_nohz_enabled = 0;
  91. else if (!strcmp(str, "on"))
  92. tick_nohz_enabled = 1;
  93. else
  94. return 0;
  95. return 1;
  96. }
  97. __setup("nohz=", setup_tick_nohz);
  98. /**
  99. * tick_nohz_update_jiffies - update jiffies when idle was interrupted
  100. *
  101. * Called from interrupt entry when the CPU was idle
  102. *
  103. * In case the sched_tick was stopped on this CPU, we have to check if jiffies
  104. * must be updated. Otherwise an interrupt handler could use a stale jiffy
  105. * value. We do this unconditionally on any cpu, as we don't know whether the
  106. * cpu, which has the update task assigned is in a long sleep.
  107. */
  108. void tick_nohz_update_jiffies(void)
  109. {
  110. int cpu = smp_processor_id();
  111. struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
  112. unsigned long flags;
  113. ktime_t now;
  114. if (!ts->tick_stopped)
  115. return;
  116. touch_softlockup_watchdog();
  117. cpu_clear(cpu, nohz_cpu_mask);
  118. now = ktime_get();
  119. local_irq_save(flags);
  120. tick_do_update_jiffies64(now);
  121. local_irq_restore(flags);
  122. }
  123. void tick_nohz_stop_idle(int cpu)
  124. {
  125. struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
  126. if (ts->idle_active) {
  127. ktime_t now, delta;
  128. now = ktime_get();
  129. delta = ktime_sub(now, ts->idle_entrytime);
  130. ts->idle_lastupdate = now;
  131. ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
  132. ts->idle_active = 0;
  133. }
  134. }
  135. static ktime_t tick_nohz_start_idle(int cpu)
  136. {
  137. struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
  138. ktime_t now, delta;
  139. now = ktime_get();
  140. if (ts->idle_active) {
  141. delta = ktime_sub(now, ts->idle_entrytime);
  142. ts->idle_lastupdate = now;
  143. ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
  144. }
  145. ts->idle_entrytime = now;
  146. ts->idle_active = 1;
  147. return now;
  148. }
  149. u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time)
  150. {
  151. struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
  152. *last_update_time = ktime_to_us(ts->idle_lastupdate);
  153. return ktime_to_us(ts->idle_sleeptime);
  154. }
  155. /**
  156. * tick_nohz_stop_sched_tick - stop the idle tick from the idle task
  157. *
  158. * When the next event is more than a tick into the future, stop the idle tick
  159. * Called either from the idle loop or from irq_exit() when an idle period was
  160. * just interrupted by an interrupt which did not cause a reschedule.
  161. */
  162. void tick_nohz_stop_sched_tick(void)
  163. {
  164. unsigned long seq, last_jiffies, next_jiffies, delta_jiffies, flags;
  165. unsigned long rt_jiffies;
  166. struct tick_sched *ts;
  167. ktime_t last_update, expires, now;
  168. struct clock_event_device *dev = __get_cpu_var(tick_cpu_device).evtdev;
  169. int cpu;
  170. local_irq_save(flags);
  171. cpu = smp_processor_id();
  172. now = tick_nohz_start_idle(cpu);
  173. ts = &per_cpu(tick_cpu_sched, cpu);
  174. /*
  175. * If this cpu is offline and it is the one which updates
  176. * jiffies, then give up the assignment and let it be taken by
  177. * the cpu which runs the tick timer next. If we don't drop
  178. * this here the jiffies might be stale and do_timer() never
  179. * invoked.
  180. */
  181. if (unlikely(!cpu_online(cpu))) {
  182. if (cpu == tick_do_timer_cpu)
  183. tick_do_timer_cpu = -1;
  184. }
  185. if (unlikely(ts->nohz_mode == NOHZ_MODE_INACTIVE))
  186. goto end;
  187. if (need_resched())
  188. goto end;
  189. cpu = smp_processor_id();
  190. if (unlikely(local_softirq_pending())) {
  191. static int ratelimit;
  192. if (ratelimit < 10) {
  193. printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  194. local_softirq_pending());
  195. ratelimit++;
  196. }
  197. }
  198. ts->idle_calls++;
  199. /* Read jiffies and the time when jiffies were updated last */
  200. do {
  201. seq = read_seqbegin(&xtime_lock);
  202. last_update = last_jiffies_update;
  203. last_jiffies = jiffies;
  204. } while (read_seqretry(&xtime_lock, seq));
  205. /* Get the next timer wheel timer */
  206. next_jiffies = get_next_timer_interrupt(last_jiffies);
  207. delta_jiffies = next_jiffies - last_jiffies;
  208. rt_jiffies = rt_needs_cpu(cpu);
  209. if (rt_jiffies && rt_jiffies < delta_jiffies)
  210. delta_jiffies = rt_jiffies;
  211. if (rcu_needs_cpu(cpu))
  212. delta_jiffies = 1;
  213. /*
  214. * Do not stop the tick, if we are only one off
  215. * or if the cpu is required for rcu
  216. */
  217. if (!ts->tick_stopped && delta_jiffies == 1)
  218. goto out;
  219. /* Schedule the tick, if we are at least one jiffie off */
  220. if ((long)delta_jiffies >= 1) {
  221. if (delta_jiffies > 1)
  222. cpu_set(cpu, nohz_cpu_mask);
  223. /*
  224. * nohz_stop_sched_tick can be called several times before
  225. * the nohz_restart_sched_tick is called. This happens when
  226. * interrupts arrive which do not cause a reschedule. In the
  227. * first call we save the current tick time, so we can restart
  228. * the scheduler tick in nohz_restart_sched_tick.
  229. */
  230. if (!ts->tick_stopped) {
  231. if (select_nohz_load_balancer(1)) {
  232. /*
  233. * sched tick not stopped!
  234. */
  235. cpu_clear(cpu, nohz_cpu_mask);
  236. goto out;
  237. }
  238. ts->idle_tick = ts->sched_timer.expires;
  239. ts->tick_stopped = 1;
  240. ts->idle_jiffies = last_jiffies;
  241. }
  242. /*
  243. * If this cpu is the one which updates jiffies, then
  244. * give up the assignment and let it be taken by the
  245. * cpu which runs the tick timer next, which might be
  246. * this cpu as well. If we don't drop this here the
  247. * jiffies might be stale and do_timer() never
  248. * invoked.
  249. */
  250. if (cpu == tick_do_timer_cpu)
  251. tick_do_timer_cpu = -1;
  252. ts->idle_sleeps++;
  253. /*
  254. * delta_jiffies >= NEXT_TIMER_MAX_DELTA signals that
  255. * there is no timer pending or at least extremly far
  256. * into the future (12 days for HZ=1000). In this case
  257. * we simply stop the tick timer:
  258. */
  259. if (unlikely(delta_jiffies >= NEXT_TIMER_MAX_DELTA)) {
  260. ts->idle_expires.tv64 = KTIME_MAX;
  261. if (ts->nohz_mode == NOHZ_MODE_HIGHRES)
  262. hrtimer_cancel(&ts->sched_timer);
  263. goto out;
  264. }
  265. /*
  266. * calculate the expiry time for the next timer wheel
  267. * timer
  268. */
  269. expires = ktime_add_ns(last_update, tick_period.tv64 *
  270. delta_jiffies);
  271. ts->idle_expires = expires;
  272. if (ts->nohz_mode == NOHZ_MODE_HIGHRES) {
  273. hrtimer_start(&ts->sched_timer, expires,
  274. HRTIMER_MODE_ABS);
  275. /* Check, if the timer was already in the past */
  276. if (hrtimer_active(&ts->sched_timer))
  277. goto out;
  278. } else if (!tick_program_event(expires, 0))
  279. goto out;
  280. /*
  281. * We are past the event already. So we crossed a
  282. * jiffie boundary. Update jiffies and raise the
  283. * softirq.
  284. */
  285. tick_do_update_jiffies64(ktime_get());
  286. cpu_clear(cpu, nohz_cpu_mask);
  287. }
  288. raise_softirq_irqoff(TIMER_SOFTIRQ);
  289. out:
  290. ts->next_jiffies = next_jiffies;
  291. ts->last_jiffies = last_jiffies;
  292. ts->sleep_length = ktime_sub(dev->next_event, now);
  293. end:
  294. local_irq_restore(flags);
  295. }
  296. /**
  297. * tick_nohz_get_sleep_length - return the length of the current sleep
  298. *
  299. * Called from power state control code with interrupts disabled
  300. */
  301. ktime_t tick_nohz_get_sleep_length(void)
  302. {
  303. struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
  304. return ts->sleep_length;
  305. }
  306. /**
  307. * tick_nohz_restart_sched_tick - restart the idle tick from the idle task
  308. *
  309. * Restart the idle tick when the CPU is woken up from idle
  310. */
  311. void tick_nohz_restart_sched_tick(void)
  312. {
  313. int cpu = smp_processor_id();
  314. struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
  315. unsigned long ticks;
  316. ktime_t now;
  317. local_irq_disable();
  318. tick_nohz_stop_idle(cpu);
  319. if (!ts->tick_stopped) {
  320. local_irq_enable();
  321. return;
  322. }
  323. /* Update jiffies first */
  324. select_nohz_load_balancer(0);
  325. now = ktime_get();
  326. tick_do_update_jiffies64(now);
  327. cpu_clear(cpu, nohz_cpu_mask);
  328. /*
  329. * We stopped the tick in idle. Update process times would miss the
  330. * time we slept as update_process_times does only a 1 tick
  331. * accounting. Enforce that this is accounted to idle !
  332. */
  333. ticks = jiffies - ts->idle_jiffies;
  334. /*
  335. * We might be one off. Do not randomly account a huge number of ticks!
  336. */
  337. if (ticks && ticks < LONG_MAX) {
  338. add_preempt_count(HARDIRQ_OFFSET);
  339. account_system_time(current, HARDIRQ_OFFSET,
  340. jiffies_to_cputime(ticks));
  341. sub_preempt_count(HARDIRQ_OFFSET);
  342. }
  343. /*
  344. * Cancel the scheduled timer and restore the tick
  345. */
  346. ts->tick_stopped = 0;
  347. hrtimer_cancel(&ts->sched_timer);
  348. ts->sched_timer.expires = ts->idle_tick;
  349. while (1) {
  350. /* Forward the time to expire in the future */
  351. hrtimer_forward(&ts->sched_timer, now, tick_period);
  352. if (ts->nohz_mode == NOHZ_MODE_HIGHRES) {
  353. hrtimer_start(&ts->sched_timer,
  354. ts->sched_timer.expires,
  355. HRTIMER_MODE_ABS);
  356. /* Check, if the timer was already in the past */
  357. if (hrtimer_active(&ts->sched_timer))
  358. break;
  359. } else {
  360. if (!tick_program_event(ts->sched_timer.expires, 0))
  361. break;
  362. }
  363. /* Update jiffies and reread time */
  364. tick_do_update_jiffies64(now);
  365. now = ktime_get();
  366. }
  367. local_irq_enable();
  368. }
  369. static int tick_nohz_reprogram(struct tick_sched *ts, ktime_t now)
  370. {
  371. hrtimer_forward(&ts->sched_timer, now, tick_period);
  372. return tick_program_event(ts->sched_timer.expires, 0);
  373. }
  374. /*
  375. * The nohz low res interrupt handler
  376. */
  377. static void tick_nohz_handler(struct clock_event_device *dev)
  378. {
  379. struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
  380. struct pt_regs *regs = get_irq_regs();
  381. int cpu = smp_processor_id();
  382. ktime_t now = ktime_get();
  383. dev->next_event.tv64 = KTIME_MAX;
  384. /*
  385. * Check if the do_timer duty was dropped. We don't care about
  386. * concurrency: This happens only when the cpu in charge went
  387. * into a long sleep. If two cpus happen to assign themself to
  388. * this duty, then the jiffies update is still serialized by
  389. * xtime_lock.
  390. */
  391. if (unlikely(tick_do_timer_cpu == -1))
  392. tick_do_timer_cpu = cpu;
  393. /* Check, if the jiffies need an update */
  394. if (tick_do_timer_cpu == cpu)
  395. tick_do_update_jiffies64(now);
  396. /*
  397. * When we are idle and the tick is stopped, we have to touch
  398. * the watchdog as we might not schedule for a really long
  399. * time. This happens on complete idle SMP systems while
  400. * waiting on the login prompt. We also increment the "start
  401. * of idle" jiffy stamp so the idle accounting adjustment we
  402. * do when we go busy again does not account too much ticks.
  403. */
  404. if (ts->tick_stopped) {
  405. touch_softlockup_watchdog();
  406. ts->idle_jiffies++;
  407. }
  408. update_process_times(user_mode(regs));
  409. profile_tick(CPU_PROFILING);
  410. /* Do not restart, when we are in the idle loop */
  411. if (ts->tick_stopped)
  412. return;
  413. while (tick_nohz_reprogram(ts, now)) {
  414. now = ktime_get();
  415. tick_do_update_jiffies64(now);
  416. }
  417. }
  418. /**
  419. * tick_nohz_switch_to_nohz - switch to nohz mode
  420. */
  421. static void tick_nohz_switch_to_nohz(void)
  422. {
  423. struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
  424. ktime_t next;
  425. if (!tick_nohz_enabled)
  426. return;
  427. local_irq_disable();
  428. if (tick_switch_to_oneshot(tick_nohz_handler)) {
  429. local_irq_enable();
  430. return;
  431. }
  432. ts->nohz_mode = NOHZ_MODE_LOWRES;
  433. /*
  434. * Recycle the hrtimer in ts, so we can share the
  435. * hrtimer_forward with the highres code.
  436. */
  437. hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  438. /* Get the next period */
  439. next = tick_init_jiffy_update();
  440. for (;;) {
  441. ts->sched_timer.expires = next;
  442. if (!tick_program_event(next, 0))
  443. break;
  444. next = ktime_add(next, tick_period);
  445. }
  446. local_irq_enable();
  447. printk(KERN_INFO "Switched to NOHz mode on CPU #%d\n",
  448. smp_processor_id());
  449. }
  450. #else
  451. static inline void tick_nohz_switch_to_nohz(void) { }
  452. #endif /* NO_HZ */
  453. /*
  454. * High resolution timer specific code
  455. */
  456. #ifdef CONFIG_HIGH_RES_TIMERS
  457. /*
  458. * We rearm the timer until we get disabled by the idle code.
  459. * Called with interrupts disabled and timer->base->cpu_base->lock held.
  460. */
  461. static enum hrtimer_restart tick_sched_timer(struct hrtimer *timer)
  462. {
  463. struct tick_sched *ts =
  464. container_of(timer, struct tick_sched, sched_timer);
  465. struct pt_regs *regs = get_irq_regs();
  466. ktime_t now = ktime_get();
  467. int cpu = smp_processor_id();
  468. #ifdef CONFIG_NO_HZ
  469. /*
  470. * Check if the do_timer duty was dropped. We don't care about
  471. * concurrency: This happens only when the cpu in charge went
  472. * into a long sleep. If two cpus happen to assign themself to
  473. * this duty, then the jiffies update is still serialized by
  474. * xtime_lock.
  475. */
  476. if (unlikely(tick_do_timer_cpu == -1))
  477. tick_do_timer_cpu = cpu;
  478. #endif
  479. /* Check, if the jiffies need an update */
  480. if (tick_do_timer_cpu == cpu)
  481. tick_do_update_jiffies64(now);
  482. /*
  483. * Do not call, when we are not in irq context and have
  484. * no valid regs pointer
  485. */
  486. if (regs) {
  487. /*
  488. * When we are idle and the tick is stopped, we have to touch
  489. * the watchdog as we might not schedule for a really long
  490. * time. This happens on complete idle SMP systems while
  491. * waiting on the login prompt. We also increment the "start of
  492. * idle" jiffy stamp so the idle accounting adjustment we do
  493. * when we go busy again does not account too much ticks.
  494. */
  495. if (ts->tick_stopped) {
  496. touch_softlockup_watchdog();
  497. ts->idle_jiffies++;
  498. }
  499. update_process_times(user_mode(regs));
  500. profile_tick(CPU_PROFILING);
  501. }
  502. /* Do not restart, when we are in the idle loop */
  503. if (ts->tick_stopped)
  504. return HRTIMER_NORESTART;
  505. hrtimer_forward(timer, now, tick_period);
  506. return HRTIMER_RESTART;
  507. }
  508. /**
  509. * tick_setup_sched_timer - setup the tick emulation timer
  510. */
  511. void tick_setup_sched_timer(void)
  512. {
  513. struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
  514. ktime_t now = ktime_get();
  515. u64 offset;
  516. /*
  517. * Emulate tick processing via per-CPU hrtimers:
  518. */
  519. hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  520. ts->sched_timer.function = tick_sched_timer;
  521. ts->sched_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ;
  522. /* Get the next period (per cpu) */
  523. ts->sched_timer.expires = tick_init_jiffy_update();
  524. offset = ktime_to_ns(tick_period) >> 1;
  525. do_div(offset, num_possible_cpus());
  526. offset *= smp_processor_id();
  527. ts->sched_timer.expires = ktime_add_ns(ts->sched_timer.expires, offset);
  528. for (;;) {
  529. hrtimer_forward(&ts->sched_timer, now, tick_period);
  530. hrtimer_start(&ts->sched_timer, ts->sched_timer.expires,
  531. HRTIMER_MODE_ABS);
  532. /* Check, if the timer was already in the past */
  533. if (hrtimer_active(&ts->sched_timer))
  534. break;
  535. now = ktime_get();
  536. }
  537. #ifdef CONFIG_NO_HZ
  538. if (tick_nohz_enabled)
  539. ts->nohz_mode = NOHZ_MODE_HIGHRES;
  540. #endif
  541. }
  542. void tick_cancel_sched_timer(int cpu)
  543. {
  544. struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
  545. if (ts->sched_timer.base)
  546. hrtimer_cancel(&ts->sched_timer);
  547. ts->tick_stopped = 0;
  548. ts->nohz_mode = NOHZ_MODE_INACTIVE;
  549. }
  550. #endif /* HIGH_RES_TIMERS */
  551. /**
  552. * Async notification about clocksource changes
  553. */
  554. void tick_clock_notify(void)
  555. {
  556. int cpu;
  557. for_each_possible_cpu(cpu)
  558. set_bit(0, &per_cpu(tick_cpu_sched, cpu).check_clocks);
  559. }
  560. /*
  561. * Async notification about clock event changes
  562. */
  563. void tick_oneshot_notify(void)
  564. {
  565. struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
  566. set_bit(0, &ts->check_clocks);
  567. }
  568. /**
  569. * Check, if a change happened, which makes oneshot possible.
  570. *
  571. * Called cyclic from the hrtimer softirq (driven by the timer
  572. * softirq) allow_nohz signals, that we can switch into low-res nohz
  573. * mode, because high resolution timers are disabled (either compile
  574. * or runtime).
  575. */
  576. int tick_check_oneshot_change(int allow_nohz)
  577. {
  578. struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched);
  579. if (!test_and_clear_bit(0, &ts->check_clocks))
  580. return 0;
  581. if (ts->nohz_mode != NOHZ_MODE_INACTIVE)
  582. return 0;
  583. if (!timekeeping_is_continuous() || !tick_is_oneshot_available())
  584. return 0;
  585. if (!allow_nohz)
  586. return 1;
  587. tick_nohz_switch_to_nohz();
  588. return 0;
  589. }