source: rtems/cpukit/libcsupport/src/__times.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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