Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/audio audio(4): Membar audit.
details: https://anonhg.NetBSD.org/src/rev/0addb514621d
branches: trunk
changeset: 363509:0addb514621d
user: riastradh <riastradh%NetBSD.org@localhost>
date: Mon Mar 14 11:47:33 2022 +0000
description:
audio(4): Membar audit.
Won't affect anything on x86 because atomic r/m/w operations are
always full sequential consistency barriers, but might potentially
fix problems on, e.g., arm.
Note 1: I'm not clear on why the track lock is a bespoke mutex made
out of an atomic -- why not just mutex(9)?
Note 2: I'm not convinced the audio_mlog_flush synchronization is
correct; what happens if the softint runs on two CPUs at the same
time and swaps mlog_wpage simultaneously?
Note 3: Should maybe use atomic_load/store_relaxed for mlog_full and
mlog_drop, and atomic_inc/dec for mlog_refs.
diffstat:
sys/dev/audio/audio.c | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
diffs (94 lines):
diff -r 5c7ef6605319 -r 0addb514621d sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c Mon Mar 14 07:05:31 2022 +0000
+++ b/sys/dev/audio/audio.c Mon Mar 14 11:47:33 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audio.c,v 1.113 2021/12/12 13:05:13 andvar Exp $ */
+/* $NetBSD: audio.c,v 1.114 2022/03/14 11:47:33 riastradh Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -138,7 +138,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.113 2021/12/12 13:05:13 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.114 2022/03/14 11:47:33 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "audio.h"
@@ -162,6 +162,7 @@
#include <sys/kauth.h>
#include <sys/kernel.h>
#include <sys/kmem.h>
+#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mman.h>
#include <sys/module.h>
@@ -272,13 +273,14 @@
/* Nothing to do if already in use ? */
if (atomic_swap_32(&mlog_inuse, 1) == 1)
return;
+ membar_enter();
int rpage = mlog_wpage;
mlog_wpage ^= 1;
mlog_buf[mlog_wpage][0] = '\0';
mlog_used = 0;
- atomic_swap_32(&mlog_inuse, 0);
+ atomic_store_reease(&mlog_inuse, 0);
if (mlog_buf[rpage][0] != '\0') {
printf("%s", mlog_buf[rpage]);
@@ -308,6 +310,7 @@
mlog_drop++;
return;
}
+ membar_enter();
va_start(ap, fmt);
len = vsnprintf(
@@ -321,7 +324,7 @@
mlog_full++;
}
- atomic_swap_32(&mlog_inuse, 0);
+ atomic_store_release(&mlog_inuse, 0);
if (mlog_sih)
softint_schedule(mlog_sih);
@@ -1652,7 +1655,11 @@
static __inline bool
audio_track_lock_tryenter(audio_track_t *track)
{
- return (atomic_cas_uint(&track->lock, 0, 1) == 0);
+
+ if (atomic_swap_uint(&track->lock, 1) != 0)
+ return false;
+ membar_enter();
+ return true;
}
/*
@@ -1661,9 +1668,10 @@
static __inline void
audio_track_lock_enter(audio_track_t *track)
{
+
/* Don't sleep here. */
while (audio_track_lock_tryenter(track) == false)
- ;
+ SPINLOCK_BACKOFF_HOOK;
}
/*
@@ -1672,7 +1680,8 @@
static __inline void
audio_track_lock_exit(audio_track_t *track)
{
- atomic_swap_uint(&track->lock, 0);
+
+ atomic_store_release(&track->lock, 0);
}
Home |
Main Index |
Thread Index |
Old Index