0006-posix-remove-ancient-run-time-fallback-to-real-time-.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. From 5d561e1e2dcde3c9fca4d925f12447009d0d4a4c Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <remi@remlab.net>
  3. Date: Wed, 18 Apr 2018 17:23:57 +0300
  4. Subject: [PATCH] posix: remove ancient run-time fallback to real-time clock
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. posix: remove ancient run-time fallback to real-time clock
  9. For hysterical raisins, GNU/Linux and possibly some other OSes still
  10. report that monotonic clock must be checked at run-time, although I
  11. doubt that VLC or even current glibc would run on such old kernel.
  12. Drop that to simplify and avoid the systematic one-time init check.
  13. Downloaded from upstream commit to fix build error on m68k:
  14. posix/thread.c:79:5: warning: #warning Monotonic clock not available. Expect timing issues. [-Wcpp]
  15. # warning Monotonic clock not available. Expect timing issues.
  16. ^~~~~~~
  17. posix/thread.c: In function ‘vlc_clock_setup_once’:
  18. posix/thread.c:88:18: error: lvalue required as left operand of assignment
  19. vlc_clock_id = (val < 0) ? CLOCK_REALTIME : CLOCK_MONOTONIC;
  20. [Bernd: rebased for 3.0.19]
  21. Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
  22. ---
  23. src/posix/thread.c | 96 +++++++-----------------------------------------------
  24. 1 file changed, 11 insertions(+), 85 deletions(-)
  25. diff --git a/src/posix/thread.c b/src/posix/thread.c
  26. index dab8b71f97..8878941913 100644
  27. --- a/src/posix/thread.c
  28. +++ b/src/posix/thread.c
  29. @@ -51,62 +51,16 @@
  30. # include <sys/pset.h>
  31. #endif
  32. -#if !defined (_POSIX_TIMERS)
  33. -# define _POSIX_TIMERS (-1)
  34. -#endif
  35. -#if !defined (_POSIX_CLOCK_SELECTION)
  36. -/* Clock selection was defined in 2001 and became mandatory in 2008. */
  37. -# define _POSIX_CLOCK_SELECTION (-1)
  38. -#endif
  39. -#if !defined (_POSIX_MONOTONIC_CLOCK)
  40. -# define _POSIX_MONOTONIC_CLOCK (-1)
  41. -#endif
  42. -
  43. -#if (_POSIX_TIMERS > 0)
  44. static unsigned vlc_clock_prec;
  45. -# if (_POSIX_MONOTONIC_CLOCK > 0) && (_POSIX_CLOCK_SELECTION > 0)
  46. -/* Compile-time POSIX monotonic clock support */
  47. -# define vlc_clock_id (CLOCK_MONOTONIC)
  48. -
  49. -# elif (_POSIX_MONOTONIC_CLOCK == 0) && (_POSIX_CLOCK_SELECTION > 0)
  50. -/* Run-time POSIX monotonic clock support (see clock_setup() below) */
  51. -static clockid_t vlc_clock_id;
  52. -
  53. -# else
  54. -/* No POSIX monotonic clock support */
  55. -# define vlc_clock_id (CLOCK_REALTIME)
  56. -# warning Monotonic clock not available. Expect timing issues.
  57. -
  58. -# endif /* _POSIX_MONOTONIC_CLOKC */
  59. -
  60. static void vlc_clock_setup_once (void)
  61. {
  62. -# if (_POSIX_MONOTONIC_CLOCK == 0)
  63. - long val = sysconf (_SC_MONOTONIC_CLOCK);
  64. - assert (val != 0);
  65. - vlc_clock_id = (val < 0) ? CLOCK_REALTIME : CLOCK_MONOTONIC;
  66. -# endif
  67. -
  68. struct timespec res;
  69. - if (unlikely(clock_getres (vlc_clock_id, &res) != 0 || res.tv_sec != 0))
  70. + if (unlikely(clock_getres(CLOCK_MONOTONIC, &res) != 0 || res.tv_sec != 0))
  71. abort ();
  72. vlc_clock_prec = (res.tv_nsec + 500) / 1000;
  73. }
  74. -static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
  75. -
  76. -# define vlc_clock_setup() \
  77. - pthread_once(&vlc_clock_once, vlc_clock_setup_once)
  78. -
  79. -#else /* _POSIX_TIMERS */
  80. -
  81. -# include <sys/time.h> /* gettimeofday() */
  82. -
  83. -# define vlc_clock_setup() (void)0
  84. -# warning Monotonic clock not available. Expect timing issues.
  85. -#endif /* _POSIX_TIMERS */
  86. -
  87. static struct timespec mtime_to_ts (vlc_tick_t date)
  88. {
  89. lldiv_t d = lldiv (date, CLOCK_FREQ);
  90. @@ -233,14 +187,11 @@ void vlc_cond_init (vlc_cond_t *p_condvar)
  91. {
  92. pthread_condattr_t attr;
  93. - if (unlikely(pthread_condattr_init (&attr)))
  94. - abort ();
  95. -#if (_POSIX_CLOCK_SELECTION > 0)
  96. - vlc_clock_setup ();
  97. - pthread_condattr_setclock (&attr, vlc_clock_id);
  98. -#endif
  99. - if (unlikely(pthread_cond_init (p_condvar, &attr)))
  100. + if (unlikely(pthread_condattr_init (&attr))
  101. + || unlikely(pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
  102. + || unlikely(pthread_cond_init (p_condvar, &attr)))
  103. abort ();
  104. +
  105. pthread_condattr_destroy (&attr);
  106. }
  107. @@ -625,44 +576,27 @@ void vlc_control_cancel (int cmd, ...)
  108. vlc_tick_t mdate (void)
  109. {
  110. -#if (_POSIX_TIMERS > 0)
  111. struct timespec ts;
  112. - vlc_clock_setup ();
  113. - if (unlikely(clock_gettime (vlc_clock_id, &ts) != 0))
  114. + if (unlikely(clock_gettime(CLOCK_MONOTONIC, &ts) != 0))
  115. abort ();
  116. return (INT64_C(1000000) * ts.tv_sec) + (ts.tv_nsec / 1000);
  117. -
  118. -#else
  119. - struct timeval tv;
  120. -
  121. - if (unlikely(gettimeofday (&tv, NULL) != 0))
  122. - abort ();
  123. - return (INT64_C(1000000) * tv.tv_sec) + tv.tv_usec;
  124. -
  125. -#endif
  126. }
  127. #undef mwait
  128. void mwait (vlc_tick_t deadline)
  129. {
  130. -#if (_POSIX_CLOCK_SELECTION > 0)
  131. - vlc_clock_setup ();
  132. + static pthread_once_t vlc_clock_once = PTHREAD_ONCE_INIT;
  133. +
  134. /* If the deadline is already elapsed, or within the clock precision,
  135. * do not even bother the system timer. */
  136. + pthread_once(&vlc_clock_once, vlc_clock_setup_once);
  137. deadline -= vlc_clock_prec;
  138. struct timespec ts = mtime_to_ts (deadline);
  139. - while (clock_nanosleep (vlc_clock_id, TIMER_ABSTIME, &ts, NULL) == EINTR);
  140. -
  141. -#else
  142. - deadline -= mdate ();
  143. - if (deadline > 0)
  144. - msleep (deadline);
  145. -
  146. -#endif
  147. + while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL) == EINTR);
  148. }
  149. #undef msleep
  150. @@ -670,15 +604,7 @@ void msleep (vlc_tick_t delay)
  151. {
  152. struct timespec ts = mtime_to_ts (delay);
  153. -#if (_POSIX_CLOCK_SELECTION > 0)
  154. - vlc_clock_setup ();
  155. - while (clock_nanosleep (vlc_clock_id, 0, &ts, &ts) == EINTR);
  156. -
  157. -#else
  158. - while (nanosleep (&ts, &ts) == -1)
  159. - assert (errno == EINTR);
  160. -
  161. -#endif
  162. + while (clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &ts) == EINTR);
  163. }
  164. unsigned vlc_GetCPUCount(void)
  165. --
  166. 2.14.4