source: rtems/cpukit/libcsupport/src/__times.c @ 9e14ca2

4.104.115
Last change on this file since 9e14ca2 was 9e14ca2, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/15/09 at 09:29:55

Add attribute((unused)) to function arguments.

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