rt/msr_jitter.c
author Florian Pose <fp@igh-essen.com>
Thu, 05 Jan 2006 14:13:34 +0000
changeset 44 68d5b57cf038
parent 43 35120a61d55e
permissions -rw-r--r--
TODO-Liste erg?nzt.
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     1
/******************************************************************************
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     2
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     3
 * msr_jitter.c
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     4
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     5
 * Autor: Wilhelm Hagemeister
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     6
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     7
 * (C) Copyright IgH 2002
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     8
 * Ingenieurgemeinschaft IgH
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
     9
 * Heinz-Bäcker Str. 34
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    10
 * D-45356 Essen
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    11
 * Tel.: +49 201/61 99 31
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    12
 * Fax.: +49 201/61 98 36
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    13
 * E-mail: hm@igh-essen.com
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    14
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    15
 * $Id$
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    16
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    17
 *****************************************************************************/
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    18
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    19
#ifndef __KERNEL__
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    20
#  define __KERNEL__
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    21
#endif
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    22
#ifndef MODULE
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    23
#  define MODULE
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    24
#endif
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    25
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    26
#include <linux/config.h>
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    27
#include <linux/module.h>
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    28
#include <linux/sched.h>
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    29
#include <linux/kernel.h>
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    30
#include <asm/msr.h> /* maschine-specific registers */
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    31
#include <linux/param.h> /* fuer HZ */
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    32
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    33
#include <msr_reg.h>
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    34
#include "msr_jitter.h"
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    35
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    36
/*--includes-----------------------------------------------------------------*/
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    37
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    38
/*--external functions-------------------------------------------------------*/
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    39
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    40
/*--external data------------------------------------------------------------*/
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    41
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    42
/*--public data--------------------------------------------------------------*/
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    43
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    44
/*--local data---------------------------------------------------------------*/
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    45
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    46
#define NUMCLASSES 16
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    47
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    48
static int jittime[NUMCLASSES]={0,1,2,5,10,20,50,100,200,500,
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    49
                                1000,2000,5000,10000,20000,50000}; //in usec
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    50
static int jitcount[NUMCLASSES];
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    51
static double jitpercent[NUMCLASSES];
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    52
static unsigned int tcount = 1;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    53
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    54
static void msr_jit_read(void)
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    55
{
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    56
    int i;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    57
    for(i=0;i<NUMCLASSES;i++) {
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    58
	if(tcount >100) {
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    59
	    jitpercent[i] = jitcount[i]*100.0/tcount;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    60
	}
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    61
    }
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    62
}
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    63
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    64
void msr_jitter_init(void)
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    65
{
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    66
    msr_reg_int_list("/Taskinfo/Jitter/Classes","usec",
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    67
                     &jittime[0],MSR_R,NUMCLASSES,NULL,NULL,NULL);
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    68
    msr_reg_int_list("/Taskinfo/Jitter/Count","",
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    69
                     &jitcount[0],MSR_R,NUMCLASSES,NULL,NULL,NULL);
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    70
    msr_reg_dbl_list("/Taskinfo/Jitter/percent","%",
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    71
                     &jitpercent[0],MSR_R,NUMCLASSES,NULL,NULL,&msr_jit_read);
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    72
}
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    73
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    74
/******************************************************************************
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    75
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    76
 * Function: msr_jitter_run
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    77
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    78
 * Beschreibung:
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    79
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    80
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    81
 * Parameter: Zeiger auf msr_data
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    82
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    83
 * Rückgabe:
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    84
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    85
 * Status: exp
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    86
 *
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
    87
 *****************************************************************************/
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    88
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    89
void msr_jitter_run(unsigned int hz) {
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    90
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    91
    int i,hit;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    92
    static int firstrun = 1;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    93
    static unsigned long k,j = 0;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    94
    unsigned int dt,jitter;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    95
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    96
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    97
    rdtscl(k);
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    98
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
    99
    tcount++;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   100
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   101
    //Zeitabstand zwischen zwei Interrupts in usec
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   102
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   103
    dt = ((unsigned long)(100000/HZ)*((unsigned long)(k-j)))
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   104
        /(current_cpu_data.loops_per_jiffy/10);
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   105
43
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   106
    jitter = (unsigned int)abs((int)dt-(int)1000000/hz);
35120a61d55e Sch?nheitskorrekturen.
Florian Pose <fp@igh-essen.com>
parents: 42
diff changeset
   107
    //jitter errechnet zum Sollabtastrate
28
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   108
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   109
    //in die Klassen einsortieren
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   110
    if(!firstrun) { //das erste mal nicht einsortieren
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   111
	hit = 0;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   112
	for(i=0;i<NUMCLASSES-1;i++) {
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   113
	    if(jitter>=jittime[i] && jitter<jittime[i+1]) {
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   114
		jitcount[i]++;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   115
		hit = 1;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   116
		break;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   117
	    }
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   118
	}
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   119
	if(hit == 0) //grŽöŽßer als der letzte
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   120
	    jitcount[NUMCLASSES-1]++;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   121
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   122
    }
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   123
    else
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   124
	firstrun = 0;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   125
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   126
    j = k;
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   127
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   128
801dc7eabf51 IPIPE,floatpoint,rtlib
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
diff changeset
   129
}