Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 May 2011 11:15:30 +0300
From:      Andriy Gapon <avg@FreeBSD.org>
To:        FreeBSD current <freebsd-current@FreeBSD.org>
Subject:   better integration of osol cyclic with clocksource
Message-ID:  <4DCB9722.1020409@FreeBSD.org>

next in thread | raw e-mail | index | archive | help

I would like to commit the following patch soon, so I would like to ask you for
reviews and testing.

Idea of the patch is to improve integration with relatively recently introduced
clocksource framework.  Practical benefits are only achieved when one-shot
timers are used to drive a system.  In this case there will not be unnecessary
timer interrupts and, which is not the least, cyclic events should happen more
close to their scheduled times.  Currently cyclic subsystem is used only by
DTrace, so that means that DTrace profile provider becomes much more accurate.
E.g. if currently you specify profile:::profile-4001 probe and your hz is 1000,
then actually most of the time this probe is invoked 4 times in succession at
every hz tick.  With the proposed change it should be generally called every 250µs.

The patch:
http://people.freebsd.org/~avg/cyclic.diff

BIG NOTE: the patch needs osol gethrtime() to be implemented with the same
(high) prevision as the clocksource code, which is not the case now.  Without
that the cyclic code will work very unstably.  So one of the following actions
should be taken additionally:

A) The following patch changes gethrtime() to sufficiently accurate
implementation.  Since gethrtime() is also used in ZFS code, there is a concern
that the patch may negatively impact ZFS performance.  This hasn't been
demonstrated/proven, but I am also unable to conclusively prove that this will
not be the case.  The only argument that I have is that OpenSolaris uses a
precise implementation (based on TSC where possible), so the change shouldn't
make things worse than in OpenSolaris.

--- sys/cddl/compat/opensolaris/sys/time.h	(revision 221802)
+++ sys/cddl/compat/opensolaris/sys/time.h	(working copy)
@@ -53,7 +53,7 @@
 	struct timespec ts;
 	hrtime_t nsec;

-	getnanouptime(&ts);
+	nanouptime(&ts);
 	nsec = (hrtime_t)ts.tv_sec * NANOSEC + ts.tv_nsec;
 	return (nsec);
 }

B) Create a private copy of gethrtime() in sys/cddl/dev/cyclic/cyclic.c and
patch only that copy.
This is a safer approach suggested by pjd.  The only minor drawback is very
small code duplication.

-- 
Andriy Gapon



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4DCB9722.1020409>