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

Add a description of the expectation of request_callback timing #422

Merged
merged 5 commits into from
Sep 30, 2024

Conversation

baconpaul
Copy link
Collaborator

Without making a requirement, indicate the intent of the timing.

Without making a requirement, indicate the intent of the timing.
@abique
Copy link
Contributor

abique commented Sep 27, 2024

Maybe add a note saying that a realtime audio engine can steal all the CPU time if the audio computation is overloaded, and there is nothing the host can do about it.

@baconpaul
Copy link
Collaborator Author

OK changed it to this

   // Request the host to schedule a call to plugin->on_main_thread(plugin) on the main thread.
    // This callback should be called as soon as practicable, usually in the host application's next
    // available main thread time slice. Typically callbacks occur at least in the 10s-to-50s-of-milliseconds
    // or 30-120hz timeslice range. Plugins should not make assumptions about the exactness of timing for
    // a main thread callback but hosts should endeavour to be prompt. However in high load situations
    // the host may starve the gui/main thread in favor of audio processing, leading to substantially
    // longer latencies for the callback than the indicative times given here.
    // [thread-safe]

@@ -35,6 +35,12 @@ typedef struct clap_host {
void(CLAP_ABI *request_process)(const struct clap_host *host);

// Request the host to schedule a call to plugin->on_main_thread(plugin) on the main thread.
// This callback should be called as soon as practicable, usually in the host application's next
// available main thread time slice. Typically callbacks occur at least in the 10s-to-50s-of-milliseconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe:
Typically callbacks occur within at 33ms (~30Hz).

Maybe just giving an idea of the worst case is enough.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK pushed

include/clap/host.h Show resolved Hide resolved
@abique
Copy link
Contributor

abique commented Sep 27, 2024

It is not directly the host that will starve the GUI thread but simply the kernel scheduler that won't allocate resource to it.
Some plugins also setup a realtime thread pool, which can as well starve the GUI.

@baconpaul
Copy link
Collaborator Author

It is not directly the host that will starve the GUI thread but simply the kernel scheduler that won't allocate resource to it. Some plugins also setup a realtime thread pool, which can as well starve the GUI.

I'd argue on modern architectures you can usually avoid that in a well written host, but yeah I changed it from host to environment to make the blame a bit more amorphous

@abique
Copy link
Contributor

abique commented Sep 27, 2024

It is not directly the host that will starve the GUI thread but simply the kernel scheduler that won't allocate resource to it. Some plugins also setup a realtime thread pool, which can as well starve the GUI.

I'd argue on modern architectures you can usually avoid that in a well written host, but yeah I changed it from host to environment to make the blame a bit more amorphous

How would you avoid it?

@baconpaul
Copy link
Collaborator Author

It is not directly the host that will starve the GUI thread but simply the kernel scheduler that won't allocate resource to it. Some plugins also setup a realtime thread pool, which can as well starve the GUI.

I'd argue on modern architectures you can usually avoid that in a well written host, but yeah I changed it from host to environment to make the blame a bit more amorphous

How would you avoid it?

Pin your ui thread to an efficiency core and pin your audio thread to the powered cores for instance would help a lot.

@abique
Copy link
Contributor

abique commented Sep 27, 2024

Pin your ui thread to an efficiency core and pin your audio thread to the powered cores for instance would help a lot.

My computer doesn't have efficiency cores :-)
Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz

But yes, if you reserve some dedicated resources for the GUI, you can achieve it.

@baconpaul
Copy link
Collaborator Author

Ha yeah

I was just reflecting on how well bitwig and logic do this in Mac honestly when I wrote that comment

but that’s just chatter here not what I put in the pr. The pr just points out it might be worse

@abique
Copy link
Contributor

abique commented Sep 27, 2024

In Bitwig we effectively don't use the efficiency cores on macOS M1 because they rarely meet the deadline.

We should try again to use them and see if the scheduler is able to do a good job. In theory it could because there's a workgroup (deadline sched) from coreaudio that you can join, and the kernel knows that all the threads that belongs to this group have to meet the audio interface's deadline.

So it isn't a specific resource allocation for the GUI that we did but more a workaround.

@baconpaul
Copy link
Collaborator Author

gotcha.

well logic does according to my cpu meter! and it works great!

@abique abique merged commit d0f0373 into free-audio:next Sep 30, 2024
4 checks passed
@abique
Copy link
Contributor

abique commented Sep 30, 2024

Thank you 👍

abique pushed a commit that referenced this pull request Nov 1, 2024
* Add a description of the expectation of request_callback timing

Without making a requirement, indicate the intent of the timing.

* Add an apostrophe

* Add host can starve feedback from alex

* more review feedback

* notjusthosts
abique pushed a commit that referenced this pull request Nov 18, 2024
* Add a description of the expectation of request_callback timing

Without making a requirement, indicate the intent of the timing.

* Add an apostrophe

* Add host can starve feedback from alex

* more review feedback

* notjusthosts
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

Successfully merging this pull request may close these issues.

2 participants