Fix #129162: High idle CPU usage with PulseAudio in Linux #129312

Merged
Sebastian Parborg merged 1 commits from neXyon/blender:fix_129162 into blender-v4.3-release 2024-10-29 16:19:22 +01:00
Member

Prevents the unnecessary calls to CPU intensive pulseaudio functions while the stream is corked.

Prevents the unnecessary calls to CPU intensive pulseaudio functions while the stream is corked.
Joerg Mueller added this to the 4.3 milestone 2024-10-21 20:27:25 +02:00
Joerg Mueller added the
Interest
Audio
label 2024-10-21 20:27:25 +02:00
Alaska was assigned by Joerg Mueller 2024-10-21 20:27:26 +02:00
Joerg Mueller added 1 commit 2024-10-21 20:27:38 +02:00
Alaska requested review from Sergey Sharybin 2024-10-22 05:08:57 +02:00
Alaska requested review from Sebastian Parborg 2024-10-22 05:08:58 +02:00
Alaska removed their assignment 2024-10-22 05:09:04 +02:00
Member

I have added Sergey and Sebastian as reviewers because they're more familiar with this area.

A note for Sergey and Sebastian, the high CPU usage issue was introduced in Blender 4.3.
Joerg then commited a fix to main. I advised them that Blender 4.3 also needs the bug fix, and advised them to open a PR (as it's best to go through review for changes to 4.3 this late in the development cycle)

As a result of this there will be merge conflicts when merging 4.3 into main after this change is commited to 4.3.

I have added Sergey and Sebastian as reviewers because they're more familiar with this area. A note for Sergey and Sebastian, the high CPU usage issue was introduced in Blender 4.3. Joerg then commited a fix to main. I advised them that Blender 4.3 also needs the bug fix, and advised them to open a PR (as it's best to go through review for changes to 4.3 this late in the development cycle) As a result of this there will be merge conflicts when merging 4.3 into main after this change is commited to 4.3.
Sergey Sharybin reviewed 2024-10-22 14:54:10 +02:00
Sergey Sharybin left a comment
Owner

I wouldn't be able to test this, as I don't have an easy access to Linux machines at this time.

The PR would definitely benefit from more explanation of what's going on, and what the fix actually does.
One of the strange things to me is a non-guarded access and write to the m_corked variable (which seems it can get out of sync with the parameter passed to AUD_pa_stream_cork.

I wouldn't be able to test this, as I don't have an easy access to Linux machines at this time. The PR would definitely benefit from more explanation of what's going on, and what the fix actually does. One of the strange things to me is a non-guarded access and write to the `m_corked` variable (which seems it can get out of sync with the parameter passed to `AUD_pa_stream_cork`.
Author
Member

I wouldn't be able to test this, as I don't have an easy access to Linux machines at this time.

The PR would definitely benefit from more explanation of what's going on, and what the fix actually does.

Added a short description.

One of the strange things to me is a non-guarded access and write to the m_corked variable (which seems it can get out of sync with the parameter passed to AUD_pa_stream_cork.

How is it unguarded? Please check again. All accesses to m_corked are properly guarded with a lock_guard!

> I wouldn't be able to test this, as I don't have an easy access to Linux machines at this time. > > The PR would definitely benefit from more explanation of what's going on, and what the fix actually does. Added a short description. > One of the strange things to me is a non-guarded access and write to the `m_corked` variable (which seems it can get out of sync with the parameter passed to `AUD_pa_stream_cork`. How is it unguarded? Please check again. All accesses to `m_corked` are properly guarded with a `lock_guard`!

Added a short description.

Thanks!

All accesses to m_corked are properly guarded with a lock_guard!

Ok, I've missed that! What seemed weird to me is that the AUD_pa_stream_cork() is guarded by the lock on m_mainloop, while m_corked = true; is not:

std::lock_guard<ILockable> device_lock(*this);
...
AUD_pa_threaded_mainloop_lock(m_mainloop);
AUD_pa_stream_cork(m_stream, 1, nullptr, nullptr);
AUD_pa_stream_flush(m_stream, nullptr, nullptr);
AUD_pa_threaded_mainloop_unlock(m_mainloop);
m_corked = true;

Keep in mind, not saying it is mistake in the code, just something that seemed a bit odd. If you confirm it's actually all fine -- I'm fine with it too!

> Added a short description. Thanks! > All accesses to `m_corked` are properly guarded with a `lock_guard`! Ok, I've missed that! What seemed weird to me is that the `AUD_pa_stream_cork()` is guarded by the lock on `m_mainloop`, while `m_corked = true;` is not: ``` std::lock_guard<ILockable> device_lock(*this); ... AUD_pa_threaded_mainloop_lock(m_mainloop); AUD_pa_stream_cork(m_stream, 1, nullptr, nullptr); AUD_pa_stream_flush(m_stream, nullptr, nullptr); AUD_pa_threaded_mainloop_unlock(m_mainloop); m_corked = true; ``` Keep in mind, not saying it is mistake in the code, just something that seemed a bit odd. If you confirm it's actually all fine -- I'm fine with it too!
Author
Member

Yep, its' alright. The pa main loop only needs to be locked during the flush and cork calls. It doesn't matter if m_corked is written while it's locked or not as it is not accessed by the main loop.

I'm always trying to lock as briefly as possible though a bool assignment likely has little to no impact. That's why I put it outside.

Yep, its' alright. The pa main loop only needs to be locked during the flush and cork calls. It doesn't matter if `m_corked` is written while it's locked or not as it is not accessed by the main loop. I'm always trying to lock as briefly as possible though a bool assignment likely has little to no impact. That's why I put it outside.
Sergey Sharybin approved these changes 2024-10-25 07:36:12 +02:00
Sergey Sharybin left a comment
Owner

Thanks for checking and explaining!

TL;DR: I think it's better to land the fix soon.

We are currently at the Blender conference, and I don't have access to a Linux box to test. But I'd trust your tests! Since it is for 4.3, it's better to land it soon, so that we have the best chance of people trying it out before the release (for the unlikely scenario we've missed something).

Thanks for checking and explaining! TL;DR: I think it's better to land the fix soon. We are currently at the Blender conference, and I don't have access to a Linux box to test. But I'd trust your tests! Since it is for 4.3, it's better to land it soon, so that we have the best chance of people trying it out before the release (for the unlikely scenario we've missed something).
Sebastian Parborg approved these changes 2024-10-29 16:17:57 +01:00
Sebastian Parborg left a comment
Member

LGTM

LGTM
Sebastian Parborg merged commit 97e9a722fc into blender-v4.3-release 2024-10-29 16:19:22 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#129312
No description provided.