File: tsc.c

package info (click to toggle)
glide 2002.04.10ds1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 58,716 kB
  • sloc: ansic: 290,120; asm: 23,271; sh: 8,117; pascal: 3,854; makefile: 1,300; perl: 168
file content (113 lines) | stat: -rw-r--r-- 2,620 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
** THIS SOFTWARE IS SUBJECT TO COPYRIGHT PROTECTION AND IS OFFERED ONLY
** PURSUANT TO THE 3DFX GLIDE GENERAL PUBLIC LICENSE. THERE IS NO RIGHT
** TO USE THE GLIDE TRADEMARK WITHOUT PRIOR WRITTEN PERMISSION OF 3DFX
** INTERACTIVE, INC. A COPY OF THIS LICENSE MAY BE OBTAINED FROM THE 
** DISTRIBUTOR OR BY CONTACTING 3DFX INTERACTIVE INC(info@3dfx.com). 
** THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 
** EXPRESSED OR IMPLIED. SEE THE 3DFX GLIDE GENERAL PUBLIC LICENSE FOR A
** FULL TEXT OF THE NON-WARRANTY PROVISIONS.  
** 
** USE, DUPLICATION OR DISCLOSURE BY THE GOVERNMENT IS SUBJECT TO
** RESTRICTIONS AS SET FORTH IN SUBDIVISION (C)(1)(II) OF THE RIGHTS IN
** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013,
** AND/OR IN SIMILAR OR SUCCESSOR CLAUSES IN THE FAR, DOD OR NASA FAR
** SUPPLEMENT. UNPUBLISHED RIGHTS RESERVED UNDER THE COPYRIGHT LAWS OF
** THE UNITED STATES.  
** 
** COPYRIGHT 3DFX INTERACTIVE, INC. 1999, ALL RIGHTS RESERVED
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <3dfx.h>
#include <tsc.h>

static FxU32 tsc_histogram[TSC_MAX_CLOCKS];

FxU32        tsc_begin, tsc_end;
static FxU32 tsc_bias;

void 
tscInit( void ) {
   FxU32 test = 100;
   int   i;
   

   for ( i = 0; i < 10; i++ )
   {
     tscBegin();
     tsc_end = tscReadTSC();
     if ( ( tsc_end - tsc_begin ) < test )
        test = tsc_end - tsc_begin;
   }
   tsc_bias = test;
}

/*
** timing routines
*/
void tscStoreDelta( void )
{
   FxU32 value = tsc_end - tsc_begin;

   if ( value < TSC_MAX_CLOCKS && value > tsc_bias )
      tsc_histogram[value-tsc_bias]++;
}

void tscPrintHistogram( void )
{
   float total = 0.0F;
   int   i;

   for ( i = 0; i < TSC_MAX_CLOCKS; i++ )
      total += tsc_histogram[i];

   for ( i = 0; i < TSC_MAX_CLOCKS; i++ )
   {
      float percent = ( tsc_histogram[i] * 100.0F ) / total;

      if ( percent > 1.0 )
      {
         printf( "%04d: %3.2f\n", i, percent );
      }
   }
}

FxU32 
tscGetMostFrequent(void) {
  float total = 0.0F;
  int   i;
  float
    maxPercent = 0.f;
  FxU32
    mostFrequentClockCount;
  
  for ( i = 0; i < TSC_MAX_CLOCKS; i++ )
    total += tsc_histogram[i];
  
  for ( i = 0; i < TSC_MAX_CLOCKS; i++ ) {
    float percent = ( tsc_histogram[i] * 100.0F ) / total;
    
    if ( percent > maxPercent ) {
      maxPercent = percent;
      mostFrequentClockCount = i;
    }
  }
  return mostFrequentClockCount;
}

FxU32 *tscGetHistogram( void )
{
   return tsc_histogram;
}

void tscResetHistogram(void)
{
  int i;
  
  for (i = 0; i < TSC_MAX_CLOCKS; i++)
    tsc_histogram[i] = 0;
}