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

4.11
Last change on this file since e6b31b27 was e6b31b27, checked in by Joel Sherrill <joel.sherrill@…>, on May 27, 2015 at 3:13:58 PM

Remove use ticks for statistics configure option.

This was obsolete and broken based upon recent time keeping changes.

Thie build option was previously enabled by adding
USE_TICKS_FOR_STATISTICS=1 to the configure command line.

This propagated into the code as preprocessor conditionals
using the RTEMS_USE_TICKS_FOR_STATISTICS conditional.

  • Property mode set to 100644
File size: 2.6 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#include <rtems/score/timestamp.h>
35#include <rtems/score/threadimpl.h>
36
37/**
38 *  POSIX 1003.1b 4.5.2 - Get Process Times
39 */
40clock_t _times(
41   struct tms  *ptms
42)
43{
44  rtems_interval ticks, us_per_tick;
45  Thread_Control *executing;
46
47  if ( !ptms )
48    rtems_set_errno_and_return_minus_one( EFAULT );
49
50  /*
51   *  This call does not depend on TOD being initialized and can't fail.
52   */
53
54  ticks = rtems_clock_get_ticks_since_boot();
55  us_per_tick = rtems_configuration_get_microseconds_per_tick();
56
57  /*
58   *  RTEMS technically has no notion of system versus user time
59   *  since there is no separation of OS from application tasks.
60   *  But we can at least make a distinction between the number
61   *  of ticks since boot and the number of ticks executed by this
62   *  this thread.
63   */
64  {
65    Timestamp_Control  per_tick;
66    uint32_t           ticks_of_executing;
67    uint32_t           fractional_ticks;
68    Per_CPU_Control   *cpu_self;
69
70    _Timestamp_Set(
71      &per_tick,
72      rtems_configuration_get_microseconds_per_tick() /
73          TOD_MICROSECONDS_PER_SECOND,
74      (rtems_configuration_get_nanoseconds_per_tick() %
75          TOD_NANOSECONDS_PER_SECOND)
76    );
77
78    cpu_self = _Thread_Dispatch_disable();
79    executing = _Thread_Executing;
80    _Thread_Update_cpu_time_used(
81      executing,
82      &_Thread_Time_of_last_context_switch
83    );
84    _Timestamp_Divide(
85      &executing->cpu_time_used,
86      &per_tick,
87      &ticks_of_executing,
88      &fractional_ticks
89    );
90    _Thread_Dispatch_enable( cpu_self );
91    ptms->tms_utime = ticks_of_executing * us_per_tick;
92  }
93  ptms->tms_stime  = ticks * us_per_tick;
94  ptms->tms_cutime = 0;
95  ptms->tms_cstime = 0;
96
97  return ticks * us_per_tick;
98}
99
100/**
101 *  times() system call wrapper for _times() above.
102 */
103clock_t times(
104   struct tms  *ptms
105)
106{
107  return _times( ptms );
108}
109
110#if defined(RTEMS_NEWLIB)
111
112#include <reent.h>
113
114/**
115 *  This is the Newlib dependent reentrant version of times().
116 */
117clock_t _times_r(
118   struct _reent *ptr __attribute__((unused)),
119   struct tms  *ptms
120)
121{
122  return _times( ptms );
123}
124#endif
Note: See TracBrowser for help on using the repository browser.