Subject: Re: bug#51734: 29.0.50; got slow

From: Ken Brown <[email-masked]>
Date: Sun, 14 Nov 2021 10:42:14 -0500

On 11/13/2021 8:13 PM, Lars Ingebrigtsen wrote:
> Would disabling timerfd (instead of disabling the POSIX timer) also fix
> the issue?

Yes.

> If so, I'd rather do that, because the timerfd timers aren't
> delivered while Emacs is busy, which makes things like the hourglass
> pointer not be displayed reliably.

How's the attached patch?

Ken

From 1aee29152833e7a121b629021f975423570ad2d2 Mon Sep 17 00:00:00 2001
From: Ken Brown <[email-masked]>
Date: Sun, 14 Nov 2021 10:30:44 -0500
Subject: [PATCH] Prefer POSIX timers to timerfd timers

* src/atimer.c (set_alarm): Try to start a POSIX timer before
starting a timerfd timer.  On Cygwin, return if the POSIX timer is
started successfully. (Bug#51734)
---
 src/atimer.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/atimer.c b/src/atimer.c
index 9bde9c2446..df35603f32 100644
--- a/src/atimer.c
+++ b/src/atimer.c
@@ -309,24 +309,29 @@ set_alarm (void)
 	  struct itimerspec ispec;
 	  ispec.it_value = atimers->expiration;
 	  ispec.it_interval.tv_sec = ispec.it_interval.tv_nsec = 0;
+	  if (alarm_timer_ok
+	      && timer_settime (alarm_timer, TIMER_ABSTIME, &ispec, 0) == 0)
+	    exit = true;
+
+	  /* Don't start both timerfd and POSIX timers on Cygwin; this
+	     causes a slowdown (bug#51734).  Prefer POSIX timers
+	     because the timerfd notifications aren't delivered while
+	     Emacs is busy, which prevents things like the hourglass
+	     pointer from being displayed reliably (bug#19776). */
+# ifdef CYGWIN
+	  if (exit)
+	    return;
+# endif
+
 # ifdef HAVE_TIMERFD
-	  if (timerfd_settime (timerfd, TFD_TIMER_ABSTIME, &ispec, 0) == 0)
+	  if (0 <= timerfd
+	      && timerfd_settime (timerfd, TFD_TIMER_ABSTIME, &ispec, 0) == 0)
 	    {
 	      add_timer_wait_descriptor (timerfd);
 	      exit = true;
 	    }
 # endif
 
-# ifdef CYGWIN
-	  /* Don't start both timerfd and alarms on Cygwin; this
-	     causes a slowdown (bug#51734). */
-	  if (exit)
-	    return;
-# endif
-	  if (alarm_timer_ok
-	      && timer_settime (alarm_timer, TIMER_ABSTIME, &ispec, 0) == 0)
-	    exit = true;
-
 	  if (exit)
 	    return;
 	}
-- 
2.33.0