GNU bug report logs - #76805
31.0.50; [PATH] Fix Emacs uses 100% CPU after switching graphic frame to inactive

Previous Next

Package: emacs;

Reported by: Lin Sun <sunlin7 <at> hotmail.com>

Date: Fri, 7 Mar 2025 08:23:01 UTC

Severity: normal

Found in version 31.0.50

Done: Stefan Kangas <stefankangas <at> gmail.com>

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 76805 in the body.
You can then email your comments to 76805 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#76805; Package emacs. (Fri, 07 Mar 2025 08:23:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Lin Sun <sunlin7 <at> hotmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 07 Mar 2025 08:23:02 GMT) Full text and rfc822 format available.

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

From: Lin Sun <sunlin7 <at> hotmail.com>
To: "bug-gnu-emacs <at> gnu.org" <bug-gnu-emacs <at> gnu.org>
Subject: 31.0.50; [PATH] Fix Emacs uses 100% CPU after switching graphic frame
 to inactive
Date: Fri, 7 Mar 2025 08:17:31 +0000
[Message part 1 (text/plain, inline)]
Hi, 
Emacs sometimes takes 100% CPU after I switch emacs graphic frame to inactive.
This patch will fix the issue.

Reproduce steps:
1. Build Emacs with gtk3 and xinput2 on Ubuntu 22.04.
2. (setq x-use-fast-mouse-position 'really-fast) in early-init.el.
3. On a windows-host start a X11 server, and ssh -XY ubuntu-host:emacs to Start emacs with X11 forwared-frame, and open emacs "src/eval.c", enable the show-paren-mode in emacs.
4. On the windows host, move the mouse out of emacs-graphic frame first, the move the mouse in emacs-graphic frame and click.
5. On the windows host, switch the emacs-graphic frame to inactive (switch a native windows app to active).
Repeat steps 4,5 sometimes the emacs will takes 100% CPU.

The issue won't happen if set the x-use-fast-mouse-position to `t` or `nil` instead of the 'really-fast.

According to my debugging and tracking the variables, I found that
1. the xterm.c:21710 will let "dpyinfo->last_mouse_motion_frame = NULL;", then 
2. later calls `x_fast_mouse_position` will no chance to let "XX->mouse_moved = false", then 
3. the function some_mouse_moved() in keyboard.c always return true; then
4. the function timer_start_idle() in keyboard.c will be called again and again, which leads 100% CPU usage.

As contrast when setting the x-use-fast-mouse-position to `t`, the "XX->mouse_moved = false;" always run, then the issue won't happen.

Please help review the patch. Thanks

Best Regards, Lin
[0001-src-xterm.c-Mark-mouse_moved-to-false-in-x_fast_mous.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76805; Package emacs. (Sun, 09 Mar 2025 10:25:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Lin Sun <sunlin7 <at> hotmail.com>, Po Lu <luangruo <at> yahoo.com>
Cc: 76805 <at> debbugs.gnu.org
Subject: Re: bug#76805: 31.0.50;
 [PATH] Fix Emacs uses 100% CPU after switching graphic frame to
 inactive
Date: Sun, 09 Mar 2025 12:23:57 +0200
> From: Lin Sun <sunlin7 <at> hotmail.com>
> Date: Fri, 7 Mar 2025 08:17:31 +0000
> 
> Emacs sometimes takes 100% CPU after I switch emacs graphic frame to inactive.
> This patch will fix the issue.
> 
> Reproduce steps:
> 1. Build Emacs with gtk3 and xinput2 on Ubuntu 22.04.
> 2. (setq x-use-fast-mouse-position 'really-fast) in early-init.el.
> 3. On a windows-host start a X11 server, and ssh -XY ubuntu-host:emacs to Start emacs with X11 forwared-frame, and open emacs "src/eval.c", enable the show-paren-mode in emacs.
> 4. On the windows host, move the mouse out of emacs-graphic frame first, the move the mouse in emacs-graphic frame and click.
> 5. On the windows host, switch the emacs-graphic frame to inactive (switch a native windows app to active).
> Repeat steps 4,5 sometimes the emacs will takes 100% CPU.
> 
> The issue won't happen if set the x-use-fast-mouse-position to `t` or `nil` instead of the 'really-fast.
> 
> According to my debugging and tracking the variables, I found that
> 1. the xterm.c:21710 will let "dpyinfo->last_mouse_motion_frame = NULL;", then 
> 2. later calls `x_fast_mouse_position` will no chance to let "XX->mouse_moved = false", then 
> 3. the function some_mouse_moved() in keyboard.c always return true; then
> 4. the function timer_start_idle() in keyboard.c will be called again and again, which leads 100% CPU usage.
> 
> As contrast when setting the x-use-fast-mouse-position to `t`, the "XX->mouse_moved = false;" always run, then the issue won't happen.
> 
> Please help review the patch. Thanks

Thanks.

Po Lu, any comments?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76805; Package emacs. (Sun, 09 Mar 2025 13:59:01 GMT) Full text and rfc822 format available.

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

From: Po Lu <luangruo <at> yahoo.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Lin Sun <sunlin7 <at> hotmail.com>, 76805 <at> debbugs.gnu.org
Subject: Re: bug#76805: 31.0.50; [PATH] Fix Emacs uses 100% CPU after
 switching graphic frame to inactive
Date: Sun, 09 Mar 2025 21:58:38 +0800
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Lin Sun <sunlin7 <at> hotmail.com>
>> Date: Fri, 7 Mar 2025 08:17:31 +0000
>> 
>> Emacs sometimes takes 100% CPU after I switch emacs graphic frame to inactive.
>> This patch will fix the issue.
>> 
>> Reproduce steps:
>> 1. Build Emacs with gtk3 and xinput2 on Ubuntu 22.04.
>> 2. (setq x-use-fast-mouse-position 'really-fast) in early-init.el.
>> 3. On a windows-host start a X11 server, and ssh -XY
>> ubuntu-host:emacs to Start emacs with X11 forwared-frame, and open
>> emacs "src/eval.c", enable the show-paren-mode in emacs.
>> 4. On the windows host, move the mouse out of emacs-graphic frame
>> first, the move the mouse in emacs-graphic frame and click.
>> 5. On the windows host, switch the emacs-graphic frame to inactive (switch a native windows app to active).
>> Repeat steps 4,5 sometimes the emacs will takes 100% CPU.
>> 
>> The issue won't happen if set the x-use-fast-mouse-position to `t` or `nil` instead of the 'really-fast.
>> 
>> According to my debugging and tracking the variables, I found that
>> 1. the xterm.c:21710 will let "dpyinfo->last_mouse_motion_frame = NULL;", then 
>> 2. later calls `x_fast_mouse_position` will no chance to let "XX->mouse_moved = false", then 
>> 3. the function some_mouse_moved() in keyboard.c always return true; then
>> 4. the function timer_start_idle() in keyboard.c will be called again and again, which leads 100% CPU usage.
>> 
>> As contrast when setting the x-use-fast-mouse-position to `t`, the
>> "XX->mouse_moved = false;" always run, then the issue won't happen.
>> 
>> Please help review the patch. Thanks
>
> Thanks.
>
> Po Lu, any comments?

I'll investigate this issue tomorrow.  Thank you for reporting it.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76805; Package emacs. (Thu, 13 Mar 2025 11:30:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Po Lu <luangruo <at> yahoo.com>
Cc: sunlin7 <at> hotmail.com, 76805 <at> debbugs.gnu.org
Subject: Re: bug#76805: 31.0.50; [PATH] Fix Emacs uses 100% CPU after
 switching graphic frame to inactive
Date: Thu, 13 Mar 2025 13:29:02 +0200
> From: Po Lu <luangruo <at> yahoo.com>
> Cc: Lin Sun <sunlin7 <at> hotmail.com>,  76805 <at> debbugs.gnu.org
> Date: Sun, 09 Mar 2025 21:58:38 +0800
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> From: Lin Sun <sunlin7 <at> hotmail.com>
> >> Date: Fri, 7 Mar 2025 08:17:31 +0000
> >> 
> >> Emacs sometimes takes 100% CPU after I switch emacs graphic frame to inactive.
> >> This patch will fix the issue.
> >> 
> >> Reproduce steps:
> >> 1. Build Emacs with gtk3 and xinput2 on Ubuntu 22.04.
> >> 2. (setq x-use-fast-mouse-position 'really-fast) in early-init.el.
> >> 3. On a windows-host start a X11 server, and ssh -XY
> >> ubuntu-host:emacs to Start emacs with X11 forwared-frame, and open
> >> emacs "src/eval.c", enable the show-paren-mode in emacs.
> >> 4. On the windows host, move the mouse out of emacs-graphic frame
> >> first, the move the mouse in emacs-graphic frame and click.
> >> 5. On the windows host, switch the emacs-graphic frame to inactive (switch a native windows app to active).
> >> Repeat steps 4,5 sometimes the emacs will takes 100% CPU.
> >> 
> >> The issue won't happen if set the x-use-fast-mouse-position to `t` or `nil` instead of the 'really-fast.
> >> 
> >> According to my debugging and tracking the variables, I found that
> >> 1. the xterm.c:21710 will let "dpyinfo->last_mouse_motion_frame = NULL;", then 
> >> 2. later calls `x_fast_mouse_position` will no chance to let "XX->mouse_moved = false", then 
> >> 3. the function some_mouse_moved() in keyboard.c always return true; then
> >> 4. the function timer_start_idle() in keyboard.c will be called again and again, which leads 100% CPU usage.
> >> 
> >> As contrast when setting the x-use-fast-mouse-position to `t`, the
> >> "XX->mouse_moved = false;" always run, then the issue won't happen.
> >> 
> >> Please help review the patch. Thanks
> >
> > Thanks.
> >
> > Po Lu, any comments?
> 
> I'll investigate this issue tomorrow.  Thank you for reporting it.

Did you have a chance to look into this?





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76805; Package emacs. (Thu, 13 Mar 2025 12:04:02 GMT) Full text and rfc822 format available.

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

From: Po Lu <luangruo <at> yahoo.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: sunlin7 <at> hotmail.com, 76805 <at> debbugs.gnu.org
Subject: Re: bug#76805: 31.0.50; [PATH] Fix Emacs uses 100% CPU after
 switching graphic frame to inactive
Date: Thu, 13 Mar 2025 20:03:09 +0800
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Po Lu <luangruo <at> yahoo.com>
>> Cc: Lin Sun <sunlin7 <at> hotmail.com>,  76805 <at> debbugs.gnu.org
>> Date: Sun, 09 Mar 2025 21:58:38 +0800
>> 
>> Eli Zaretskii <eliz <at> gnu.org> writes:
>> 
>> >> From: Lin Sun <sunlin7 <at> hotmail.com>
>> >> Date: Fri, 7 Mar 2025 08:17:31 +0000
>> >> 
>> >> Emacs sometimes takes 100% CPU after I switch emacs graphic frame to inactive.
>> >> This patch will fix the issue.
>> >> 
>> >> Reproduce steps:
>> >> 1. Build Emacs with gtk3 and xinput2 on Ubuntu 22.04.
>> >> 2. (setq x-use-fast-mouse-position 'really-fast) in early-init.el.
>> >> 3. On a windows-host start a X11 server, and ssh -XY
>> >> ubuntu-host:emacs to Start emacs with X11 forwared-frame, and open
>> >> emacs "src/eval.c", enable the show-paren-mode in emacs.
>> >> 4. On the windows host, move the mouse out of emacs-graphic frame
>> >> first, the move the mouse in emacs-graphic frame and click.
>> >> 5. On the windows host, switch the emacs-graphic frame to inactive (switch a native windows app to active).
>> >> Repeat steps 4,5 sometimes the emacs will takes 100% CPU.
>> >> 
>> >> The issue won't happen if set the x-use-fast-mouse-position to `t` or `nil` instead of the 'really-fast.
>> >> 
>> >> According to my debugging and tracking the variables, I found that
>> >> 1. the xterm.c:21710 will let "dpyinfo->last_mouse_motion_frame = NULL;", then 
>> >> 2. later calls `x_fast_mouse_position` will no chance to let "XX->mouse_moved = false", then 
>> >> 3. the function some_mouse_moved() in keyboard.c always return true; then
>> >> 4. the function timer_start_idle() in keyboard.c will be called again and again, which leads 100% CPU usage.
>> >> 
>> >> As contrast when setting the x-use-fast-mouse-position to `t`, the
>> >> "XX->mouse_moved = false;" always run, then the issue won't happen.
>> >> 
>> >> Please help review the patch. Thanks
>> >
>> > Thanks.
>> >
>> > Po Lu, any comments?
>> 
>> I'll investigate this issue tomorrow.  Thank you for reporting it.
>
> Did you have a chance to look into this?

I fixed it but neglected to report the fact here, my apologies.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76805; Package emacs. (Thu, 13 Mar 2025 14:44:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Po Lu <luangruo <at> yahoo.com>
Cc: sunlin7 <at> hotmail.com, 76805 <at> debbugs.gnu.org
Subject: Re: bug#76805: 31.0.50; [PATH] Fix Emacs uses 100% CPU after
 switching graphic frame to inactive
Date: Thu, 13 Mar 2025 16:43:46 +0200
> From: Po Lu <luangruo <at> yahoo.com>
> Cc: sunlin7 <at> hotmail.com,  76805 <at> debbugs.gnu.org
> Date: Thu, 13 Mar 2025 20:03:09 +0800
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> From: Po Lu <luangruo <at> yahoo.com>
> >> Cc: Lin Sun <sunlin7 <at> hotmail.com>,  76805 <at> debbugs.gnu.org
> >> Date: Sun, 09 Mar 2025 21:58:38 +0800
> >> 
> >> Eli Zaretskii <eliz <at> gnu.org> writes:
> >> 
> >> >> From: Lin Sun <sunlin7 <at> hotmail.com>
> >> >> Date: Fri, 7 Mar 2025 08:17:31 +0000
> >> >> 
> >> >> Emacs sometimes takes 100% CPU after I switch emacs graphic frame to inactive.
> >> >> This patch will fix the issue.
> >> >> 
> >> >> Reproduce steps:
> >> >> 1. Build Emacs with gtk3 and xinput2 on Ubuntu 22.04.
> >> >> 2. (setq x-use-fast-mouse-position 'really-fast) in early-init.el.
> >> >> 3. On a windows-host start a X11 server, and ssh -XY
> >> >> ubuntu-host:emacs to Start emacs with X11 forwared-frame, and open
> >> >> emacs "src/eval.c", enable the show-paren-mode in emacs.
> >> >> 4. On the windows host, move the mouse out of emacs-graphic frame
> >> >> first, the move the mouse in emacs-graphic frame and click.
> >> >> 5. On the windows host, switch the emacs-graphic frame to inactive (switch a native windows app to active).
> >> >> Repeat steps 4,5 sometimes the emacs will takes 100% CPU.
> >> >> 
> >> >> The issue won't happen if set the x-use-fast-mouse-position to `t` or `nil` instead of the 'really-fast.
> >> >> 
> >> >> According to my debugging and tracking the variables, I found that
> >> >> 1. the xterm.c:21710 will let "dpyinfo->last_mouse_motion_frame = NULL;", then 
> >> >> 2. later calls `x_fast_mouse_position` will no chance to let "XX->mouse_moved = false", then 
> >> >> 3. the function some_mouse_moved() in keyboard.c always return true; then
> >> >> 4. the function timer_start_idle() in keyboard.c will be called again and again, which leads 100% CPU usage.
> >> >> 
> >> >> As contrast when setting the x-use-fast-mouse-position to `t`, the
> >> >> "XX->mouse_moved = false;" always run, then the issue won't happen.
> >> >> 
> >> >> Please help review the patch. Thanks
> >> >
> >> > Thanks.
> >> >
> >> > Po Lu, any comments?
> >> 
> >> I'll investigate this issue tomorrow.  Thank you for reporting it.
> >
> > Did you have a chance to look into this?
> 
> I fixed it but neglected to report the fact here, my apologies.

Thanks, so should this bug be closed now?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76805; Package emacs. (Thu, 13 Mar 2025 17:53:02 GMT) Full text and rfc822 format available.

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

From: Lin Sun <sunlin7 <at> hotmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Po Lu <luangruo <at> yahoo.com>
Cc: "76805 <at> debbugs.gnu.org" <76805 <at> debbugs.gnu.org>
Subject: Re: bug#76805: 31.0.50; [PATH] Fix Emacs uses 100% CPU after
 switching graphic frame to inactive
Date: Thu, 13 Mar 2025 17:52:29 +0000
[Message part 1 (text/plain, inline)]
From: Eli Zaretskii <eliz <at> gnu.org>
Sent: Thursday, March 13, 2025 02:43 PM
To: Po Lu <luangruo <at> yahoo.com>

> From: Po Lu <luangruo <at> yahoo.com>
> Cc: sunlin7 <at> hotmail.com,  76805 <at> debbugs.gnu.org
> Date: Thu, 13 Mar 2025 20:03:09 +0800
>
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> >> From: Po Lu <luangruo <at> yahoo.com>
> >> Cc: Lin Sun <sunlin7 <at> hotmail.com>,  76805 <at> debbugs.gnu.org
> >> Date: Sun, 09 Mar 2025 21:58:38 +0800
> >>
> >> Eli Zaretskii <eliz <at> gnu.org> writes:
> >>
> >> >> From: Lin Sun <sunlin7 <at> hotmail.com>
> >> >> Date: Fri, 7 Mar 2025 08:17:31 +0000
> >> >>
> >> >> Emacs sometimes takes 100% CPU after I switch emacs graphic frame to inactive.
> >> >> This patch will fix the issue.
> >> >>
> >> >> Reproduce steps:
> >> >> 1. Build Emacs with gtk3 and xinput2 on Ubuntu 22.04.
> >> >> 2. (setq x-use-fast-mouse-position 'really-fast) in early-init.el.
> >> >> 3. On a windows-host start a X11 server, and ssh -XY
> >> >> ubuntu-host:emacs to Start emacs with X11 forwared-frame, and open
> >> >> emacs "src/eval.c", enable the show-paren-mode in emacs.
> >> >> 4. On the windows host, move the mouse out of emacs-graphic frame
> >> >> first, the move the mouse in emacs-graphic frame and click.
> >> >> 5. On the windows host, switch the emacs-graphic frame to inactive (switch a native windows app to active).
> >> >> Repeat steps 4,5 sometimes the emacs will takes 100% CPU.
> >> >>
> >> >> The issue won't happen if set the x-use-fast-mouse-position to `t` or `nil` instead of the 'really-fast.
> >> >>
> >> >> According to my debugging and tracking the variables, I found that
> >> >> 1. the xterm.c:21710 will let "dpyinfo->last_mouse_motion_frame = NULL;", then
> >> >> 2. later calls `x_fast_mouse_position` will no chance to let "XX->mouse_moved = false", then
> >> >> 3. the function some_mouse_moved() in keyboard.c always return true; then
> >> >> 4. the function timer_start_idle() in keyboard.c will be called again and again, which leads 100% CPU usage.
> >> >>
> >> >> As contrast when setting the x-use-fast-mouse-position to `t`, the
> >> >> "XX->mouse_moved = false;" always run, then the issue won't happen.
> >> >>
> >> >> Please help review the patch. Thanks
> >> >
> >> > Thanks.
> >> >
> >> > Po Lu, any comments?
> >>
> >> I'll investigate this issue tomorrow.  Thank you for reporting it.
> >
> > Did you have a chance to look into this?
>
> I fixed it but neglected to report the fact here, my apologies.

> Thanks, so should this bug be closed now?

I found commit now: https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=ab5bfcebddf4c0613ef352231628d4034c8cb178 .

Thank you all of you. Please feel free to close the ticket.
[Message part 2 (text/html, inline)]

Reply sent to Stefan Kangas <stefankangas <at> gmail.com>:
You have taken responsibility. (Fri, 14 Mar 2025 19:32:02 GMT) Full text and rfc822 format available.

Notification sent to Lin Sun <sunlin7 <at> hotmail.com>:
bug acknowledged by developer. (Fri, 14 Mar 2025 19:32:02 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Lin Sun <sunlin7 <at> hotmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 76805-done <at> debbugs.gnu.org
Subject: Re: bug#76805: 31.0.50; [PATH] Fix Emacs uses 100% CPU after
 switching graphic frame to inactive
Date: Fri, 14 Mar 2025 12:31:12 -0700
Lin Sun <sunlin7 <at> hotmail.com> writes:

> Thank you all of you. Please feel free to close the ticket.

Done.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 12 Apr 2025 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 67 days ago.

Previous Next


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