28
|
1 |
/**************************************************************************************************
|
|
2 |
*
|
|
3 |
* msr_jitter.c
|
|
4 |
*
|
|
5 |
*
|
|
6 |
* Autor: Wilhelm Hagemeister
|
|
7 |
*
|
|
8 |
* (C) Copyright IgH 2002
|
|
9 |
* Ingenieurgemeinschaft IgH
|
|
10 |
* Heinz-Bäcker Str. 34
|
|
11 |
* D-45356 Essen
|
|
12 |
* Tel.: +49 201/61 99 31
|
|
13 |
* Fax.: +49 201/61 98 36
|
|
14 |
* E-mail: hm@igh-essen.com
|
|
15 |
*
|
|
16 |
*
|
|
17 |
* $RCSfile: msr_adeos_latency.c,v $
|
|
18 |
* $Revision: 1.3 $
|
|
19 |
* $Author: hm $
|
|
20 |
* $Date: 2005/12/07 20:13:53 $
|
|
21 |
* $State: Exp $
|
|
22 |
*
|
|
23 |
*
|
|
24 |
* $Log: msr_adeos_latency.c,v $
|
|
25 |
* Revision 1.3 2005/12/07 20:13:53 hm
|
|
26 |
* *** empty log message ***
|
|
27 |
*
|
|
28 |
* Revision 1.2 2005/12/07 15:56:13 hm
|
|
29 |
* *** empty log message ***
|
|
30 |
*
|
|
31 |
* Revision 1.1 2005/12/07 08:43:40 hm
|
|
32 |
* Initial revision
|
|
33 |
*
|
|
34 |
* Revision 1.5 2005/11/14 20:28:09 hm
|
|
35 |
* *** empty log message ***
|
|
36 |
*
|
|
37 |
* Revision 1.4 2005/11/13 10:34:07 hm
|
|
38 |
* *** empty log message ***
|
|
39 |
*
|
|
40 |
* Revision 1.3 2005/11/12 20:52:46 hm
|
|
41 |
* *** empty log message ***
|
|
42 |
*
|
|
43 |
* Revision 1.2 2005/11/12 20:51:27 hm
|
|
44 |
* *** empty log message ***
|
|
45 |
*
|
|
46 |
* Revision 1.1 2005/11/12 19:16:02 hm
|
|
47 |
* Initial revision
|
|
48 |
*
|
|
49 |
* Revision 1.13 2005/06/17 11:35:13 hm
|
|
50 |
* *** empty log message ***
|
|
51 |
*
|
|
52 |
*
|
|
53 |
*
|
|
54 |
*
|
|
55 |
**************************************************************************************************/
|
|
56 |
|
|
57 |
#ifndef __KERNEL__
|
|
58 |
# define __KERNEL__
|
|
59 |
#endif
|
|
60 |
#ifndef MODULE
|
|
61 |
# define MODULE
|
|
62 |
#endif
|
|
63 |
|
|
64 |
#include <linux/config.h>
|
|
65 |
#include <linux/module.h>
|
|
66 |
#include <linux/sched.h>
|
|
67 |
#include <linux/kernel.h>
|
|
68 |
#include <asm/msr.h> /* maschine-specific registers */
|
|
69 |
#include <linux/param.h> /* fuer HZ */
|
|
70 |
|
|
71 |
#include <msr_reg.h>
|
|
72 |
#include "msr_jitter.h"
|
|
73 |
|
|
74 |
/*--includes-------------------------------------------------------------------------------------*/
|
|
75 |
|
|
76 |
|
|
77 |
/*--external functions---------------------------------------------------------------------------*/
|
|
78 |
|
|
79 |
/*--external data--------------------------------------------------------------------------------*/
|
|
80 |
|
|
81 |
/*--public data----------------------------------------------------------------------------------*/
|
|
82 |
|
|
83 |
/*--local data-----------------------------------------------------------------------------------*/
|
|
84 |
|
|
85 |
#define NUMCLASSES 16
|
|
86 |
|
|
87 |
static int jittime[NUMCLASSES]={0,1,2,5,10,20,50,100,200,500,1000,2000,5000,10000,20000,50000}; //in usec
|
|
88 |
static int jitcount[NUMCLASSES];
|
|
89 |
static double jitpercent[NUMCLASSES];
|
|
90 |
|
|
91 |
static unsigned int tcount = 1;
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
static void msr_jit_read(void)
|
|
96 |
{
|
|
97 |
int i;
|
|
98 |
for(i=0;i<NUMCLASSES;i++) {
|
|
99 |
if(tcount >100) {
|
|
100 |
jitpercent[i] = jitcount[i]*100.0/tcount;
|
|
101 |
}
|
|
102 |
}
|
|
103 |
}
|
|
104 |
|
|
105 |
void msr_jitter_init(void)
|
|
106 |
{
|
|
107 |
msr_reg_int_list("/Taskinfo/Jitter/Classes","usec",&jittime[0],MSR_R,NUMCLASSES,NULL,NULL,NULL);
|
|
108 |
msr_reg_int_list("/Taskinfo/Jitter/Count","",&jitcount[0],MSR_R,NUMCLASSES,NULL,NULL,NULL);
|
|
109 |
msr_reg_dbl_list("/Taskinfo/Jitter/percent","%",&jitpercent[0],MSR_R,NUMCLASSES,NULL,NULL,&msr_jit_read);
|
|
110 |
}
|
|
111 |
|
|
112 |
/*
|
|
113 |
***************************************************************************************************
|
|
114 |
*
|
|
115 |
* Function: msr_jitter_run
|
|
116 |
*
|
|
117 |
* Beschreibung:
|
|
118 |
*
|
|
119 |
*
|
|
120 |
* Parameter: Zeiger auf msr_data
|
|
121 |
*
|
|
122 |
* Rückgabe:
|
|
123 |
*
|
|
124 |
* Status: exp
|
|
125 |
*
|
|
126 |
***************************************************************************************************
|
|
127 |
*/
|
|
128 |
|
|
129 |
void msr_jitter_run(unsigned int hz) {
|
|
130 |
|
|
131 |
int i,hit;
|
|
132 |
static int firstrun = 1;
|
|
133 |
static int counter = 0;
|
|
134 |
static unsigned long k,j = 0;
|
|
135 |
unsigned int dt,jitter;
|
|
136 |
|
|
137 |
|
|
138 |
rdtscl(k);
|
|
139 |
|
|
140 |
tcount++;
|
|
141 |
|
|
142 |
//Zeitabstand zwischen zwei Interrupts in usec
|
|
143 |
|
|
144 |
dt = ((unsigned long)(100000/HZ)*((unsigned long)(k-j)))/(current_cpu_data.loops_per_jiffy/10);
|
|
145 |
|
|
146 |
jitter = (unsigned int)abs((int)dt-(int)1000000/hz); //jitter errechnet zum Sollabtastrate
|
|
147 |
|
|
148 |
//in die Klassen einsortieren
|
|
149 |
if(!firstrun) { //das erste mal nicht einsortieren
|
|
150 |
hit = 0;
|
|
151 |
for(i=0;i<NUMCLASSES-1;i++) {
|
|
152 |
if(jitter>=jittime[i] && jitter<jittime[i+1]) {
|
|
153 |
jitcount[i]++;
|
|
154 |
hit = 1;
|
|
155 |
break;
|
|
156 |
}
|
|
157 |
}
|
|
158 |
if(hit == 0) //grŽöŽßer als der letzte
|
|
159 |
jitcount[NUMCLASSES-1]++;
|
|
160 |
|
|
161 |
}
|
|
162 |
else
|
|
163 |
firstrun = 0;
|
|
164 |
|
|
165 |
j = k;
|
|
166 |
|
|
167 |
|
|
168 |
}
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|