* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
@ 2011-12-29 23:40 Daniel Colascione
2013-06-12 17:25 ` Glenn Morris
0 siblings, 1 reply; 8+ messages in thread
From: Daniel Colascione @ 2011-12-29 23:40 UTC (permalink / raw)
To: 10404
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
^ permalink raw reply related [flat|nested] 8+ messages in thread
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
2011-12-29 23:40 bug#10404: [PATCH] Power: sleep longer than two seconds at a time Daniel Colascione
@ 2013-06-12 17:25 ` Glenn Morris
2013-06-12 18:14 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2013-06-12 17:25 UTC (permalink / raw)
To: 10404
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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
2013-06-12 17:25 ` Glenn Morris
@ 2013-06-12 18:14 ` Eli Zaretskii
2013-07-20 19:46 ` Glenn Morris
0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-06-12 18:14 UTC (permalink / raw)
To: Glenn Morris; +Cc: 10404
> From: Glenn Morris <rgm@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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
2013-06-12 18:14 ` Eli Zaretskii
@ 2013-07-20 19:46 ` Glenn Morris
2016-02-25 6:20 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2013-07-20 19:46 UTC (permalink / raw)
To: dancol; +Cc: 10404
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 )
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
2013-07-20 19:46 ` Glenn Morris
@ 2016-02-25 6:20 ` Lars Ingebrigtsen
2016-12-13 1:18 ` Glenn Morris
0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-25 6:20 UTC (permalink / raw)
To: Glenn Morris; +Cc: 10404
Glenn Morris <rgm@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
2016-02-25 6:20 ` Lars Ingebrigtsen
@ 2016-12-13 1:18 ` Glenn Morris
2016-12-13 23:43 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2016-12-13 1:18 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 10404
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
2016-12-13 1:18 ` Glenn Morris
@ 2016-12-13 23:43 ` Lars Ingebrigtsen
2019-06-27 15:46 ` Lars Ingebrigtsen
0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2016-12-13 23:43 UTC (permalink / raw)
To: Glenn Morris; +Cc: 10404
Glenn Morris <rgm@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
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#10404: [PATCH] Power: sleep longer than two seconds at a time
2016-12-13 23:43 ` Lars Ingebrigtsen
@ 2019-06-27 15:46 ` Lars Ingebrigtsen
0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-27 15:46 UTC (permalink / raw)
To: Glenn Morris; +Cc: 10404
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Glenn Morris <rgm@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
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-06-27 15:46 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-29 23:40 bug#10404: [PATCH] Power: sleep longer than two seconds at a time Daniel Colascione
2013-06-12 17:25 ` Glenn Morris
2013-06-12 18:14 ` Eli Zaretskii
2013-07-20 19:46 ` Glenn Morris
2016-02-25 6:20 ` Lars Ingebrigtsen
2016-12-13 1:18 ` Glenn Morris
2016-12-13 23:43 ` Lars Ingebrigtsen
2019-06-27 15:46 ` Lars Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).