[PD] Re: AOO plugin for PD on SGI Irix
All works now, Great! I love clean solutions! Me too :) In the next AOO version I might use sync::shared_spinlock for the update lock resp. provide a compile time option to choose between mutex and spinlock. The reason is that a mutex try-lock is not guaranteed to be realtime safe because the *unlock* operation might have to wake up waiting threads, which requires calling into the kernel. (In practice, I think unlocking a mutex should be comparable to signalling a semaphore, which is a pretty common thing in audio apps. Nevertheless, I want to give people a 100% realtime safe option.) Christof On 8/13/2026 5:27 PM, Wolfgang Gaggl via Pd-list wrote: As I said, you just need to replace the shared_mutex with a shared_spinlock. Yes, that was the best solution all along! In sink.hpp #if defined(__sgi) && defined(__mips__) using sink_update_lock = sync::shared_spinlock; #else using sink_update_lock = sync::shared_mutex; #endif And further down: private: using shared_lock = sync::shared_lock; // sink_update_lock, not shared_mutex using unique_lock = sync::unique_lock; using scoped_lock = sync::scoped_lock; using scoped_shared_lock = sync::scoped_shared_lock; In source.hpp #if defined(__sgi) && defined(__mips__) using source_update_lock = sync::shared_spinlock; #else using source_update_lock = sync::shared_mutex; #endif and further down: private: using shared_lock = sync::shared_lock; // source_update_lock, not shared_mutex using unique_lock = sync::unique_lock; using scoped_lock = sync::scoped_lock; using scoped_shared_lock = sync::scoped_shared_lock; using scoped_spinlock = sync::scoped_lock; Or maybe just once in sync.hpp... No changes in source.cpp or sink.cpp needed (even the try_to_lock works fine as is). All works now, I love clean solutions! Thank you! --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/HSGOXJKTTKJ6D3G4WPQFK2KLXD5S3FSJ/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/ --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/QFDZWY4R5TKDFP7MV7N4KUKB66IERB3A/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
>> As I said, you just need to replace the shared_mutex with a shared_spinlock. Yes, that was the best solution all along! In sink.hpp #if defined(__sgi) && defined(__mips__) using sink_update_lock = sync::shared_spinlock; #else using sink_update_lock = sync::shared_mutex; #endif And further down: private: using shared_lock = sync::shared_lock; // sink_update_lock, not shared_mutex using unique_lock = sync::unique_lock; using scoped_lock = sync::scoped_lock; using scoped_shared_lock = sync::scoped_shared_lock; In source.hpp #if defined(__sgi) && defined(__mips__) using source_update_lock = sync::shared_spinlock; #else using source_update_lock = sync::shared_mutex; #endif and further down: private: using shared_lock = sync::shared_lock; // source_update_lock, not shared_mutex using unique_lock = sync::unique_lock; using scoped_lock = sync::scoped_lock; using scoped_shared_lock = sync::scoped_shared_lock; using scoped_spinlock = sync::scoped_lock; Or maybe just once in sync.hpp... No changes in source.cpp or sink.cpp needed (even the try_to_lock works fine as is). All works now, I love clean solutions! Thank you! --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/HSGOXJKTTKJ6D3G4WPQFK2KLXD5S3FSJ/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
On 8/13/2026 12:04 AM, Wolfgang Gaggl via Pd-list wrote:
I have been thinking: how could anyone implement synchronization
primitives without reliable atomic operations? To me, a bug in the
pthread_rwlock implementation seems more likely.
Generally, it all seems to work, including atomics.
I believe there's an issue with the GCC implementation for pthread_rwlock on
this platform; as far I can observe only with the try_to_lock shared_lock.
There are some mentioned differences (occasionally having to try_to_lock
multiple times to get a lock on an uncontested lock) that I can also see on the
native MIPSPro compiler.
But at times it fails to get a reader lock with try_to_lock when another
scoped_shared_lock is active which looks like a bug.
I observed this only in GCC. Since the native MIPSPro compiler supports only
C++98 I didn't fully test the exact scenario with the specific timing there.
Since you pointed out that sink.cpp may have concurrent writers active during
the stream I chose another way to do this.
std::atomic process_active_{0};
std::atomic writer_gate_{0};
In source_desc::process():
// Writers set writer_gate_ and wait for process_active_ == 0 before
mutating
// This prevents writer/process overlap without using rwlock try_lock in
audio path.
if (writer_gate_.load(std::memory_order_acquire) != 0) {
if (stream_state_ != stream_state::inactive) {
LOG_DEBUG("AooSink: process blocked by writer gate");
add_xrun(1);
}
}
// process() sets process_active_ to to set writer block
sink_process_activity_guard process_guard(process_active_);
// For the extra-cautious, recheck after announcing active status to avoid
race condition.
if (writer_gate_.load(std::memory_order_acquire) != 0) {
if (stream_state_ != stream_state::inactive) {
LOG_DEBUG("AooSink: process blocked by writer gate");
add_xrun(1);
}
}
// now do the processing stuff...
}
For all writer calls:
// Writer gate guard: blocks new process() entries while a writer is
pending.
sink_writer_gate_guard _writer_gate(writer_gate_);
// This function loops pause_cpu() while process() is active
wait_for_sink_process_idle(process_active_);
// do write stuff...
This looks overly complicated to me. I can't even tell if it's correct
without looking at the implementation of sink_process_activity_guard,
sink_writer_gate_guard and wait_for_sink_process_idle. In general, I
would advice against ad-hoc solutions with atomics. If possible, stick
to standard synchronization patterns.
(BTW, that additional writer_gate_.load(std::memory_order_acquire) is
essential because otherwise you run into the ABA problem.)
As I said, you just need to replace the shared_mutex with a
shared_spinlock. Apart from that you can revert back to the original
code. (The process() method does a try-lock, but because it's now a
simple CAS operation there is no need for a retry-loop. By default, the
readers and writers would do full spinlocks, but you can replace them
with try-lock loops that occasionally sleep for a short time to fight
priority inversion.)
Christof
This method does not block in the process() thread and avoids using the
problematic try_to_lock.
It also uses fewer CPU cycles than looping try_to_lock in process().
As you suggested, I tested it by changing format parameters during the running
stream in quick succession to see if I can break it, but it all works without
issues.
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/6323HU2BWSBL2R4RPCZBSRS3XBLWW3P5/
To unsubscribe send an email [email protected] mailing list
UNSUBSCRIBE and account-management ->https://lists.iem.at/
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/T6TL6VSZEPVPZF55H36XAVWY4FJ22RF3/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
>> I have been thinking: how could anyone implement synchronization
primitives without reliable atomic operations? To me, a bug in the
pthread_rwlock implementation seems more likely.
Generally, it all seems to work, including atomics.
I believe there's an issue with the GCC implementation for pthread_rwlock on
this platform; as far I can observe only with the try_to_lock shared_lock.
There are some mentioned differences (occasionally having to try_to_lock
multiple times to get a lock on an uncontested lock) that I can also see on the
native MIPSPro compiler.
But at times it fails to get a reader lock with try_to_lock when another
scoped_shared_lock is active which looks like a bug.
I observed this only in GCC. Since the native MIPSPro compiler supports only
C++98 I didn't fully test the exact scenario with the specific timing there.
Since you pointed out that sink.cpp may have concurrent writers active during
the stream I chose another way to do this.
std::atomic process_active_{0};
std::atomic writer_gate_{0};
In source_desc::process():
// Writers set writer_gate_ and wait for process_active_ == 0 before
mutating
// This prevents writer/process overlap without using rwlock try_lock in
audio path.
if (writer_gate_.load(std::memory_order_acquire) != 0) {
if (stream_state_ != stream_state::inactive) {
LOG_DEBUG("AooSink: process blocked by writer gate");
add_xrun(1);
}
}
// process() sets process_active_ to to set writer block
sink_process_activity_guard process_guard(process_active_);
// For the extra-cautious, recheck after announcing active status to avoid
race condition.
if (writer_gate_.load(std::memory_order_acquire) != 0) {
if (stream_state_ != stream_state::inactive) {
LOG_DEBUG("AooSink: process blocked by writer gate");
add_xrun(1);
}
}
// now do the processing stuff...
}
For all writer calls:
// Writer gate guard: blocks new process() entries while a writer is
pending.
sink_writer_gate_guard _writer_gate(writer_gate_);
// This function loops pause_cpu() while process() is active
wait_for_sink_process_idle(process_active_);
// do write stuff...
This method does not block in the process() thread and avoids using the
problematic try_to_lock.
It also uses fewer CPU cycles than looping try_to_lock in process().
As you suggested, I tested it by changing format parameters during the running
stream in quick succession to see if I can break it, but it all works without
issues.
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/6323HU2BWSBL2R4RPCZBSRS3XBLWW3P5/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
On 8/12/2026 3:31 AM, Wolfgang Gaggl via Pd-list wrote: Since atomic RMW operations might fail spuriously on your platform, you would need a bounded retry-loop in the process() method, like you had before. That is a point I am still a bit unsure about. I have done a lot of testing by now and the only failure case or long time delays to get a lock I have actually observed is the try_to_lock reader. But I have not measured how long blocking locks actually take, but they do what's expected of them. I have been thinking: how could anyone implement synchronization primitives without reliable atomic operations? To me, a bug in the pthread_rwlock implementation seems more likely. However, I know next to nothing about SGI or MIPS, so all I can do is speculate. All good points re locks. In [aoo_receive~] the network thread might actually take a writer lock, see source_desc::handle_start. How do you suggest to test a failure of this during a running stream? Starting/Stopping by itself seems fine. If you send "stop" before "start", the source_desc::process() method returns early and therefore doesn't touch the shared data until the next "start" message has been processed. Send the "start" message (without "stop" messages) or change the format many times in quick succession. Without proper synchronization, you should eventually trigger a data trace. Thanks, Wolfgang --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/T7FW35VSQ5N2TJBHG5IVYP7QSH52X2XO/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/ --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/6X7FDAFLQEOMLIJ7BHJOC4KHV7OCBTEX/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
>> Since atomic RMW operations might fail spuriously on your platform, you would need a bounded retry-loop in the process() method, like you had before. That is a point I am still a bit unsure about. I have done a lot of testing by now and the only failure case or long time delays to get a lock I have actually observed is the try_to_lock reader. But I have not measured how long blocking locks actually take, but they do what's expected of them. All good points re locks. >> In [aoo_receive~] the network thread might actually take a writer lock, see source_desc::handle_start. How do you suggest to test a failure of this during a running stream? Starting/Stopping by itself seems fine. Thanks, Wolfgang --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/T7FW35VSQ5N2TJBHG5IVYP7QSH52X2XO/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
On 8/12/2026 2:00 AM, Wolfgang Gaggl via Pd-list wrote:
I would not expect #3 to follow from #1. #1 just means I have to try a few
times due to system architecture, but a scoped_shared_lock is still a reader
lock. So they should work simultaneously, you should not have to wait for a
scoped_shared_lock to release the lock before the shared_lock(try_to_lock) can
obtain a reader lock as long as there is no writer requesting a lock at the
same time.
Whether it's a bug or not, it does not behave as I would expect it here.
Aha, so you are saying that the shared try lock would not succeed at all
while another thread holds a shared lock? That would be very bad indeed.
write_guard (always non-blocking):
std::atomic update_gen_{0}; // seqlock generation: even=idle, odd=write in progress
struct update_write_guard {
std::atomic& gen_;
explicit update_write_guard(std::atomic& g) : gen_(g) {
g.fetch_add(1, std::memory_order_release);
}
~update_write_guard() {
gen_.fetch_add(1, std::memory_order_release);
}
update_write_guard(const update_write_guard&) = delete;
update_write_guard& operator=(const update_write_guard&) = delete;
};
Before every write lock call for update_mutex_:
update_write_guard uwg(update_gen_);
scoped_lock lock(update_mutex_); // writer lock!
Replace reader lock try_to_lock in process() of source.cpp with this:
auto gen_before = update_gen_.load(std::memory_order_acquire);
if (gen_before & 1) {
// a write is currently in progress
LOG_DEBUG("AooSource: process blocked by active writer");
add_xrun(nsamples);
return kAooErrorIdle;
}
// we are good to go now!
// do processing stuff here
// done with processing stuff.
// Verify no write occurred while audio was being processed.
if (update_gen_.load(std::memory_order_acquire) != gen_before) {
LOG_DEBUG("AooSource: write detected during audio processing, xrun");
add_xrun(nsamples);
return kAooErrorIdle;
}
return kAooOk;
Similar in sink.cpp.
This assumes that typically there's generally low probability of writer lock
activity going on during process() execution.
Works well so far (at least for PD objects).
This doesn't look right. First, the seq lock only works with a single
writer, so the scoped_lock must come before the 'update_write_guard' to
prevent concurrent access. Also, the 'update_write_guard' does not look
correct. You can't write a seqlock with only acquire-release operations,
you need full barriers to prevent the compiler from reordering the
instructions in any direction. See for example:
https://github.com/rigtorp/Seqlock/blob/master/include/rigtorp/Seqlock.h
But most importantly, a seqlock can only be used for reading/writing
trivial objects in memory because there can be data races and those must
be "safe". In your case, you are accessing all kinds of shared data
structures in the process() method after the first load() succeeds, but
nothing prevents another thread from concurrently modifying the data and
wreaking havoc.
Your code only works as long as all writers run on the same thread as
the process() method. But then why do you need the seqlock in the first
place? You can just get rid of the try_lock and call it a day. However,
this is only true for [aoo_send~]. In [aoo_receive~] the network thread
might actually take a writer lock, see source_desc::handle_start.
If you want a "proper" fix, you can replace the shared_mutex with a
shared_spinlock. To avoid burning CPU cycles on contention, you can
replace the blocking shared|unique locks with shared|unique try locks in
a loop with some backoff. Since atomic RMW operations might fail
spuriously on your platform, you would need a bounded retry-loop in the
process() method, like you had before.
Christof
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/BQSSH5QXUGFTNDVRY6NB7PSICXMVZ7OH/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/GSRPG225B6ATTAYMZHWB5VGDTZVRXR33/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
I would not expect #3 to follow from #1. #1 just means I have to try a few
times due to system architecture, but a scoped_shared_lock is still a reader
lock. So they should work simultaneously, you should not have to wait for a
scoped_shared_lock to release the lock before the shared_lock(try_to_lock) can
obtain a reader lock as long as there is no writer requesting a lock at the
same time.
Whether it's a bug or not, it does not behave as I would expect it here.
write_guard (always non-blocking):
std::atomic update_gen_{0}; // seqlock generation: even=idle,
odd=write in progress
struct update_write_guard {
std::atomic& gen_;
explicit update_write_guard(std::atomic& g) : gen_(g) {
g.fetch_add(1, std::memory_order_release);
}
~update_write_guard() {
gen_.fetch_add(1, std::memory_order_release);
}
update_write_guard(const update_write_guard&) = delete;
update_write_guard& operator=(const update_write_guard&) = delete;
};
Before every write lock call for update_mutex_:
update_write_guard uwg(update_gen_);
scoped_lock lock(update_mutex_); // writer lock!
Replace reader lock try_to_lock in process() of source.cpp with this:
auto gen_before = update_gen_.load(std::memory_order_acquire);
if (gen_before & 1) {
// a write is currently in progress
LOG_DEBUG("AooSource: process blocked by active writer");
add_xrun(nsamples);
return kAooErrorIdle;
}
// we are good to go now!
// do processing stuff here
// done with processing stuff.
// Verify no write occurred while audio was being processed.
if (update_gen_.load(std::memory_order_acquire) != gen_before) {
LOG_DEBUG("AooSource: write detected during audio processing, xrun");
add_xrun(nsamples);
return kAooErrorIdle;
}
return kAooOk;
Similar in sink.cpp.
This assumes that typically there's generally low probability of writer lock
activity going on during process() execution.
Works well so far (at least for PD objects).
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/BQSSH5QXUGFTNDVRY6NB7PSICXMVZ7OH/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Glad you found a solution! 3) I'm also convinced now that there is indeed a subtle bug in the gcc pthread implementation for the mips4 architecture; a scoped_shared_lock as in handle_data() in sink.cpp can sometimes make the shared_lock try_to_lock in process() fail, which should not happen. doesn't that follow from 1)? So I decided to avoid the try_to_lock shared reader lock in process() for sink.cpp and source.cpp and converted it to a write_guard (RAII) / generation counter (keeping all the other write and read locks the same, just for that reader trylock). Can you tell me more about that write_guard / generation counter? How does it work? Christof On 8/12/2026 12:41 AM, Wolfgang Gaggl via Pd-list wrote: Finally, I found a good solution for this trylock issue. It appears that there are a few things going on platform and compiler dependent: 1) In Irix, trylock does not guarantee a lock on the first try by design even if uncontested as mentioned in my previous post; trying it a few times can fix that 2) It appears that trylock can take a bit longer depending on what the system is doing at the time. Context switching is expensive for this architecture, I observed that to be even more unpredictable on the Origin than the Octane, since the NUMA bus and page/cache migration between node boards add layers of complexity. This can increase the time to obtain a lock. 3) I'm also convinced now that there is indeed a subtle bug in the gcc pthread implementation for the mips4 architecture; a scoped_shared_lock as in handle_data() in sink.cpp can sometimes make the shared_lock try_to_lock in process() fail, which should not happen. And these are very busy, so any lock failures are eventually converted into xruns. So I decided to avoid the try_to_lock shared reader lock in process() for sink.cpp and source.cpp and converted it to a write_guard (RAII) / generation counter (keeping all the other write and read locks the same, just for that reader trylock). It works really well since this lock is not contested usually, no looping needed, no apparent performance expense. I'm really happy with AOO for PD on SGI Irix now! --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/4ZIU4SQPNYQGO25ORB7KJFMMHRCZYWZT/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/ --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/2HYTBMVKINADEE67F6NGP3EWNNOFNW5M/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Finally, I found a good solution for this trylock issue. It appears that there are a few things going on platform and compiler dependent: 1) In Irix, trylock does not guarantee a lock on the first try by design even if uncontested as mentioned in my previous post; trying it a few times can fix that 2) It appears that trylock can take a bit longer depending on what the system is doing at the time. Context switching is expensive for this architecture, I observed that to be even more unpredictable on the Origin than the Octane, since the NUMA bus and page/cache migration between node boards add layers of complexity. This can increase the time to obtain a lock. 3) I'm also convinced now that there is indeed a subtle bug in the gcc pthread implementation for the mips4 architecture; a scoped_shared_lock as in handle_data() in sink.cpp can sometimes make the shared_lock try_to_lock in process() fail, which should not happen. And these are very busy, so any lock failures are eventually converted into xruns. So I decided to avoid the try_to_lock shared reader lock in process() for sink.cpp and source.cpp and converted it to a write_guard (RAII) / generation counter (keeping all the other write and read locks the same, just for that reader trylock). It works really well since this lock is not contested usually, no looping needed, no apparent performance expense. I'm really happy with AOO for PD on SGI Irix now! --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/4ZIU4SQPNYQGO25ORB7KJFMMHRCZYWZT/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Thanks for checking! In that case, the retry loop is indeed the only
reasonable solution I can think of.
On a MIPS4 CPU (R8k and newer) the load-linked/store-conditional (LL/SC) is not
infallible (like the modern CAS implementation).
That's interesting! This means that a reader-writer-spinlock (instead of
a reader-writer-mutex) wouldn't help either because it would still
require reliable CAS operations.
I think the retry-loop would be a good idea anyway.
To avoid bombarding the OS/CPU with too many trylocks when the optimizer does
for-loop-unrolling
I don't think that the compiler is allowed to unroll the spin loop.
After all, the try-lock issues at least a compiler barrier, if not a
memory barrier. Have you checked the assembly? I would have assumed that
a plain (bounded) spin loop with pause instructions would be sufficient.
Since the failures are spurious (i.e. the lock is not really contended),
the retry-loop should only take a few iterations at most.
Christof
On 8/9/2026 12:17 AM, Wolfgang Gaggl via Pd-list wrote:
I confirmed it is the Irix pthread implementation.
A trylock is not guaranteed to succeed immediately even if it is uncontested.
This is not a bug of the newer gcc implementation as I suspected earlier, but
also true for the native MipsPro compiler as well.
On a MIPS4 CPU (R8k and newer) the load-linked/store-conditional (LL/SC) is not infallible (like the modern CAS implementation). Also context switches, hardware interrupts, and other stuff can cause spurious failures of trylock. I also found some suggestions that the M:N Hybrid user:kernel space threading for Posix threads on Irix increases the chance of trylock failure.
The solution is exactly that, to try a few times (most times it works at the
first attempt anyway).
To avoid bombarding the OS/CPU with too many trylocks when the optimizer does
for-loop-unrolling and the CPU applies things like speculative execution and
runtime optimization I added a yield() once in a while, which turned out to be
a not-so-good idea. If the thread priority is normal, overtime it might be
deprioritized in Irix and yields can add unpredictable amounts of time. On the
other hand increasing the priority for the AOO process made the yield mostly
useless since it would not yield most of the time. So I replaced it by a timer
loop instead now (code sniplet below).
This works well, I have not had any problems since (no clicks or pops with low
CPU usage), have PD with AOO running on an SGI Octane2 Dual-CPU as frontend,
and an SGI Origin2200 deskside server with 8 CPUS as compute engine connected
by dedicated GBit ethernet.
shared_lock lock(update_mutex_, sync::try_to_lock); // reader lock!
#if defined(__sgi) && defined(__mips__)
for (int i = 0; !lock.owns_lock() && i < kIrixReadTryLockRetries; ++i) {
sync::pause_cpu();
if ((i & 7) == 7) {
struct timespec start, current;
clock_gettime(CLOCK_SGI_CYCLE, &start);
long elapsed = 0;
while (elapsed < RWLOCK_WAIT_TIME) {
sync::pause_cpu();
clock_gettime(CLOCK_SGI_CYCLE, ¤t);
elapsed = (current.tv_sec - start.tv_sec) * 10L +
(current.tv_nsec - start.tv_nsec);
}
}
lock = shared_lock(update_mutex_, sync::try_to_lock);
}
#endif
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/Y65QNUEXRONWASJTCUYAM3OP3ZCEJXM3/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/ZHUF34C7PUYWWC55VY2JOP5RHUVL66KF/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
I confirmed it is the Irix pthread implementation.
A trylock is not guaranteed to succeed immediately even if it is uncontested.
This is not a bug of the newer gcc implementation as I suspected earlier, but
also true for the native MipsPro compiler as well.
On a MIPS4 CPU (R8k and newer) the load-linked/store-conditional (LL/SC) is not
infallible (like the modern CAS implementation). Also context switches,
hardware interrupts, and other stuff can cause spurious failures of trylock. I
also found some suggestions that the M:N Hybrid user:kernel space threading for
Posix threads on Irix increases the chance of trylock failure.
The solution is exactly that, to try a few times (most times it works at the
first attempt anyway).
To avoid bombarding the OS/CPU with too many trylocks when the optimizer does
for-loop-unrolling and the CPU applies things like speculative execution and
runtime optimization I added a yield() once in a while, which turned out to be
a not-so-good idea. If the thread priority is normal, overtime it might be
deprioritized in Irix and yields can add unpredictable amounts of time. On the
other hand increasing the priority for the AOO process made the yield mostly
useless since it would not yield most of the time. So I replaced it by a timer
loop instead now (code sniplet below).
This works well, I have not had any problems since (no clicks or pops with low
CPU usage), have PD with AOO running on an SGI Octane2 Dual-CPU as frontend,
and an SGI Origin2200 deskside server with 8 CPUS as compute engine connected
by dedicated GBit ethernet.
shared_lock lock(update_mutex_, sync::try_to_lock); // reader lock!
#if defined(__sgi) && defined(__mips__)
for (int i = 0; !lock.owns_lock() && i < kIrixReadTryLockRetries; ++i) {
sync::pause_cpu();
if ((i & 7) == 7) {
struct timespec start, current;
clock_gettime(CLOCK_SGI_CYCLE, &start);
long elapsed = 0;
while (elapsed < RWLOCK_WAIT_TIME) {
sync::pause_cpu();
clock_gettime(CLOCK_SGI_CYCLE, ¤t);
elapsed = (current.tv_sec - start.tv_sec) * 10L +
(current.tv_nsec - start.tv_nsec);
}
}
lock = shared_lock(update_mutex_, sync::try_to_lock);
}
#endif
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/Y65QNUEXRONWASJTCUYAM3OP3ZCEJXM3/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Thanks for checking! So I wrote a test that does an exclusive write lock/unlock and a couple of concurrent shared reader locks, it worked when just run without repetition. When repeating it a thousand times, I started to see once in a while when it seemingly randomly missed to get a reader lock. I'm not sure I understand your test case. When you grab an exclusive lock, it is expected that you can't get a shared lock concurrently. What you should do instead is repeatedly obtaining short reader try-locks from several threads and see if any of them fail. If that test still fails, it confirms our shared suspicion that it is a bug in the MIPS pthread implementation. (I'm pretty sure std::shared_mutext just uses pthread_rw_lock under the hood. If you have time, you can try to verify that.) Christof On 7/21/2026 12:28 AM, Wolfgang Gaggl via Pd-list wrote: I checked, AOO_HAVE_PTHREAD_RWLOCK is set true. I also intentionally failed this test to get mutex implementation, same behavior (maybe a bit worse in performance). So I wrote a test that does an exclusive write lock/unlock and a couple of concurrent shared reader locks, it worked when just run without repetition. When repeating it a thousand times, I started to see once in a while when it seemingly randomly missed to get a reader lock. This looks like a bug in the newer GCC pthread implementation for legacy MIPS (needed for C++11/17). Atomics and locks work with the native MIPSpro compiler, which however can only do C99/C++98. The workaround above works because if it misses that shared lock once in many executions only, a repeat try catches it without adding much computational overhead. Maybe I find a better solution at some point, or some platform specific compiler flag optimization that improve/fix it. Thanks for your debug suggestions! --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/O4T6IFNXJAOC2ESOQ7DGKTT6H73RDUPY/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/ --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/UDZ2ED7KZ2Y5C4453QU2WLM5IDB2WMOR/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
I checked, AOO_HAVE_PTHREAD_RWLOCK is set true. I also intentionally failed this test to get mutex implementation, same behavior (maybe a bit worse in performance). So I wrote a test that does an exclusive write lock/unlock and a couple of concurrent shared reader locks, it worked when just run without repetition. When repeating it a thousand times, I started to see once in a while when it seemingly randomly missed to get a reader lock. This looks like a bug in the newer GCC pthread implementation for legacy MIPS (needed for C++11/17). Atomics and locks work with the native MIPSpro compiler, which however can only do C99/C++98. The workaround above works because if it misses that shared lock once in many executions only, a repeat try catches it without adding much computational overhead. Maybe I find a better solution at some point, or some platform specific compiler flag optimization that improve/fix it. Thanks for your debug suggestions! --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/O4T6IFNXJAOC2ESOQ7DGKTT6H73RDUPY/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
That works now for me without clicks and crackling.
Good that you found a workaround!
Just keep in mind that this doesn't fix the underlying issue, namely
that the process() method can't take a reader lock.
As I said, the network threads only take reader locks, so they should
never block the process() method. The methods that do take a writer lock
are never called in parallel with the process() method, at least not in
the Pd version.
I see two potential problems:
1. I made a mistake somewhere and accidentally take a writer lock. I
don't think this is the case. I checked every lock of update_mutex in
aoo/src/source.cpp and everything looks fine. Also, if there really was
a problem with the code, it should affect every platform, not only SGI.
2. The aoo::shared_mutex implementation is broken on SGI.
Actually, aoo::shared_mutex has several implementations. On SGI it
should use pthread_rwlock if available, or fall back to
std::shared_mutex otherwise. Can you check if AOO_HAVE_PTHREAD_RWLOCK is
defined resp. check the value of the (internal) AOO_HAVE_PTHREAD_RWLOCK
CMake cache variable?
Christof
On 7/19/2026 7:43 PM, Wolfgang Gaggl via Pd-list wrote:
...sent that last reply to quickly.
added a poor-mans pause_cpu() implementation for the above lock retry case:
inline void pause_cpu() {
#if defined(_MSC_VER)
YieldProcessor();
#elif defined(__SSE2__)
_mm_pause();
#elif defined(__aarch64__)
__asm__ __volatile__("isb");
#elif defined(__arm__)
__asm__ __volatile__("yield");
#elif defined(__mips__)
# if (defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)) || \
(defined(__mips_isa_rev) && __mips_isa_rev >= 2)
// MIPS32r2+: PAUSE instruction (architectural spin-loop hint)
__asm__ __volatile__(".set push\n\t"
".set mips32r2\n\t"
"pause\n\t"
".set pop");
# else
// MIPS4 / R1 / R12000: SSNOP (SuperScalar NO-OP)
// Encoding: sll $0,$0,1 (sa=1 distinguishes SSNOP from plain NOP sa=0)
// Writing to $0 is a no-op data-wise; the sa=1 field tells the CPU not to
// dual-issue the following instruction, reducing bus pressure in spin
loops.
__asm__ __volatile__("sll $0,$0,1");
# endif
That works now for me without clicks and crackling.
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/FLHJJLJIH5ZOABTCT6QMQ3J6V3JQVBWU/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/WMM46LFFTQ3MQQGODNMGLJZXW6PBLSHE/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
...sent that last reply to quickly.
added a poor-mans pause_cpu() implementation for the above lock retry case:
inline void pause_cpu() {
#if defined(_MSC_VER)
YieldProcessor();
#elif defined(__SSE2__)
_mm_pause();
#elif defined(__aarch64__)
__asm__ __volatile__("isb");
#elif defined(__arm__)
__asm__ __volatile__("yield");
#elif defined(__mips__)
# if (defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2)) || \
(defined(__mips_isa_rev) && __mips_isa_rev >= 2)
// MIPS32r2+: PAUSE instruction (architectural spin-loop hint)
__asm__ __volatile__(".set push\n\t"
".set mips32r2\n\t"
"pause\n\t"
".set pop");
# else
// MIPS4 / R1 / R12000: SSNOP (SuperScalar NO-OP)
// Encoding: sll $0,$0,1 (sa=1 distinguishes SSNOP from plain NOP sa=0)
// Writing to $0 is a no-op data-wise; the sa=1 field tells the CPU not to
// dual-issue the following instruction, reducing bus pressure in spin
loops.
__asm__ __volatile__("sll $0,$0,1");
# endif
That works now for me without clicks and crackling.
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/FLHJJLJIH5ZOABTCT6QMQ3J6V3JQVBWU/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Given that it's coming from a blocked lock, I have added a bounded retry to
both source.cpp and sink.cpp:
shared_lock lock(update_mutex_, sync::try_to_lock); // reader lock!
#if defined(__sgi) && defined(__mips__)
for (int i = 0; !lock.owns_lock() && i < kIrixReadTryLockRetries; ++i) {
sync::pause_cpu();
if ((i & 7) == 7) {
std::this_thread::yield();
}
lock = shared_lock(update_mutex_, sync::try_to_lock);
}
#endif
if (!lock.owns_lock()){
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/XFXX3QJFPJAVFUPD7SGD72NHPRLHUAU5/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Hi Christof,
This is a dual-CPU Octane, so it fulfills the minimum definition of "multi-core
system" :)
Compiled using AOO_LOG_LEVEL=Debug, seeing your case #1 with process would
block right before xrun:
[aoo][debug] AooSink: handle pong
[aoo][debug] AooSink: handle ping
[aoo][debug] AooSource: process would block
[aoo][debug] AooSource: send 1 empty blocks for xrun (1 blocks)
[aoo][debug] AooSource: process would block
[aoo][debug] AooSource: send 1 empty blocks for xrun (1 blocks)
[aoo][debug] AooSource: process would block
[aoo][debug] AooSource: send 1 empty blocks for xrun (1 blocks)
[aoo][debug] AooSource: send /ping to 127.0.0.1:|1
[aoo][debug] AooSink: handle ping
[aoo][debug] AooSink: handle ping
[aoo][debug] AooSink: send /pong to 127.0.0.1:9998|1
[aoo][debug] AooSink: ping delta: 1.00426, packet loss: 0
[aoo][debug] AooSink: send /ping to 127.0.0.1:9998|1
[aoo][debug] AooSource: handle pong
[aoo][debug] AooSource: handle ping
[aoo][debug] AooSource: send /pong to 127.0.0.1:|1
[aoo][debug] AooSink: handle pong
[aoo][debug] AooSink: handle ping
[aoo][debug] AooSource: process would block
[aoo][debug] AooSource: send 1 empty blocks for xrun (1 blocks)
[aoo][debug] AooSource: send /ping to 127.0.0.1:|1
[aoo][debug] AooSink: handle ping
[aoo][debug] AooSink: handle ping
Apparently it runs into a situation where it cannot obtain a lock in
./aoo/src/source.cpp:
shared_lock lock(update_mutex_, sync::try_to_lock); // reader lock!
if (!lock.owns_lock()){
LOG_DEBUG("AooSource: process would block");
add_xrun(nsamples);
return kAooErrorIdle; // ?
}
Any suggestions what we could do about it (maybe it helps to try_to_lock again)?
Thanks,
Wolfgang
---
[email protected] - the Pure Data mailinglist
https://lists.iem.at/hyperkitty/list/[email protected]/message/XXTUEYDULZDO2Q2BBK7OHLTVQ5GHBY7D/
To unsubscribe send an email to [email protected] mailing list
UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
This means that either the source or sink experienced an xrun (= dropped block). The sink automatically replaces the missing samples with silence, hence the crackling. Usually, xruns must be reported explicitly by the library user. This is typically done to forward xruns reported by the audio backend. However, there are two situations where xruns are caused and reported internally: 1. the process() method of AooSource or AooSink could not obtain a reader lock. This should not never happen in Pd. If configured with -DAOO_LOG_LEVEL=Debug, you should see a message "AooSource|AooSink: process would block" in the terminal. 2. the process() method of AooSource could not write into the send buffer. In that case you should see a message "AooSource: send buffer overflow" in the terminal. If that happens, try to increase the send buffer size by sending the "buffersize" message to the [aoo_send~] object. The default send buffer size is 25 ms, which should be more than enough on modern systems. If the network thread is slow or sometimes hangs, a larger send buffer size might be necessary. I should note that the AOO Pd externals are written with the assumption of modern multi-core systems as they use separate threads for network I/O to avoid blocking the audio thread. This could be a problem on ancient systems like the SGI Octane. Christof On 7/11/2026 4:14 AM, Wolfgang Gaggl via Pd-list wrote: What does it mean to get these messages when running aoo_send/receive~-help.pd: aoo_receive~: block_xrun 127.0.0.1 9998 1 1 --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/6K2S2JQAPBAJP42ACC3EF47LJB5GKKD5/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/ --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/WHZZI5VSUXWYMQDMIAVP4D576W767T2C/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
What does it mean to get these messages when running aoo_send/receive~-help.pd: aoo_receive~: block_xrun 127.0.0.1 9998 1 1 --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/6K2S2JQAPBAJP42ACC3EF47LJB5GKKD5/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Finally got around to compile aoo-master on Irix 6.5.22 (datestamp says 11-Oct-2024) by backporting the cmake requirement to versions 3.5. This would be helpful to stream across multiple instances of PD on my headless 8 CPU Origin 2200 server controlled from the Octane2. However, it keeps crackling ever so often (maybe every few seconds up to half a minute give or take between clicks), I cannot figure out why. I'm using the aoo_send~-help.pd and aoo_receive~-help.pd on localhost only with PCM codec to test. The CPUs are not stressed at all, so that part should be fine. Tried different buffer and data sizes unsuccessfully. My fallback currently is udpsend~ and udpreceive~ which do not suffer from this issue. Any ideas what to look at? --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/TFFFLJGGEKVDUQ36MBI6EUE6F5IKFKG7/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Spent some time looking at bus errors with AOO on Irix and realized that the Osc package itself created many of them. So went back to the AOO Fontana release which looked quite alignment safe from the lightweight AOO code itself, and branched BIG_ENDIAN code into a STRICT_ALIGMENT branch using memcpy() instead of direct pointer wizardry. That works now! So there's an AOO Fontana IRIX version now (still under test). --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/RULMOEQ4BM23LXCGQ3CGGPSDZ4GFILPL/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Update: The bind issue was as suspected related to an IPv6 issue. The test IP provided was either a IPv6 address (Google) which was recognized (but didn't work with IPv6 deliberately disabled, just causes issues on SW that mostly predates the full standard implementation) or a random internal IPv4 address that didn't pass with my subnet mask (and I assume same for many others, but for them the IPv6 address will work). The aoo-v2.0-pre3 version that I used because it complies with my cmake version, didn't have the IPv6 address commented out (which is fixed in the current version). Second issue was that ai_socktype = 0 (any) didn't work for getaddr(), it wanted a specified service type, easily fixed by providing either SOCK_DGRAM or SOCK_STREAM. Once that was done, things really started to break during runtime once steams were established. Bus error with core dump signalized that there are memory alignment issues, which can have a wide range of root causes, after many hours of debugging and addressing a few, I stopped here. --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/RFGGZG3FKU2I2UX7RNHACA5S7NRDR7XQ/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
[PD] Re: AOO plugin for PD on SGI Irix
Was able to fix this particular issue before running into a new one... emutls as in emulated thread-local storage requires PD_INSTANCE https://lists.iem.at/hyperkitty/list/[email protected]/thread/6WHCZPLHOGWQG7BO6EX4VFJL3SYO7KAH/#6WHCZPLHOGWQG7BO6EX4VFJL3SYO7KAH Turning off PD_MULTI_INSTANCE in aoo compile solved that issue for the Pd plugin and allows loading the aoo library. However, now it's crashing when trying to use any aoo pd objects: bind: Invalid argument [22] (22) terminate called after throwing an instance of 'aoo::udp_error' terminate called recursively Pd: signal 6 gui socket 4 - closing audio... closing MIDI... ... done. Any ideas here? The "bind: Invalid argument [22] (22)" is all I see here, maybe IPv6 issue? Thanks, Wolfgang --- [email protected] - the Pure Data mailinglist https://lists.iem.at/hyperkitty/list/[email protected]/message/6OEOBRLPNAPP6WZFZAJRWPLIT5OACTNA/ To unsubscribe send an email to [email protected] mailing list UNSUBSCRIBE and account-management -> https://lists.iem.at/
