updated to 2.6.13.3-vs2.1.0-rc4 headers
[util-vserver.git] / util-vserver / kernel / 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_quota;
28 extern unsigned int vx_debug_cvirt;
29 extern unsigned int vx_debug_misc;
30
31
32 #define VX_LOGLEVEL     "vxD: "
33 #define VX_WARNLEVEL    KERN_WARNING "vxW: "
34
35 #define vxdprintk(c,f,x...)                                     \
36         do {                                                    \
37                 if (c)                                          \
38                         printk(VX_LOGLEVEL f "\n" , ##x);       \
39         } while (0)
40
41 #define vxlprintk(c,f,x...)                                     \
42         do {                                                    \
43                 if (c)                                          \
44                         printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
45         } while (0)
46
47 #define vxfprintk(c,f,x...)                                     \
48         do {                                                    \
49                 if (c)                                          \
50                         printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
51         } while (0)
52
53
54 #define vxwprintk(c,f,x...)                                     \
55         do {                                                    \
56                 if (c)                                          \
57                         printk(VX_WARNLEVEL f "\n" , ##x);      \
58         } while (0)
59
60
61 #define vxd_path(d,m)                                           \
62         ({ static char _buffer[PATH_MAX];                       \
63            d_path((d), (m), _buffer, sizeof(_buffer)); })
64
65
66 void dump_vx_info(struct vx_info *, int);
67 void dump_vx_info_inactive(int);
68
69 #else   /* CONFIG_VSERVER_DEBUG */
70
71 #define vx_debug_switch 0
72 #define vx_debug_xid    0
73 #define vx_debug_nid    0
74 #define vx_debug_net    0
75 #define vx_debug_limit  0
76 #define vx_debug_dlim   0
77 #define vx_debug_cvirt  0
78
79 #define vxdprintk(x...) do { } while (0)
80 #define vxlprintk(x...) do { } while (0)
81 #define vxfprintk(x...) do { } while (0)
82 #define vxwprintk(x...) do { } while (0)
83
84 #define vxd_path        "<none>"
85
86
87 #endif  /* CONFIG_VSERVER_DEBUG */
88
89
90 /* history stuff */
91
92 #ifdef  CONFIG_VSERVER_HISTORY
93
94
95 extern unsigned volatile int vxh_active;
96
97 struct _vxhe_vxi {
98         struct vx_info *ptr;
99         unsigned xid;
100         unsigned usecnt;
101         unsigned tasks;
102 };
103
104 struct _vxhe_set_clr {
105         void *data;
106 };
107
108 struct _vxhe_loc_lookup {
109         unsigned arg;
110 };
111
112 enum {
113         VXH_UNUSED=0,
114         VXH_THROW_OOPS=1,
115
116         VXH_GET_VX_INFO,
117         VXH_PUT_VX_INFO,
118         VXH_INIT_VX_INFO,
119         VXH_SET_VX_INFO,
120         VXH_CLR_VX_INFO,
121         VXH_CLAIM_VX_INFO,
122         VXH_RELEASE_VX_INFO,
123         VXH_ALLOC_VX_INFO,
124         VXH_DEALLOC_VX_INFO,
125         VXH_HASH_VX_INFO,
126         VXH_UNHASH_VX_INFO,
127         VXH_LOC_VX_INFO,
128         VXH_LOOKUP_VX_INFO,
129         VXH_CREATE_VX_INFO,
130 };
131
132 struct _vx_hist_entry {
133         void *loc;
134         unsigned short seq;
135         unsigned short type;
136         struct _vxhe_vxi vxi;
137         union {
138                 struct _vxhe_set_clr sc;
139                 struct _vxhe_loc_lookup ll;
140         };
141 };
142
143 struct _vx_hist_entry *vxh_advance(void *loc);
144
145
146 static inline
147 void    __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
148 {
149         entry->vxi.ptr = vxi;
150         if (vxi) {
151                 entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
152                 entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
153                 entry->vxi.xid = vxi->vx_id;
154         }
155 }
156
157
158 #define __HERE__ \
159         ({ __label__ __vxh_label; __vxh_label:; &&__vxh_label; })
160
161 #define __VXH_BODY(__type, __data, __here)      \
162         struct _vx_hist_entry *entry;           \
163                                                 \
164         preempt_disable();                      \
165         entry = vxh_advance(__here);            \
166         __data;                                 \
167         entry->type = __type;                   \
168         preempt_enable();
169
170
171         /* pass vxi only */
172
173 #define __VXH_SMPL                              \
174         __vxh_copy_vxi(entry, vxi)
175
176 static inline
177 void    __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
178 {
179         __VXH_BODY(__type, __VXH_SMPL, __here)
180 }
181
182         /* pass vxi and data (void *) */
183
184 #define __VXH_DATA                              \
185         __vxh_copy_vxi(entry, vxi);             \
186         entry->sc.data = data
187
188 static inline
189 void    __vxh_data(struct vx_info *vxi, void *data,
190                         int __type, void *__here)
191 {
192         __VXH_BODY(__type, __VXH_DATA, __here)
193 }
194
195         /* pass vxi and arg (long) */
196
197 #define __VXH_LONG                              \
198         __vxh_copy_vxi(entry, vxi);             \
199         entry->ll.arg = arg
200
201 static inline
202 void    __vxh_long(struct vx_info *vxi, long arg,
203                         int __type, void *__here)
204 {
205         __VXH_BODY(__type, __VXH_LONG, __here)
206 }
207
208
209 static inline
210 void    __vxh_throw_oops(void *__here)
211 {
212         __VXH_BODY(VXH_THROW_OOPS, {}, __here);
213         /* prevent further acquisition */
214         vxh_active = 0;
215 }
216
217
218 #define vxh_throw_oops()        __vxh_throw_oops(__HERE__);
219
220 #define __vxh_get_vx_info(v,h)  __vxh_smpl(v, VXH_GET_VX_INFO, h);
221 #define __vxh_put_vx_info(v,h)  __vxh_smpl(v, VXH_PUT_VX_INFO, h);
222
223 #define __vxh_init_vx_info(v,d,h) \
224         __vxh_data(v,d, VXH_INIT_VX_INFO, h);
225 #define __vxh_set_vx_info(v,d,h) \
226         __vxh_data(v,d, VXH_SET_VX_INFO, h);
227 #define __vxh_clr_vx_info(v,d,h) \
228         __vxh_data(v,d, VXH_CLR_VX_INFO, h);
229
230 #define __vxh_claim_vx_info(v,d,h) \
231         __vxh_data(v,d, VXH_CLAIM_VX_INFO, h);
232 #define __vxh_release_vx_info(v,d,h) \
233         __vxh_data(v,d, VXH_RELEASE_VX_INFO, h);
234
235 #define vxh_alloc_vx_info(v) \
236         __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
237 #define vxh_dealloc_vx_info(v) \
238         __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
239
240 #define vxh_hash_vx_info(v) \
241         __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
242 #define vxh_unhash_vx_info(v) \
243         __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
244
245 #define vxh_loc_vx_info(v,l) \
246         __vxh_long(v,l, VXH_LOC_VX_INFO, __HERE__);
247 #define vxh_lookup_vx_info(v,l) \
248         __vxh_long(v,l, VXH_LOOKUP_VX_INFO, __HERE__);
249 #define vxh_create_vx_info(v,l) \
250         __vxh_long(v,l, VXH_CREATE_VX_INFO, __HERE__);
251
252 extern void vxh_dump_history(void);
253
254
255 #else  /* CONFIG_VSERVER_HISTORY */
256
257 #define __HERE__        0
258
259 #define vxh_throw_oops()                do { } while (0)
260
261 #define __vxh_get_vx_info(v,h)          do { } while (0)
262 #define __vxh_put_vx_info(v,h)          do { } while (0)
263
264 #define __vxh_init_vx_info(v,d,h)       do { } while (0)
265 #define __vxh_set_vx_info(v,d,h)        do { } while (0)
266 #define __vxh_clr_vx_info(v,d,h)        do { } while (0)
267
268 #define __vxh_claim_vx_info(v,d,h)      do { } while (0)
269 #define __vxh_release_vx_info(v,d,h)    do { } while (0)
270
271 #define vxh_alloc_vx_info(v)            do { } while (0)
272 #define vxh_dealloc_vx_info(v)          do { } while (0)
273
274 #define vxh_hash_vx_info(v)             do { } while (0)
275 #define vxh_unhash_vx_info(v)           do { } while (0)
276
277 #define vxh_loc_vx_info(a,v)            do { } while (0)
278 #define vxh_lookup_vx_info(a,v)         do { } while (0)
279 #define vxh_create_vx_info(a,v)         do { } while (0)
280
281 #define vxh_dump_history()              do { } while (0)
282
283
284 #endif /* CONFIG_VSERVER_HISTORY */
285
286
287 #ifdef  CONFIG_VSERVER_DEBUG
288 #define vxd_assert_lock(l)      assert_spin_locked(l)
289 #define vxd_assert(c,f,x...)    vxlprintk(!(c), \
290         "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
291 #else
292 #define vxd_assert_lock(l)      do { } while (0)
293 #define vxd_assert(c,f,x...)    do { } while (0)
294 #endif
295
296
297 #endif /* _VX_DEBUG_H */