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

4.115
Last change on this file since d566f33e was d566f33e, checked in by Sebastian Huber <sebastian.huber@…>, on 07/19/13 at 15:16:58

libcsupport: Use _Thread_Get_executing()

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