1 | /* |
---|
2 | * times() - POSIX 1003.1b 4.5.2 - Get Process Times |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989-2010. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.com/license/LICENSE. |
---|
10 | * |
---|
11 | * $Id$ |
---|
12 | */ |
---|
13 | |
---|
14 | #if HAVE_CONFIG_H |
---|
15 | #include "config.h" |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <rtems.h> |
---|
19 | |
---|
20 | #include <sys/times.h> |
---|
21 | #include <time.h> |
---|
22 | #include <sys/time.h> |
---|
23 | #include <errno.h> |
---|
24 | #include <rtems/seterr.h> |
---|
25 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
26 | #include <rtems/score/timestamp.h> |
---|
27 | #endif |
---|
28 | |
---|
29 | clock_t _times( |
---|
30 | struct tms *ptms |
---|
31 | ) |
---|
32 | { |
---|
33 | rtems_interval ticks; |
---|
34 | |
---|
35 | if ( !ptms ) |
---|
36 | rtems_set_errno_and_return_minus_one( EFAULT ); |
---|
37 | |
---|
38 | /* |
---|
39 | * This call does not depend on TOD being initialized and can't fail. |
---|
40 | */ |
---|
41 | |
---|
42 | ticks = rtems_clock_get_ticks_since_boot(); |
---|
43 | |
---|
44 | /* |
---|
45 | * RTEMS technically has no notion of system versus user time |
---|
46 | * since there is no separation of OS from application tasks. |
---|
47 | * But we can at least make a distinction between the number |
---|
48 | * of ticks since boot and the number of ticks executed by this |
---|
49 | * this thread. |
---|
50 | */ |
---|
51 | |
---|
52 | #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ |
---|
53 | { |
---|
54 | Timestamp_Control per_tick; |
---|
55 | uint32_t ticks; |
---|
56 | uint32_t fractional_ticks; |
---|
57 | |
---|
58 | _Timestamp_Set( |
---|
59 | &per_tick, |
---|
60 | rtems_configuration_get_microseconds_per_tick() / |
---|
61 | TOD_MICROSECONDS_PER_SECOND, |
---|
62 | (rtems_configuration_get_nanoseconds_per_tick() % |
---|
63 | TOD_NANOSECONDS_PER_SECOND) |
---|
64 | ); |
---|
65 | |
---|
66 | _Timestamp_Divide( |
---|
67 | &_Thread_Executing->cpu_time_used, |
---|
68 | &per_tick, |
---|
69 | &ticks, |
---|
70 | &fractional_ticks |
---|
71 | ); |
---|
72 | ptms->tms_utime = ticks; |
---|
73 | } |
---|
74 | #else |
---|
75 | ptms->tms_utime = _Thread_Executing->cpu_time_used; |
---|
76 | #endif |
---|
77 | ptms->tms_stime = ticks; |
---|
78 | ptms->tms_cutime = 0; |
---|
79 | ptms->tms_cstime = 0; |
---|
80 | |
---|
81 | return ticks; |
---|
82 | } |
---|
83 | |
---|
84 | /* |
---|
85 | * times() |
---|
86 | * |
---|
87 | * times() system call wrapper for _times() above. |
---|
88 | */ |
---|
89 | |
---|
90 | clock_t times( |
---|
91 | struct tms *ptms |
---|
92 | ) |
---|
93 | { |
---|
94 | return _times( ptms ); |
---|
95 | } |
---|
96 | |
---|
97 | /* |
---|
98 | * _times_r |
---|
99 | * |
---|
100 | * This is the Newlib dependent reentrant version of times(). |
---|
101 | */ |
---|
102 | |
---|
103 | #if defined(RTEMS_NEWLIB) |
---|
104 | |
---|
105 | #include <reent.h> |
---|
106 | |
---|
107 | clock_t _times_r( |
---|
108 | struct _reent *ptr __attribute__((unused)), |
---|
109 | struct tms *ptms |
---|
110 | ) |
---|
111 | { |
---|
112 | return _times( ptms ); |
---|
113 | } |
---|
114 | #endif |
---|