Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pad Rework of previous.
details: https://anonhg.NetBSD.org/src/rev/afc1632441c3
branches: trunk
changeset: 353888:afc1632441c3
user: nat <nat%NetBSD.org@localhost>
date: Sat May 27 10:02:26 2017 +0000
description:
Rework of previous.
Math for BYTESTOSLEEP and TIMENEXTREAD is now correct.
diffstat:
sys/dev/pad/pad.c | 37 ++++++++++++++++++++++++++-----------
sys/dev/pad/padvar.h | 4 +++-
2 files changed, 29 insertions(+), 12 deletions(-)
diffs (102 lines):
diff -r 9abc8d200985 -r afc1632441c3 sys/dev/pad/pad.c
--- a/sys/dev/pad/pad.c Sat May 27 06:32:12 2017 +0000
+++ b/sys/dev/pad/pad.c Sat May 27 10:02:26 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pad.c,v 1.28 2017/02/23 23:13:27 nat Exp $ */
+/* $NetBSD: pad.c,v 1.29 2017/05/27 10:02:26 nat Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.28 2017/02/23 23:13:27 nat Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.29 2017/05/27 10:02:26 nat Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -321,6 +321,8 @@
}
getmicrotime(&sc->sc_last);
+ sc->sc_bytes_count = 0;
+ sc->sc_remainder = 0;
return 0;
}
@@ -340,8 +342,9 @@
return 0;
}
-#define PAD_BYTES_PER_SEC (44100 * sizeof(int16_t) * 2)
-#define TIMENEXTREAD (PAD_BLKSIZE * 1000 / PAD_BYTES_PER_SEC)
+#define PAD_BYTES_PER_SEC (44100 * sizeof(int16_t) * 2)
+#define TIMENEXTREAD (PAD_BLKSIZE * 1000000 / PAD_BYTES_PER_SEC)
+#define BYTESTOSLEEP (PAD_BLKSIZE)
int
pad_read(dev_t dev, struct uio *uio, int flags)
@@ -369,18 +372,28 @@
nowusec = (now.tv_sec * 1000000) + now.tv_usec;
lastusec = (sc->sc_last.tv_sec * 1000000) +
sc->sc_last.tv_usec;
- if (lastusec + TIMENEXTREAD > nowusec) {
- wait_ticks = (hz * ((lastusec + TIMENEXTREAD) -
- nowusec)) / 1000000;
+ if (lastusec + TIMENEXTREAD > nowusec &&
+ sc->sc_bytes_count >= BYTESTOSLEEP) {
+ sc->sc_remainder +=
+ ((lastusec + TIMENEXTREAD) - nowusec);
+
+ wait_ticks = (hz * sc->sc_remainder) / 1000000;
if (wait_ticks > 0) {
+ sc->sc_remainder -= wait_ticks * 1000000 / hz;
kpause("padwait", TRUE, wait_ticks,
&sc->sc_lock);
}
+
+ sc->sc_bytes_count -= BYTESTOSLEEP;
+ getmicrotime(&sc->sc_last);
+ } else if (sc->sc_bytes_count >= BYTESTOSLEEP) {
+ sc->sc_bytes_count -= BYTESTOSLEEP;
+ getmicrotime(&sc->sc_last);
+ } else if (lastusec + TIMENEXTREAD <= nowusec) {
+ getmicrotime(&sc->sc_last);
+ sc->sc_remainder = 0;
}
- sc->sc_last.tv_sec =
- (lastusec + TIMENEXTREAD) / 1000000;
- sc->sc_last.tv_usec =
- (lastusec + TIMENEXTREAD) % 1000000;
+
err = pad_get_block(sc, &pb, min(uio->uio_resid, PAD_BLKSIZE));
if (!err) {
mutex_exit(&sc->sc_lock);
@@ -422,6 +435,8 @@
return EIO;
getmicrotime(&sc->sc_last);
+ sc->sc_remainder = 0;
+
return 0;
}
diff -r 9abc8d200985 -r afc1632441c3 sys/dev/pad/padvar.h
--- a/sys/dev/pad/padvar.h Sat May 27 06:32:12 2017 +0000
+++ b/sys/dev/pad/padvar.h Sat May 27 10:02:26 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: padvar.h,v 1.7 2017/02/23 23:13:27 nat Exp $ */
+/* $NetBSD: padvar.h,v 1.8 2017/05/27 10:02:26 nat Exp $ */
/*-
* Copyright (c) 2007 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -52,6 +52,8 @@
uint8_t sc_swvol;
struct timeval sc_last;
+ int sc_bytes_count;
+ uint32_t sc_remainder;
} pad_softc_t;
#endif /* !_SYS_DEV_PAD_PADVAR_H */
Home |
Main Index |
Thread Index |
Old Index