2
* Copyright (C) 2009 Philippe Gerum <rpm@xenomai.org>.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19
#ifndef _XENO_ASM_GENERIC_BITS_TIMECONV_H
20
#define _XENO_ASM_GENERIC_BITS_TIMECONV_H
22
#include <asm/xenomai/arith.h>
24
static unsigned long long cpufreq;
26
#ifdef XNARCH_HAVE_LLMULSHFT
27
static unsigned int tsc_scale, tsc_shift;
30
#ifdef XNARCH_HAVE_LLMULSHFT
31
long long xnarch_tsc_to_ns(long long ticks)
33
return xnarch_llmulshft(ticks, tsc_scale, tsc_shift);
35
long long xnarch_tsc_to_ns_rounded(long long ticks)
37
unsigned int shift = tsc_shift - 1;
38
return (xnarch_llmulshft(ticks, tsc_scale, shift) + 1) / 2;
40
#else /* !XNARCH_HAVE_LLMULSHFT */
41
long long xnarch_tsc_to_ns(long long ticks)
43
return xnarch_llimd(ticks, 1000000000, cpufreq);
45
long long xnarch_tsc_to_ns_rounded(long long ticks)
47
return (xnarch_llimd(ticks, 1000000000, cpufreq/2) + 1) / 2;
49
#endif /* !XNARCH_HAVE_LLMULSHFT */
51
long long xnarch_ns_to_tsc(long long ns)
53
return xnarch_llimd(ns, cpufreq, 1000000000);
56
static inline void xnarch_init_timeconv(unsigned long long freq)
59
#ifdef XNARCH_HAVE_LLMULSHFT
60
xnarch_init_llmulshft(1000000000, freq, &tsc_scale, &tsc_shift);
65
EXPORT_SYMBOL(xnarch_tsc_to_ns);
66
EXPORT_SYMBOL(xnarch_ns_to_tsc);
67
#endif /* __KERNEL__ */
69
#endif /* !_XENO_ASM_GENERIC_BITS_TIMECONV_H */