tech-kern archive

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

Re: nanosleep() for shorter than schedule slice



On Sun, Jul 02, 2017 at 10:33:58AM +0200, Emmanuel Dreyfus wrote:
> but that kind of performance problem could exist in many other softwares.

With Go:
go test -short -v -run=TestWaitGroupMisuse2 -count=5000 sync

Performance was so bad they made a bug report for it (10-100s runtime
vs. 0.2s on linux: https://github.com/golang/go/issues/22944

I initially got units confused and used this, it's not the scheduler
timeslice (20ms) but 20hz. switching to scheduler timeslice made it as
bad as before. (??)

this gets the go example to run in 0.3-0.01 s

Index: kern_time.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_time.c,v
retrieving revision 1.189
diff -u -p -r1.189 kern_time.c
--- kern_time.c	11 Nov 2016 15:29:36 -0000	1.189
+++ kern_time.c	9 Dec 2017 14:46:08 -0000
@@ -343,11 +343,12 @@ nanosleep1(struct lwp *l, clockid_t cloc
 		return error;
 	}
 
-	/*
-	 * Avoid inadvertently sleeping forever
-	 */
-	if (timo == 0)
-		timo = 1;
+	/* Can't do anything useful in so little time */
+	if (timo < 20) {
+		DELAY(hztoms(timo));
+		return 0;
+	}
+
 again:
 	error = kpause("nanoslp", true, timo, NULL);
 	if (rmt != NULL || error == 0) {



Home | Main Index | Thread Index | Old Index