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 370937 - Excessive CPU Utilisation
Excessive CPU Utilisation
Status: RESOLVED FIXED
Product: gnome-applets
Classification: Other
Component: mixer
2.16.x
Other Linux
: Normal minor
: ---
Assigned To: gnome-applets Maintainers
gnome-applets Maintainers
Depends on: 152864
Blocks: 356586
 
 
Reported: 2006-11-05 10:11 UTC by David Murrell
Modified: 2009-01-11 20:35 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16


Attachments
Use notifications (see Bug 152864) (1.93 KB, patch)
2007-05-12 22:43 UTC, Marc-Andre Lureau
none Details | Review
Updated patch to use notification bus messages (4.68 KB, patch)
2007-07-20 23:34 UTC, Jan Schmidt
none Details | Review
updated updated patch, with an errant g_print debug statement removed. (4.63 KB, patch)
2007-07-20 23:35 UTC, Jan Schmidt
none Details | Review
handle gconf switches too (4.24 KB, patch)
2007-07-21 09:13 UTC, Jan Schmidt
none Details | Review
Force updates on user interaction (4.36 KB, patch)
2007-08-30 20:37 UTC, Matthew Garrett
committed Details | Review

Description David Murrell 2006-11-05 10:11:36 UTC
Running strace on the mixer_applet2 process: (on ubuntu edgy eft)

david@radon:~/Desktop$ ps ax|grep mixer_applet2
 3701 ?        S      0:03 /usr/lib/gnome-applets/mixer_applet2 


david@radon:~/Desktop$ time strace -p 3701
Process 3701 attached - interrupt to quit
gettimeofday({1162720948, 122526}, NULL) = 0
ioctl(3, FIONREAD, [0])                 = 0
gettimeofday({1162720948, 123256}, NULL) = 0
poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=8, events=POLLIN|POLLPRI}, {fd=10, events=POLLIN|POLLPRI}, {fd=11, events=POLLIN|POLLPRI}, {fd=12, events=POLLIN|POLLPRI}, {fd=14, events=POLLIN|POLLPRI}, {fd=13, events=POLLIN|POLLPRI}, {fd=15, events=POLLIN|POLLPRI}, {fd=16, events=POLLIN|POLLPRI}], 10, 12) = 0
gettimeofday({1162720948, 134808}, NULL) = 0
ioctl(3, FIONREAD, [0])                 = 0
gettimeofday({1162720948, 134867}, NULL) = 0
poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=8, events=POLLIN|POLLPRI}, {fd=10, events=POLLIN|POLLPRI}, {fd=11, events=POLLIN|POLLPRI}, {fd=12, events=POLLIN|POLLPRI}, {fd=14, events=POLLIN|POLLPRI}, {fd=13, events=POLLIN|POLLPRI}, {fd=15, events=POLLIN|POLLPRI}, {fd=16, events=POLLIN|POLLPRI}], 10, 0) = 0
read(18, 0xbfaef260, 72)                = -1 EAGAIN (Resource temporarily unavailable)
ioctl(3, FIONREAD, [0])                 = 0
gettimeofday({1162720948, 135039}, NULL) = 0
poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=8, events=POLLIN|POLLPRI}, {fd=10, events=POLLIN|POLLPRI}, {fd=11, events=POLLIN|POLLPRI}, {fd=12, events=POLLIN|POLLPRI}, {fd=14, events=POLLIN|POLLPRI}, {fd=13, events=POLLIN|POLLPRI}, {fd=15, events=POLLIN|POLLPRI}, {fd=16, events=POLLIN|POLLPRI}], 10, 99) = 0
gettimeofday({1162720948, 234504}, NULL) = 0
ioctl(3, FIONREAD, [0])                 = 0
gettimeofday({1162720948, 235176}, NULL) = 0
poll([{fd=4, events=POLLIN}, {fd=3, events=POLLIN}, {fd=8, events=POLLIN|POLLPRI}, {fd=10, events=POLLIN|POLLPRI}, {fd=11, events=POLLIN|POLLPRI}, {fd=12, events=POLLIN|POLLPRI}, {fd=14, events=POLLIN|POLLPRI}, {fd=13, events=POLLIN|POLLPRI}, {fd=15, events=POLLIN|POLLPRI}, {fd=16, events=POLLIN|POLLPRI}], 10, 0) = 0
read(18, 0xbfaef260, 72)                = -1 EAGAIN (Resource temporarily unavailable)
ioctl(3, FIONREAD, [0])                 = 0
gettimeofday({1162720948, 235991}, NULL) = 0
poll( <unfinished ...>
Process 3701 detached

real    0m0.213s
user    0m0.002s
sys     0m0.002s



Summarized version, for simplicities sake:

david@radon:~/Desktop$ time strace -p 3701 -c
Process 3701 attached - interrupt to quit
Process 3701 detached
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
   nan    0.000000           0        81        81 read
   nan    0.000000           0       185           ioctl
   nan    0.000000           0       307           gettimeofday
   nan    0.000000           0       185           poll
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                   758        81 total

real    0m8.209s
user    0m0.001s
sys     0m0.001s

Why does a mixer need to know the time of day every 200 milliseconds?
Thats 758 calls in 8.2 seconds, or almost 100 calls per second!



Calling ltrace (library trace) on the same process:
david@radon:~/Desktop$ time ltrace -p 3701
--- SIGSTOP (Stopped (signal)) ---
--- SIGSTOP (Stopped (signal)) ---
g_type_check_instance_cast(0x80a0040, 0x809d6f0, 0xbfaef458, 0xb783ddd6, 0x80a0040)                             = 0x80a0040
g_list_first(0x8116940, 1, 0xbfaef3e8, 0xb78ca711, 0xb78a31e4)                                                  = 0x8116940
g_malloc(8, 0x8319508, 0x83291b0, 0xb798432f, 0)                                                                = 0x83291b0
gst_mixer_get_volume(0x8309850, 0x8319508, 0x83291b0, 0xb798432f, 0)                                            = 0x8319508
g_free(0x83291b0, 0x8319508, 0x83291b0, 0xb798432f, 0)                                                          = 0
g_type_check_instance_cast(0x80a0040, 0x809d6f0, 0xbfaef458, 0xb783ddd6, 0x80a0040)                             = 0x80a0040
g_list_first(0x8116940, 1, 0xbfaef3e8, 0xb78ca711, 0xb78a31e4)                                                  = 0x8116940
g_malloc(8, 0x8319508, 0x83291b0, 0xb798432f, 0)                                                                = 0x83291b0
gst_mixer_get_volume(0x8309850, 0x8319508, 0x83291b0, 0xb798432f, 0)                                            = 0x8319508
g_free(0x83291b0, 0x8319508, 0x83291b0, 0xb798432f, 0)                                                          = 0

real    0m0.246s
user    0m0.003s
sys     0m0.000s




david@radon:~/Desktop$ time ltrace -p 3701 -c
% time     seconds  usecs/call     calls      function
------ ----------- ----------- --------- --------------------
 38.38    0.000989          41        24 gst_mixer_get_volume
 18.08    0.000466          19        24 g_type_check_instance_cast
 15.29    0.000394          16        24 g_malloc
 14.24    0.000367          15        24 g_free
 14.01    0.000361          15        24 g_list_first
------ ----------- ----------- --------- --------------------
100.00    0.002577                   120 total

real    0m2.313s
user    0m0.001s
sys     0m0.005s

Regardless, the result is that a mixer applet is using resources that it really doesn't need to be :)
Use inotify or something similar.
Comment 1 Ronald Bultje 2007-01-06 17:09:42 UTC
There are signals in the mixer interface in gst, but those are unimplemented. For ALSA, in theory, we could implement them, please do so if you're good at ALSA. For OSS and others, there's no way to do that, and we'd need to poll inside the plugin to keep the signals updated properly. Once that's done, the polls can be removed and we can just rely on signals as you'd want.
Comment 2 Marc-Andre Lureau 2007-05-12 22:43:08 UTC
Created attachment 88102 [details] [review]
Use notifications (see Bug 152864)

It listen to volume_changed & mute_toggled. I don't see the need for other signals.

We might consider a GST_MIXER_HAS_NOTIFICATION (as suggested in bug 152864)
and keep the timeout callback for OSS/...

For strange reason, it was impossible to force use of GST_PLUGIN_PATH... I ended up overwriting my system libgstalsa.so, and was happy to see that it works !!
Comment 3 Ronald Bultje 2007-05-12 23:23:59 UTC
record-toggled needs to be there also, if you want that. Not for the mixer btw, but for g-v-c.

What is your plan for OSS&stuff? Keep polling code in apps? Move it to gst (you have my permission to use the code in gvc/mixer-applet under the LGPL if it isn't licensed so already).
Comment 4 Marc-Andre Lureau 2007-05-13 11:34:46 UTC
(In reply to comment #3)
> record-toggled needs to be there also, if you want that. Not for the mixer btw,
> but for g-v-c.

yes, + "option-changed" or whatever

> What is your plan for OSS&stuff? Keep polling code in apps? Move it to gst (you
> have my permission to use the code in gvc/mixer-applet under the LGPL if it
> isn't licensed so already).

Thanks! I don't know. I'd rather like the idea that there is no polling in the gstreamer code. Thus, we'd need the GST_MIXER_HAS_NOTIFY to keep the current polling code in apps running if the mixer element does not support it.

What would you think then?

Comment 5 Ronald Bultje 2007-05-13 14:30:07 UTC
(In reply to comment #4)
> Thanks! I don't know. I'd rather like the idea that there is no polling in the
> gstreamer code. Thus, we'd need the GST_MIXER_HAS_NOTIFY to keep the current
> polling code in apps running if the mixer element does not support it.
> 
> What would you think then?

All apps will duplicate the polling code anyway, can we add a helper in the gstmixerinterface lib? The app can still do the setup, that's like one line of code, but the polling itself is quite a lot since it involves two code paths. If the helper lib can do that for us, it saves a whole lot of duplication (=bugs).
Comment 6 Marc-Andre Lureau 2007-05-13 15:00:28 UTC
Add an abstract in the iface:

class _GstMixerClass {
+  void           (* update)    (GstMixer      *mixer);
}

+helper friend:
void            gst_mixer_update (GstMixer      *mixer);

+ a property "refresh-interval" that would call this function repeatedly if set to a value > 0 ?



Comment 7 Jan Schmidt 2007-07-20 23:34:28 UTC
Created attachment 92070 [details] [review]
Updated patch to use notification bus messages

Updated patch which uses the proposed API in bug #152864 when available, but continues using the polling method when a) the new GStreamer API is not available, or b) the GstMixer implementation does not provide notifications.

I opted not to add any extra helper API for implementing the polling for the moment, since the mixer needs to keep the existing polling code anyway for backwards compatibility.
Comment 8 Jan Schmidt 2007-07-20 23:35:44 UTC
Created attachment 92071 [details] [review]
updated updated patch, with an errant g_print debug statement removed.
Comment 9 Jan Schmidt 2007-07-21 09:13:30 UTC
Created attachment 92114 [details] [review]
handle gconf switches too

This updated patch handles turning the timeout on/off when the current mixer element is changed in gconf too, so things continue to work as expected.
Comment 10 Sebastien Bacher 2007-08-30 17:13:08 UTC
The patch doesn't work correctly, the applet icon is not updated when changing the volume with the applet slider or using the mouse whell on it
Comment 11 Marc-Andre Lureau 2007-08-30 18:35:58 UTC
(In reply to comment #10)
> The patch doesn't work correctly, the applet icon is not updated when changing
> the volume with the applet slider or using the mouse whell on it
> 

With pulseaudio? Did you try without it?
Comment 12 Sebastien Bacher 2007-08-30 19:13:30 UTC
no, pulseaudio is not installed, esound is running though
Comment 13 Matthew Garrett 2007-08-30 20:37:45 UTC
Created attachment 94667 [details] [review]
Force updates on user interaction

This seems to fix it - if there's no update loop running, the ui wouldn't update itself.
Comment 14 Federico Mena Quintero 2007-09-13 20:14:16 UTC
Even better...

-    applet->timeout = g_timeout_add (100, cb_check, applet);
+    applet->timeout = g_timeout_add_seconds (1, cb_check, applet);

So that laptops with old gstreamers can still sleep.
Comment 15 Ronald Bultje 2007-09-13 23:38:36 UTC
They will need to update gnome anyway to receive the update, so don't include that patch please.
Comment 16 Federico Mena Quintero 2007-09-14 00:39:39 UTC
I mean - Matthew's patch is great, but it still has the 1/10 sec timer.  We can safely make it much longer, so that laptops can sleep even if they have a GStreamer that doesn't support notifications.
Comment 17 Ronald Bultje 2007-09-14 03:00:03 UTC
I understand, but to get that, they'll need to update gnome. New gnome will include a new gstreamer anyway. It seems like a chicken-and-egg issue to me.
Comment 18 Matthew Garrett 2007-09-14 10:23:54 UTC
Not everyone uses ALSA, so increasing the timeout would be worth it anyway.
Comment 19 Ronald Bultje 2007-09-14 13:59:48 UTC
Hmk... Possibly a regression, but it's ok I guess.
Comment 20 Patrick Ohearn 2007-11-01 21:19:10 UTC
Is there any news on the gst and alsa stuff? If not can we get this patch merged until gst and alsa are fixed?
Comment 21 Ronald Bultje 2007-11-11 17:03:25 UTC
No. I merged a different patch that does it better, keeping the 1/10th of a second when busy and decreasing that to a second or so when there's no activity, that's the best way to handle it. this patch will not go in.

The gst/alsa patch is in head already.
Comment 22 Frederic Crozat 2008-01-18 10:14:09 UTC
gstreamer part is now available in released version of gstreamer-plugins-base.

Any reason for not merged this patch in gnome-applets trunk ?
Comment 23 Pacho Ramos 2008-03-27 12:58:46 UTC
Any news on this?
Comment 24 Baptiste Mille-Mathias 2008-12-19 10:51:56 UTC
PING PING PING !!!
Could someone commit this patch please ? 

--
This insightful comment was brought to you by the Bugsquad GNOME team :)
Comment 25 Bastien Nocera 2008-12-19 10:57:30 UTC
Not following latest development, are we? The mixer applet should be dead in trunk, replaced by the one in gnome-media, see bug 564872
Comment 26 Callum McKenzie 2008-12-19 23:55:46 UTC
Actually, the patch was committed some months ago in time for the 2.24 release. I have no idea why I didn't close the bug then. Sorry.
Comment 27 Matthias Clasen 2009-01-11 20:35:16 UTC
It seems that the nullification of the mixer applet doesn't work quite correctly in 2.25.3. I keep getting the dialog every time I log in. It seems that

        g_hash_table_insert (hash_table,
                             "OAFIID:GNOME_MixerApplet_Factory", "Volume Control");


should be

        g_hash_table_insert (hash_table,
                             "OAFIID:GNOME_MixerApplet", "Volume Control");