Rev 355 | Rev 363 | 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 | |||
362 | giacomo | 68 | int tracer_initialize(int OutputType, int MemorySize); |
69 | void tracer_enable(); |
||
70 | void tracer_disable(); |
||
71 | void tracer_print_statistics(); |
||
72 | |||
352 | giacomo | 73 | #define TRACER_SERIALIZE |
74 | |||
75 | /* Save bytes => 1(type) + 4(tsc_high) + 4(tsc_low) + 1(size) |
||
76 | if (flag & 1) + 4(par1) |
||
77 | if (flag & 3) + 4(par2) |
||
78 | * Return 0 -> Success |
||
79 | * Return 1 -> Inactive |
||
80 | * Return 2 -> Error |
||
81 | */ |
||
82 | extern __inline__ int fast_logevent(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
83 | { |
||
84 | |||
85 | extern void *StartTracerBuffer; |
||
86 | extern void *EndTracerBuffer; |
||
362 | giacomo | 87 | extern void *LastBeforeEndTracerBuffer; |
352 | giacomo | 88 | extern void *CurrentTracerBuffer; |
362 | giacomo | 89 | extern void *FirstTracerBuffer; |
90 | |||
352 | giacomo | 91 | extern int TracerActive; |
92 | extern unsigned long long TracerEventsRecorded; |
||
93 | |||
94 | SYS_FLAGS f; |
||
95 | |||
96 | DWORD tsc_low, tsc_high; |
||
97 | BYTE size = 10; |
||
98 | |||
99 | f = ll_fsave(); |
||
100 | |||
101 | if (!TracerActive) { |
||
102 | ll_frestore(f); |
||
103 | return 1; |
||
104 | } |
||
105 | |||
106 | #ifdef TRACER_SERIALIZE |
||
107 | __asm__("xorl %%eax,%%eax\n\t" |
||
108 | "cpuid\n\t" |
||
109 | "rdtsc\n\t" |
||
110 | :"=a" (tsc_low), "=d" (tsc_high) |
||
111 | : |
||
112 | :"ebx","ecx"); |
||
113 | #else |
||
114 | __asm__("rdtsc\n\t" |
||
115 | :"=a" (tsc_low), "=d" (tsc_high) |
||
116 | ::); |
||
117 | #endif |
||
118 | |||
119 | if (flag & 1) size += 4; |
||
120 | if (flag & 3) size += 4; |
||
121 | |||
362 | giacomo | 122 | // Adjust FirstTracerBuffer |
123 | if (FirstTracerBuffer != StartTracerBuffer) { |
||
124 | while ((CurrentTracerBuffer + size - 1) > FirstTracerBuffer) { |
||
125 | FirstTracerBuffer += *(BYTE *)(FirstTracerBuffer + 9); |
||
126 | if (FirstTracerBuffer > LastBeforeEndTracerBuffer) FirstTracerBuffer = StartTracerBuffer; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | // Check if we overcome EndTracerBuffer |
||
352 | giacomo | 131 | if ((CurrentTracerBuffer + size - 1) > EndTracerBuffer) { |
132 | int i; |
||
133 | //Clear remain memory |
||
134 | for (i=0;i<(EndTracerBuffer-CurrentTracerBuffer+1);i++) |
||
135 | *(BYTE *)(CurrentTracerBuffer + i) = 0; |
||
136 | //Cyclical Buffer implementation |
||
362 | giacomo | 137 | LastBeforeEndTracerBuffer = CurrentTracerBuffer; |
352 | giacomo | 138 | CurrentTracerBuffer = StartTracerBuffer; |
362 | giacomo | 139 | //Set the First Event |
140 | FirstTracerBuffer = StartTracerBuffer + *(BYTE *)(StartTracerBuffer + 9); |
||
352 | giacomo | 141 | } |
142 | |||
362 | giacomo | 143 | // Add the new event |
352 | giacomo | 144 | *(BYTE *)CurrentTracerBuffer = type; |
145 | CurrentTracerBuffer++; |
||
146 | *(DWORD *)(CurrentTracerBuffer) = tsc_high; |
||
147 | CurrentTracerBuffer+=4; |
||
148 | *(DWORD *)(CurrentTracerBuffer) = tsc_low; |
||
149 | CurrentTracerBuffer+=4; |
||
150 | *(BYTE *)(CurrentTracerBuffer) = size; |
||
151 | CurrentTracerBuffer++; |
||
152 | if (flag & 1) { |
||
153 | *(DWORD *)(CurrentTracerBuffer) = par1; |
||
154 | CurrentTracerBuffer+=4; |
||
155 | } |
||
156 | if (flag & 3) { |
||
157 | *(DWORD *)(CurrentTracerBuffer) = par2; |
||
158 | CurrentTracerBuffer+=4; |
||
159 | } |
||
160 | |||
161 | if (CurrentTracerBuffer > EndTracerBuffer) { |
||
162 | ll_frestore(f); |
||
163 | return 2; |
||
164 | } |
||
165 | |||
166 | TracerEventsRecorded++; |
||
167 | |||
168 | ll_frestore(f); |
||
169 | return 0; |
||
170 | |||
171 | } |
||
172 | |||
173 | #else |
||
174 | |||
175 | #define TRACER_LOGEVENT(a,b,c,d) |
||
176 | |||
177 | #endif |
||
178 | |||
179 | #endif |
||
180 | |||
181 | #endif |