GNOME Bugzilla – Bug 370937
Excessive CPU Utilisation
Last modified: 2009-01-11 20:35:16 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.
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.
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 !!
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).
(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?
(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).
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 ?
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.
Created attachment 92071 [details] [review] updated updated patch, with an errant g_print debug statement removed.
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.
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
(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?
no, pulseaudio is not installed, esound is running though
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.
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.
They will need to update gnome anyway to receive the update, so don't include that patch please.
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.
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.
Not everyone uses ALSA, so increasing the timeout would be worth it anyway.
Hmk... Possibly a regression, but it's ok I guess.
Is there any news on the gst and alsa stuff? If not can we get this patch merged until gst and alsa are fixed?
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.
gstreamer part is now available in released version of gstreamer-plugins-base. Any reason for not merged this patch in gnome-applets trunk ?
Any news on this?
PING PING PING !!! Could someone commit this patch please ? -- This insightful comment was brought to you by the Bugsquad GNOME team :)
Not following latest development, are we? The mixer applet should be dead in trunk, replaced by the one in gnome-media, see bug 564872
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.
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");