4.8
Last change
on this file since bd029d87 was
0f4f543,
checked in by Glenn Humphrey <glenn.humphrey@…>, on 10/26/07 at 21:31:04
|
2007-10-26 Glenn Humphrey <glenn.humphrey@…>
- libmisc/cpuuse/cpuusagereport.c, rtems/src/ratemonreportstatistics.c:
Cleaned up reports and fixed a bug related the printf format which
resulted in lack of leading zeroes and misleading magnitude.
- score/src/timespecdivide.c: Fixed bugs related to zero divide case.
|
-
Property mode set to
100644
|
File size:
1.3 KB
|
Line | |
---|
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 <stdio.h> |
---|
21 | |
---|
22 | #include <rtems/system.h> |
---|
23 | #include <sys/types.h> |
---|
24 | #include <rtems/score/timespec.h> |
---|
25 | #include <rtems/score/tod.h> |
---|
26 | |
---|
27 | void _Timespec_Divide( |
---|
28 | const struct timespec *lhs, |
---|
29 | const struct timespec *rhs, |
---|
30 | uint32_t *ival_percentage, |
---|
31 | uint32_t *fval_percentage |
---|
32 | ) |
---|
33 | { |
---|
34 | uint64_t left, right, answer; |
---|
35 | |
---|
36 | /* |
---|
37 | * For math simplicity just convert the timespec to nanoseconds |
---|
38 | * in a 64-bit integer. |
---|
39 | */ |
---|
40 | left = lhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND; |
---|
41 | left += lhs->tv_nsec; |
---|
42 | right = rhs->tv_sec * (uint64_t)TOD_NANOSECONDS_PER_SECOND; |
---|
43 | right += rhs->tv_nsec; |
---|
44 | |
---|
45 | if ( right == 0 ) { |
---|
46 | *ival_percentage = 0; |
---|
47 | *fval_percentage = 0; |
---|
48 | return; |
---|
49 | } |
---|
50 | |
---|
51 | /* |
---|
52 | * Put it back in the timespec result. |
---|
53 | * |
---|
54 | * TODO: Rounding on the last digit of the fval. |
---|
55 | */ |
---|
56 | |
---|
57 | answer = (left * 100000) / right; |
---|
58 | |
---|
59 | *ival_percentage = answer / 1000; |
---|
60 | *fval_percentage = answer % 1000; |
---|
61 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.