]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4util/include/ARCH-x86/thread_time.h
8f66f0a2d954050b6186db7313ab13b349207182
[l4.git] / l4 / pkg / l4util / include / ARCH-x86 / thread_time.h
1 /**
2  * \file
3  * \brief  Functions to acquire thread time fast (without kernel entry)
4  *
5  * \date   Martin Pohlack  <mp26@os.inf.tu-dresden.de> */
6
7 /*
8  * (c) 2005-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9  *               Martin Pohlack <mp26@os.inf.tu-dresden.de>
10  *     economic rights: Technische Universität Dresden (Germany)
11  * This file is part of TUD:OS and distributed under the terms of the
12  * GNU Lesser General Public License 2.1.
13  * Please see the COPYING-LGPL-2.1 file for details.
14  */
15
16
17 #ifndef __L4UTIL__INCLUDE__ARCH_X86__THREAD_TIME_H__
18 #define __L4UTIL__INCLUDE__ARCH_X86__THREAD_TIME_H__
19
20 #include <l4/sys/kip.h>
21 #include <l4/util/rdtsc.h>
22
23 EXTERN_C_BEGIN
24
25 /**
26  * \brief Acquire accumulated runtime  from the kernel info page for currently
27  *        running thread
28  *
29  * @param kinfo pointer to mapped kernel info page
30  *
31  * \return Accumulated thread time (cycles)
32  */
33 L4_INLINE l4_cpu_time_t l4util_thread_time(const l4_kernel_info_t * kinfo);
34 L4_INLINE l4_cpu_time_t l4util_thread_time(const l4_kernel_info_t * kinfo)
35 {
36     l4_cpu_time_t switch_time, thread_time, now;
37
38     do
39       {
40         now          = l4_rdtsc();
41         /* fixme: make 64 bit reads atomic ??? */
42         thread_time  = kinfo->thread_time;
43         switch_time  = kinfo->switch_time;
44       }
45     while (now < switch_time);
46
47     return now - switch_time + thread_time;
48 }
49
50 EXTERN_C_END
51
52
53 #endif /* ! __L4UTIL__INCLUDE__ARCH_X86__THREAD_TIME_H__ */