Rev 352 | Rev 362 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
352 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://shark.sssup.it |
||
16 | */ |
||
17 | |||
18 | #ifndef __TRACER_H__ |
||
19 | #define __TRACER_H__ |
||
20 | |||
21 | #ifdef __OLD_TRACER__ |
||
22 | |||
23 | #include <ll/sys/types.h> |
||
24 | #include "types.h" |
||
25 | #include "trace.h" |
||
355 | giacomo | 26 | #include "FTrace.h" |
352 | giacomo | 27 | |
28 | #define TRACER_LOGEVENT oldtrace |
||
29 | |||
30 | extern int (*trc_register_eventclass) |
||
31 | (int class,int num,int(*func)(trc_event_t *, int event, void *ptr)); |
||
32 | |||
33 | extern void (*trc_logevent)(int event, void *ptr); |
||
34 | |||
35 | extern int (*trc_resume)(void); |
||
36 | extern int (*trc_suspend)(void); |
||
37 | |||
38 | #define NOT_DEFINED 0xFF |
||
39 | |||
40 | extern __inline__ void oldtrace(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
41 | { |
||
42 | |||
43 | static int oldtype; |
||
44 | static int oldpar; |
||
45 | extern BYTE conv[256]; // Conversion table: ctable.c |
||
46 | BYTE ttype = 0; |
||
47 | |||
48 | ttype = type & 0x0F; |
||
49 | type = type >> 4; |
||
50 | type |= (ttype << 4); |
||
51 | |||
52 | oldtype = conv[type]; |
||
53 | |||
54 | if (oldtype != NOT_DEFINED) trc_logevent(oldtype,&oldpar); |
||
55 | |||
56 | } |
||
57 | |||
58 | |||
59 | #else |
||
60 | #ifdef __NEW_TRACER__ |
||
61 | |||
62 | #include <ll/sys/types.h> |
||
63 | #include <ll/i386/hw-instr.h> |
||
64 | #include "FTrace.h" |
||
65 | |||
66 | #define TRACER_LOGEVENT fast_logevent |
||
67 | |||
68 | #define TRACER_SERIALIZE |
||
69 | |||
70 | /* Save bytes => 1(type) + 4(tsc_high) + 4(tsc_low) + 1(size) |
||
71 | if (flag & 1) + 4(par1) |
||
72 | if (flag & 3) + 4(par2) |
||
73 | * Return 0 -> Success |
||
74 | * Return 1 -> Inactive |
||
75 | * Return 2 -> Error |
||
76 | */ |
||
77 | extern __inline__ int fast_logevent(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
78 | { |
||
79 | |||
80 | extern void *StartTracerBuffer; |
||
81 | extern void *EndTracerBuffer; |
||
82 | extern void *CurrentTracerBuffer; |
||
83 | extern int TracerActive; |
||
84 | extern unsigned long long TracerEventsRecorded; |
||
85 | |||
86 | SYS_FLAGS f; |
||
87 | |||
88 | DWORD tsc_low, tsc_high; |
||
89 | BYTE size = 10; |
||
90 | |||
91 | f = ll_fsave(); |
||
92 | |||
93 | if (!TracerActive) { |
||
94 | ll_frestore(f); |
||
95 | return 1; |
||
96 | } |
||
97 | |||
98 | #ifdef TRACER_SERIALIZE |
||
99 | __asm__("xorl %%eax,%%eax\n\t" |
||
100 | "cpuid\n\t" |
||
101 | "rdtsc\n\t" |
||
102 | :"=a" (tsc_low), "=d" (tsc_high) |
||
103 | : |
||
104 | :"ebx","ecx"); |
||
105 | #else |
||
106 | __asm__("rdtsc\n\t" |
||
107 | :"=a" (tsc_low), "=d" (tsc_high) |
||
108 | ::); |
||
109 | #endif |
||
110 | |||
111 | if (flag & 1) size += 4; |
||
112 | if (flag & 3) size += 4; |
||
113 | |||
114 | if ((CurrentTracerBuffer + size - 1) > EndTracerBuffer) { |
||
115 | int i; |
||
116 | //Clear remain memory |
||
117 | for (i=0;i<(EndTracerBuffer-CurrentTracerBuffer+1);i++) |
||
118 | *(BYTE *)(CurrentTracerBuffer + i) = 0; |
||
119 | //Cyclical Buffer implementation |
||
120 | CurrentTracerBuffer = StartTracerBuffer; |
||
121 | } |
||
122 | |||
123 | *(BYTE *)CurrentTracerBuffer = type; |
||
124 | CurrentTracerBuffer++; |
||
125 | *(DWORD *)(CurrentTracerBuffer) = tsc_high; |
||
126 | CurrentTracerBuffer+=4; |
||
127 | *(DWORD *)(CurrentTracerBuffer) = tsc_low; |
||
128 | CurrentTracerBuffer+=4; |
||
129 | *(BYTE *)(CurrentTracerBuffer) = size; |
||
130 | CurrentTracerBuffer++; |
||
131 | if (flag & 1) { |
||
132 | *(DWORD *)(CurrentTracerBuffer) = par1; |
||
133 | CurrentTracerBuffer+=4; |
||
134 | } |
||
135 | if (flag & 3) { |
||
136 | *(DWORD *)(CurrentTracerBuffer) = par2; |
||
137 | CurrentTracerBuffer+=4; |
||
138 | } |
||
139 | |||
140 | if (CurrentTracerBuffer > EndTracerBuffer) { |
||
141 | ll_frestore(f); |
||
142 | return 2; |
||
143 | } |
||
144 | |||
145 | TracerEventsRecorded++; |
||
146 | |||
147 | ll_frestore(f); |
||
148 | return 0; |
||
149 | |||
150 | } |
||
151 | |||
152 | #else |
||
153 | |||
154 | #define TRACER_LOGEVENT(a,b,c,d) |
||
155 | |||
156 | #endif |
||
157 | |||
158 | #endif |
||
159 | |||
160 | #endif |