Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pad Simplification of rate limiter. It now works un...



details:   https://anonhg.NetBSD.org/src/rev/4d34f3db422b
branches:  trunk
changeset: 354174:4d34f3db422b
user:      nat <nat%NetBSD.org@localhost>
date:      Tue Jun 06 07:29:35 2017 +0000

description:
Simplification of rate limiter.  It now works uni/multiprocessor.

diffstat:

 sys/dev/pad/pad.c |  24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diffs (57 lines):

diff -r 48930ceb0384 -r 4d34f3db422b sys/dev/pad/pad.c
--- a/sys/dev/pad/pad.c Tue Jun 06 07:27:15 2017 +0000
+++ b/sys/dev/pad/pad.c Tue Jun 06 07:29:35 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
                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 @@
                                kpause("padwait", TRUE, wait_ticks,
                                    &sc->sc_lock);
                        }
+               }
 
-                       sc->sc_bytes_count -= BYTESTOSLEEP;
-                       getmicrotime(&sc->sc_last);
-               } else if (sc->sc_bytes_count >= BYTESTOSLEEP) {
+               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);



Home | Main Index | Thread Index | Old Index