[Git][ghc/ghc][master] RTS: workaround a Linux kernel bug in timerfd

Marge Bot gitlab at gitlab.haskell.org
Thu Apr 23 03:17:45 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
8ea37b01 by Sylvain Henry at 2020-04-22T23:17:34-04:00
RTS: workaround a Linux kernel bug in timerfd

Reading a timerfd may return 0: https://lkml.org/lkml/2019/8/16/335.

This is currently undocumented behavior and documentation "won't happen
anytime soon" (https://lkml.org/lkml/2020/2/13/295).

With this patch, we just ignore the result instead of crashing. It may
fix #18033 but we can't be sure because we don't have enough
information.

See also this discussion about the kernel bug:
https://github.com/Azure/sonic-swss-common/pull/302/files/1f070e7920c2e5d63316c0105bf4481e73d72dc9

- - - - -


1 changed file:

- rts/posix/itimer/Pthread.c


Changes:

=====================================
rts/posix/itimer/Pthread.c
=====================================
@@ -122,10 +122,18 @@ static void *itimer_thread_func(void *_handle_tick)
 
     while (!exited) {
         if (USE_TIMERFD_FOR_ITIMER) {
-            if (read(timerfd, &nticks, sizeof(nticks)) != sizeof(nticks)) {
-                if (errno != EINTR) {
-                    barf("Itimer: read(timerfd) failed: %s", strerror(errno));
-                }
+            ssize_t r = read(timerfd, &nticks, sizeof(nticks));
+            if ((r == 0) && (errno == 0)) {
+               /* r == 0 is expected only for non-blocking fd (in which case
+                * errno should be EAGAIN) but we use a blocking fd.
+                *
+                * Due to a kernel bug (cf https://lkml.org/lkml/2019/8/16/335)
+                * on some platforms we could see r == 0 and errno == 0.
+                */
+               IF_DEBUG(scheduler, debugBelch("read(timerfd) returned 0 with errno=0. This is a known kernel bug. We just ignore it."));
+            }
+            else if (r != sizeof(nticks) && errno != EINTR) {
+               barf("Itimer: read(timerfd) failed with %s and returned %zd", strerror(errno), r);
             }
         } else {
             if (rtsSleep(itimer_interval) != 0) {



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8ea37b01b6ab16937f7b528b6bbae9fade9f1361

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8ea37b01b6ab16937f7b528b6bbae9fade9f1361
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200422/0a118896/attachment.html>


More information about the ghc-commits mailing list