After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 568162 - Gnome power manager causes high CPU usage with an expensive call
Gnome power manager causes high CPU usage with an expensive call
Status: RESOLVED FIXED
Product: gnome-power-manager
Classification: Deprecated
Component: gnome-power-manager
SVN TRUNK
Other All
: Normal critical
: ---
Assigned To: GNOME Power Manager Maintainer(s)
GNOME Power Manager Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2009-01-18 10:49 UTC by Alberto Milone
Modified: 2009-06-26 01:06 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26


Attachments
Patch to fix the bug (2.07 KB, patch)
2009-01-18 10:51 UTC, Alberto Milone
none Details | Review
Patch to fix the bug at compilation time (836 bytes, patch)
2009-01-19 13:26 UTC, Alberto Milone
none Details | Review
Patch to fix the bug at compilation time based on randr.h (585 bytes, patch)
2009-01-19 16:14 UTC, Alberto Milone
none Details | Review
Fixed version of 79-randr13-speed-fix.patch (1.76 KB, patch)
2009-06-26 01:06 UTC, Scott Howard
none Details | Review

Description Alberto Milone 2009-01-18 10:49:30 UTC
Please describe the problem:
According to the following bug report the gnome settings daemon causes high CPU usage with libxrandr 1.2.99.2 or higher:
https://bugs.edge.launchpad.net/ubuntu/+source/libxrandr/+bug/307306

The problem is that it calls XRRGetScreenResources() (which is an rather expensive call) instead of XRRGetScreenResourcesCurrent() which is cheaper and doesn't cause hardware to be reprobed.

While I agree that listening to events which represent changes in output properties is ideal, calling XRRGetScreenResources each time a property (e.g. the backlight) changes is really expensive and (if RandR 1.3 is available) this can be avoided.

Steps to reproduce:
1. Start the gnome session
2. 
3. 


Actual results:
high CPU usage makes the session unusable

Expected results:


Does this happen every time?
yes

Other information:
Comment 1 Alberto Milone 2009-01-18 10:50:38 UTC
Actually I meant "gnome power manager" instead of "gnome settings daemon". They are both affected by this problem
Comment 2 Alberto Milone 2009-01-18 10:51:33 UTC
Created attachment 126678 [details] [review]
Patch to fix the bug

This patch will detect the version of RandR and use
XRRGetScreenResourcesCurrent when available.
Comment 3 Alberto Milone 2009-01-19 13:26:32 UTC
Created attachment 126753 [details] [review]
Patch to fix the bug at compilation time

With my previous patch compilation fails if RandR 1.3 is not available since the new function doesn't exist in 1.2.

This new patch is even simpler and checks the availability of RandR 1.3 at
compilation time
Comment 4 Richard Hughes 2009-01-19 14:13:41 UTC
2009-01-19  Richard Hughes  <richard@hughsie.com>

	* src/gpm-brightness-xrandr.c:
	(gpm_brightness_xrandr_update_cache):
	According to the following bug report the gnome settings daemon causes
	high CPU usage with libxrandr 1.2.99.2 or higher:
	https://bugs.edge.launchpad.net/ubuntu/+source/libxrandr/+bug/307306

	The problem is that it calls XRRGetScreenResources() (which is an rather
	expensive call) instead of XRRGetScreenResourcesCurrent() which is
	cheaper and doesn't cause hardware to be reprobed.

	While I agree that listening to events which represent changes in output
	properties is ideal, calling XRRGetScreenResources each time a property
	(e.g. the backlight) changes is really expensive and (if RandR 1.3 is
	available) this can be avoided.

	Patch from Alberto Milone <albertomilone@alice.it>, many thanks.
Comment 5 Alberto Milone 2009-01-19 16:14:20 UTC
Created attachment 126770 [details] [review]
Patch to fix the bug at compilation time based on randr.h

This patch relies on randr.h i.e. on the RandR procol rather than on the xserver itself. This will prevent us from adding the xserver development libraries as build dependencies (thus preserving the previous behaviour).
Comment 6 Richard Hughes 2009-01-19 16:20:56 UTC
2009-01-19  Richard Hughes  <richard@hughsie.com>

	* src/gpm-brightness-xrandr.c:
	(gpm_brightness_xrandr_update_cache):
	This patch relies on randr.h i.e. on the RandR procol rather than on the
	xserver itself. This will prevent us from adding the xserver development
	libraries as build dependencies (thus preserving the previous behaviour).

	Patch from Alberto Milone <albertomilone@alice.it>, many thanks.
Comment 7 Peter Clifton 2009-01-20 15:05:08 UTC
You still need to check the version of the extension at runtime, otherwise you
will fail if communicating with an older server.
Comment 8 Scott Howard 2009-06-26 01:06:54 UTC
Created attachment 137397 [details] [review]
Fixed version of 79-randr13-speed-fix.patch

From:
https://bugs.launchpad.net/ubuntu/+source/gnome-power-manager/+bug/372468

The following is by the original reporter "mdw" on launchpad.



Binary package hint: gnome-power-manager

This is gnome-power-manager 2.24.2-2ubuntu8 (jaunty).

[crybaby ~]gnome-power-manager --no-daemon --sync
The program 'gnome-power-manager' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadRequest (invalid request code or no such operation)'.
  (Details: serial 187 error_code 1 request_code 154 minor_code 25)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

A little playing with gdb shows that it's caused by a call to XRRGetScreenResourcesCurrent in gpm_brightness_xrandr_update_cache (src/gpm-brightness-xrandr.c), added by debian/patches/79-randr13-speed-fix.patch as part of #307306.

But the fix is wrong, as mentioned in further discussion on that bug: the call is guarded by #ifdef but that only helps if the code is compiled against an old client library (which can anyway be prevented by appropriate Build-Depends). The problem is that my X server doesn't provide Xrandr 1.3, because I'm holding it back (because of the Intel graphics driver bug warned of in the Jaunty release notes).

I've attached a fixed version of the patch which (a) stores the server's Xrandr version number, and (b) checks it before calling the offending function, falling back to XRRGetScreenResources.