Module Name: src Committed By: nat Date: Tue Jun 6 07:29:35 UTC 2017
Modified Files: src/sys/dev/pad: pad.c Log Message: Simplification of rate limiter. It now works uni/multiprocessor. To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/sys/dev/pad/pad.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pad/pad.c diff -u src/sys/dev/pad/pad.c:1.34 src/sys/dev/pad/pad.c:1.35 --- src/sys/dev/pad/pad.c:1.34 Tue Jun 6 07:27:15 2017 +++ src/sys/dev/pad/pad.c Tue Jun 6 07:29:35 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: pad.c,v 1.34 2017/06/06 07:27:15 nat Exp $ */ +/* $NetBSD: pad.c,v 1.35 2017/06/06 07:29:35 nat Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.34 2017/06/06 07:27:15 nat Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.35 2017/06/06 07:29:35 nat Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -370,10 +370,11 @@ pad_read(dev_t dev, struct uio *uio, int nowusec = (now.tv_sec * 1000000) + now.tv_usec; lastusec = (sc->sc_last.tv_sec * 1000000) + sc->sc_last.tv_usec; - if (lastusec + TIMENEXTREAD > nowusec && - sc->sc_bytes_count >= BYTESTOSLEEP) { - sc->sc_remainder += - ((lastusec + TIMENEXTREAD) - nowusec); + if (lastusec + TIMENEXTREAD > nowusec) { + if (sc->sc_bytes_count >= BYTESTOSLEEP) { + sc->sc_remainder += + ((lastusec + TIMENEXTREAD) - nowusec); + } wait_ticks = (hz * sc->sc_remainder) / 1000000; if (wait_ticks > 0) { @@ -381,19 +382,14 @@ pad_read(dev_t dev, struct uio *uio, int kpause("padwait", TRUE, wait_ticks, &sc->sc_lock); } + } + if (sc->sc_bytes_count >= BYTESTOSLEEP) 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; - } err = pad_get_block(sc, &pb, min(uio->uio_resid, PAD_BLKSIZE)); if (!err) { + getmicrotime(&sc->sc_last); sc->sc_bytes_count += pb.pb_len; mutex_exit(&sc->sc_lock); err = uiomove(pb.pb_ptr, pb.pb_len, uio);