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

[AUDIO_WORKLET] Add compatible spinlock tests #22995

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

cwoffenden
Copy link
Contributor

@cwoffenden cwoffenden commented Nov 23, 2024

Fix for #22962. The fixes include:

  • adds tests for various spinlock cases
  • locks fixed so they work in audio worklets
  • test for atomic wait exposed as a public function
  • test renamed to match its new use
  • test converted to C-only (like the other tests, plus it wasn't using C++ features)

(The git mv lost the old to new mapping at some point)

// Note: using emscripten_get_now() over emscripten_performance_now() to allow
// compatibility with Audio Worklets (but for workers this will defer to the
// performance call with its higher granularity). We keep the non-busy locks
// using the performance version since they have waits, incompatible with AWs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not really sure we need this comment, and I think we we should probably just convert everything to emscripten_get_now.

If you do go with a comment how about "Use emscripten_get_now over emscripten_performance_now since the former is available in all contexts and uses performance.now under the hood where available.".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All the other lock types used waits, so it was a limited set of functions that could work. There’s no current benefit, unless I’m missing something, to changing all uses over to plain now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it useful to leave a comment in case someone later thinks to change it.

It does need docs adding in the web audio page to explain what locks can be used. I’ll do this, and finish the tests, in the next days.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess i just don't see the point of emscripten_performance_now at all. I'm not sure why it was ever added. Why wouldn't all callsites simply prefer emscripten_get_now? The works in more places (i.e. all places) and lowers the same thing when performance.now is available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had time to think about this: emscripten_performance_now() when supported is very lightweight (it maps directly to the browser's call). emscripten_get_now() has a bit of indirection, and for high performance code I'd prefer the option to know I'm avoiding indirection.

For this PR I've kept the change to the parts that need changing to prove out a set of lock calls work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW emscripten_get_now() maps directly to performance.now() whenever `performance.now() is available. See

emscripten/src/library.js

Lines 1393 to 1396 in 7342ee8

// Modern environment where performance.now() is supported:
// N.B. a shorter form "_emscripten_get_now = performance.now;" is
// unfortunately not allowed even in current browsers (e.g. FF Nightly 75).
emscripten_get_now: () => {{{ getPerformanceNow() }}}(),
. There is no indirection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know, thanks.

system/lib/pthread/emscripten_thread_state.S Outdated Show resolved Hide resolved
test/webaudio/audioworklet_emscripten_locks.cpp Outdated Show resolved Hide resolved
@cwoffenden cwoffenden force-pushed the cw-audio-tweaks-4 branch 2 times, most recently from b70f88c to 81bcaa2 Compare November 26, 2024 00:28
@cwoffenden cwoffenden force-pushed the cw-audio-tweaks-4 branch 8 times, most recently from cf23f0e to aa78b84 Compare December 10, 2024 17:43
@cwoffenden cwoffenden marked this pull request as ready for review December 10, 2024 17:43
@cwoffenden cwoffenden force-pushed the cw-audio-tweaks-4 branch 2 times, most recently from 1c4834e to cbd6be7 Compare December 10, 2024 21:44
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