Module Name: src Committed By: jruoho Date: Fri Mar 11 19:50:34 UTC 2011
Modified Files: src/distrib/sets/lists/comp: mi src/share/man/man9/man9.x86: Makefile Added Files: src/share/man/man9/man9.x86: tsc.9 Log Message: Add x86/tsc(9). To generate a diff of this commit: cvs rdiff -u -r1.1596 -r1.1597 src/distrib/sets/lists/comp/mi cvs rdiff -u -r1.2 -r1.3 src/share/man/man9/man9.x86/Makefile cvs rdiff -u -r0 -r1.1 src/share/man/man9/man9.x86/tsc.9 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/comp/mi diff -u src/distrib/sets/lists/comp/mi:1.1596 src/distrib/sets/lists/comp/mi:1.1597 --- src/distrib/sets/lists/comp/mi:1.1596 Thu Mar 10 16:50:10 2011 +++ src/distrib/sets/lists/comp/mi Fri Mar 11 19:50:33 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1596 2011/03/10 16:50:10 njoly Exp $ +# $NetBSD: mi,v 1.1597 2011/03/11 19:50:33 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -10277,6 +10277,11 @@ ./usr/share/man/cat9/x86/nmi.0 comp-sys-catman .cat ./usr/share/man/cat9/x86/nmi_disestablish.0 comp-sys-catman .cat ./usr/share/man/cat9/x86/nmi_establish.0 comp-sys-catman .cat +./usr/share/man/cat9/x86/tsc.0 comp-sys-catman .cat +./usr/share/man/cat9/x86/tsc_tc_init.0 comp-sys-catman .cat +./usr/share/man/cat9/x86/tsc_sync_ap.0 comp-sys-catman .cat +./usr/share/man/cat9/x86/tsc_sync_bp.0 comp-sys-catman .cat +./usr/share/man/cat9/x86/tsc_sync_drift.0 comp-sys-catman .cat ./usr/share/man/cat9/x86/x86_msr_xcall.0 comp-sys-catman .cat ./usr/share/man/cat9/xc_broadcast.0 comp-sys-catman .cat ./usr/share/man/cat9/xc_unicast.0 comp-sys-catman .cat @@ -16158,6 +16163,11 @@ ./usr/share/man/html9/x86/nmi.html comp-sys-htmlman html ./usr/share/man/html9/x86/nmi_disestablish.html comp-sys-htmlman html ./usr/share/man/html9/x86/nmi_establish.html comp-sys-htmlman html +./usr/share/man/html9/x86/tsc.html comp-sys-htmlman html +./usr/share/man/html9/x86/tsc_tc_init.html comp-sys-htmlman html +./usr/share/man/html9/x86/tsc_sync_ap.html comp-sys-htmlman html +./usr/share/man/html9/x86/tsc_sync_bp.html comp-sys-htmlman html +./usr/share/man/html9/x86/tsc_sync_drift.html comp-sys-htmlman html ./usr/share/man/html9/x86/x86_msr_xcall.html comp-sys-htmlman html ./usr/share/man/html9/xc_broadcast.html comp-sys-htmlman html ./usr/share/man/html9/xc_unicast.html comp-sys-htmlman html @@ -22297,6 +22307,11 @@ ./usr/share/man/man9/x86/nmi.9 comp-sys-man .man ./usr/share/man/man9/x86/nmi_disestablish.9 comp-sys-man .man ./usr/share/man/man9/x86/nmi_establish.9 comp-sys-man .man +./usr/share/man/man9/x86/tsc.9 comp-sys-man .man +./usr/share/man/man9/x86/tsc_tc_init.9 comp-sys-man .man +./usr/share/man/man9/x86/tsc_sync_ap.9 comp-sys-man .man +./usr/share/man/man9/x86/tsc_sync_bp.9 comp-sys-man .man +./usr/share/man/man9/x86/tsc_sync_drift.9 comp-sys-man .man ./usr/share/man/man9/x86/x86_msr_xcall.9 comp-sys-man .man ./usr/share/man/man9/xc_broadcast.9 comp-sys-man .man ./usr/share/man/man9/xc_unicast.9 comp-sys-man .man Index: src/share/man/man9/man9.x86/Makefile diff -u src/share/man/man9/man9.x86/Makefile:1.2 src/share/man/man9/man9.x86/Makefile:1.3 --- src/share/man/man9/man9.x86/Makefile:1.2 Sat Aug 21 10:32:35 2010 +++ src/share/man/man9/man9.x86/Makefile Fri Mar 11 19:50:33 2011 @@ -1,10 +1,15 @@ -# $NetBSD: Makefile,v 1.2 2010/08/21 10:32:35 jruoho Exp $ +# $NetBSD: Makefile,v 1.3 2011/03/11 19:50:33 jruoho Exp $ -MAN= nmi.9 x86_msr_xcall.9 +MAN= nmi.9 tsc.9 x86_msr_xcall.9 MANSUBDIR=/x86 -MLINKS+=nmi.9 nmi_establish.9 -MLINKS+=nmi.9 nmi_disestablish.9 +MLINKS+=nmi.9 nmi_establish.9 \ + nmi.9 nmi_disestablish.9 + +MLINKS+=tsc.9 tsc_tc_init.9 \ + tsc.9 tsc_sync_ap.9 \ + tsc.9 tsc_sync_bp.9 \ + tsc.9 tsc_sync_drift.9 .include <bsd.man.mk> Added files: Index: src/share/man/man9/man9.x86/tsc.9 diff -u /dev/null src/share/man/man9/man9.x86/tsc.9:1.1 --- /dev/null Fri Mar 11 19:50:35 2011 +++ src/share/man/man9/man9.x86/tsc.9 Fri Mar 11 19:50:33 2011 @@ -0,0 +1,150 @@ +.\" $NetBSD: tsc.9,v 1.1 2011/03/11 19:50:33 jruoho Exp $ +.\" +.\" Copyright (c) 2011 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jukka Ruohonen. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd March 5, 2011 +.Dt TSC 9 x86 +.Os +.Sh NAME +.Nm tsc +.Nd Time Stamp Counter +.Sh SYNOPSIS +.In x86/x86/tsc.h +.Ft void +.Fn tsc_tc_init "void" +.Ft void +.Fn tsc_sync_ap "struct cpu_info *ci" +.Ft void +.Fn tsc_sync_bp "struct cpu_info *ci" +.Ft void +.Fn tsc_sync_drift "int64_t drift" +.Sh DESCRIPTION +The time stamp sounter +.Pq Tn TSC +is a hardware counter found in all contemporary x86 processors. +The counter is implemented as a 64-bit model-specific register +.Pq Tn MSR +that is incremented at every clock cycle. +The +.Tn RDTSC +.Pq Dq read time stamp counter +register has been present since the original Pentium. +.Pp +Already because of the access method, +.Tn TSC +has traditionally provided a low-overhead and high-resolution +way to obtain +.Tn CPU +timing information. +Recently, however, this reliability has been undermined by +such factors as system sleep states, +.Tn CPU +.Dq hotplugging , +.Dq hiberanation , +and +.Tn CPU +frequency scaling. +.Pp +These potential new sources of unreliability are easily understandable +when one recalls that the counter measures cycles and not +.Dq time . +Comparing the cycle counts only makes sense when the clock frequency +is stable; to convert the cycle counts to time units, a general equation +would be: +.Dq seconds = cycles / frequency in Hz . +The use of +.Tn TSC +as a source of high-resolution timing can be thus discouraged. +But the basic premise is still guaranteed: +.Tn TSC +is a monotonically increasing counter. +.Sh FUNCTIONS +.Bl -tag -width abcd +.It Fn tsc_tc_init "" +The +.Fn tsc_tc_init +function initializes the +.Tn TSC +as a +.Xr timecounter 9 . +The function is called early in the boot process when the processors attach. +.It Fn tsc_sync_ap "ci" +The +.Fn tsc_sync_ap +function synchronizes the counter for the boot processor +.Pq Tn BP . +The supplied +.Fa ci +must refer to the +.Tn BP +itself. +The +.Nm +interface takes internally care of such issues as out-of-order execution, +where instructions are not necessarily performed in the order of execution, +possibly causing a misleading cycle count. +.It Fn tsc_sync_bp "ci" +The +.Fn tsc_sync_bp +function synchronize the counter for the application processor +.Fa ci . +Interrupts must be off at machine-level when the function is called. +.Pp +It is necessary to call both +.Fn tsc_sync_ap +and +.Fn tsc_sync_bp +during the boot, but additional synchronization +may be required also during runtime. +As an example, the +.Tn TSC +needs to be synchronized for all processors when the system resumes from an +.Xr acpi 4 +sleep state. +.It Fn tsc_sync_drift "drift" +Finally, the +.Fn tsc_sync_drift +function records +.Fa drift , +measured in clock cycles. +This is called when the +.Tn APs +attach. +.El +.\" +.\" Some references that are not worth adding to the actual page: +.\" +.\" http://lwn.net/Articles/209101/ +.\" http://lwn.net/Articles/388188/ +.\" http://lkml.org/lkml/2005/11/4/173 +.\" http://www.ccsl.carleton.ca/~jamuir/rdtscpm1.pdf +.\" +.Sh SEE ALSO +.Xr gettimeofday 2 , +.Xr timeval 3 , +.Xr timecounter 9