tsc.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* kern/i386/tsc.c - x86 TSC time source implementation
  2. * Requires Pentium or better x86 CPU that supports the RDTSC instruction.
  3. * This module uses the PIT to calibrate the TSC to
  4. * real time.
  5. *
  6. * GRUB -- GRand Unified Bootloader
  7. * Copyright (C) 2008 Free Software Foundation, Inc.
  8. *
  9. * GRUB is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * GRUB is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <grub/types.h>
  23. #include <grub/time.h>
  24. #include <grub/misc.h>
  25. #include <grub/i386/tsc.h>
  26. #include <grub/xen.h>
  27. int
  28. grub_tsc_calibrate_from_xen (void)
  29. {
  30. grub_uint64_t t;
  31. t = grub_xen_shared_info->vcpu_info[0].time.tsc_to_system_mul;
  32. if (grub_xen_shared_info->vcpu_info[0].time.tsc_shift > 0)
  33. t <<= grub_xen_shared_info->vcpu_info[0].time.tsc_shift;
  34. else
  35. t >>= -grub_xen_shared_info->vcpu_info[0].time.tsc_shift;
  36. grub_tsc_rate = grub_divmod64 (t, 1000000, 0);
  37. return 1;
  38. }