Rev 355 | Go to most recent revision | Details | 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" |
||
26 | |||
27 | #define TRACER_LOGEVENT oldtrace |
||
28 | |||
29 | extern int (*trc_register_eventclass) |
||
30 | (int class,int num,int(*func)(trc_event_t *, int event, void *ptr)); |
||
31 | |||
32 | extern void (*trc_logevent)(int event, void *ptr); |
||
33 | |||
34 | extern int (*trc_resume)(void); |
||
35 | extern int (*trc_suspend)(void); |
||
36 | |||
37 | #define NOT_DEFINED 0xFF |
||
38 | |||
39 | extern __inline__ void oldtrace(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
40 | { |
||
41 | |||
42 | static int oldtype; |
||
43 | static int oldpar; |
||
44 | extern BYTE conv[256]; // Conversion table: ctable.c |
||
45 | BYTE ttype = 0; |
||
46 | |||
47 | ttype = type & 0x0F; |
||
48 | type = type >> 4; |
||
49 | type |= (ttype << 4); |
||
50 | |||
51 | oldtype = conv[type]; |
||
52 | |||
53 | if (oldtype != NOT_DEFINED) trc_logevent(oldtype,&oldpar); |
||
54 | |||
55 | } |
||
56 | |||
57 | |||
58 | #else |
||
59 | #ifdef __NEW_TRACER__ |
||
60 | |||
61 | #include <ll/sys/types.h> |
||
62 | #include <ll/i386/hw-instr.h> |
||
63 | #include "FTrace.h" |
||
64 | |||
65 | #define TRACER_LOGEVENT fast_logevent |
||
66 | |||
67 | #define TRACER_SERIALIZE |
||
68 | |||
69 | /* Save bytes => 1(type) + 4(tsc_high) + 4(tsc_low) + 1(size) |
||
70 | if (flag & 1) + 4(par1) |
||
71 | if (flag & 3) + 4(par2) |
||
72 | * Return 0 -> Success |
||
73 | * Return 1 -> Inactive |
||
74 | * Return 2 -> Error |
||
75 | */ |
||
76 | extern __inline__ int fast_logevent(BYTE type, BYTE flag, DWORD par1, DWORD par2) |
||
77 | { |
||
78 | |||
79 | extern void *StartTracerBuffer; |
||
80 | extern void *EndTracerBuffer; |
||
81 | extern void *CurrentTracerBuffer; |
||
82 | extern int TracerActive; |
||
83 | extern unsigned long long TracerEventsRecorded; |
||
84 | |||
85 | SYS_FLAGS f; |
||
86 | |||
87 | DWORD tsc_low, tsc_high; |
||
88 | BYTE size = 10; |
||
89 | |||
90 | f = ll_fsave(); |
||
91 | |||
92 | if (!TracerActive) { |
||
93 | ll_frestore(f); |
||
94 | return 1; |
||
95 | } |
||
96 | |||
97 | #ifdef TRACER_SERIALIZE |
||
98 | __asm__("xorl %%eax,%%eax\n\t" |
||
99 | "cpuid\n\t" |
||
100 | "rdtsc\n\t" |
||
101 | :"=a" (tsc_low), "=d" (tsc_high) |
||
102 | : |
||
103 | :"ebx","ecx"); |
||
104 | #else |
||
105 | __asm__("rdtsc\n\t" |
||
106 | :"=a" (tsc_low), "=d" (tsc_high) |
||
107 | ::); |
||
108 | #endif |
||
109 | |||
110 | if (flag & 1) size += 4; |
||
111 | if (flag & 3) size += 4; |
||
112 | |||
113 | if ((CurrentTracerBuffer + size - 1) > EndTracerBuffer) { |
||
114 | int i; |
||
115 | //Clear remain memory |
||
116 | for (i=0;i<(EndTracerBuffer-CurrentTracerBuffer+1);i++) |
||
117 | *(BYTE *)(CurrentTracerBuffer + i) = 0; |
||
118 | //Cyclical Buffer implementation |
||
119 | CurrentTracerBuffer = StartTracerBuffer; |
||
120 | } |
||
121 | |||
122 | *(BYTE *)CurrentTracerBuffer = type; |
||
123 | CurrentTracerBuffer++; |
||
124 | *(DWORD *)(CurrentTracerBuffer) = tsc_high; |
||
125 | CurrentTracerBuffer+=4; |
||
126 | *(DWORD *)(CurrentTracerBuffer) = tsc_low; |
||
127 | CurrentTracerBuffer+=4; |
||
128 | *(BYTE *)(CurrentTracerBuffer) = size; |
||
129 | CurrentTracerBuffer++; |
||
130 | if (flag & 1) { |
||
131 | *(DWORD *)(CurrentTracerBuffer) = par1; |
||
132 | CurrentTracerBuffer+=4; |
||
133 | } |
||
134 | if (flag & 3) { |
||
135 | *(DWORD *)(CurrentTracerBuffer) = par2; |
||
136 | CurrentTracerBuffer+=4; |
||
137 | } |
||
138 | |||
139 | if (CurrentTracerBuffer > EndTracerBuffer) { |
||
140 | ll_frestore(f); |
||
141 | return 2; |
||
142 | } |
||
143 | |||
144 | TracerEventsRecorded++; |
||
145 | |||
146 | ll_frestore(f); |
||
147 | return 0; |
||
148 | |||
149 | } |
||
150 | |||
151 | #else |
||
152 | |||
153 | #define TRACER_LOGEVENT(a,b,c,d) |
||
154 | |||
155 | #endif |
||
156 | |||
157 | #endif |
||
158 | |||
159 | #endif |