[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sit-for

From: Chong Yidong
Subject: Re: sit-for
Date: Sat, 29 Jul 2006 10:43:53 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> Update: it still happens.  I am working for a while in a web browser,
> suddenly the fans engage, the Emacs frame (not even mapped when this
> happens) shows a very slow and erratically blinking cursor, and `top'
> shows that Emacs is consuming close to 100% of CPU power.
> So yes, even an off-screen Emacs sitting idle in some frame suddenly
> decides to suck up all CPU power.

My guess is that it's a `sit-for' call in the jit-lock stealth timer
causing the problem.

There are two places in read_char that could conceivably carry out
some expensive operations while waiting for input.  I doubt these are
the culprits, but to rule them out, could you apply the following
patch and see if the problem still occurs?

Apart from that, there are two other possibilities I can think of that
may cause this kind of trouble.  The first is that some invalid "input
event" is continuously firing, causing wait_reading_process_output to
return instantly.  Since kbd_buffer_get_event loops calling
wait_reading_process_output until it gets a valid event, this could
cause high CPU consumption.  If this is indeed the case, we'll
probably have to somehow fix wait_read_process_output itself to ignore
those fake events (which makes the entire strategy of the Lisp-level
sit-for redundant).

The other possibility is some kind of bad timer interaction, in which
a timer is called during sit-for, but that timer itself contains a
sit-for, so each sit-for never returns.  But that kind of bug would
probably have affected the old sit-for implementation too, so this
seems unlikely.

*** emacs/src/keyboard.c.~1.861.~       2006-07-28 09:21:33.000000000 -0400
--- emacs/src/keyboard.c        2006-07-29 10:06:29.000000000 -0400
*** 2556,2561 ****
--- 2556,2570 ----
            /* Normal case: no input arrived during redisplay.  */
+         /* Don't keep looping if the timeout expires.  */
+         if (end_time)
+           {
+             EMACS_TIME now;
+             EMACS_GET_TIME (now);
+             if (EMACS_TIME_GE (now, *end_time))
+               goto exit;
+           }
          /* Input arrived and pre-empted redisplay.
             Process any events which are not user-visible.  */
          swallow_events (0);
*** 2749,2755 ****
    /* Maybe autosave and/or garbage collect due to idleness.  */
!   if (INTERACTIVE && NILP (c))
        int delay_level, buffer_size;
--- 2758,2764 ----
    /* Maybe autosave and/or garbage collect due to idleness.  */
!   if (INTERACTIVE && NILP (c) && !end_time)
        int delay_level, buffer_size;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]