vsyscall_gtod.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
  3. * Copyright 2003 Andi Kleen, SuSE Labs.
  4. *
  5. * Modified for x86 32 bit architecture by
  6. * Stefani Seibold <stefani@seibold.net>
  7. * sponsored by Rohde & Schwarz GmbH & Co. KG Munich/Germany
  8. *
  9. * Thanks to hpa@transmeta.com for some useful hint.
  10. * Special thanks to Ingo Molnar for his early experience with
  11. * a different vsyscall implementation for Linux/IA32 and for the name.
  12. *
  13. */
  14. #include <linux/timekeeper_internal.h>
  15. #include <asm/vgtod.h>
  16. #include <asm/vvar.h>
  17. DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
  18. void update_vsyscall_tz(void)
  19. {
  20. vsyscall_gtod_data.tz_minuteswest = sys_tz.tz_minuteswest;
  21. vsyscall_gtod_data.tz_dsttime = sys_tz.tz_dsttime;
  22. }
  23. void update_vsyscall(struct timekeeper *tk)
  24. {
  25. struct vsyscall_gtod_data *vdata = &vsyscall_gtod_data;
  26. gtod_write_begin(vdata);
  27. /* copy vsyscall data */
  28. vdata->vclock_mode = tk->tkr_mono.clock->archdata.vclock_mode;
  29. vdata->cycle_last = tk->tkr_mono.cycle_last;
  30. vdata->mask = tk->tkr_mono.mask;
  31. vdata->mult = tk->tkr_mono.mult;
  32. vdata->shift = tk->tkr_mono.shift;
  33. vdata->wall_time_sec = tk->xtime_sec;
  34. vdata->wall_time_snsec = tk->tkr_mono.xtime_nsec;
  35. vdata->monotonic_time_sec = tk->xtime_sec
  36. + tk->wall_to_monotonic.tv_sec;
  37. vdata->monotonic_time_snsec = tk->tkr_mono.xtime_nsec
  38. + ((u64)tk->wall_to_monotonic.tv_nsec
  39. << tk->tkr_mono.shift);
  40. while (vdata->monotonic_time_snsec >=
  41. (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
  42. vdata->monotonic_time_snsec -=
  43. ((u64)NSEC_PER_SEC) << tk->tkr_mono.shift;
  44. vdata->monotonic_time_sec++;
  45. }
  46. vdata->wall_time_coarse_sec = tk->xtime_sec;
  47. vdata->wall_time_coarse_nsec = (long)(tk->tkr_mono.xtime_nsec >>
  48. tk->tkr_mono.shift);
  49. vdata->monotonic_time_coarse_sec =
  50. vdata->wall_time_coarse_sec + tk->wall_to_monotonic.tv_sec;
  51. vdata->monotonic_time_coarse_nsec =
  52. vdata->wall_time_coarse_nsec + tk->wall_to_monotonic.tv_nsec;
  53. while (vdata->monotonic_time_coarse_nsec >= NSEC_PER_SEC) {
  54. vdata->monotonic_time_coarse_nsec -= NSEC_PER_SEC;
  55. vdata->monotonic_time_coarse_sec++;
  56. }
  57. gtod_write_end(vdata);
  58. }