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

FFT Window Threadsafety #7145

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

marcusmueller
Copy link
Member

@marcusmueller marcusmueller commented Feb 21, 2024

Description

I add locks around window setting/usage.

As a drive-by improvement, let's not use floor, ceil to implement (inherent) integer division semantics.

Related Issue

Fixes #7144

Which blocks/areas does this affect?

FFT

Testing Done

Checklist

@willcode willcode added fft Bug Fix Backport-3.10 Should be backported to 3.10 labels Feb 22, 2024
@marcusmueller marcusmueller marked this pull request as ready for review February 22, 2024 18:43
Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
…antics

Also, remove unused config.h

Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
Copy link
Member

@daniestevez daniestevez left a comment

Choose a reason for hiding this comment

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

The code looks good to me, but performance-wise I'm wondering if it wouldn't be better to get the window lock at the beginning of the work() function and hold it for the whole duration of work(). I'm slightly worried that if the FFT size is small, locking and unlocking the mutex for each individual FFT might introduce too much overhead.

@willcode
Copy link
Member

CI stopped on Python formatting:
/gr-fft/python/fft/qa_fft.py:288:76: E226 missing whitespace around arithmetic operator

Copy link
Member

@mbr0wn mbr0wn left a comment

Choose a reason for hiding this comment

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

I tend to agree with @daniestevez, although I don't know about the performance overhead. But what if we flip it around: If we unlock sooner, we get better concurrency. To which I say "so what", what's the value of being able to call set_window() more often from a different thread. So if we lock for the duration of work(), we get maybe some, maybe very little performance gains, but we lose nothing of value.

gr-fft/python/fft/qa_fft.py Outdated Show resolved Hide resolved
@daniestevez
Copy link
Member

@mbr0wn that's exactly what I had in mind. set_window() will typically be called infrequently, and it can wait until work() finishes to update the window.

Co-authored-by: Martin Braun <mail@martin-braun.org>
@marcusmueller
Copy link
Member Author

I'm fine either way, but I remember I had to be finer in locking granularity in one place, because otherwise I could deadlock our CI, then made it consistent in every place. Will have to check what the precise reason was, and whether it affects work, probably not. Anyways, currently no time, so this becomes a draft for now.

@marcusmueller marcusmueller marked this pull request as draft March 7, 2024 14:52
@mbr0wn mbr0wn added the medium label Mar 11, 2024
"""
for fftlength in [1, 2, 3] + [2**i for i in range(2, 10)] + list(primes):
self.assertTrue(self._set_length_and_test(fftlength, fftlength))
self.assertFalse(self._set_length_and_test(fftlength, fftlength+2))
Copy link
Contributor

@StudHamza StudHamza Mar 27, 2024

Choose a reason for hiding this comment

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

Not sure if this will solve ./gr-fft/python/fft/qa_fft.py:288:76: E226 missing whitespace around arithmetic operator but probability it will, according to E226

Suggested change
self.assertFalse(self._set_length_and_test(fftlength, fftlength+2))
self.assertFalse(self._set_length_and_test(fftlength, fftlength + 2 ))

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

Successfully merging this pull request may close these issues.

FFT block: thread-unsafe window setting
5 participants