source: rtems/cpukit/libcsupport/src/__times.c @ 838167e

4.104.114.84.95
Last change on this file since 838167e was c3330a8, checked in by Joel Sherrill <joel.sherrill@…>, on 05/17/07 at 22:46:45

2007-05-17 Joel Sherrill <joel.sherrill@…>

  • ChangeLog?, configure.ac, libcsupport/src/times.c, libmisc/cpuuse/cpuuse.c, libmisc/stackchk/check.c, rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c, rtems/src/ratemonreportstatistics.c, rtems/src/ratemonresetall.c, rtems/src/ratemontimeout.c, score/Makefile.am, score/include/rtems/score/thread.h, score/include/rtems/score/timespec.h, score/src/threaddispatch.c, score/src/threadinitialize.c, score/src/threadtickletimeslice.c, score/src/timespecdivide.c: Add nanoseconds granularity to the rate monotonic period statistics and CPU usage statistics. This capability is enabled by default although may be conditionally disabled by the user. It could be too much overhead on small targets but it does not appear to be bad in early testing. Its impact on code size has not been evaluated either. It is possible that both forms of statistics gathering could be disabled with further tweaking of the conditional compilation.
  • score/src/timespecdividebyinteger.c: New file.
  • 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-1999.
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/timespec.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  (void) rtems_clock_get( RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &ticks );
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      struct timespec per_tick;
57      uint32_t ticks;
58      uint32_t fractional_ticks;
59     
60      per_tick.tv_sec =
61        _TOD_Microseconds_per_tick / TOD_MILLISECONDS_PER_SECOND;
62      per_tick.tv_nsec =
63        (_TOD_Microseconds_per_tick % TOD_MILLISECONDS_PER_SECOND) / 1000;
64
65      _Timespec_Divide(
66        &_Thread_Executing->cpu_time_used,
67        &per_tick,
68        &ticks,
69        &fractional_ticks
70      );
71      ptms->tms_utime = ticks;
72    }
73  #else
74    ptms->tms_utime  = _Thread_Executing->ticks_executed;
75  #endif
76  ptms->tms_stime  = ticks;
77  ptms->tms_cutime = 0;
78  ptms->tms_cstime = 0;
79
80  return ticks;
81}
82
83/*
84 *  times()
85 *
86 *  times() system call wrapper for _times() above.
87 */
88
89clock_t times(
90   struct tms  *ptms
91)
92{
93  return _times( ptms );
94}
95
96/*
97 *  _times_r
98 *
99 *  This is the Newlib dependent reentrant version of times().
100 */
101
102#if defined(RTEMS_NEWLIB)
103
104#include <reent.h>
105
106clock_t _times_r(
107   struct _reent *ptr,
108   struct tms  *ptms
109)
110{
111  return _times( ptms );
112}
113#endif
Note: See TracBrowser for help on using the repository browser.