source: rtems/cpukit/score/src/timespecdivide.c @ c3330a8

4.104.114.84.95
Last change on this file since c3330a8 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: 1.2 KB
RevLine 
[f919582d]1/**
2 *  @file  score/src/timespecdivide.c
3 */
4
5/*
6 *  COPYRIGHT (c) 1989-2007.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <rtems/system.h>
21#include <sys/types.h>
22#include <rtems/score/timespec.h>
23#include <rtems/score/tod.h>
24
25void _Timespec_Divide(
[c3330a8]26  const struct timespec *lhs,
27  const struct timespec *rhs,
28  uint32_t              *ival_percentage,
29  uint32_t              *fval_percentage
[f919582d]30)
31{
[c3330a8]32  uint64_t left, right, answer;
[f919582d]33
34  /*
35   *  For math simplicity just convert the timespec to nanoseconds
36   *  in a 64-bit integer.
37   */
[c3330a8]38  left   = lhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
39  left  += lhs->tv_nsec;
40  right  = rhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND;
41  right += rhs->tv_nsec;
[f919582d]42
[c3330a8]43  if ( rhs == 0 ) {
44    *ival_percentage = 0;
45    *ival_percentage = 0;
46    return;
47  }
[f919582d]48
49  /*
50   *  Put it back in the timespec result
51   */
52
[c3330a8]53  answer = (left * 1000) / right;
54
55  *fval_percentage = answer % 1000;
56  *ival_percentage = answer / 1000;
[f919582d]57}
Note: See TracBrowser for help on using the repository browser.