Cleaned up limit setting code
[util-vserver.git] / 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_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
156 #define __VXH_BODY(__type, __data)              \
157         struct _vx_hist_entry *entry;           \
158                                                 \
159         preempt_disable();                      \
160         entry = vxh_advance(VXH_HERE());        \
161         __data;                                 \
162         entry->type = __type;                   \
163         preempt_enable();
164
165
166         /* pass vxi only */
167 #define __VXH_SIMPLE                            \
168         __vxh_copy_vxi(entry, vxi)
169
170 #define VXH_SIMPLE(__name, __type)              \
171 static inline void __name(struct vx_info *vxi)  \
172 {                                               \
173         __VXH_BODY(__type, __VXH_SIMPLE)        \
174 }
175
176         /* pass vxi and data (void *) */
177 #define __VXH_DATA                              \
178         __vxh_copy_vxi(entry, vxi);             \
179         entry->sc.data = data
180
181 #define VXH_DATA(__name, __type)                \
182 static inline                                   \
183 void __name(struct vx_info *vxi, void *data)    \
184 {                                               \
185         __VXH_BODY(__type, __VXH_DATA)          \
186 }
187
188         /* pass vxi and arg (long) */
189 #define __VXH_LARG                              \
190         __vxh_copy_vxi(entry, vxi);             \
191         entry->ll.arg = arg
192
193 #define VXH_LARG(__name, __type)                \
194 static inline                                   \
195 void __name(struct vx_info *vxi, long arg)      \
196 {                                               \
197         __VXH_BODY(__type, __VXH_LARG)          \
198 }
199
200
201 static inline void vxh_throw_oops(void)
202 {
203         __VXH_BODY(VXH_THROW_OOPS, {});
204         /* prevent further acquisition */
205         vxh_active = 0;
206 }
207
208 VXH_SIMPLE(vxh_get_vx_info,     VXH_GET_VX_INFO);
209 VXH_SIMPLE(vxh_put_vx_info,     VXH_PUT_VX_INFO);
210
211 VXH_DATA(vxh_init_vx_info,      VXH_INIT_VX_INFO);
212 VXH_DATA(vxh_set_vx_info,       VXH_SET_VX_INFO);
213 VXH_DATA(vxh_clr_vx_info,       VXH_CLR_VX_INFO);
214
215 VXH_DATA(vxh_claim_vx_info,     VXH_CLAIM_VX_INFO);
216 VXH_DATA(vxh_release_vx_info,   VXH_RELEASE_VX_INFO);
217
218 VXH_SIMPLE(vxh_alloc_vx_info,   VXH_ALLOC_VX_INFO);
219 VXH_SIMPLE(vxh_dealloc_vx_info, VXH_DEALLOC_VX_INFO);
220
221 VXH_SIMPLE(vxh_hash_vx_info,    VXH_HASH_VX_INFO);
222 VXH_SIMPLE(vxh_unhash_vx_info,  VXH_UNHASH_VX_INFO);
223
224 VXH_LARG(vxh_loc_vx_info,       VXH_LOC_VX_INFO);
225 VXH_LARG(vxh_lookup_vx_info,    VXH_LOOKUP_VX_INFO);
226 VXH_LARG(vxh_create_vx_info,    VXH_CREATE_VX_INFO);
227
228 extern void vxh_dump_history(void);
229
230
231 #else  /* CONFIG_VSERVER_HISTORY */
232
233
234 #define vxh_throw_oops()                do { } while (0)
235
236 #define vxh_get_vx_info(v)              do { } while (0)
237 #define vxh_put_vx_info(v)              do { } while (0)
238
239 #define vxh_init_vx_info(v,d)           do { } while (0)
240 #define vxh_set_vx_info(v,d)            do { } while (0)
241 #define vxh_clr_vx_info(v,d)            do { } while (0)
242
243 #define vxh_claim_vx_info(v,d)          do { } while (0)
244 #define vxh_release_vx_info(v,d)        do { } while (0)
245
246 #define vxh_alloc_vx_info(v)            do { } while (0)
247 #define vxh_dealloc_vx_info(v)          do { } while (0)
248
249 #define vxh_hash_vx_info(v)             do { } while (0)
250 #define vxh_unhash_vx_info(v)           do { } while (0)
251
252 #define vxh_loc_vx_info(a,v)            do { } while (0)
253 #define vxh_lookup_vx_info(a,v)         do { } while (0)
254 #define vxh_create_vx_info(a,v)         do { } while (0)
255
256 #define vxh_dump_history()              do { } while (0)
257
258
259 #endif /* CONFIG_VSERVER_HISTORY */
260
261
262 #ifdef  CONFIG_VSERVER_DEBUG
263 #define vxd_assert_lock(l)      assert_spin_locked(l)
264 #else
265 #define vxd_assert_lock(l)      do { } while (0)
266 #endif
267
268
269 #endif /* _VX_DEBUG_H */