Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: changing volume affects CPU usage #442

Open
adl1995 opened this issue Dec 22, 2020 · 11 comments
Open

Bug: changing volume affects CPU usage #442

adl1995 opened this issue Dec 22, 2020 · 11 comments

Comments

@adl1995
Copy link

adl1995 commented Dec 22, 2020

In my .i3status.conf file I have:

order += "volume master"
order += "cpu_usage"

volume master {
        separator_block_width = 10
        format = "♪:%volume"
        format_muted = "♪:(%volume)"
        device = "default"
        mixer = "Master"
        mixer_idx = 0
}

cpu_usage {
        separator_block_width = 10
        format = "CPU:%usage"
}

When I increase or decrease my volume, the CPU usage abnormally fluctuates +20-30% and then goes back to the previous state after a few seconds.

I suspect the issue is with the volume directive as removing it from the config file resolves the issue.

There is a similar issue reported here: https://www.reddit.com/r/i3wm/comments/jf7i1s/i3bar_cpu_usage_immediately_jumps_to_a_set_figure/

@snprajwal
Copy link

Do you have pulseaudio and pulseaudio-alsa installed?

@adl1995
Copy link
Author

adl1995 commented Jan 16, 2021

@snprajwal - Yes, I have both of these installed. Do these cause a conflict?

@snprajwal
Copy link

@snprajwal - Yes, I have both of these installed. Do these cause a conflict?

No they don't, sometimes you need both modules for pulse to work properly. I guess your last resort can be to force reinstall i3status. Use sudo apt install --reinstall i3status or your respective package manager's variation.

@adl1995
Copy link
Author

adl1995 commented Jan 20, 2021

Reinstalling i3status didn't solve this issue for me. I'm pasting my i3status.conf file below in case I misconfigured something.

general {
        colors = true
        interval = 5
}

#order += "ipv6"
order += "wireless _first_"
order += "volume master"
order += "battery all"
order += "disk /"
#order += "load"
order += "cpu_usage"
order += "memory"
order += "tztime local"

wireless _first_ {
        #format_up = "W: (%quality at %essid) %ip"
        separator_block_width = 10
        format_up = "W:%essid(%quality)"
        format_down = "W:down"
}

#ethernet _first_ {
#        format_up = "E: %ip (%speed)"
#        format_down = "E: down"
#}

volume master {
        separator_block_width = 10
        format = "♪:%volume"
        format_muted = "♪:(%volume)"
        device = "default"
        mixer = "Master"
        mixer_idx = 0
}

battery all {
        separator_block_width = 10
        format = "%percentage(%status)"
}

disk "/" {
        format = "DISK:%avail"
        separator_block_width = 10
}

#load {
#        format = "%1min"
#}

cpu_usage {
        separator_block_width = 10
        format = "CPU:%usage"
}

memory {
        separator_block_width = 10
        format = "RAM:%percentage_used"
        threshold_degraded = "1G"
        format_degraded = "MEMORY < %available"
}

tztime local {
        separator_block_width = 10
        format = "%a|%d/%m|%H:%M:%S"
}

@snprajwal
Copy link

snprajwal commented Jan 21, 2021 via email

@adl1995
Copy link
Author

adl1995 commented Jan 25, 2021

I just removed the mixer and mixer_idx but it didn't have any effect. (I restarted i3 ($mod + Shift + r) and tried logging in to a new TTY.)

@su8
Copy link

su8 commented Jan 28, 2021

Try pinky-bar https://github.com/su8/pinky-bar

@fuzzah
Copy link

fuzzah commented Jul 1, 2023

I have a similar problem: if I change volume via headphone's buttons, then cpu starts to rapidly change up and down, though i3status is configured to only run at interval of 5 seconds. At the same time I can't use things like context menus (they instantly disappear), and active UI control (e.g. this textbox I'm currently using to type this comment) blinks very fast like it's becoming inactive and then active again multiple times a second. It's like the whole screen redraws itself but at the same time opened windows do not disappear or it happens way too fast to notice.

I use Arch and pulseaudio. If I change volume via pulseaudio (by holding mouse over the tray icon and using mouse scroll wheel) the problem doesn't happen.
I don't have any volume settings in my i3status config!

@fuzzah
Copy link

fuzzah commented Sep 26, 2023

Today I noticed the following: when changing volume via headphones buttons, cpu started to jump up and down again, but this time the volume icon of pasystray also started to quickly change between 1 and 2 bars of volume.
Maybe previously the state wasn't changing between 1 and 2 bars, so the icon wasn't flashing, but was still updating rapidly?
Feels like both i3status and pasystray get their volume information from some notification system, and headphones buttons cause volume to change indefinitely to extremely close values, e.g. 49%-51%-49%-51%-...

The headphones I use have this volume control:
image
The volume wheel pulls back by itself after you press it up or down, so it's not actually a wheel, as you can't make a full turn with it. Maybe that's exactly the reason with that 49-51% thing?

UPD: on the other hand, when this happens, it's easily fixable by changing volume with mouse wheel, while hovering over pasystray icon. So hardware buttons don't actually change volume indefinitely?

@joshuacrotts

This comment was marked as spam.

@orestisfl
Copy link
Member

This is pretty-much a side-effect of intended behavior:

i3status/src/pulse.c

Lines 133 to 134 in c07b9ca

/* if the volume, mute flag or description changed, wake the main thread */
pthread_kill(main_thread, SIGUSR1);

We wake up the main thread every time we get an event from pulseaudio. I imagine the temporary spike in the system's CPU from the change of the volume (UI elements, pulseaudio, potentially bluetooth all fire up at the same moment) is actually captured in i3status which produces a misleading number.

i3status does not from my tests cause any CPU spike/high usage so this is only a problem with what information is displayed.

As for way to fix it:

  • Perhaps we could continuously collect CPU usage data points instead of relying on the very last reading. I am not sure if we want the complexity though.
  • We could conditionally exclude fetching new CPU info on SIGUSR1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants