__vdso_gettc.c revision 240819
122347Spst/*- 222347Spst * Copyright (c) 2012 Konstantin Belousov <kib@FreeBSD.org> 322347Spst * 422347Spst * Redistribution and use in source and binary forms, with or without 522347Spst * modification, are permitted provided that the following conditions 622347Spst * are met: 722347Spst * 1. Redistributions of source code must retain the above copyright 822347Spst * notice, this list of conditions and the following disclaimer. 922347Spst * 2. Redistributions in binary form must reproduce the above copyright 1022347Spst * notice, this list of conditions and the following disclaimer in the 1122347Spst * documentation and/or other materials provided with the distribution. 1222347Spst * 1322347Spst * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1422347Spst * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1522347Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1622347Spst * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1722347Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1822347Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1922347Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2022347Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2122347Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2222347Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2322347Spst * SUCH DAMAGE. 2422347Spst */ 2522347Spst 2622347Spst#include <sys/cdefs.h> 2722347Spst__FBSDID("$FreeBSD: stable/9/lib/libc/amd64/sys/__vdso_gettc.c 240819 2012-09-22 12:38:19Z kib $"); 2822347Spst 2922347Spst#include <sys/types.h> 3022347Spst#include <sys/time.h> 3122347Spst#include <sys/vdso.h> 3222347Spst#include <machine/cpufunc.h> 3322347Spst 3422347Spststatic u_int 3522347Spst__vdso_gettc_low(const struct vdso_timehands *th) 3622347Spst{ 3722347Spst uint32_t rv; 3822347Spst 3922347Spst __asm __volatile("rdtsc; shrd %%cl, %%edx, %0" 4022347Spst : "=a" (rv) : "c" (th->th_x86_shift) : "edx"); 4122347Spst return (rv); 4222347Spst} 4322347Spst 4422347Spstu_int 4522347Spst__vdso_gettc(const struct vdso_timehands *th) 4622347Spst{ 4722347Spst 4822347Spst return (th->th_x86_shift > 0 ? __vdso_gettc_low(th) : rdtsc32()); 4922347Spst} 5022347Spst