GNU bug report logs - #10404
[PATCH] Power: sleep longer than two seconds at a time

Previous Next

Package: emacs;

Reported by: Daniel Colascione <dancol <at> dancol.org>

Date: Thu, 29 Dec 2011 23:44:02 UTC

Severity: normal

Tags: help, patch

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10404 in the body.
You can then email your comments to 10404 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Thu, 29 Dec 2011 23:44:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Colascione <dancol <at> dancol.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 29 Dec 2011 23:44:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Colascione <dancol <at> dancol.org>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Power: sleep longer than two seconds at a time
Date: Thu, 29 Dec 2011 15:40:09 -0800
Emacs uses an atimer to poll for input every so often so it can detect
C-g presses while lisp code is running; atimer arranges for this polling
to be done by having a SIGALRM delivered every so often --- by default,
every two seconds.  But while lisp code is not running and emacs is
blocked in select() [or a platform-specific analogue], we want to
stop this polling to save power: we don't need it because the select
will return as soon as there's input.

Emacs has code that's meant to turn off atimers while we wait for
input --- wait_reading_process_output calls stop_polling and
turn_on_atimers (0).  But time ago, we started calling redisplay
code inside the select loop, and this select code turns atimers
back on.  The effect is that we don't sleep longer than two second
at a time.

This patch turns off SIGALRM delivery around select, making sure that
we stay asleep.  With this patch (and blink-cursor-mode off), Emacs
will process input, then sleep for 30 seconds, and if no input
arrives in that time, will sleep for several hours.  The patch
does not adversely any functionality.
---
 src/process.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/process.c b/src/process.c
index 5c8eef7..f81a5c4 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4304,6 +4304,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
   int got_some_input = 0;
   int count = SPECPDL_INDEX ();
 
+#ifdef SIGALRM
+  SIGMASKTYPE mask;
+#endif /* SIGALRM */
+
   FD_ZERO (&Available);
   FD_ZERO (&Writeok);
 
@@ -4606,6 +4610,14 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
 	    }
 #endif
 
+#ifdef SIGALRM
+          /* We don't want SIGALRM going off while we're blocked in
+             select.  If there any any pending timers, timeout has
+             been set appropriately already and we'll wake up
+             automatically.  */
+          mask = sigblock (sigmask (SIGALRM));
+#endif /* SIGALRM */
+
 #if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
           nfds = xg_select
 #elif defined (HAVE_NS)
@@ -4618,6 +4630,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
              (check_write ? &Writeok : (SELECT_TYPE *)0),
              (SELECT_TYPE *)0, &timeout);
 
+#ifdef SIGALRM
+          sigsetmask (mask);
+#endif /* SIGALRM */
+
 #ifdef HAVE_GNUTLS
           /* GnuTLS buffers data internally.  In lowat mode it leaves
              some data in the TCP buffers so that select works, but
-- 
1.7.5.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Wed, 12 Jun 2013 17:27:02 GMT) Full text and rfc822 format available.

Message #8 received at 10404 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: 10404 <at> debbugs.gnu.org
Cc: Daniel Colascione <dancol <at> dancol.org>
Subject: Re: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Wed, 12 Jun 2013 13:25:57 -0400
This sounds like a good idea.
Does anyone have any comments?

Daniel Colascione wrote:

> Emacs uses an atimer to poll for input every so often so it can detect
> C-g presses while lisp code is running; atimer arranges for this polling
> to be done by having a SIGALRM delivered every so often --- by default,
> every two seconds.  But while lisp code is not running and emacs is
> blocked in select() [or a platform-specific analogue], we want to
> stop this polling to save power: we don't need it because the select
> will return as soon as there's input.
>
> Emacs has code that's meant to turn off atimers while we wait for
> input --- wait_reading_process_output calls stop_polling and
> turn_on_atimers (0).  But time ago, we started calling redisplay
> code inside the select loop, and this select code turns atimers
> back on.  The effect is that we don't sleep longer than two second
> at a time.
>
> This patch turns off SIGALRM delivery around select, making sure that
> we stay asleep.  With this patch (and blink-cursor-mode off), Emacs
> will process input, then sleep for 30 seconds, and if no input
> arrives in that time, will sleep for several hours.  The patch
> does not adversely any functionality.
> ---
>  src/process.c |   16 ++++++++++++++++
>  1 files changed, 16 insertions(+), 0 deletions(-)
>
> diff --git a/src/process.c b/src/process.c
> index 5c8eef7..f81a5c4 100644
> --- a/src/process.c
> +++ b/src/process.c
> @@ -4304,6 +4304,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
>    int got_some_input = 0;
>    int count = SPECPDL_INDEX ();
>  
> +#ifdef SIGALRM
> +  SIGMASKTYPE mask;
> +#endif /* SIGALRM */
> +
>    FD_ZERO (&Available);
>    FD_ZERO (&Writeok);
>  
> @@ -4606,6 +4610,14 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
>  	    }
>  #endif
>  
> +#ifdef SIGALRM
> +          /* We don't want SIGALRM going off while we're blocked in
> +             select.  If there any any pending timers, timeout has
> +             been set appropriately already and we'll wake up
> +             automatically.  */
> +          mask = sigblock (sigmask (SIGALRM));
> +#endif /* SIGALRM */
> +
>  #if defined (USE_GTK) || defined (HAVE_GCONF) || defined (HAVE_GSETTINGS)
>            nfds = xg_select
>  #elif defined (HAVE_NS)
> @@ -4618,6 +4630,10 @@ wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
>               (check_write ? &Writeok : (SELECT_TYPE *)0),
>               (SELECT_TYPE *)0, &timeout);
>  
> +#ifdef SIGALRM
> +          sigsetmask (mask);
> +#endif /* SIGALRM */
> +
>  #ifdef HAVE_GNUTLS
>            /* GnuTLS buffers data internally.  In lowat mode it leaves
>               some data in the TCP buffers so that select works, but




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Wed, 12 Jun 2013 18:15:02 GMT) Full text and rfc822 format available.

Message #11 received at 10404 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 10404 <at> debbugs.gnu.org
Subject: Re: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Wed, 12 Jun 2013 21:14:12 +0300
> From: Glenn Morris <rgm <at> gnu.org>
> Date: Wed, 12 Jun 2013 13:25:57 -0400
> 
> 
> This sounds like a good idea.
> Does anyone have any comments?

We don't use sigblock or sigsetmask, I believe because they are
obsolescent.  We use sigprocmask instead.

The other comment is that these changes ignore the MS-Windows
implementation of SIGALRM.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Sat, 20 Jul 2013 19:47:02 GMT) Full text and rfc822 format available.

Message #14 received at 10404 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: dancol <at> dancol.org
Cc: 10404 <at> debbugs.gnu.org
Subject: Re: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Sat, 20 Jul 2013 15:46:52 -0400
Comments from Jan in
http://lists.gnu.org/archive/html/emacs-devel/2013-07/msg00540.html

    I don't know, I haven't seen this 2 second polling that is mentioned
    (with strace/dtruss). When the cursor stops blinking, there is a 30
    second timeout, and after that a very long timeout (thousands of
    seconds, I don't have the exact value). But on the other hand, I was
    not running Lisp at the time.

I don't know where that leaves this patch.
(See also comments in http://debbugs.gnu.org/10404#11 )




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Thu, 25 Feb 2016 06:22:01 GMT) Full text and rfc822 format available.

Message #17 received at 10404 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: dancol <at> dancol.org, 10404 <at> debbugs.gnu.org
Subject: Re: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Thu, 25 Feb 2016 16:50:36 +1030
Glenn Morris <rgm <at> gnu.org> writes:

> Comments from Jan in
> http://lists.gnu.org/archive/html/emacs-devel/2013-07/msg00540.html
>
>     I don't know, I haven't seen this 2 second polling that is mentioned
>     (with strace/dtruss). When the cursor stops blinking, there is a 30
>     second timeout, and after that a very long timeout (thousands of
>     seconds, I don't have the exact value). But on the other hand, I was
>     not running Lisp at the time.
>
> I don't know where that leaves this patch.
> (See also comments in http://debbugs.gnu.org/10404#11 )

If I start "emacs -Q" and strace it, I see basically the following every
couple of seconds.

[pid  8439] --- SIGIO {si_signo=SIGIO, si_code=SI_KERNEL} ---
[pid  8439] rt_sigreturn()              = 1
[pid  8439] recvmsg(9, {msg_name(0)=NULL, msg_iov(1)=[{"\241 \33\f\263\0\340\3!\1\0\0.\1\0\0000\5\0\0\263\0\340\3\0\0\0\0\0\0\0\0", 4096}], msg_controllen=0, msg_flags=0}, 0) = 32
[pid  8439] recvmsg(9, 0x7ffda37f3120, 0) = -1 EAGAIN (Resource temporarily unavailable)
[pid  8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
[pid  8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
[pid  8439] poll([{fd=9, events=POLLIN|POLLOUT}], 1, 4294967295) = 1 ([{fd=9, revents=POLLOUT}])
[pid  8439] writev(9, [{"\31\0\v\0\366\0\0\0\0\0\30\0! \0\0\366\0\0\0!\1\0\0.\1\0\0000\5\0\0"..., 44}, {NULL, 0}, {"", 0}], 3) = 44
[pid  8439] recvmsg(9, 0x7ffda37f2ff0, 0) = -1 EAGAIN (Resource temporarily unavailable)
[pid  8439] recvmsg(9, 0x7ffda37f3120, 0) = -1 EAGAIN (Resource temporarily unavailable)
[pid  8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
[pid  8439] recvmsg(9, 0x7ffda37f3340, 0) = -1 EAGAIN (Resource temporarily unavailable)
[pid  8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9, events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
[pid  8439] pselect6(14, [6 8 9 13], [], NULL, {100000, 0}, {NULL, 8}) = 1 (in [9], left {99998, 551877999})

So something is polling and stuff on Linux, at least...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Tue, 13 Dec 2016 01:19:01 GMT) Full text and rfc822 format available.

Message #20 received at 10404 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: dancol <at> dancol.org, 10404 <at> debbugs.gnu.org
Subject: Re: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Mon, 12 Dec 2016 20:18:36 -0500
Lars Ingebrigtsen wrote:

> If I start "emacs -Q" and strace it, I see basically the following every
> couple of seconds.
>
> [pid  8439] --- SIGIO {si_signo=SIGIO, si_code=SI_KERNEL} ---
> [pid  8439] rt_sigreturn()              = 1
> [pid 8439] recvmsg(9, {msg_name(0)=NULL, msg_iov(1)=[{"\241
> \33\f\263\0\340\3!\1\0\0.\1\0\0000\5\0\0\263\0\340\3\0\0\0\0\0\0\0\0",
> 4096}], msg_controllen=0, msg_flags=0}, 0) = 32
> [pid 8439] recvmsg(9, 0x7ffda37f3120, 0) = -1 EAGAIN (Resource
> temporarily unavailable)
> [pid 8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9,
> events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
> [pid 8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9,
> events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
> [pid 8439] poll([{fd=9, events=POLLIN|POLLOUT}], 1, 4294967295) = 1
> ([{fd=9, revents=POLLOUT}])
> [pid 8439] writev(9, [{"\31\0\v\0\366\0\0\0\0\0\30\0!
> \0\0\366\0\0\0!\1\0\0.\1\0\0000\5\0\0"..., 44}, {NULL, 0}, {"", 0}],
> 3) = 44
> [pid 8439] recvmsg(9, 0x7ffda37f2ff0, 0) = -1 EAGAIN (Resource
> temporarily unavailable)
> [pid 8439] recvmsg(9, 0x7ffda37f3120, 0) = -1 EAGAIN (Resource
> temporarily unavailable)
> [pid 8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9,
> events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
> [pid 8439] recvmsg(9, 0x7ffda37f3340, 0) = -1 EAGAIN (Resource
> temporarily unavailable)
> [pid 8439] poll([{fd=6, events=POLLIN}, {fd=8, events=POLLIN}, {fd=9,
> events=POLLIN}, {fd=13, events=POLLIN}], 4, 0) = 0 (Timeout)
> [pid 8439] pselect6(14, [6 8 9 13], [], NULL, {100000, 0}, {NULL, 8})
> = 1 (in [9], left {99998, 551877999})
>
> So something is polling and stuff on Linux, at least...


I don't see anything, unless I do something with the Emacs window, like
move the cursor over it, or move another application's window over it.

This report is 5 years old. It would be good to resolve it one way or
the other. I'm not qualified to do so.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Tue, 13 Dec 2016 23:44:02 GMT) Full text and rfc822 format available.

Message #23 received at 10404 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: dancol <at> dancol.org, 10404 <at> debbugs.gnu.org
Subject: Re: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Wed, 14 Dec 2016 00:43:43 +0100
Glenn Morris <rgm <at> gnu.org> writes:

> I don't see anything, unless I do something with the Emacs window, like
> move the cursor over it, or move another application's window over it.
>
> This report is 5 years old. It would be good to resolve it one way or
> the other. I'm not qualified to do so.

Yeah, I don't see it either on Debian Jessie, so it's presumably
something that's dependent on the distribution...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) help. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Wed, 14 Dec 2016 16:48:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#10404; Package emacs. (Thu, 27 Jun 2019 15:47:02 GMT) Full text and rfc822 format available.

Message #28 received at 10404 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: dancol <at> dancol.org, 10404 <at> debbugs.gnu.org
Subject: Re: bug#10404: [PATCH] Power: sleep longer than two seconds at a time
Date: Thu, 27 Jun 2019 17:46:00 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Glenn Morris <rgm <at> gnu.org> writes:
>
>> I don't see anything, unless I do something with the Emacs window, like
>> move the cursor over it, or move another application's window over it.
>>
>> This report is 5 years old. It would be good to resolve it one way or
>> the other. I'm not qualified to do so.
>
> Yeah, I don't see it either on Debian Jessie, so it's presumably
> something that's dependent on the distribution...

So I don't think there's anything more to be done here, and I'm closing
this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 10404 <at> debbugs.gnu.org and Daniel Colascione <dancol <at> dancol.org> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 27 Jun 2019 15:47:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 26 Jul 2019 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 269 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.