time.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  4. * Copyright (c) 2003, 2004 Maciej W. Rozycki
  5. *
  6. * Common time service routines for MIPS machines. See
  7. * Documentation/mips/time.README.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/sched.h>
  18. #include <linux/param.h>
  19. #include <linux/time.h>
  20. #include <linux/timex.h>
  21. #include <linux/smp.h>
  22. #include <linux/kernel_stat.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/module.h>
  26. #include <asm/bootinfo.h>
  27. #include <asm/cache.h>
  28. #include <asm/compiler.h>
  29. #include <asm/cpu.h>
  30. #include <asm/cpu-features.h>
  31. #include <asm/div64.h>
  32. #include <asm/sections.h>
  33. #include <asm/time.h>
  34. /*
  35. * The integer part of the number of usecs per jiffy is taken from tick,
  36. * but the fractional part is not recorded, so we calculate it using the
  37. * initial value of HZ. This aids systems where tick isn't really an
  38. * integer (e.g. for HZ = 128).
  39. */
  40. #define USECS_PER_JIFFY TICK_SIZE
  41. #define USECS_PER_JIFFY_FRAC ((unsigned long)(u32)((1000000ULL << 32) / HZ))
  42. #define TICK_SIZE (tick_nsec / 1000)
  43. /*
  44. * forward reference
  45. */
  46. DEFINE_SPINLOCK(rtc_lock);
  47. /*
  48. * By default we provide the null RTC ops
  49. */
  50. static unsigned long null_rtc_get_time(void)
  51. {
  52. return mktime(2000, 1, 1, 0, 0, 0);
  53. }
  54. static int null_rtc_set_time(unsigned long sec)
  55. {
  56. return 0;
  57. }
  58. unsigned long (*rtc_mips_get_time)(void) = null_rtc_get_time;
  59. int (*rtc_mips_set_time)(unsigned long) = null_rtc_set_time;
  60. int (*rtc_mips_set_mmss)(unsigned long);
  61. /* usecs per counter cycle, shifted to left by 32 bits */
  62. static unsigned int sll32_usecs_per_cycle;
  63. /* how many counter cycles in a jiffy */
  64. static unsigned long cycles_per_jiffy __read_mostly;
  65. /* Cycle counter value at the previous timer interrupt.. */
  66. static unsigned int timerhi, timerlo;
  67. /* expirelo is the count value for next CPU timer interrupt */
  68. static unsigned int expirelo;
  69. /*
  70. * Null timer ack for systems not needing one (e.g. i8254).
  71. */
  72. static void null_timer_ack(void) { /* nothing */ }
  73. /*
  74. * Null high precision timer functions for systems lacking one.
  75. */
  76. static unsigned int null_hpt_read(void)
  77. {
  78. return 0;
  79. }
  80. static void null_hpt_init(unsigned int count)
  81. {
  82. /* nothing */
  83. }
  84. /*
  85. * Timer ack for an R4k-compatible timer of a known frequency.
  86. */
  87. static void c0_timer_ack(void)
  88. {
  89. unsigned int count;
  90. #ifndef CONFIG_SOC_PNX8550 /* pnx8550 resets to zero */
  91. /* Ack this timer interrupt and set the next one. */
  92. expirelo += cycles_per_jiffy;
  93. #endif
  94. write_c0_compare(expirelo);
  95. /* Check to see if we have missed any timer interrupts. */
  96. while (((count = read_c0_count()) - expirelo) < 0x7fffffff) {
  97. /* missed_timer_count++; */
  98. expirelo = count + cycles_per_jiffy;
  99. write_c0_compare(expirelo);
  100. }
  101. }
  102. /*
  103. * High precision timer functions for a R4k-compatible timer.
  104. */
  105. static unsigned int c0_hpt_read(void)
  106. {
  107. return read_c0_count();
  108. }
  109. /* For use solely as a high precision timer. */
  110. static void c0_hpt_init(unsigned int count)
  111. {
  112. write_c0_count(read_c0_count() - count);
  113. }
  114. /* For use both as a high precision timer and an interrupt source. */
  115. static void c0_hpt_timer_init(unsigned int count)
  116. {
  117. count = read_c0_count() - count;
  118. expirelo = (count / cycles_per_jiffy + 1) * cycles_per_jiffy;
  119. write_c0_count(expirelo - cycles_per_jiffy);
  120. write_c0_compare(expirelo);
  121. write_c0_count(count);
  122. }
  123. int (*mips_timer_state)(void);
  124. void (*mips_timer_ack)(void);
  125. unsigned int (*mips_hpt_read)(void);
  126. void (*mips_hpt_init)(unsigned int);
  127. /*
  128. * Gettimeoffset routines. These routines returns the time duration
  129. * since last timer interrupt in usecs.
  130. *
  131. * If the exact CPU counter frequency is known, use fixed_rate_gettimeoffset.
  132. * Otherwise use calibrate_gettimeoffset()
  133. *
  134. * If the CPU does not have the counter register, you can either supply
  135. * your own gettimeoffset() routine, or use null_gettimeoffset(), which
  136. * gives the same resolution as HZ.
  137. */
  138. static unsigned long null_gettimeoffset(void)
  139. {
  140. return 0;
  141. }
  142. /* The function pointer to one of the gettimeoffset funcs. */
  143. unsigned long (*do_gettimeoffset)(void) = null_gettimeoffset;
  144. static unsigned long fixed_rate_gettimeoffset(void)
  145. {
  146. u32 count;
  147. unsigned long res;
  148. /* Get last timer tick in absolute kernel time */
  149. count = mips_hpt_read();
  150. /* .. relative to previous jiffy (32 bits is enough) */
  151. count -= timerlo;
  152. __asm__("multu %1,%2"
  153. : "=h" (res)
  154. : "r" (count), "r" (sll32_usecs_per_cycle)
  155. : "lo", GCC_REG_ACCUM);
  156. /*
  157. * Due to possible jiffies inconsistencies, we need to check
  158. * the result so that we'll get a timer that is monotonic.
  159. */
  160. if (res >= USECS_PER_JIFFY)
  161. res = USECS_PER_JIFFY - 1;
  162. return res;
  163. }
  164. /*
  165. * Cached "1/(clocks per usec) * 2^32" value.
  166. * It has to be recalculated once each jiffy.
  167. */
  168. static unsigned long cached_quotient;
  169. /* Last jiffy when calibrate_divXX_gettimeoffset() was called. */
  170. static unsigned long last_jiffies;
  171. /*
  172. * This is moved from dec/time.c:do_ioasic_gettimeoffset() by Maciej.
  173. */
  174. static unsigned long calibrate_div32_gettimeoffset(void)
  175. {
  176. u32 count;
  177. unsigned long res, tmp;
  178. unsigned long quotient;
  179. tmp = jiffies;
  180. quotient = cached_quotient;
  181. if (last_jiffies != tmp) {
  182. last_jiffies = tmp;
  183. if (last_jiffies != 0) {
  184. unsigned long r0;
  185. do_div64_32(r0, timerhi, timerlo, tmp);
  186. do_div64_32(quotient, USECS_PER_JIFFY,
  187. USECS_PER_JIFFY_FRAC, r0);
  188. cached_quotient = quotient;
  189. }
  190. }
  191. /* Get last timer tick in absolute kernel time */
  192. count = mips_hpt_read();
  193. /* .. relative to previous jiffy (32 bits is enough) */
  194. count -= timerlo;
  195. __asm__("multu %1,%2"
  196. : "=h" (res)
  197. : "r" (count), "r" (quotient)
  198. : "lo", GCC_REG_ACCUM);
  199. /*
  200. * Due to possible jiffies inconsistencies, we need to check
  201. * the result so that we'll get a timer that is monotonic.
  202. */
  203. if (res >= USECS_PER_JIFFY)
  204. res = USECS_PER_JIFFY - 1;
  205. return res;
  206. }
  207. static unsigned long calibrate_div64_gettimeoffset(void)
  208. {
  209. u32 count;
  210. unsigned long res, tmp;
  211. unsigned long quotient;
  212. tmp = jiffies;
  213. quotient = cached_quotient;
  214. if (last_jiffies != tmp) {
  215. last_jiffies = tmp;
  216. if (last_jiffies) {
  217. unsigned long r0;
  218. __asm__(".set push\n\t"
  219. ".set mips3\n\t"
  220. "lwu %0,%3\n\t"
  221. "dsll32 %1,%2,0\n\t"
  222. "or %1,%1,%0\n\t"
  223. "ddivu $0,%1,%4\n\t"
  224. "mflo %1\n\t"
  225. "dsll32 %0,%5,0\n\t"
  226. "or %0,%0,%6\n\t"
  227. "ddivu $0,%0,%1\n\t"
  228. "mflo %0\n\t"
  229. ".set pop"
  230. : "=&r" (quotient), "=&r" (r0)
  231. : "r" (timerhi), "m" (timerlo),
  232. "r" (tmp), "r" (USECS_PER_JIFFY),
  233. "r" (USECS_PER_JIFFY_FRAC)
  234. : "hi", "lo", GCC_REG_ACCUM);
  235. cached_quotient = quotient;
  236. }
  237. }
  238. /* Get last timer tick in absolute kernel time */
  239. count = mips_hpt_read();
  240. /* .. relative to previous jiffy (32 bits is enough) */
  241. count -= timerlo;
  242. __asm__("multu %1,%2"
  243. : "=h" (res)
  244. : "r" (count), "r" (quotient)
  245. : "lo", GCC_REG_ACCUM);
  246. /*
  247. * Due to possible jiffies inconsistencies, we need to check
  248. * the result so that we'll get a timer that is monotonic.
  249. */
  250. if (res >= USECS_PER_JIFFY)
  251. res = USECS_PER_JIFFY - 1;
  252. return res;
  253. }
  254. /* last time when xtime and rtc are sync'ed up */
  255. static long last_rtc_update;
  256. /*
  257. * local_timer_interrupt() does profiling and process accounting
  258. * on a per-CPU basis.
  259. *
  260. * In UP mode, it is invoked from the (global) timer_interrupt.
  261. *
  262. * In SMP mode, it might invoked by per-CPU timer interrupt, or
  263. * a broadcasted inter-processor interrupt which itself is triggered
  264. * by the global timer interrupt.
  265. */
  266. void local_timer_interrupt(int irq, void *dev_id)
  267. {
  268. if (current->pid)
  269. profile_tick(CPU_PROFILING);
  270. update_process_times(user_mode(get_irq_regs()));
  271. }
  272. /*
  273. * High-level timer interrupt service routines. This function
  274. * is set as irqaction->handler and is invoked through do_IRQ.
  275. */
  276. irqreturn_t timer_interrupt(int irq, void *dev_id)
  277. {
  278. unsigned long j;
  279. unsigned int count;
  280. write_seqlock(&xtime_lock);
  281. count = mips_hpt_read();
  282. mips_timer_ack();
  283. /* Update timerhi/timerlo for intra-jiffy calibration. */
  284. timerhi += count < timerlo; /* Wrap around */
  285. timerlo = count;
  286. /*
  287. * call the generic timer interrupt handling
  288. */
  289. do_timer(1);
  290. /*
  291. * If we have an externally synchronized Linux clock, then update
  292. * CMOS clock accordingly every ~11 minutes. rtc_mips_set_time() has to be
  293. * called as close as possible to 500 ms before the new second starts.
  294. */
  295. if (ntp_synced() &&
  296. xtime.tv_sec > last_rtc_update + 660 &&
  297. (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
  298. (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
  299. if (rtc_mips_set_mmss(xtime.tv_sec) == 0) {
  300. last_rtc_update = xtime.tv_sec;
  301. } else {
  302. /* do it again in 60 s */
  303. last_rtc_update = xtime.tv_sec - 600;
  304. }
  305. }
  306. /*
  307. * If jiffies has overflown in this timer_interrupt, we must
  308. * update the timer[hi]/[lo] to make fast gettimeoffset funcs
  309. * quotient calc still valid. -arca
  310. *
  311. * The first timer interrupt comes late as interrupts are
  312. * enabled long after timers are initialized. Therefore the
  313. * high precision timer is fast, leading to wrong gettimeoffset()
  314. * calculations. We deal with it by setting it based on the
  315. * number of its ticks between the second and the third interrupt.
  316. * That is still somewhat imprecise, but it's a good estimate.
  317. * --macro
  318. */
  319. j = jiffies;
  320. if (j < 4) {
  321. static unsigned int prev_count;
  322. static int hpt_initialized;
  323. switch (j) {
  324. case 0:
  325. timerhi = timerlo = 0;
  326. mips_hpt_init(count);
  327. break;
  328. case 2:
  329. prev_count = count;
  330. break;
  331. case 3:
  332. if (!hpt_initialized) {
  333. unsigned int c3 = 3 * (count - prev_count);
  334. timerhi = 0;
  335. timerlo = c3;
  336. mips_hpt_init(count - c3);
  337. hpt_initialized = 1;
  338. }
  339. break;
  340. default:
  341. break;
  342. }
  343. }
  344. write_sequnlock(&xtime_lock);
  345. /*
  346. * In UP mode, we call local_timer_interrupt() to do profiling
  347. * and process accouting.
  348. *
  349. * In SMP mode, local_timer_interrupt() is invoked by appropriate
  350. * low-level local timer interrupt handler.
  351. */
  352. local_timer_interrupt(irq, dev_id);
  353. return IRQ_HANDLED;
  354. }
  355. int null_perf_irq(void)
  356. {
  357. return 0;
  358. }
  359. int (*perf_irq)(void) = null_perf_irq;
  360. EXPORT_SYMBOL(null_perf_irq);
  361. EXPORT_SYMBOL(perf_irq);
  362. asmlinkage void ll_timer_interrupt(int irq, struct pt_regs *regs)
  363. {
  364. struct pt_regs *old_regs = set_irq_regs(regs);
  365. int r2 = cpu_has_mips_r2;
  366. irq_enter();
  367. kstat_this_cpu.irqs[irq]++;
  368. /*
  369. * Suckage alert:
  370. * Before R2 of the architecture there was no way to see if a
  371. * performance counter interrupt was pending, so we have to run the
  372. * performance counter interrupt handler anyway.
  373. */
  374. if (!r2 || (read_c0_cause() & (1 << 26)))
  375. if (perf_irq())
  376. goto out;
  377. /* we keep interrupt disabled all the time */
  378. if (!r2 || (read_c0_cause() & (1 << 30)))
  379. timer_interrupt(irq, NULL);
  380. out:
  381. irq_exit();
  382. set_irq_regs(old_regs);
  383. }
  384. asmlinkage void ll_local_timer_interrupt(int irq, struct pt_regs *regs)
  385. {
  386. struct pt_regs *old_regs = set_irq_regs(regs);
  387. irq_enter();
  388. if (smp_processor_id() != 0)
  389. kstat_this_cpu.irqs[irq]++;
  390. /* we keep interrupt disabled all the time */
  391. local_timer_interrupt(irq, NULL);
  392. irq_exit();
  393. set_irq_regs(old_regs);
  394. }
  395. /*
  396. * time_init() - it does the following things.
  397. *
  398. * 1) board_time_init() -
  399. * a) (optional) set up RTC routines,
  400. * b) (optional) calibrate and set the mips_hpt_frequency
  401. * (only needed if you intended to use fixed_rate_gettimeoffset
  402. * or use cpu counter as timer interrupt source)
  403. * 2) setup xtime based on rtc_mips_get_time().
  404. * 3) choose a appropriate gettimeoffset routine.
  405. * 4) calculate a couple of cached variables for later usage
  406. * 5) plat_timer_setup() -
  407. * a) (optional) over-write any choices made above by time_init().
  408. * b) machine specific code should setup the timer irqaction.
  409. * c) enable the timer interrupt
  410. */
  411. void (*board_time_init)(void);
  412. unsigned int mips_hpt_frequency;
  413. static struct irqaction timer_irqaction = {
  414. .handler = timer_interrupt,
  415. .flags = IRQF_DISABLED,
  416. .name = "timer",
  417. };
  418. static unsigned int __init calibrate_hpt(void)
  419. {
  420. u64 frequency;
  421. u32 hpt_start, hpt_end, hpt_count, hz;
  422. const int loops = HZ / 10;
  423. int log_2_loops = 0;
  424. int i;
  425. /*
  426. * We want to calibrate for 0.1s, but to avoid a 64-bit
  427. * division we round the number of loops up to the nearest
  428. * power of 2.
  429. */
  430. while (loops > 1 << log_2_loops)
  431. log_2_loops++;
  432. i = 1 << log_2_loops;
  433. /*
  434. * Wait for a rising edge of the timer interrupt.
  435. */
  436. while (mips_timer_state());
  437. while (!mips_timer_state());
  438. /*
  439. * Now see how many high precision timer ticks happen
  440. * during the calculated number of periods between timer
  441. * interrupts.
  442. */
  443. hpt_start = mips_hpt_read();
  444. do {
  445. while (mips_timer_state());
  446. while (!mips_timer_state());
  447. } while (--i);
  448. hpt_end = mips_hpt_read();
  449. hpt_count = hpt_end - hpt_start;
  450. hz = HZ;
  451. frequency = (u64)hpt_count * (u64)hz;
  452. return frequency >> log_2_loops;
  453. }
  454. void __init time_init(void)
  455. {
  456. if (board_time_init)
  457. board_time_init();
  458. if (!rtc_mips_set_mmss)
  459. rtc_mips_set_mmss = rtc_mips_set_time;
  460. xtime.tv_sec = rtc_mips_get_time();
  461. xtime.tv_nsec = 0;
  462. set_normalized_timespec(&wall_to_monotonic,
  463. -xtime.tv_sec, -xtime.tv_nsec);
  464. /* Choose appropriate high precision timer routines. */
  465. if (!cpu_has_counter && !mips_hpt_read) {
  466. /* No high precision timer -- sorry. */
  467. mips_hpt_read = null_hpt_read;
  468. mips_hpt_init = null_hpt_init;
  469. } else if (!mips_hpt_frequency && !mips_timer_state) {
  470. /* A high precision timer of unknown frequency. */
  471. if (!mips_hpt_read) {
  472. /* No external high precision timer -- use R4k. */
  473. mips_hpt_read = c0_hpt_read;
  474. mips_hpt_init = c0_hpt_init;
  475. }
  476. if (cpu_has_mips32r1 || cpu_has_mips32r2 ||
  477. (current_cpu_data.isa_level == MIPS_CPU_ISA_I) ||
  478. (current_cpu_data.isa_level == MIPS_CPU_ISA_II))
  479. /*
  480. * We need to calibrate the counter but we don't have
  481. * 64-bit division.
  482. */
  483. do_gettimeoffset = calibrate_div32_gettimeoffset;
  484. else
  485. /*
  486. * We need to calibrate the counter but we *do* have
  487. * 64-bit division.
  488. */
  489. do_gettimeoffset = calibrate_div64_gettimeoffset;
  490. } else {
  491. /* We know counter frequency. Or we can get it. */
  492. if (!mips_hpt_read) {
  493. /* No external high precision timer -- use R4k. */
  494. mips_hpt_read = c0_hpt_read;
  495. if (mips_timer_state)
  496. mips_hpt_init = c0_hpt_init;
  497. else {
  498. /* No external timer interrupt -- use R4k. */
  499. mips_hpt_init = c0_hpt_timer_init;
  500. mips_timer_ack = c0_timer_ack;
  501. }
  502. }
  503. if (!mips_hpt_frequency)
  504. mips_hpt_frequency = calibrate_hpt();
  505. do_gettimeoffset = fixed_rate_gettimeoffset;
  506. /* Calculate cache parameters. */
  507. cycles_per_jiffy = (mips_hpt_frequency + HZ / 2) / HZ;
  508. /* sll32_usecs_per_cycle = 10^6 * 2^32 / mips_counter_freq */
  509. do_div64_32(sll32_usecs_per_cycle,
  510. 1000000, mips_hpt_frequency / 2,
  511. mips_hpt_frequency);
  512. /* Report the high precision timer rate for a reference. */
  513. printk("Using %u.%03u MHz high precision timer.\n",
  514. ((mips_hpt_frequency + 500) / 1000) / 1000,
  515. ((mips_hpt_frequency + 500) / 1000) % 1000);
  516. }
  517. if (!mips_timer_ack)
  518. /* No timer interrupt ack (e.g. i8254). */
  519. mips_timer_ack = null_timer_ack;
  520. /* This sets up the high precision timer for the first interrupt. */
  521. mips_hpt_init(mips_hpt_read());
  522. /*
  523. * Call board specific timer interrupt setup.
  524. *
  525. * this pointer must be setup in machine setup routine.
  526. *
  527. * Even if a machine chooses to use a low-level timer interrupt,
  528. * it still needs to setup the timer_irqaction.
  529. * In that case, it might be better to set timer_irqaction.handler
  530. * to be NULL function so that we are sure the high-level code
  531. * is not invoked accidentally.
  532. */
  533. plat_timer_setup(&timer_irqaction);
  534. }
  535. #define FEBRUARY 2
  536. #define STARTOFTIME 1970
  537. #define SECDAY 86400L
  538. #define SECYR (SECDAY * 365)
  539. #define leapyear(y) ((!((y) % 4) && ((y) % 100)) || !((y) % 400))
  540. #define days_in_year(y) (leapyear(y) ? 366 : 365)
  541. #define days_in_month(m) (month_days[(m) - 1])
  542. static int month_days[12] = {
  543. 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  544. };
  545. void to_tm(unsigned long tim, struct rtc_time *tm)
  546. {
  547. long hms, day, gday;
  548. int i;
  549. gday = day = tim / SECDAY;
  550. hms = tim % SECDAY;
  551. /* Hours, minutes, seconds are easy */
  552. tm->tm_hour = hms / 3600;
  553. tm->tm_min = (hms % 3600) / 60;
  554. tm->tm_sec = (hms % 3600) % 60;
  555. /* Number of years in days */
  556. for (i = STARTOFTIME; day >= days_in_year(i); i++)
  557. day -= days_in_year(i);
  558. tm->tm_year = i;
  559. /* Number of months in days left */
  560. if (leapyear(tm->tm_year))
  561. days_in_month(FEBRUARY) = 29;
  562. for (i = 1; day >= days_in_month(i); i++)
  563. day -= days_in_month(i);
  564. days_in_month(FEBRUARY) = 28;
  565. tm->tm_mon = i - 1; /* tm_mon starts from 0 to 11 */
  566. /* Days are what is left over (+1) from all that. */
  567. tm->tm_mday = day + 1;
  568. /*
  569. * Determine the day of week
  570. */
  571. tm->tm_wday = (gday + 4) % 7; /* 1970/1/1 was Thursday */
  572. }
  573. EXPORT_SYMBOL(rtc_lock);
  574. EXPORT_SYMBOL(to_tm);
  575. EXPORT_SYMBOL(rtc_mips_set_time);
  576. EXPORT_SYMBOL(rtc_mips_get_time);
  577. unsigned long long sched_clock(void)
  578. {
  579. return (unsigned long long)jiffies*(1000000000/HZ);
  580. }