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/efi/efi.h>
  27. #include <grub/efi/api.h>
  28. int
  29. grub_tsc_calibrate_from_efi (void)
  30. {
  31. grub_uint64_t start_tsc, end_tsc;
  32. /* Use EFI Time Service to calibrate TSC */
  33. start_tsc = grub_get_tsc ();
  34. grub_efi_system_table->boot_services->stall (1000);
  35. end_tsc = grub_get_tsc ();
  36. grub_tsc_rate = grub_divmod64 ((1ULL << 32), end_tsc - start_tsc, 0);
  37. return 1;
  38. }