hrtimer.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905
  1. /*
  2. * linux/kernel/hrtimer.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. * High-resolution kernel timers
  9. *
  10. * In contrast to the low-resolution timeout API implemented in
  11. * kernel/timer.c, hrtimers provide finer resolution and accuracy
  12. * depending on system configuration and capabilities.
  13. *
  14. * These timers are currently used for:
  15. * - itimers
  16. * - POSIX timers
  17. * - nanosleep
  18. * - precise in-kernel timing
  19. *
  20. * Started by: Thomas Gleixner and Ingo Molnar
  21. *
  22. * Credits:
  23. * based on kernel/timer.c
  24. *
  25. * Help, testing, suggestions, bugfixes, improvements were
  26. * provided by:
  27. *
  28. * George Anzinger, Andrew Morton, Steven Rostedt, Roman Zippel
  29. * et. al.
  30. *
  31. * For licencing details see kernel-base/COPYING
  32. */
  33. #include <linux/cpu.h>
  34. #include <linux/export.h>
  35. #include <linux/percpu.h>
  36. #include <linux/hrtimer.h>
  37. #include <linux/notifier.h>
  38. #include <linux/syscalls.h>
  39. #include <linux/kallsyms.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/tick.h>
  42. #include <linux/seq_file.h>
  43. #include <linux/err.h>
  44. #include <linux/debugobjects.h>
  45. #include <linux/sched.h>
  46. #include <linux/timer.h>
  47. #include <linux/freezer.h>
  48. #include <asm/uaccess.h>
  49. #include <trace/events/timer.h>
  50. #ifdef CONFIG_SEC_DEBUG
  51. #include <mach/sec_debug.h>
  52. #endif
  53. /*
  54. * The timer bases:
  55. *
  56. * There are more clockids then hrtimer bases. Thus, we index
  57. * into the timer bases by the hrtimer_base_type enum. When trying
  58. * to reach a base using a clockid, hrtimer_clockid_to_base()
  59. * is used to convert from clockid to the proper hrtimer_base_type.
  60. */
  61. DEFINE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases) =
  62. {
  63. .lock = __RAW_SPIN_LOCK_UNLOCKED(hrtimer_bases.lock),
  64. .clock_base =
  65. {
  66. {
  67. .index = HRTIMER_BASE_MONOTONIC,
  68. .clockid = CLOCK_MONOTONIC,
  69. .get_time = &ktime_get,
  70. .resolution = KTIME_LOW_RES,
  71. },
  72. {
  73. .index = HRTIMER_BASE_REALTIME,
  74. .clockid = CLOCK_REALTIME,
  75. .get_time = &ktime_get_real,
  76. .resolution = KTIME_LOW_RES,
  77. },
  78. {
  79. .index = HRTIMER_BASE_BOOTTIME,
  80. .clockid = CLOCK_BOOTTIME,
  81. .get_time = &ktime_get_boottime,
  82. .resolution = KTIME_LOW_RES,
  83. },
  84. }
  85. };
  86. static const int hrtimer_clock_to_base_table[MAX_CLOCKS] = {
  87. /* Make sure we catch unsupported clockids */
  88. [0 ... MAX_CLOCKS - 1] = HRTIMER_MAX_CLOCK_BASES,
  89. [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
  90. [CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
  91. [CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
  92. };
  93. /*
  94. * Get the coarse grained time at the softirq based on xtime and
  95. * wall_to_monotonic.
  96. */
  97. static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
  98. {
  99. ktime_t xtim, mono, boot;
  100. struct timespec xts, tom, slp;
  101. get_xtime_and_monotonic_and_sleep_offset(&xts, &tom, &slp);
  102. xtim = timespec_to_ktime(xts);
  103. mono = ktime_add(xtim, timespec_to_ktime(tom));
  104. boot = ktime_add(mono, timespec_to_ktime(slp));
  105. base->clock_base[HRTIMER_BASE_REALTIME].softirq_time = xtim;
  106. base->clock_base[HRTIMER_BASE_MONOTONIC].softirq_time = mono;
  107. base->clock_base[HRTIMER_BASE_BOOTTIME].softirq_time = boot;
  108. }
  109. /*
  110. * Functions and macros which are different for UP/SMP systems are kept in a
  111. * single place
  112. */
  113. #ifdef CONFIG_SMP
  114. /*
  115. * We are using hashed locking: holding per_cpu(hrtimer_bases)[n].lock
  116. * means that all timers which are tied to this base via timer->base are
  117. * locked, and the base itself is locked too.
  118. *
  119. * So __run_timers/migrate_timers can safely modify all timers which could
  120. * be found on the lists/queues.
  121. *
  122. * When the timer's base is locked, and the timer removed from list, it is
  123. * possible to set timer->base = NULL and drop the lock: the timer remains
  124. * locked.
  125. */
  126. static
  127. struct hrtimer_clock_base *lock_hrtimer_base(const struct hrtimer *timer,
  128. unsigned long *flags)
  129. {
  130. struct hrtimer_clock_base *base;
  131. for (;;) {
  132. base = timer->base;
  133. if (likely(base != NULL)) {
  134. raw_spin_lock_irqsave(&base->cpu_base->lock, *flags);
  135. if (likely(base == timer->base))
  136. return base;
  137. /* The timer has migrated to another CPU: */
  138. raw_spin_unlock_irqrestore(&base->cpu_base->lock, *flags);
  139. }
  140. cpu_relax();
  141. }
  142. }
  143. /*
  144. * Get the preferred target CPU for NOHZ
  145. */
  146. static int hrtimer_get_target(int this_cpu, int pinned)
  147. {
  148. #ifdef CONFIG_NO_HZ
  149. if (!pinned && get_sysctl_timer_migration() && idle_cpu(this_cpu))
  150. return get_nohz_timer_target();
  151. #endif
  152. return this_cpu;
  153. }
  154. /*
  155. * With HIGHRES=y we do not migrate the timer when it is expiring
  156. * before the next event on the target cpu because we cannot reprogram
  157. * the target cpu hardware and we would cause it to fire late.
  158. *
  159. * Called with cpu_base->lock of target cpu held.
  160. */
  161. static int
  162. hrtimer_check_target(struct hrtimer *timer, struct hrtimer_clock_base *new_base)
  163. {
  164. #ifdef CONFIG_HIGH_RES_TIMERS
  165. ktime_t expires;
  166. if (!new_base->cpu_base->hres_active)
  167. return 0;
  168. expires = ktime_sub(hrtimer_get_expires(timer), new_base->offset);
  169. return expires.tv64 <= new_base->cpu_base->expires_next.tv64;
  170. #else
  171. return 0;
  172. #endif
  173. }
  174. /*
  175. * Switch the timer base to the current CPU when possible.
  176. */
  177. static inline struct hrtimer_clock_base *
  178. switch_hrtimer_base(struct hrtimer *timer, struct hrtimer_clock_base *base,
  179. int pinned)
  180. {
  181. struct hrtimer_clock_base *new_base;
  182. struct hrtimer_cpu_base *new_cpu_base;
  183. int this_cpu = smp_processor_id();
  184. int cpu = hrtimer_get_target(this_cpu, pinned);
  185. int basenum = base->index;
  186. again:
  187. new_cpu_base = &per_cpu(hrtimer_bases, cpu);
  188. new_base = &new_cpu_base->clock_base[basenum];
  189. if (base != new_base) {
  190. /*
  191. * We are trying to move timer to new_base.
  192. * However we can't change timer's base while it is running,
  193. * so we keep it on the same CPU. No hassle vs. reprogramming
  194. * the event source in the high resolution case. The softirq
  195. * code will take care of this when the timer function has
  196. * completed. There is no conflict as we hold the lock until
  197. * the timer is enqueued.
  198. */
  199. if (unlikely(hrtimer_callback_running(timer)))
  200. return base;
  201. /* See the comment in lock_timer_base() */
  202. timer->base = NULL;
  203. raw_spin_unlock(&base->cpu_base->lock);
  204. raw_spin_lock(&new_base->cpu_base->lock);
  205. if (cpu != this_cpu && hrtimer_check_target(timer, new_base)) {
  206. cpu = this_cpu;
  207. raw_spin_unlock(&new_base->cpu_base->lock);
  208. raw_spin_lock(&base->cpu_base->lock);
  209. timer->base = base;
  210. goto again;
  211. }
  212. timer->base = new_base;
  213. } else {
  214. if (cpu != this_cpu && hrtimer_check_target(timer, new_base)) {
  215. cpu = this_cpu;
  216. goto again;
  217. }
  218. }
  219. return new_base;
  220. }
  221. #else /* CONFIG_SMP */
  222. static inline struct hrtimer_clock_base *
  223. lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
  224. {
  225. struct hrtimer_clock_base *base = timer->base;
  226. raw_spin_lock_irqsave(&base->cpu_base->lock, *flags);
  227. return base;
  228. }
  229. # define switch_hrtimer_base(t, b, p) (b)
  230. #endif /* !CONFIG_SMP */
  231. /*
  232. * Functions for the union type storage format of ktime_t which are
  233. * too large for inlining:
  234. */
  235. #if BITS_PER_LONG < 64
  236. # ifndef CONFIG_KTIME_SCALAR
  237. /**
  238. * ktime_add_ns - Add a scalar nanoseconds value to a ktime_t variable
  239. * @kt: addend
  240. * @nsec: the scalar nsec value to add
  241. *
  242. * Returns the sum of kt and nsec in ktime_t format
  243. */
  244. ktime_t ktime_add_ns(const ktime_t kt, u64 nsec)
  245. {
  246. ktime_t tmp;
  247. if (likely(nsec < NSEC_PER_SEC)) {
  248. tmp.tv64 = nsec;
  249. } else {
  250. unsigned long rem = do_div(nsec, NSEC_PER_SEC);
  251. tmp = ktime_set((long)nsec, rem);
  252. }
  253. return ktime_add(kt, tmp);
  254. }
  255. EXPORT_SYMBOL_GPL(ktime_add_ns);
  256. /**
  257. * ktime_sub_ns - Subtract a scalar nanoseconds value from a ktime_t variable
  258. * @kt: minuend
  259. * @nsec: the scalar nsec value to subtract
  260. *
  261. * Returns the subtraction of @nsec from @kt in ktime_t format
  262. */
  263. ktime_t ktime_sub_ns(const ktime_t kt, u64 nsec)
  264. {
  265. ktime_t tmp;
  266. if (likely(nsec < NSEC_PER_SEC)) {
  267. tmp.tv64 = nsec;
  268. } else {
  269. unsigned long rem = do_div(nsec, NSEC_PER_SEC);
  270. /* Make sure nsec fits into long */
  271. if (unlikely(nsec > KTIME_SEC_MAX))
  272. return (ktime_t){ .tv64 = KTIME_MAX };
  273. tmp = ktime_set((long)nsec, rem);
  274. }
  275. return ktime_sub(kt, tmp);
  276. }
  277. EXPORT_SYMBOL_GPL(ktime_sub_ns);
  278. # endif /* !CONFIG_KTIME_SCALAR */
  279. /*
  280. * Divide a ktime value by a nanosecond value
  281. */
  282. s64 __ktime_divns(const ktime_t kt, s64 div)
  283. {
  284. int sft = 0;
  285. s64 dclc;
  286. u64 tmp;
  287. dclc = ktime_to_ns(kt);
  288. tmp = dclc < 0 ? -dclc : dclc;
  289. /* Make sure the divisor is less than 2^32: */
  290. while (div >> 32) {
  291. sft++;
  292. div >>= 1;
  293. }
  294. tmp >>= sft;
  295. do_div(tmp, (unsigned long) div);
  296. return dclc < 0 ? -tmp : tmp;
  297. }
  298. EXPORT_SYMBOL_GPL(__ktime_divns);
  299. #endif /* BITS_PER_LONG >= 64 */
  300. /*
  301. * Add two ktime values and do a safety check for overflow:
  302. */
  303. ktime_t ktime_add_safe(const ktime_t lhs, const ktime_t rhs)
  304. {
  305. ktime_t res = ktime_add(lhs, rhs);
  306. /*
  307. * We use KTIME_SEC_MAX here, the maximum timeout which we can
  308. * return to user space in a timespec:
  309. */
  310. if (res.tv64 < 0 || res.tv64 < lhs.tv64 || res.tv64 < rhs.tv64)
  311. res = ktime_set(KTIME_SEC_MAX, 0);
  312. return res;
  313. }
  314. EXPORT_SYMBOL_GPL(ktime_add_safe);
  315. #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
  316. static struct debug_obj_descr hrtimer_debug_descr;
  317. static void *hrtimer_debug_hint(void *addr)
  318. {
  319. return ((struct hrtimer *) addr)->function;
  320. }
  321. /*
  322. * fixup_init is called when:
  323. * - an active object is initialized
  324. */
  325. static int hrtimer_fixup_init(void *addr, enum debug_obj_state state)
  326. {
  327. struct hrtimer *timer = addr;
  328. switch (state) {
  329. case ODEBUG_STATE_ACTIVE:
  330. hrtimer_cancel(timer);
  331. debug_object_init(timer, &hrtimer_debug_descr);
  332. return 1;
  333. default:
  334. return 0;
  335. }
  336. }
  337. /*
  338. * fixup_activate is called when:
  339. * - an active object is activated
  340. * - an unknown object is activated (might be a statically initialized object)
  341. */
  342. static int hrtimer_fixup_activate(void *addr, enum debug_obj_state state)
  343. {
  344. switch (state) {
  345. case ODEBUG_STATE_NOTAVAILABLE:
  346. WARN_ON_ONCE(1);
  347. return 0;
  348. case ODEBUG_STATE_ACTIVE:
  349. WARN_ON(1);
  350. default:
  351. return 0;
  352. }
  353. }
  354. /*
  355. * fixup_free is called when:
  356. * - an active object is freed
  357. */
  358. static int hrtimer_fixup_free(void *addr, enum debug_obj_state state)
  359. {
  360. struct hrtimer *timer = addr;
  361. switch (state) {
  362. case ODEBUG_STATE_ACTIVE:
  363. hrtimer_cancel(timer);
  364. debug_object_free(timer, &hrtimer_debug_descr);
  365. return 1;
  366. default:
  367. return 0;
  368. }
  369. }
  370. static struct debug_obj_descr hrtimer_debug_descr = {
  371. .name = "hrtimer",
  372. .debug_hint = hrtimer_debug_hint,
  373. .fixup_init = hrtimer_fixup_init,
  374. .fixup_activate = hrtimer_fixup_activate,
  375. .fixup_free = hrtimer_fixup_free,
  376. };
  377. static inline void debug_hrtimer_init(struct hrtimer *timer)
  378. {
  379. debug_object_init(timer, &hrtimer_debug_descr);
  380. }
  381. static inline void debug_hrtimer_activate(struct hrtimer *timer)
  382. {
  383. debug_object_activate(timer, &hrtimer_debug_descr);
  384. }
  385. static inline void debug_hrtimer_deactivate(struct hrtimer *timer)
  386. {
  387. debug_object_deactivate(timer, &hrtimer_debug_descr);
  388. }
  389. static inline void debug_hrtimer_free(struct hrtimer *timer)
  390. {
  391. debug_object_free(timer, &hrtimer_debug_descr);
  392. }
  393. static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
  394. enum hrtimer_mode mode);
  395. void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id,
  396. enum hrtimer_mode mode)
  397. {
  398. debug_object_init_on_stack(timer, &hrtimer_debug_descr);
  399. __hrtimer_init(timer, clock_id, mode);
  400. }
  401. EXPORT_SYMBOL_GPL(hrtimer_init_on_stack);
  402. void destroy_hrtimer_on_stack(struct hrtimer *timer)
  403. {
  404. debug_object_free(timer, &hrtimer_debug_descr);
  405. }
  406. EXPORT_SYMBOL_GPL(destroy_hrtimer_on_stack);
  407. #else
  408. static inline void debug_hrtimer_init(struct hrtimer *timer) { }
  409. static inline void debug_hrtimer_activate(struct hrtimer *timer) { }
  410. static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { }
  411. #endif
  412. static inline void
  413. debug_init(struct hrtimer *timer, clockid_t clockid,
  414. enum hrtimer_mode mode)
  415. {
  416. debug_hrtimer_init(timer);
  417. trace_hrtimer_init(timer, clockid, mode);
  418. }
  419. static inline void debug_activate(struct hrtimer *timer)
  420. {
  421. debug_hrtimer_activate(timer);
  422. trace_hrtimer_start(timer);
  423. }
  424. static inline void debug_deactivate(struct hrtimer *timer)
  425. {
  426. debug_hrtimer_deactivate(timer);
  427. trace_hrtimer_cancel(timer);
  428. }
  429. /* High resolution timer related functions */
  430. #ifdef CONFIG_HIGH_RES_TIMERS
  431. /*
  432. * High resolution timer enabled ?
  433. */
  434. static int hrtimer_hres_enabled __read_mostly = 1;
  435. /*
  436. * Enable / Disable high resolution mode
  437. */
  438. static int __init setup_hrtimer_hres(char *str)
  439. {
  440. if (!strcmp(str, "off"))
  441. hrtimer_hres_enabled = 0;
  442. else if (!strcmp(str, "on"))
  443. hrtimer_hres_enabled = 1;
  444. else
  445. return 0;
  446. return 1;
  447. }
  448. __setup("highres=", setup_hrtimer_hres);
  449. /*
  450. * hrtimer_high_res_enabled - query, if the highres mode is enabled
  451. */
  452. static inline int hrtimer_is_hres_enabled(void)
  453. {
  454. return hrtimer_hres_enabled;
  455. }
  456. /*
  457. * Is the high resolution mode active ?
  458. */
  459. static inline int hrtimer_hres_active(void)
  460. {
  461. return __this_cpu_read(hrtimer_bases.hres_active);
  462. }
  463. /*
  464. * Reprogram the event source with checking both queues for the
  465. * next event
  466. * Called with interrupts disabled and base->lock held
  467. */
  468. static void
  469. hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base, int skip_equal)
  470. {
  471. int i;
  472. struct hrtimer_clock_base *base = cpu_base->clock_base;
  473. ktime_t expires, expires_next;
  474. expires_next.tv64 = KTIME_MAX;
  475. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
  476. struct hrtimer *timer;
  477. struct timerqueue_node *next;
  478. next = timerqueue_getnext(&base->active);
  479. if (!next)
  480. continue;
  481. timer = container_of(next, struct hrtimer, node);
  482. expires = ktime_sub(hrtimer_get_expires(timer), base->offset);
  483. /*
  484. * clock_was_set() has changed base->offset so the
  485. * result might be negative. Fix it up to prevent a
  486. * false positive in clockevents_program_event()
  487. */
  488. if (expires.tv64 < 0)
  489. expires.tv64 = 0;
  490. if (expires.tv64 < expires_next.tv64)
  491. expires_next = expires;
  492. }
  493. if (skip_equal && expires_next.tv64 == cpu_base->expires_next.tv64)
  494. return;
  495. cpu_base->expires_next.tv64 = expires_next.tv64;
  496. /*
  497. * If a hang was detected in the last timer interrupt then we
  498. * leave the hang delay active in the hardware. We want the
  499. * system to make progress. That also prevents the following
  500. * scenario:
  501. * T1 expires 50ms from now
  502. * T2 expires 5s from now
  503. *
  504. * T1 is removed, so this code is called and would reprogram
  505. * the hardware to 5s from now. Any hrtimer_start after that
  506. * will not reprogram the hardware due to hang_detected being
  507. * set. So we'd effectivly block all timers until the T2 event
  508. * fires.
  509. */
  510. if (cpu_base->hang_detected)
  511. return;
  512. if (cpu_base->expires_next.tv64 != KTIME_MAX)
  513. tick_program_event(cpu_base->expires_next, 1);
  514. }
  515. /*
  516. * Shared reprogramming for clock_realtime and clock_monotonic
  517. *
  518. * When a timer is enqueued and expires earlier than the already enqueued
  519. * timers, we have to check, whether it expires earlier than the timer for
  520. * which the clock event device was armed.
  521. *
  522. * Called with interrupts disabled and base->cpu_base.lock held
  523. */
  524. static int hrtimer_reprogram(struct hrtimer *timer,
  525. struct hrtimer_clock_base *base)
  526. {
  527. struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
  528. ktime_t expires = ktime_sub(hrtimer_get_expires(timer), base->offset);
  529. int res;
  530. WARN_ON_ONCE(hrtimer_get_expires_tv64(timer) < 0);
  531. /*
  532. * When the callback is running, we do not reprogram the clock event
  533. * device. The timer callback is either running on a different CPU or
  534. * the callback is executed in the hrtimer_interrupt context. The
  535. * reprogramming is handled either by the softirq, which called the
  536. * callback or at the end of the hrtimer_interrupt.
  537. */
  538. if (hrtimer_callback_running(timer))
  539. return 0;
  540. /*
  541. * CLOCK_REALTIME timer might be requested with an absolute
  542. * expiry time which is less than base->offset. Nothing wrong
  543. * about that, just avoid to call into the tick code, which
  544. * has now objections against negative expiry values.
  545. */
  546. if (expires.tv64 < 0)
  547. return -ETIME;
  548. if (expires.tv64 >= cpu_base->expires_next.tv64)
  549. return 0;
  550. /*
  551. * If a hang was detected in the last timer interrupt then we
  552. * do not schedule a timer which is earlier than the expiry
  553. * which we enforced in the hang detection. We want the system
  554. * to make progress.
  555. */
  556. if (cpu_base->hang_detected)
  557. return 0;
  558. /*
  559. * Clockevents returns -ETIME, when the event was in the past.
  560. */
  561. res = tick_program_event(expires, 0);
  562. if (!IS_ERR_VALUE(res))
  563. cpu_base->expires_next = expires;
  564. return res;
  565. }
  566. /*
  567. * Initialize the high resolution related parts of cpu_base
  568. */
  569. static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base)
  570. {
  571. base->expires_next.tv64 = KTIME_MAX;
  572. base->hang_detected = 0;
  573. base->hres_active = 0;
  574. }
  575. /*
  576. * When High resolution timers are active, try to reprogram. Note, that in case
  577. * the state has HRTIMER_STATE_CALLBACK set, no reprogramming and no expiry
  578. * check happens. The timer gets enqueued into the rbtree. The reprogramming
  579. * and expiry check is done in the hrtimer_interrupt or in the softirq.
  580. */
  581. static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
  582. struct hrtimer_clock_base *base)
  583. {
  584. return base->cpu_base->hres_active && hrtimer_reprogram(timer, base);
  585. }
  586. static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
  587. {
  588. ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset;
  589. ktime_t *offs_boot = &base->clock_base[HRTIMER_BASE_BOOTTIME].offset;
  590. return ktime_get_update_offsets(offs_real, offs_boot);
  591. }
  592. /*
  593. * Retrigger next event is called after clock was set
  594. *
  595. * Called with interrupts disabled via on_each_cpu()
  596. */
  597. static void retrigger_next_event(void *arg)
  598. {
  599. struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
  600. if (!hrtimer_hres_active())
  601. return;
  602. raw_spin_lock(&base->lock);
  603. hrtimer_update_base(base);
  604. hrtimer_force_reprogram(base, 0);
  605. raw_spin_unlock(&base->lock);
  606. }
  607. /*
  608. * Switch to high resolution mode
  609. */
  610. static int hrtimer_switch_to_hres(void)
  611. {
  612. int i, cpu = smp_processor_id();
  613. struct hrtimer_cpu_base *base = &per_cpu(hrtimer_bases, cpu);
  614. unsigned long flags;
  615. if (base->hres_active)
  616. return 1;
  617. local_irq_save(flags);
  618. if (tick_init_highres()) {
  619. local_irq_restore(flags);
  620. printk(KERN_WARNING "Could not switch to high resolution "
  621. "mode on CPU %d\n", cpu);
  622. return 0;
  623. }
  624. base->hres_active = 1;
  625. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++)
  626. base->clock_base[i].resolution = KTIME_HIGH_RES;
  627. tick_setup_sched_timer();
  628. /* "Retrigger" the interrupt to get things going */
  629. retrigger_next_event(NULL);
  630. local_irq_restore(flags);
  631. return 1;
  632. }
  633. static void clock_was_set_work(struct work_struct *work)
  634. {
  635. clock_was_set();
  636. }
  637. static DECLARE_WORK(hrtimer_work, clock_was_set_work);
  638. /*
  639. * Called from timekeeping and resume code to reprogramm the hrtimer
  640. * interrupt device on all cpus.
  641. */
  642. void clock_was_set_delayed(void)
  643. {
  644. schedule_work(&hrtimer_work);
  645. }
  646. #else
  647. static inline int hrtimer_hres_active(void) { return 0; }
  648. static inline int hrtimer_is_hres_enabled(void) { return 0; }
  649. static inline int hrtimer_switch_to_hres(void) { return 0; }
  650. static inline void
  651. hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
  652. static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
  653. struct hrtimer_clock_base *base)
  654. {
  655. return 0;
  656. }
  657. static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
  658. static inline void retrigger_next_event(void *arg) { }
  659. #endif /* CONFIG_HIGH_RES_TIMERS */
  660. /*
  661. * Clock realtime was set
  662. *
  663. * Change the offset of the realtime clock vs. the monotonic
  664. * clock.
  665. *
  666. * We might have to reprogram the high resolution timer interrupt. On
  667. * SMP we call the architecture specific code to retrigger _all_ high
  668. * resolution timer interrupts. On UP we just disable interrupts and
  669. * call the high resolution interrupt code.
  670. */
  671. void clock_was_set(void)
  672. {
  673. #ifdef CONFIG_HIGH_RES_TIMERS
  674. /* Retrigger the CPU local events everywhere */
  675. on_each_cpu(retrigger_next_event, NULL, 1);
  676. #endif
  677. timerfd_clock_was_set();
  678. }
  679. /*
  680. * During resume we might have to reprogram the high resolution timer
  681. * interrupt (on the local CPU):
  682. */
  683. void hrtimers_resume(void)
  684. {
  685. WARN_ONCE(!irqs_disabled(),
  686. KERN_INFO "hrtimers_resume() called with IRQs enabled!");
  687. /* Retrigger on the local CPU */
  688. retrigger_next_event(NULL);
  689. /* And schedule a retrigger for all others */
  690. clock_was_set_delayed();
  691. }
  692. /*
  693. * Counterpart to lock_hrtimer_base above:
  694. */
  695. static inline
  696. void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
  697. {
  698. raw_spin_unlock_irqrestore(&timer->base->cpu_base->lock, *flags);
  699. }
  700. /**
  701. * hrtimer_forward - forward the timer expiry
  702. * @timer: hrtimer to forward
  703. * @now: forward past this time
  704. * @interval: the interval to forward
  705. *
  706. * Forward the timer expiry so it will expire in the future.
  707. * Returns the number of overruns.
  708. */
  709. u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval)
  710. {
  711. u64 orun = 1;
  712. ktime_t delta;
  713. delta = ktime_sub(now, hrtimer_get_expires(timer));
  714. if (delta.tv64 < 0)
  715. return 0;
  716. if (WARN_ON(timer->state & HRTIMER_STATE_ENQUEUED))
  717. return 0;
  718. if (interval.tv64 < timer->base->resolution.tv64)
  719. interval.tv64 = timer->base->resolution.tv64;
  720. if (unlikely(delta.tv64 >= interval.tv64)) {
  721. s64 incr = ktime_to_ns(interval);
  722. orun = ktime_divns(delta, incr);
  723. hrtimer_add_expires_ns(timer, incr * orun);
  724. if (hrtimer_get_expires_tv64(timer) > now.tv64)
  725. return orun;
  726. /*
  727. * This (and the ktime_add() below) is the
  728. * correction for exact:
  729. */
  730. orun++;
  731. }
  732. hrtimer_add_expires(timer, interval);
  733. return orun;
  734. }
  735. EXPORT_SYMBOL_GPL(hrtimer_forward);
  736. /*
  737. * enqueue_hrtimer - internal function to (re)start a timer
  738. *
  739. * The timer is inserted in expiry order. Insertion into the
  740. * red black tree is O(log(n)). Must hold the base lock.
  741. *
  742. * Returns 1 when the new timer is the leftmost timer in the tree.
  743. */
  744. static int enqueue_hrtimer(struct hrtimer *timer,
  745. struct hrtimer_clock_base *base)
  746. {
  747. debug_activate(timer);
  748. timerqueue_add(&base->active, &timer->node);
  749. base->cpu_base->active_bases |= 1 << base->index;
  750. /*
  751. * HRTIMER_STATE_ENQUEUED is or'ed to the current state to preserve the
  752. * state of a possibly running callback.
  753. */
  754. timer->state |= HRTIMER_STATE_ENQUEUED;
  755. return (&timer->node == base->active.next);
  756. }
  757. /*
  758. * __remove_hrtimer - internal function to remove a timer
  759. *
  760. * Caller must hold the base lock.
  761. *
  762. * High resolution timer mode reprograms the clock event device when the
  763. * timer is the one which expires next. The caller can disable this by setting
  764. * reprogram to zero. This is useful, when the context does a reprogramming
  765. * anyway (e.g. timer interrupt)
  766. */
  767. static void __remove_hrtimer(struct hrtimer *timer,
  768. struct hrtimer_clock_base *base,
  769. unsigned long newstate, int reprogram)
  770. {
  771. struct timerqueue_node *next_timer;
  772. if (!(timer->state & HRTIMER_STATE_ENQUEUED))
  773. goto out;
  774. next_timer = timerqueue_getnext(&base->active);
  775. timerqueue_del(&base->active, &timer->node);
  776. if (&timer->node == next_timer) {
  777. #ifdef CONFIG_HIGH_RES_TIMERS
  778. /* Reprogram the clock event device. if enabled */
  779. if (reprogram && hrtimer_hres_active()) {
  780. ktime_t expires;
  781. expires = ktime_sub(hrtimer_get_expires(timer),
  782. base->offset);
  783. if (base->cpu_base->expires_next.tv64 == expires.tv64)
  784. hrtimer_force_reprogram(base->cpu_base, 1);
  785. }
  786. #endif
  787. }
  788. if (!timerqueue_getnext(&base->active))
  789. base->cpu_base->active_bases &= ~(1 << base->index);
  790. out:
  791. timer->state = newstate;
  792. }
  793. /*
  794. * remove hrtimer, called with base lock held
  795. */
  796. static inline int
  797. remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base)
  798. {
  799. if (hrtimer_is_queued(timer)) {
  800. unsigned long state;
  801. int reprogram;
  802. /*
  803. * Remove the timer and force reprogramming when high
  804. * resolution mode is active and the timer is on the current
  805. * CPU. If we remove a timer on another CPU, reprogramming is
  806. * skipped. The interrupt event on this CPU is fired and
  807. * reprogramming happens in the interrupt handler. This is a
  808. * rare case and less expensive than a smp call.
  809. */
  810. debug_deactivate(timer);
  811. reprogram = base->cpu_base == &__get_cpu_var(hrtimer_bases);
  812. /*
  813. * We must preserve the CALLBACK state flag here,
  814. * otherwise we could move the timer base in
  815. * switch_hrtimer_base.
  816. */
  817. state = timer->state & HRTIMER_STATE_CALLBACK;
  818. __remove_hrtimer(timer, base, state, reprogram);
  819. return 1;
  820. }
  821. return 0;
  822. }
  823. int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
  824. u64 delta_ns, const enum hrtimer_mode mode,
  825. int wakeup)
  826. {
  827. struct hrtimer_clock_base *base, *new_base;
  828. unsigned long flags;
  829. int ret, leftmost;
  830. base = lock_hrtimer_base(timer, &flags);
  831. /* Remove an active timer from the queue: */
  832. ret = remove_hrtimer(timer, base);
  833. if (mode & HRTIMER_MODE_REL) {
  834. tim = ktime_add_safe(tim, base->get_time());
  835. /*
  836. * CONFIG_TIME_LOW_RES is a temporary way for architectures
  837. * to signal that they simply return xtime in
  838. * do_gettimeoffset(). In this case we want to round up by
  839. * resolution when starting a relative timer, to avoid short
  840. * timeouts. This will go away with the GTOD framework.
  841. */
  842. #ifdef CONFIG_TIME_LOW_RES
  843. tim = ktime_add_safe(tim, base->resolution);
  844. #endif
  845. }
  846. hrtimer_set_expires_range_ns(timer, tim, delta_ns);
  847. /* Switch the timer base, if necessary: */
  848. new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
  849. leftmost = enqueue_hrtimer(timer, new_base);
  850. /*
  851. * Only allow reprogramming if the new base is on this CPU.
  852. * (it might still be on another CPU if the timer was pending)
  853. *
  854. * XXX send_remote_softirq() ?
  855. */
  856. if (leftmost && new_base->cpu_base == &__get_cpu_var(hrtimer_bases)
  857. && hrtimer_enqueue_reprogram(timer, new_base)) {
  858. if (wakeup) {
  859. /*
  860. * We need to drop cpu_base->lock to avoid a
  861. * lock ordering issue vs. rq->lock.
  862. */
  863. raw_spin_unlock(&new_base->cpu_base->lock);
  864. raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  865. local_irq_restore(flags);
  866. return ret;
  867. } else {
  868. __raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  869. }
  870. }
  871. unlock_hrtimer_base(timer, &flags);
  872. return ret;
  873. }
  874. /**
  875. * hrtimer_start_range_ns - (re)start an hrtimer on the current CPU
  876. * @timer: the timer to be added
  877. * @tim: expiry time
  878. * @delta_ns: "slack" range for the timer
  879. * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)
  880. *
  881. * Returns:
  882. * 0 on success
  883. * 1 when the timer was active
  884. */
  885. int hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
  886. u64 delta_ns, const enum hrtimer_mode mode)
  887. {
  888. return __hrtimer_start_range_ns(timer, tim, delta_ns, mode, 1);
  889. }
  890. EXPORT_SYMBOL_GPL(hrtimer_start_range_ns);
  891. /**
  892. * hrtimer_start - (re)start an hrtimer on the current CPU
  893. * @timer: the timer to be added
  894. * @tim: expiry time
  895. * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL)
  896. *
  897. * Returns:
  898. * 0 on success
  899. * 1 when the timer was active
  900. */
  901. int
  902. hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode)
  903. {
  904. return __hrtimer_start_range_ns(timer, tim, 0, mode, 1);
  905. }
  906. EXPORT_SYMBOL_GPL(hrtimer_start);
  907. /**
  908. * hrtimer_try_to_cancel - try to deactivate a timer
  909. * @timer: hrtimer to stop
  910. *
  911. * Returns:
  912. * 0 when the timer was not active
  913. * 1 when the timer was active
  914. * -1 when the timer is currently excuting the callback function and
  915. * cannot be stopped
  916. */
  917. int hrtimer_try_to_cancel(struct hrtimer *timer)
  918. {
  919. struct hrtimer_clock_base *base;
  920. unsigned long flags;
  921. int ret = -1;
  922. base = lock_hrtimer_base(timer, &flags);
  923. if (!hrtimer_callback_running(timer))
  924. ret = remove_hrtimer(timer, base);
  925. unlock_hrtimer_base(timer, &flags);
  926. return ret;
  927. }
  928. EXPORT_SYMBOL_GPL(hrtimer_try_to_cancel);
  929. /**
  930. * hrtimer_cancel - cancel a timer and wait for the handler to finish.
  931. * @timer: the timer to be cancelled
  932. *
  933. * Returns:
  934. * 0 when the timer was not active
  935. * 1 when the timer was active
  936. */
  937. int hrtimer_cancel(struct hrtimer *timer)
  938. {
  939. for (;;) {
  940. int ret = hrtimer_try_to_cancel(timer);
  941. if (ret >= 0)
  942. return ret;
  943. cpu_relax();
  944. }
  945. }
  946. EXPORT_SYMBOL_GPL(hrtimer_cancel);
  947. /**
  948. * hrtimer_get_remaining - get remaining time for the timer
  949. * @timer: the timer to read
  950. */
  951. ktime_t hrtimer_get_remaining(const struct hrtimer *timer)
  952. {
  953. unsigned long flags;
  954. ktime_t rem;
  955. lock_hrtimer_base(timer, &flags);
  956. rem = hrtimer_expires_remaining(timer);
  957. unlock_hrtimer_base(timer, &flags);
  958. return rem;
  959. }
  960. EXPORT_SYMBOL_GPL(hrtimer_get_remaining);
  961. #ifdef CONFIG_NO_HZ
  962. /**
  963. * hrtimer_get_next_event - get the time until next expiry event
  964. *
  965. * Returns the delta to the next expiry event or KTIME_MAX if no timer
  966. * is pending.
  967. */
  968. ktime_t hrtimer_get_next_event(void)
  969. {
  970. struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
  971. struct hrtimer_clock_base *base = cpu_base->clock_base;
  972. ktime_t delta, mindelta = { .tv64 = KTIME_MAX };
  973. unsigned long flags;
  974. int i;
  975. raw_spin_lock_irqsave(&cpu_base->lock, flags);
  976. if (!hrtimer_hres_active()) {
  977. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
  978. struct hrtimer *timer;
  979. struct timerqueue_node *next;
  980. next = timerqueue_getnext(&base->active);
  981. if (!next)
  982. continue;
  983. timer = container_of(next, struct hrtimer, node);
  984. delta.tv64 = hrtimer_get_expires_tv64(timer);
  985. delta = ktime_sub(delta, base->get_time());
  986. if (delta.tv64 < mindelta.tv64)
  987. mindelta.tv64 = delta.tv64;
  988. }
  989. }
  990. raw_spin_unlock_irqrestore(&cpu_base->lock, flags);
  991. if (mindelta.tv64 < 0)
  992. mindelta.tv64 = 0;
  993. return mindelta;
  994. }
  995. #endif
  996. static inline int hrtimer_clockid_to_base(clockid_t clock_id)
  997. {
  998. if (likely(clock_id < MAX_CLOCKS)) {
  999. int base = hrtimer_clock_to_base_table[clock_id];
  1000. if (likely(base != HRTIMER_MAX_CLOCK_BASES))
  1001. return base;
  1002. }
  1003. WARN(1, "Invalid clockid %d. Using MONOTONIC\n", clock_id);
  1004. return HRTIMER_BASE_MONOTONIC;
  1005. }
  1006. static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
  1007. enum hrtimer_mode mode)
  1008. {
  1009. struct hrtimer_cpu_base *cpu_base;
  1010. int base;
  1011. memset(timer, 0, sizeof(struct hrtimer));
  1012. cpu_base = &__raw_get_cpu_var(hrtimer_bases);
  1013. /*
  1014. * POSIX magic: Relative CLOCK_REALTIME timers are not affected by
  1015. * clock modifications, so they needs to become CLOCK_MONOTONIC to
  1016. * ensure POSIX compliance.
  1017. */
  1018. if (clock_id == CLOCK_REALTIME && mode & HRTIMER_MODE_REL)
  1019. clock_id = CLOCK_MONOTONIC;
  1020. base = hrtimer_clockid_to_base(clock_id);
  1021. timer->base = &cpu_base->clock_base[base];
  1022. timerqueue_init(&timer->node);
  1023. }
  1024. /**
  1025. * hrtimer_init - initialize a timer to the given clock
  1026. * @timer: the timer to be initialized
  1027. * @clock_id: the clock to be used
  1028. * @mode: timer mode abs/rel
  1029. */
  1030. void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
  1031. enum hrtimer_mode mode)
  1032. {
  1033. debug_init(timer, clock_id, mode);
  1034. __hrtimer_init(timer, clock_id, mode);
  1035. }
  1036. EXPORT_SYMBOL_GPL(hrtimer_init);
  1037. /**
  1038. * hrtimer_get_res - get the timer resolution for a clock
  1039. * @which_clock: which clock to query
  1040. * @tp: pointer to timespec variable to store the resolution
  1041. *
  1042. * Store the resolution of the clock selected by @which_clock in the
  1043. * variable pointed to by @tp.
  1044. */
  1045. int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
  1046. {
  1047. struct hrtimer_cpu_base *cpu_base;
  1048. int base = hrtimer_clockid_to_base(which_clock);
  1049. cpu_base = &__raw_get_cpu_var(hrtimer_bases);
  1050. *tp = ktime_to_timespec(cpu_base->clock_base[base].resolution);
  1051. return 0;
  1052. }
  1053. EXPORT_SYMBOL_GPL(hrtimer_get_res);
  1054. static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
  1055. {
  1056. struct hrtimer_clock_base *base = timer->base;
  1057. struct hrtimer_cpu_base *cpu_base = base->cpu_base;
  1058. enum hrtimer_restart (*fn)(struct hrtimer *);
  1059. int restart;
  1060. WARN_ON(!irqs_disabled());
  1061. debug_deactivate(timer);
  1062. __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0);
  1063. fn = timer->function;
  1064. /*
  1065. * Because we run timers from hardirq context, there is no chance
  1066. * they get migrated to another cpu, therefore its safe to unlock
  1067. * the timer base.
  1068. */
  1069. raw_spin_unlock(&cpu_base->lock);
  1070. trace_hrtimer_expire_entry(timer, now);
  1071. #ifdef CONFIG_SEC_DEBUG
  1072. secdbg_msg("hrtimer %pS entry", fn);
  1073. #endif
  1074. restart = fn(timer);
  1075. #ifdef CONFIG_SEC_DEBUG
  1076. secdbg_msg("hrtimer %pS exit", fn);
  1077. #endif
  1078. trace_hrtimer_expire_exit(timer);
  1079. raw_spin_lock(&cpu_base->lock);
  1080. /*
  1081. * Note: We clear the CALLBACK bit after enqueue_hrtimer and
  1082. * we do not reprogramm the event hardware. Happens either in
  1083. * hrtimer_start_range_ns() or in hrtimer_interrupt()
  1084. *
  1085. * Note: Because we dropped the cpu_base->lock above,
  1086. * hrtimer_start_range_ns() can have popped in and enqueued the timer
  1087. * for us already.
  1088. */
  1089. if (restart != HRTIMER_NORESTART &&
  1090. !(timer->state & HRTIMER_STATE_ENQUEUED))
  1091. enqueue_hrtimer(timer, base);
  1092. WARN_ON_ONCE(!(timer->state & HRTIMER_STATE_CALLBACK));
  1093. timer->state &= ~HRTIMER_STATE_CALLBACK;
  1094. }
  1095. #ifdef CONFIG_HIGH_RES_TIMERS
  1096. /*
  1097. * High resolution timer interrupt
  1098. * Called with interrupts disabled
  1099. */
  1100. void hrtimer_interrupt(struct clock_event_device *dev)
  1101. {
  1102. struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
  1103. ktime_t expires_next, now, entry_time, delta;
  1104. int i, retries = 0;
  1105. BUG_ON(!cpu_base->hres_active);
  1106. cpu_base->nr_events++;
  1107. dev->next_event.tv64 = KTIME_MAX;
  1108. raw_spin_lock(&cpu_base->lock);
  1109. entry_time = now = hrtimer_update_base(cpu_base);
  1110. retry:
  1111. expires_next.tv64 = KTIME_MAX;
  1112. /*
  1113. * We set expires_next to KTIME_MAX here with cpu_base->lock
  1114. * held to prevent that a timer is enqueued in our queue via
  1115. * the migration code. This does not affect enqueueing of
  1116. * timers which run their callback and need to be requeued on
  1117. * this CPU.
  1118. */
  1119. cpu_base->expires_next.tv64 = KTIME_MAX;
  1120. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  1121. struct hrtimer_clock_base *base;
  1122. struct timerqueue_node *node;
  1123. ktime_t basenow;
  1124. if (!(cpu_base->active_bases & (1 << i)))
  1125. continue;
  1126. base = cpu_base->clock_base + i;
  1127. basenow = ktime_add(now, base->offset);
  1128. while ((node = timerqueue_getnext(&base->active))) {
  1129. struct hrtimer *timer;
  1130. timer = container_of(node, struct hrtimer, node);
  1131. /*
  1132. * The immediate goal for using the softexpires is
  1133. * minimizing wakeups, not running timers at the
  1134. * earliest interrupt after their soft expiration.
  1135. * This allows us to avoid using a Priority Search
  1136. * Tree, which can answer a stabbing querry for
  1137. * overlapping intervals and instead use the simple
  1138. * BST we already have.
  1139. * We don't add extra wakeups by delaying timers that
  1140. * are right-of a not yet expired timer, because that
  1141. * timer will have to trigger a wakeup anyway.
  1142. */
  1143. if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer)) {
  1144. ktime_t expires;
  1145. expires = ktime_sub(hrtimer_get_expires(timer),
  1146. base->offset);
  1147. if (expires.tv64 < 0)
  1148. expires.tv64 = KTIME_MAX;
  1149. if (expires.tv64 < expires_next.tv64)
  1150. expires_next = expires;
  1151. break;
  1152. }
  1153. __run_hrtimer(timer, &basenow);
  1154. }
  1155. }
  1156. /*
  1157. * Store the new expiry value so the migration code can verify
  1158. * against it.
  1159. */
  1160. cpu_base->expires_next = expires_next;
  1161. raw_spin_unlock(&cpu_base->lock);
  1162. /* Reprogramming necessary ? */
  1163. if (expires_next.tv64 == KTIME_MAX ||
  1164. !tick_program_event(expires_next, 0)) {
  1165. cpu_base->hang_detected = 0;
  1166. return;
  1167. }
  1168. /*
  1169. * The next timer was already expired due to:
  1170. * - tracing
  1171. * - long lasting callbacks
  1172. * - being scheduled away when running in a VM
  1173. *
  1174. * We need to prevent that we loop forever in the hrtimer
  1175. * interrupt routine. We give it 3 attempts to avoid
  1176. * overreacting on some spurious event.
  1177. *
  1178. * Acquire base lock for updating the offsets and retrieving
  1179. * the current time.
  1180. */
  1181. raw_spin_lock(&cpu_base->lock);
  1182. now = hrtimer_update_base(cpu_base);
  1183. cpu_base->nr_retries++;
  1184. if (++retries < 3)
  1185. goto retry;
  1186. /*
  1187. * Give the system a chance to do something else than looping
  1188. * here. We stored the entry time, so we know exactly how long
  1189. * we spent here. We schedule the next event this amount of
  1190. * time away.
  1191. */
  1192. cpu_base->nr_hangs++;
  1193. cpu_base->hang_detected = 1;
  1194. raw_spin_unlock(&cpu_base->lock);
  1195. delta = ktime_sub(now, entry_time);
  1196. if (delta.tv64 > cpu_base->max_hang_time.tv64)
  1197. cpu_base->max_hang_time = delta;
  1198. /*
  1199. * Limit it to a sensible value as we enforce a longer
  1200. * delay. Give the CPU at least 100ms to catch up.
  1201. */
  1202. if (delta.tv64 > 100 * NSEC_PER_MSEC)
  1203. expires_next = ktime_add_ns(now, 100 * NSEC_PER_MSEC);
  1204. else
  1205. expires_next = ktime_add(now, delta);
  1206. tick_program_event(expires_next, 1);
  1207. printk_once(KERN_WARNING "hrtimer: interrupt took %llu ns\n",
  1208. ktime_to_ns(delta));
  1209. }
  1210. /*
  1211. * local version of hrtimer_peek_ahead_timers() called with interrupts
  1212. * disabled.
  1213. */
  1214. static void __hrtimer_peek_ahead_timers(void)
  1215. {
  1216. struct tick_device *td;
  1217. if (!hrtimer_hres_active())
  1218. return;
  1219. td = &__get_cpu_var(tick_cpu_device);
  1220. if (td && td->evtdev)
  1221. hrtimer_interrupt(td->evtdev);
  1222. }
  1223. /**
  1224. * hrtimer_peek_ahead_timers -- run soft-expired timers now
  1225. *
  1226. * hrtimer_peek_ahead_timers will peek at the timer queue of
  1227. * the current cpu and check if there are any timers for which
  1228. * the soft expires time has passed. If any such timers exist,
  1229. * they are run immediately and then removed from the timer queue.
  1230. *
  1231. */
  1232. void hrtimer_peek_ahead_timers(void)
  1233. {
  1234. unsigned long flags;
  1235. local_irq_save(flags);
  1236. __hrtimer_peek_ahead_timers();
  1237. local_irq_restore(flags);
  1238. }
  1239. static void run_hrtimer_softirq(struct softirq_action *h)
  1240. {
  1241. hrtimer_peek_ahead_timers();
  1242. }
  1243. #else /* CONFIG_HIGH_RES_TIMERS */
  1244. static inline void __hrtimer_peek_ahead_timers(void) { }
  1245. #endif /* !CONFIG_HIGH_RES_TIMERS */
  1246. /*
  1247. * Called from timer softirq every jiffy, expire hrtimers:
  1248. *
  1249. * For HRT its the fall back code to run the softirq in the timer
  1250. * softirq context in case the hrtimer initialization failed or has
  1251. * not been done yet.
  1252. */
  1253. void hrtimer_run_pending(void)
  1254. {
  1255. if (hrtimer_hres_active())
  1256. return;
  1257. /*
  1258. * This _is_ ugly: We have to check in the softirq context,
  1259. * whether we can switch to highres and / or nohz mode. The
  1260. * clocksource switch happens in the timer interrupt with
  1261. * xtime_lock held. Notification from there only sets the
  1262. * check bit in the tick_oneshot code, otherwise we might
  1263. * deadlock vs. xtime_lock.
  1264. */
  1265. if (tick_check_oneshot_change(!hrtimer_is_hres_enabled()))
  1266. hrtimer_switch_to_hres();
  1267. }
  1268. /*
  1269. * Called from hardirq context every jiffy
  1270. */
  1271. void hrtimer_run_queues(void)
  1272. {
  1273. struct timerqueue_node *node;
  1274. struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
  1275. struct hrtimer_clock_base *base;
  1276. int index, gettime = 1;
  1277. if (hrtimer_hres_active())
  1278. return;
  1279. for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) {
  1280. base = &cpu_base->clock_base[index];
  1281. if (!timerqueue_getnext(&base->active))
  1282. continue;
  1283. if (gettime) {
  1284. hrtimer_get_softirq_time(cpu_base);
  1285. gettime = 0;
  1286. }
  1287. raw_spin_lock(&cpu_base->lock);
  1288. while ((node = timerqueue_getnext(&base->active))) {
  1289. struct hrtimer *timer;
  1290. timer = container_of(node, struct hrtimer, node);
  1291. if (base->softirq_time.tv64 <=
  1292. hrtimer_get_expires_tv64(timer))
  1293. break;
  1294. __run_hrtimer(timer, &base->softirq_time);
  1295. }
  1296. raw_spin_unlock(&cpu_base->lock);
  1297. }
  1298. }
  1299. /*
  1300. * Sleep related functions:
  1301. */
  1302. static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
  1303. {
  1304. struct hrtimer_sleeper *t =
  1305. container_of(timer, struct hrtimer_sleeper, timer);
  1306. struct task_struct *task = t->task;
  1307. t->task = NULL;
  1308. if (task)
  1309. wake_up_process(task);
  1310. return HRTIMER_NORESTART;
  1311. }
  1312. void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
  1313. {
  1314. sl->timer.function = hrtimer_wakeup;
  1315. sl->task = task;
  1316. }
  1317. EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
  1318. static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
  1319. {
  1320. hrtimer_init_sleeper(t, current);
  1321. do {
  1322. set_current_state(TASK_INTERRUPTIBLE);
  1323. hrtimer_start_expires(&t->timer, mode);
  1324. if (!hrtimer_active(&t->timer))
  1325. t->task = NULL;
  1326. if (likely(t->task))
  1327. freezable_schedule();
  1328. hrtimer_cancel(&t->timer);
  1329. mode = HRTIMER_MODE_ABS;
  1330. } while (t->task && !signal_pending(current));
  1331. __set_current_state(TASK_RUNNING);
  1332. return t->task == NULL;
  1333. }
  1334. static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp)
  1335. {
  1336. struct timespec rmt;
  1337. ktime_t rem;
  1338. rem = hrtimer_expires_remaining(timer);
  1339. if (rem.tv64 <= 0)
  1340. return 0;
  1341. rmt = ktime_to_timespec(rem);
  1342. if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
  1343. return -EFAULT;
  1344. return 1;
  1345. }
  1346. long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
  1347. {
  1348. struct hrtimer_sleeper t;
  1349. struct timespec __user *rmtp;
  1350. int ret = 0;
  1351. hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid,
  1352. HRTIMER_MODE_ABS);
  1353. hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
  1354. if (do_nanosleep(&t, HRTIMER_MODE_ABS))
  1355. goto out;
  1356. rmtp = restart->nanosleep.rmtp;
  1357. if (rmtp) {
  1358. ret = update_rmtp(&t.timer, rmtp);
  1359. if (ret <= 0)
  1360. goto out;
  1361. }
  1362. /* The other values in restart are already filled in */
  1363. ret = -ERESTART_RESTARTBLOCK;
  1364. out:
  1365. destroy_hrtimer_on_stack(&t.timer);
  1366. return ret;
  1367. }
  1368. long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  1369. const enum hrtimer_mode mode, const clockid_t clockid)
  1370. {
  1371. struct restart_block *restart;
  1372. struct hrtimer_sleeper t;
  1373. int ret = 0;
  1374. u64 slack;
  1375. slack = current->timer_slack_ns;
  1376. if (rt_task(current))
  1377. slack = 0;
  1378. hrtimer_init_on_stack(&t.timer, clockid, mode);
  1379. hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
  1380. if (do_nanosleep(&t, mode))
  1381. goto out;
  1382. /* Absolute timers do not update the rmtp value and restart: */
  1383. if (mode == HRTIMER_MODE_ABS) {
  1384. ret = -ERESTARTNOHAND;
  1385. goto out;
  1386. }
  1387. if (rmtp) {
  1388. ret = update_rmtp(&t.timer, rmtp);
  1389. if (ret <= 0)
  1390. goto out;
  1391. }
  1392. restart = &current_thread_info()->restart_block;
  1393. restart->fn = hrtimer_nanosleep_restart;
  1394. restart->nanosleep.clockid = t.timer.base->clockid;
  1395. restart->nanosleep.rmtp = rmtp;
  1396. restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer);
  1397. ret = -ERESTART_RESTARTBLOCK;
  1398. out:
  1399. destroy_hrtimer_on_stack(&t.timer);
  1400. return ret;
  1401. }
  1402. SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
  1403. struct timespec __user *, rmtp)
  1404. {
  1405. struct timespec tu;
  1406. if (copy_from_user(&tu, rqtp, sizeof(tu)))
  1407. return -EFAULT;
  1408. if (!timespec_valid(&tu))
  1409. return -EINVAL;
  1410. return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
  1411. }
  1412. /*
  1413. * Functions related to boot-time initialization:
  1414. */
  1415. static void __cpuinit init_hrtimers_cpu(int cpu)
  1416. {
  1417. struct hrtimer_cpu_base *cpu_base = &per_cpu(hrtimer_bases, cpu);
  1418. int i;
  1419. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  1420. cpu_base->clock_base[i].cpu_base = cpu_base;
  1421. timerqueue_init_head(&cpu_base->clock_base[i].active);
  1422. }
  1423. cpu_base->active_bases = 0;
  1424. hrtimer_init_hres(cpu_base);
  1425. }
  1426. #ifdef CONFIG_HOTPLUG_CPU
  1427. static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base,
  1428. struct hrtimer_clock_base *new_base)
  1429. {
  1430. struct hrtimer *timer;
  1431. struct timerqueue_node *node;
  1432. while ((node = timerqueue_getnext(&old_base->active))) {
  1433. timer = container_of(node, struct hrtimer, node);
  1434. BUG_ON(hrtimer_callback_running(timer));
  1435. debug_deactivate(timer);
  1436. /*
  1437. * Mark it as STATE_MIGRATE not INACTIVE otherwise the
  1438. * timer could be seen as !active and just vanish away
  1439. * under us on another CPU
  1440. */
  1441. __remove_hrtimer(timer, old_base, HRTIMER_STATE_MIGRATE, 0);
  1442. timer->base = new_base;
  1443. /*
  1444. * Enqueue the timers on the new cpu. This does not
  1445. * reprogram the event device in case the timer
  1446. * expires before the earliest on this CPU, but we run
  1447. * hrtimer_interrupt after we migrated everything to
  1448. * sort out already expired timers and reprogram the
  1449. * event device.
  1450. */
  1451. enqueue_hrtimer(timer, new_base);
  1452. /* Clear the migration state bit */
  1453. timer->state &= ~HRTIMER_STATE_MIGRATE;
  1454. }
  1455. }
  1456. static void migrate_hrtimers(int scpu)
  1457. {
  1458. struct hrtimer_cpu_base *old_base, *new_base;
  1459. int i;
  1460. BUG_ON(cpu_online(scpu));
  1461. tick_cancel_sched_timer(scpu);
  1462. local_irq_disable();
  1463. old_base = &per_cpu(hrtimer_bases, scpu);
  1464. new_base = &__get_cpu_var(hrtimer_bases);
  1465. /*
  1466. * The caller is globally serialized and nobody else
  1467. * takes two locks at once, deadlock is not possible.
  1468. */
  1469. raw_spin_lock(&new_base->lock);
  1470. raw_spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING);
  1471. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  1472. migrate_hrtimer_list(&old_base->clock_base[i],
  1473. &new_base->clock_base[i]);
  1474. }
  1475. raw_spin_unlock(&old_base->lock);
  1476. raw_spin_unlock(&new_base->lock);
  1477. /* Check, if we got expired work to do */
  1478. __hrtimer_peek_ahead_timers();
  1479. local_irq_enable();
  1480. }
  1481. #endif /* CONFIG_HOTPLUG_CPU */
  1482. static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
  1483. unsigned long action, void *hcpu)
  1484. {
  1485. int scpu = (long)hcpu;
  1486. switch (action) {
  1487. case CPU_UP_PREPARE:
  1488. case CPU_UP_PREPARE_FROZEN:
  1489. init_hrtimers_cpu(scpu);
  1490. break;
  1491. #ifdef CONFIG_HOTPLUG_CPU
  1492. case CPU_DYING:
  1493. case CPU_DYING_FROZEN:
  1494. clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DYING, &scpu);
  1495. break;
  1496. case CPU_DEAD:
  1497. case CPU_DEAD_FROZEN:
  1498. {
  1499. clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &scpu);
  1500. migrate_hrtimers(scpu);
  1501. break;
  1502. }
  1503. #endif
  1504. default:
  1505. break;
  1506. }
  1507. return NOTIFY_OK;
  1508. }
  1509. static struct notifier_block __cpuinitdata hrtimers_nb = {
  1510. .notifier_call = hrtimer_cpu_notify,
  1511. };
  1512. void __init hrtimers_init(void)
  1513. {
  1514. hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
  1515. (void *)(long)smp_processor_id());
  1516. register_cpu_notifier(&hrtimers_nb);
  1517. #ifdef CONFIG_HIGH_RES_TIMERS
  1518. open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
  1519. #endif
  1520. }
  1521. /**
  1522. * schedule_hrtimeout_range_clock - sleep until timeout
  1523. * @expires: timeout value (ktime_t)
  1524. * @delta: slack in expires timeout (ktime_t)
  1525. * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
  1526. * @clock: timer clock, CLOCK_MONOTONIC or CLOCK_REALTIME
  1527. */
  1528. int __sched
  1529. schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta,
  1530. const enum hrtimer_mode mode, int clock)
  1531. {
  1532. struct hrtimer_sleeper t;
  1533. /*
  1534. * Optimize when a zero timeout value is given. It does not
  1535. * matter whether this is an absolute or a relative time.
  1536. */
  1537. if (expires && !expires->tv64) {
  1538. __set_current_state(TASK_RUNNING);
  1539. return 0;
  1540. }
  1541. /*
  1542. * A NULL parameter means "infinite"
  1543. */
  1544. if (!expires) {
  1545. schedule();
  1546. __set_current_state(TASK_RUNNING);
  1547. return -EINTR;
  1548. }
  1549. hrtimer_init_on_stack(&t.timer, clock, mode);
  1550. hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
  1551. hrtimer_init_sleeper(&t, current);
  1552. hrtimer_start_expires(&t.timer, mode);
  1553. if (!hrtimer_active(&t.timer))
  1554. t.task = NULL;
  1555. if (likely(t.task))
  1556. schedule();
  1557. hrtimer_cancel(&t.timer);
  1558. destroy_hrtimer_on_stack(&t.timer);
  1559. __set_current_state(TASK_RUNNING);
  1560. return !t.task ? 0 : -EINTR;
  1561. }
  1562. /**
  1563. * schedule_hrtimeout_range - sleep until timeout
  1564. * @expires: timeout value (ktime_t)
  1565. * @delta: slack in expires timeout (ktime_t)
  1566. * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
  1567. *
  1568. * Make the current task sleep until the given expiry time has
  1569. * elapsed. The routine will return immediately unless
  1570. * the current task state has been set (see set_current_state()).
  1571. *
  1572. * The @delta argument gives the kernel the freedom to schedule the
  1573. * actual wakeup to a time that is both power and performance friendly.
  1574. * The kernel give the normal best effort behavior for "@expires+@delta",
  1575. * but may decide to fire the timer earlier, but no earlier than @expires.
  1576. *
  1577. * You can set the task state as follows -
  1578. *
  1579. * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
  1580. * pass before the routine returns.
  1581. *
  1582. * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
  1583. * delivered to the current task.
  1584. *
  1585. * The current task state is guaranteed to be TASK_RUNNING when this
  1586. * routine returns.
  1587. *
  1588. * Returns 0 when the timer has expired otherwise -EINTR
  1589. */
  1590. int __sched schedule_hrtimeout_range(ktime_t *expires, u64 delta,
  1591. const enum hrtimer_mode mode)
  1592. {
  1593. return schedule_hrtimeout_range_clock(expires, delta, mode,
  1594. CLOCK_MONOTONIC);
  1595. }
  1596. EXPORT_SYMBOL_GPL(schedule_hrtimeout_range);
  1597. /**
  1598. * schedule_hrtimeout - sleep until timeout
  1599. * @expires: timeout value (ktime_t)
  1600. * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
  1601. *
  1602. * Make the current task sleep until the given expiry time has
  1603. * elapsed. The routine will return immediately unless
  1604. * the current task state has been set (see set_current_state()).
  1605. *
  1606. * You can set the task state as follows -
  1607. *
  1608. * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
  1609. * pass before the routine returns.
  1610. *
  1611. * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
  1612. * delivered to the current task.
  1613. *
  1614. * The current task state is guaranteed to be TASK_RUNNING when this
  1615. * routine returns.
  1616. *
  1617. * Returns 0 when the timer has expired otherwise -EINTR
  1618. */
  1619. int __sched schedule_hrtimeout(ktime_t *expires,
  1620. const enum hrtimer_mode mode)
  1621. {
  1622. return schedule_hrtimeout_range(expires, 0, mode);
  1623. }
  1624. EXPORT_SYMBOL_GPL(schedule_hrtimeout);