1a18fe8c92b89faaea3be733c6a051b1f92c3b5a
[linux-2.6.git] / include / linux / vserver / debug.h
1 #ifndef _VX_DEBUG_H
2 #define _VX_DEBUG_H
3
4 #ifndef CONFIG_VSERVER
5 #warning config options missing
6 #endif
7
8 #define VXD_CBIT(n,m)   (vx_debug_ ## n & (1 << (m)))
9 #define VXD_CMIN(n,m)   (vx_debug_ ## n > (m))
10 #define VXD_MASK(n,m)   (vx_debug_ ## n & (m))
11
12 #define VXD_QPOS(v,p)   (((uint32_t)(v) >> ((p)*8)) & 0xFF)
13 #define VXD_QUAD(v)     VXD_QPOS(v,0), VXD_QPOS(v,1),           \
14                         VXD_QPOS(v,2), VXD_QPOS(v,3)
15
16 #define __FUNC__        __func__
17
18
19 #ifdef  CONFIG_VSERVER_DEBUG
20
21 extern unsigned int vx_debug_switch;
22 extern unsigned int vx_debug_xid;
23 extern unsigned int vx_debug_nid;
24 extern unsigned int vx_debug_net;
25 extern unsigned int vx_debug_limit;
26 extern unsigned int vx_debug_dlim;
27 extern unsigned int vx_debug_cvirt;
28
29
30 #define VX_LOGLEVEL     "vxD: "
31 #define VX_WARNLEVEL    KERN_WARNING "vxW: "
32
33 #define vxdprintk(c,f,x...)                                     \
34         do {                                                    \
35                 if (c)                                          \
36                         printk(VX_LOGLEVEL f "\n" , ##x);       \
37         } while (0)
38
39 #define vxlprintk(c,f,x...)                                     \
40         do {                                                    \
41                 if (c)                                          \
42                         printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
43         } while (0)
44
45 #define vxfprintk(c,f,x...)                                     \
46         do {                                                    \
47                 if (c)                                          \
48                         printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
49         } while (0)
50
51
52 #define vxwprintk(c,f,x...)                                     \
53         do {                                                    \
54                 if (c)                                          \
55                         printk(VX_WARNLEVEL f "\n" , ##x);      \
56         } while (0)
57
58
59 #define vxd_path(d,m)                                           \
60         ({ static char _buffer[PATH_MAX];                       \
61            d_path((d), (m), _buffer, sizeof(_buffer)); })
62
63 #else   /* CONFIG_VSERVER_DEBUG */
64
65 #define vx_debug_switch 0
66 #define vx_debug_xid    0
67 #define vx_debug_nid    0
68 #define vx_debug_net    0
69 #define vx_debug_limit  0
70 #define vx_debug_dlim   0
71 #define vx_debug_cvirt  0
72
73 #define vxdprintk(x...) do { } while (0)
74 #define vxlprintk(x...) do { } while (0)
75 #define vxfprintk(x...) do { } while (0)
76 #define vxwprintk(x...) do { } while (0)
77
78 #define vxd_path        "<none>"
79
80 #endif  /* CONFIG_VSERVER_DEBUG */
81
82
83 /* history stuff */
84
85 #ifdef  CONFIG_VSERVER_HISTORY
86
87
88 extern unsigned volatile int vxh_active;
89
90 struct _vxhe_vxi {
91         struct vx_info *ptr;
92         unsigned xid;
93         unsigned usecnt;
94         unsigned tasks;
95 };
96
97 struct _vxhe_set_clr {
98         void *data;
99 };
100
101 struct _vxhe_loc_lookup {
102         unsigned arg;
103 };
104
105 enum {
106         VXH_UNUSED=0,
107         VXH_THROW_OOPS=1,
108
109         VXH_GET_VX_INFO,
110         VXH_PUT_VX_INFO,
111         VXH_INIT_VX_INFO,
112         VXH_SET_VX_INFO,
113         VXH_CLR_VX_INFO,
114         VXH_CLAIM_VX_INFO,
115         VXH_RELEASE_VX_INFO,
116         VXH_ALLOC_VX_INFO,
117         VXH_DEALLOC_VX_INFO,
118         VXH_HASH_VX_INFO,
119         VXH_UNHASH_VX_INFO,
120         VXH_LOC_VX_INFO,
121         VXH_LOOKUP_VX_INFO,
122         VXH_CREATE_VX_INFO,
123 };
124
125 struct _vx_hist_entry {
126         void *loc;
127         unsigned short seq;
128         unsigned short type;
129         struct _vxhe_vxi vxi;
130         union {
131                 struct _vxhe_set_clr sc;
132                 struct _vxhe_loc_lookup ll;
133         };
134 };
135
136 struct _vx_hist_entry *vxh_advance(void *loc);
137
138 #define VXH_HERE()              \
139         ({ __label__ here;      \
140                 here:;          \
141                 &&here; })
142
143
144
145 static inline void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
146 {
147         entry->vxi.ptr = vxi;
148         if (vxi) {
149                 entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
150                 entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
151                 entry->vxi.xid = vxi->vx_id;
152         }
153 }
154
155 static inline void vxh_throw_oops(void)
156 {
157         struct _vx_hist_entry *entry;
158
159         preempt_disable();
160         entry = vxh_advance(VXH_HERE());
161         entry->type = VXH_THROW_OOPS;
162         preempt_enable();
163
164         /* prevent further acquisition */
165         vxh_active = 0;
166 }
167
168 static inline void vxh_get_vx_info(struct vx_info *vxi)
169 {
170         struct _vx_hist_entry *entry;
171
172         preempt_disable();
173         entry = vxh_advance(VXH_HERE());
174         __vxh_copy_vxi(entry, vxi);
175         entry->type = VXH_GET_VX_INFO;
176         preempt_enable();
177 }
178
179 static inline void vxh_put_vx_info(struct vx_info *vxi)
180 {
181         struct _vx_hist_entry *entry;
182
183         preempt_disable();
184         entry = vxh_advance(VXH_HERE());
185         __vxh_copy_vxi(entry, vxi);
186         entry->type = VXH_PUT_VX_INFO;
187         preempt_enable();
188 }
189
190 static inline void vxh_init_vx_info(struct vx_info *vxi, void *data)
191 {
192         struct _vx_hist_entry *entry;
193
194         preempt_disable();
195         entry = vxh_advance(VXH_HERE());
196         __vxh_copy_vxi(entry, vxi);
197         entry->sc.data = data;
198         entry->type = VXH_INIT_VX_INFO;
199         preempt_enable();
200 }
201
202 static inline void vxh_set_vx_info(struct vx_info *vxi, void *data)
203 {
204         struct _vx_hist_entry *entry;
205
206         preempt_disable();
207         entry = vxh_advance(VXH_HERE());
208         __vxh_copy_vxi(entry, vxi);
209         entry->sc.data = data;
210         entry->type = VXH_SET_VX_INFO;
211         preempt_enable();
212 }
213
214 static inline void vxh_clr_vx_info(struct vx_info *vxi, void *data)
215 {
216         struct _vx_hist_entry *entry;
217
218         preempt_disable();
219         entry = vxh_advance(VXH_HERE());
220         __vxh_copy_vxi(entry, vxi);
221         entry->sc.data = data;
222         entry->type = VXH_CLR_VX_INFO;
223         preempt_enable();
224 }
225
226 static inline void vxh_claim_vx_info(struct vx_info *vxi, void *data)
227 {
228         struct _vx_hist_entry *entry;
229
230         preempt_disable();
231         entry = vxh_advance(VXH_HERE());
232         __vxh_copy_vxi(entry, vxi);
233         entry->sc.data = data;
234         entry->type = VXH_CLAIM_VX_INFO;
235         preempt_enable();
236 }
237
238 static inline void vxh_release_vx_info(struct vx_info *vxi, void *data)
239 {
240         struct _vx_hist_entry *entry;
241
242         preempt_disable();
243         entry = vxh_advance(VXH_HERE());
244         __vxh_copy_vxi(entry, vxi);
245         entry->sc.data = data;
246         entry->type = VXH_RELEASE_VX_INFO;
247         preempt_enable();
248 }
249
250 static inline void vxh_alloc_vx_info(struct vx_info *vxi)
251 {
252         struct _vx_hist_entry *entry;
253
254         preempt_disable();
255         entry = vxh_advance(VXH_HERE());
256         __vxh_copy_vxi(entry, vxi);
257         entry->type = VXH_ALLOC_VX_INFO;
258         preempt_enable();
259 }
260
261 static inline void vxh_dealloc_vx_info(struct vx_info *vxi)
262 {
263         struct _vx_hist_entry *entry;
264
265         preempt_disable();
266         entry = vxh_advance(VXH_HERE());
267         __vxh_copy_vxi(entry, vxi);
268         entry->type = VXH_DEALLOC_VX_INFO;
269         preempt_enable();
270 }
271
272 static inline void vxh_hash_vx_info(struct vx_info *vxi)
273 {
274         struct _vx_hist_entry *entry;
275
276         preempt_disable();
277         entry = vxh_advance(VXH_HERE());
278         __vxh_copy_vxi(entry, vxi);
279         entry->type = VXH_HASH_VX_INFO;
280         preempt_enable();
281 }
282
283 static inline void vxh_unhash_vx_info(struct vx_info *vxi)
284 {
285         struct _vx_hist_entry *entry;
286
287         preempt_disable();
288         entry = vxh_advance(VXH_HERE());
289         __vxh_copy_vxi(entry, vxi);
290         entry->type = VXH_UNHASH_VX_INFO;
291         preempt_enable();
292 }
293
294 static inline void vxh_loc_vx_info(unsigned arg, struct vx_info *vxi)
295 {
296         struct _vx_hist_entry *entry;
297
298         preempt_disable();
299         entry = vxh_advance(VXH_HERE());
300         __vxh_copy_vxi(entry, vxi);
301         entry->ll.arg = arg;
302         entry->type = VXH_LOC_VX_INFO;
303         preempt_enable();
304 }
305
306 static inline void vxh_lookup_vx_info(unsigned arg, struct vx_info *vxi)
307 {
308         struct _vx_hist_entry *entry;
309
310         preempt_disable();
311         entry = vxh_advance(VXH_HERE());
312         __vxh_copy_vxi(entry, vxi);
313         entry->ll.arg = arg;
314         entry->type = VXH_LOOKUP_VX_INFO;
315         preempt_enable();
316 }
317
318 static inline void vxh_create_vx_info(unsigned arg, struct vx_info *vxi)
319 {
320         struct _vx_hist_entry *entry;
321
322         preempt_disable();
323         entry = vxh_advance(VXH_HERE());
324         __vxh_copy_vxi(entry, vxi);
325         entry->ll.arg = arg;
326         entry->type = VXH_CREATE_VX_INFO;
327         preempt_enable();
328 }
329
330
331 extern void vxh_dump_history(void);
332
333 #else  /* CONFIG_VSERVER_HISTORY */
334
335 #define vxh_throw_oops()                do { } while (0)
336
337 #define vxh_get_vx_info(v)              do { } while (0)
338 #define vxh_put_vx_info(v)              do { } while (0)
339
340 #define vxh_init_vx_info(v,d)           do { } while (0)
341 #define vxh_set_vx_info(v,d)            do { } while (0)
342 #define vxh_clr_vx_info(v,d)            do { } while (0)
343
344 #define vxh_claim_vx_info(v,d)          do { } while (0)
345 #define vxh_release_vx_info(v,d)        do { } while (0)
346
347 #define vxh_alloc_vx_info(v)            do { } while (0)
348 #define vxh_dealloc_vx_info(v)          do { } while (0)
349
350 #define vxh_hash_vx_info(v)             do { } while (0)
351 #define vxh_unhash_vx_info(v)           do { } while (0)
352
353 #define vxh_loc_vx_info(a,v)            do { } while (0)
354 #define vxh_lookup_vx_info(a,v)         do { } while (0)
355 #define vxh_create_vx_info(a,v)         do { } while (0)
356
357 #define vxh_dump_history()              do { } while (0)
358
359
360 #endif /* CONFIG_VSERVER_HISTORY */
361
362
363 #ifdef  CONFIG_VSERVER_DEBUG
364 #define vxd_assert_lock(l)      assert_spin_locked(l)
365 #else
366 #define vxd_assert_lock(l)      do { } while (0)
367 #endif
368
369
370 #endif /* _VX_DEBUG_H */