Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

linux_timer.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. FILE_LICENCE(GPL2_OR_LATER);
  19. #include <stddef.h>
  20. #include <ipxe/timer.h>
  21. #include <linux_api.h>
  22. /** @file
  23. *
  24. * iPXE timer API for linux
  25. *
  26. */
  27. /**
  28. * Delay for a fixed number of microseconds
  29. *
  30. * @v usecs Number of microseconds for which to delay
  31. */
  32. static void linux_udelay(unsigned long usecs)
  33. {
  34. linux_usleep(usecs);
  35. }
  36. /**
  37. * Get current system time in ticks
  38. *
  39. * linux doesn't provide an easy access to jiffies so implement it by measuring
  40. * the time since the first call to this function.
  41. *
  42. * Since this function is used to seed the (non-cryptographic) random
  43. * number generator, we round the start time down to the nearest whole
  44. * second. This minimises the chances of generating identical RNG
  45. * sequences (and hence identical TCP port numbers, etc) on
  46. * consecutive invocations of iPXE.
  47. *
  48. * @ret ticks Current time, in ticks
  49. */
  50. static unsigned long linux_currticks(void)
  51. {
  52. static struct timeval start;
  53. static int initialized = 0;
  54. struct timeval now;
  55. unsigned long ticks;
  56. if (! initialized) {
  57. linux_gettimeofday(&start, NULL);
  58. initialized = 1;
  59. }
  60. linux_gettimeofday(&now, NULL);
  61. ticks = ( ( now.tv_sec - start.tv_sec ) * TICKS_PER_SEC );
  62. ticks += ( now.tv_usec / ( 1000000 / TICKS_PER_SEC ) );
  63. return ticks;
  64. }
  65. /** Linux timer */
  66. struct timer linux_timer __timer ( TIMER_NORMAL ) = {
  67. .name = "linux",
  68. .currticks = linux_currticks,
  69. .udelay = linux_udelay,
  70. };