home-assistant / plugin-audio

Pulseaudio implementation for Home Assistant
Apache License 2.0
24 stars 13 forks source link

Extra CPU usage when a USB sound card is plugged in but not used #170

Open pspot2 opened 1 month ago

pspot2 commented 1 month ago

Hi,

I have a USB sound card (Plantronics headset for testing) that I passed through in Proxmox to the VM with HA supervised installation. Everything works well, I can play sound. However, I noticed that when nothing is played and the whole system is idling around, the power consumption jumps from ca. 7W (on my particular mini-PC) to around 13W when the headset is plugged in. This is quite a lot for idle mode, so I did some digging around.

Stopping HA (e.g. disabling it in systemd and booting the VM without it) seems to solve the issue - there is now a difference of maybe 0.5W between the headset plugged and unplugged.

Running docker stats, I noticed that the hassio_audio container is constantly consuming 0.5-0.6% CPU with the headset plugged. This drops to zero when the headset is unplugged.

CONTAINER ID   NAME                      CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O   PIDS
0da538e4068b   addon_core_configurator   0.01%     22.95MiB / 3.789GiB   0.59%     1.66MB / 73.3kB   0B / 0B     8
0be40ff63796   hassio_multicast          0.00%     4.867MiB / 3.789GiB   0.13%     0B / 0B           0B / 0B     8
8a8098b5adcc   hassio_audio              0.54%     41.29MiB / 3.789GiB   1.06%     12.2kB / 0B       0B / 0B     13
8b9358433e15   hassio_dns                0.03%     6.852MiB / 3.789GiB   0.18%     24.1kB / 9.79kB   0B / 0B     15
3c947612f386   hassio_cli                0.00%     8.738MiB / 3.789GiB   0.23%     16.7kB / 3.88kB   0B / 0B     6
5e95af66986e   homeassistant             0.02%     308.5MiB / 3.789GiB   7.95%     0B / 0B           0B / 0B     25
bbe586023102   hassio_observer           0.00%     10.99MiB / 3.789GiB   0.28%     16.5kB / 2.1kB    0B / 0B     5
adc400fa772e   hassio_supervisor         0.00%     169.5MiB / 3.789GiB   4.37%     727kB / 2.72MB    0B / 0B     26

Below are more details about my environment:

cat /etc/os-release

``` PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" ```

uname -a

``` Linux home-assistant 6.1.0-20-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.85-1 (2024-04-11) x86_64 GNU/Linux ```

ha info

``` arch: amd64 channel: stable docker: 26.1.1 features: - reboot - shutdown - services - network - hostname - timedate - os_agent - resolved - journal - disk - mount hassos: null homeassistant: 2024.4.4 hostname: home-assistant logging: info machine: qemux86-64 operating_system: Debian GNU/Linux 12 (bookworm) state: running supervisor: 2024.04.4 supported: true supported_arch: - amd64 - i386 timezone: Europe/Berlin ```

ha audio info

``` audio: application: [] card: - driver: module-alsa-card.c index: 1 name: alsa_card.usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-00 profiles: - active: false description: Analog Stereo Input name: input:analog-stereo - active: false description: Digital Stereo (IEC958) Input name: input:iec958-stereo - active: false description: Analog Stereo Output name: output:analog-stereo - active: true description: Analog Stereo Duplex name: output:analog-stereo+input:analog-stereo - active: false description: Analog Stereo Output + Digital Stereo (IEC958) Input name: output:analog-stereo+input:iec958-stereo - active: false description: Digital Stereo (IEC958) Output name: output:iec958-stereo - active: false description: Digital Stereo (IEC958) Output + Analog Stereo Input name: output:iec958-stereo+input:analog-stereo - active: false description: Digital Stereo Duplex (IEC958) name: output:iec958-stereo+input:iec958-stereo - active: false description: "Off" name: "off" input: - applications: [] card: 1 default: true description: Plantronics C725 Analog Stereo index: 4 mute: false name: alsa_input.usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-00.analog-stereo volume: 0.8912506103515625 output: - applications: [] card: 1 default: true description: Plantronics C725 Analog Stereo index: 2 mute: false name: alsa_output.usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-00.analog-stereo volume: 0.8333282470703125 host: 172.30.32.4 update_available: false version: 2023.12.0 version_latest: 2023.12.0 ```

pactl info

``` Server String: unix://run/audio/pulse.sock Library Protocol Version: 35 Server Protocol Version: 35 Is Local: yes Client Index: 0 Tile Size: 65472 User Name: root Host Name: hassio-audio Server Name: pulseaudio Server Version: 16.1 Default Sample Specification: s16le 2ch 44100Hz Default Channel Map: front-left,front-right Default Sink: alsa_output.usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-00.analog-stereo Default Source: alsa_input.usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-00.analog-stereo Cookie: 1329:46e3 ```

journalctl log when the headset is plugged:

``` May 03 23:29:45 home-assistant kernel: usb 3-1: new full-speed USB device number 4 using xhci_hcd May 03 23:29:45 home-assistant kernel: usb 3-1: New USB device found, idVendor=047f, idProduct=c034, bcdDevice= 1.35 May 03 23:29:45 home-assistant kernel: usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 May 03 23:29:45 home-assistant kernel: usb 3-1: Product: Plantronics C725 May 03 23:29:45 home-assistant kernel: usb 3-1: Manufacturer: Plantronics May 03 23:29:45 home-assistant kernel: usb 3-1: SerialNumber: BC1B9FDA711E5D4C8232961FCC6F1C5C May 03 23:29:46 home-assistant kernel: usb 3-1: Warning! Unlikely big volume range (=8192), cval->res is probably wrong. May 03 23:29:46 home-assistant kernel: usb 3-1: [11] FU [Sidetone Playback Volume] ch = 1, val = 0/8192/1 May 03 23:29:47 home-assistant hassio_audio[557]: [23:29:47] INFO: Add ALSA mixer: controlC1 May 03 23:29:47 home-assistant kernel: input: Plantronics Plantronics C725 as /devices/pci0000:00/0000:00:1e.0/0000:05:02.0/0000:07:1b.0/usb3/3-1/3-1:1.3/0003:047F:C034.0003/input/input7 May 03 23:29:47 home-assistant kernel: plantronics 0003:047F:C034.0003: input,hiddev0,hidraw0: USB HID v1.11 Device [Plantronics Plantronics C725] on usb-0000:07:1b.0-1/input3 May 03 23:29:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:48.002 INFO (MainThread) [supervisor.hardware.monitor] Detecting add hardware /dev/bus/usb/003/004 - None May 03 23:29:49 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:49.441 INFO (MainThread) [supervisor.hardware.monitor] Detecting add hardware /dev/snd/pcmC1D0p - None May 03 23:29:49 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:49.442 INFO (MainThread) [supervisor.hardware.monitor] Detecting add hardware /dev/snd/pcmC1D0c - None May 03 23:29:49 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:49.443 INFO (MainThread) [supervisor.hardware.monitor] Detecting add hardware /dev/snd/controlC1 - /dev/snd/by-id/usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-00 May 03 23:29:49 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:49.443 INFO (MainThread) [supervisor.host.sound] Updating PulseAudio information May 03 23:29:49 home-assistant hassio_audio[557]: W: [pulseaudio] module-udev-detect.c: Failed to open /proc/asound/card0: No such file or directory May 03 23:29:49 home-assistant hassio_audio[557]: E: [pulseaudio] module-alsa-card.c: Failed to find a working profile. May 03 23:29:49 home-assistant hassio_audio[557]: E: [pulseaudio] module.c: Failed to load module "module-alsa-card" (argument: "device_id="0" name="pci-0000_00_1b.0" card_name="alsa_card.pci-0000_00_1b.0" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes avoid_resampling=no card_properties="module-udev-detect.discovered=1""): initialization failed. May 03 23:29:49 home-assistant hassio_audio[557]: W: [pulseaudio] module-udev-detect.c: Failed to open /proc/asound/card1: No such file or directory May 03 23:29:49 home-assistant hassio_audio[557]: W: [pulseaudio] alsa-mixer.c: The decibel volume range for element 'Headset' (-5300 dB - -500 dB) has negative maximum. Disabling the decibel range. May 03 23:29:49 home-assistant hassio_audio[557]: N: [pulseaudio] alsa-util.c: Disabling timer-based scheduling because running inside a VM. May 03 23:29:49 home-assistant hassio_audio[557]: N: [pulseaudio] alsa-util.c: Disabling timer-based scheduling because running inside a VM. May 03 23:29:49 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:49.760 INFO (MainThread) [supervisor.hardware.monitor] Detecting add hardware /dev/input/event3 - /dev/input/by-id/usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-event-if03 May 03 23:29:49 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:49.761 INFO (MainThread) [supervisor.hardware.monitor] Detecting add hardware /dev/usb/hiddev0 - None May 03 23:29:49 home-assistant hassio_supervisor[557]: 2024-05-03 23:29:49.762 INFO (MainThread) [supervisor.hardware.monitor] Detecting add hardware /dev/hidraw0 - None ```

journalctl log when the headset is unplugged:

``` May 03 23:28:48 home-assistant hassio_audio[557]: W: [alsa-source-USB Audio] alsa-util.c: Got POLLNVAL from ALSA May 03 23:28:48 home-assistant hassio_audio[557]: W: [alsa-sink-USB Audio] alsa-util.c: Got POLLNVAL from ALSA May 03 23:28:48 home-assistant kernel: usb 3-1: USB disconnect, device number 3 May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.882 INFO (MainThread) [supervisor.hardware.monitor] Detecting remove hardware /dev/snd/controlC1 - /dev/snd/by-id/usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-00 May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.882 INFO (MainThread) [supervisor.host.sound] Updating PulseAudio information May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.883 INFO (MainThread) [supervisor.hardware.monitor] Detecting remove hardware /dev/snd/pcmC1D0p - None May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.884 INFO (MainThread) [supervisor.hardware.monitor] Detecting remove hardware /dev/snd/pcmC1D0c - None May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.901 INFO (MainThread) [supervisor.hardware.monitor] Detecting remove hardware /dev/input/event3 - /dev/input/by-id/usb-Plantronics_Plantronics_C725_BC1B9FDA711E5D4C8232961FCC6F1C5C-event-if03 May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.922 INFO (MainThread) [supervisor.hardware.monitor] Detecting remove hardware /dev/usb/hiddev0 - None May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.922 INFO (MainThread) [supervisor.hardware.monitor] Detecting remove hardware /dev/hidraw0 - None May 03 23:28:48 home-assistant hassio_supervisor[557]: 2024-05-03 23:28:48.923 INFO (MainThread) [supervisor.hardware.monitor] Detecting remove hardware /dev/bus/usb/003/003 - None May 03 23:28:48 home-assistant hassio_audio[557]: E: [alsa-source-USB Audio] alsa-source.c: Error opening PCM device front:1: No such file or directory May 03 23:28:48 home-assistant hassio_audio[557]: W: [pulseaudio] module-udev-detect.c: Failed to open /proc/asound/card0: No such file or directory May 03 23:28:49 home-assistant hassio_audio[557]: E: [pulseaudio] module-alsa-card.c: Failed to find a working profile. May 03 23:28:49 home-assistant hassio_audio[557]: E: [pulseaudio] module.c: Failed to load module "module-alsa-card" (argument: "device_id="0" name="pci-0000_00_1b.0" card_name="alsa_card.pci-0000_00_1b.0" namereg_fail=false tsched=yes fixed_latency_range=no ignore_dB=no deferred_volume=yes use_ucm=yes avoid_resampling=no card_properties="module-udev-detect.discovered=1""): initialization failed. ```
pspot2 commented 1 month ago

Today the CPU usage went up to 5% and stayed there:

CONTAINER ID   NAME                      CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O   PIDS
fd62f1b06917   addon_a0d7b954_vscode     0.01%     141.7MiB / 3.789GiB   3.65%     12MB / 57.5MB     0B / 0B     29
b11b983dcc35   hassio_supervisor         0.00%     184.4MiB / 3.789GiB   4.75%     209MB / 712MB     0B / 0B     32
b7a36cfe077a   hassio_cli                0.00%     1.289MiB / 3.789GiB   0.03%     105kB / 0B        0B / 0B     6
967296532b50   homeassistant             0.02%     287.9MiB / 3.789GiB   7.42%     0B / 0B           0B / 0B     24
0da538e4068b   addon_core_configurator   0.01%     24.88MiB / 3.789GiB   0.64%     1.31GB / 48.3MB   0B / 0B     8
0be40ff63796   hassio_multicast          0.00%     3.715MiB / 3.789GiB   0.10%     0B / 0B           0B / 0B     8
8a8098b5adcc   hassio_audio              5.37%     42.85MiB / 3.789GiB   1.10%     240kB / 0B        0B / 0B     13
8b9358433e15   hassio_dns                0.01%     19.32MiB / 3.789GiB   0.50%     1.23MB / 653kB    0B / 0B     16
bbe586023102   hassio_observer           0.00%     18.22MiB / 3.789GiB   0.47%     2.46MB / 1.54MB   0B / 0B     5

The power consumption went from 12W to 21W without the system playing any audio.

After unplugging the device the CPU went back to 0%.