Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[fs/lustre-release.git] / lnet / include / libcfs / darwin / libcfs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #ifndef __LIBCFS_DARWIN_LIBCFS_H__
5 #define __LIBCFS_DARWIN_LIBCFS_H__
6
7 #ifndef __LIBCFS_LIBCFS_H__
8 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
9 #endif
10
11 #include <mach/mach_types.h>
12 #include <string.h>
13 #include <libcfs/darwin/darwin-types.h>
14 #include <libcfs/darwin/darwin-time.h>
15 #include <libcfs/darwin/darwin-prim.h>
16 #include <libcfs/darwin/darwin-mem.h>
17 #include <libcfs/darwin/darwin-lock.h>
18 #include <libcfs/darwin/darwin-fs.h>
19
20 #ifdef __KERNEL__
21 # include <sys/types.h>
22 # include <sys/time.h>
23 # define do_gettimeofday(tv) microuptime(tv)
24 #else
25 # include <sys/time.h>
26 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
27 typedef unsigned long long cycles_t;
28 #endif
29
30 #define __cpu_to_le64(x)                        OSSwapHostToLittleInt64(x)
31 #define __cpu_to_le32(x)                        OSSwapHostToLittleInt32(x)
32 #define __cpu_to_le16(x)                        OSSwapHostToLittleInt16(x)
33
34 #define __le16_to_cpu(x)                        OSSwapLittleToHostInt16(x)
35 #define __le32_to_cpu(x)                        OSSwapLittleToHostInt32(x)
36 #define __le64_to_cpu(x)                        OSSwapLittleToHostInt64(x)
37
38 #define cpu_to_le64(x)                          __cpu_to_le64(x)
39 #define cpu_to_le32(x)                          __cpu_to_le32(x)
40 #define cpu_to_le16(x)                          __cpu_to_le16(x)
41
42 #define le64_to_cpu(x)                          __le64_to_cpu(x)
43 #define le32_to_cpu(x)                          __le32_to_cpu(x)
44 #define le16_to_cpu(x)                          __le16_to_cpu(x)
45
46 #define __swab16(x)                             OSSwapInt16(x)
47 #define __swab32(x)                             OSSwapInt32(x)
48 #define __swab64(x)                             OSSwapInt64(x)
49 #define __swab16s(x)                            do { *(x) = __swab16(*(x)); } while (0)
50 #define __swab32s(x)                            do { *(x) = __swab32(*(x)); } while (0)
51 #define __swab64s(x)                            do { *(x) = __swab64(*(x)); } while (0)
52
53 struct ptldebug_header {
54         __u32 ph_len;
55         __u32 ph_flags;
56         __u32 ph_subsys;
57         __u32 ph_mask;
58         __u32 ph_cpu_id;
59         __u32 ph_sec;
60         __u64 ph_usec;
61         __u32 ph_stack;
62         __u32 ph_pid;
63         __u32 ph_extern_pid;
64         __u32 ph_line_num;
65 } __attribute__((packed));
66
67
68 #ifdef __KERNEL__
69 # include <sys/systm.h>
70 # include <pexpert/pexpert.h>
71 /* Fix me */
72 # define THREAD_SIZE 8192
73 #else
74 # define THREAD_SIZE 8192
75 #endif
76 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
77
78 #define CHECK_STACK(stack) do { } while(0)
79 #define CDEBUG_STACK (0L)
80
81 /* Darwin has defined RETURN, so we have to undef it in lustre */
82 #ifdef RETURN
83 #undef RETURN
84 #endif
85
86 /*
87  * When this is enabled debugging messages are indented according to the
88  * current "nesting level". Nesting level in increased when ENTRY macro
89  * is executed, and decreased on EXIT and RETURN.
90  */
91 #ifdef __KERNEL__
92 #define ENTRY_NESTING_SUPPORT (0)
93 #endif
94
95 #if ENTRY_NESTING_SUPPORT
96
97 /*
98  * Currently ENTRY_NESTING_SUPPORT is only supported for XNU port. Basic
99  * idea is to keep per-thread pointer to small data structure (struct
100  * cfs_debug_data) describing current nesting level. In XNU unused
101  * proc->p_wmegs field in hijacked for this. On Linux
102  * current->journal_info can be used. In user space
103  * pthread_{g,s}etspecific().
104  *
105  * ENTRY macro allocates new cfs_debug_data on stack, and installs it as
106  * a current nesting level, storing old data in cfs_debug_data it just
107  * created.
108  *
109  * EXIT pops old value back.
110  *
111  */
112
113 /*
114  * One problem with this approach is that there is a lot of code that
115  * does ENTRY and then escapes scope without doing EXIT/RETURN. In this
116  * case per-thread current nesting level pointer is dangling (it points
117  * to the stack area that is possible already overridden). To detect
118  * such cases, we add two magic fields to the cfs_debug_data and check
119  * them whenever current nesting level pointer is dereferenced. While
120  * looking flaky this works because stack is always consumed
121  * "continously".
122  */
123 enum {
124         CDD_MAGIC1 = 0x02128506,
125         CDD_MAGIC2 = 0x42424242
126 };
127
128 struct cfs_debug_data {
129         unsigned int           magic1;
130         struct cfs_debug_data *parent;
131         int                    nesting_level;
132         unsigned int           magic2;
133 };
134
135 void __entry_nesting(struct cfs_debug_data *child);
136 void __exit_nesting(struct cfs_debug_data *child);
137 unsigned int __current_nesting_level(void);
138
139 #define ENTRY_NESTING                                           \
140 struct cfs_debug_data __cdd = { .magic1        = CDD_MAGIC1,    \
141                                 .parent        = NULL,          \
142                                 .nesting_level = 0,             \
143                                 .magic2        = CDD_MAGIC2 };  \
144 __entry_nesting(&__cdd);
145
146 #define EXIT_NESTING __exit_nesting(&__cdd)
147
148 /* ENTRY_NESTING_SUPPORT */
149 #else
150
151 #define ENTRY_NESTING   do {;} while (0)
152 #define EXIT_NESTING   do {;} while (0)
153 #define __current_nesting_level() (0)
154
155 /* ENTRY_NESTING_SUPPORT */
156 #endif
157
158 #define LUSTRE_PTL_PID          12345
159
160 #define _XNU_LIBCFS_H
161
162 /*
163  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
164  *
165  * Implementation is in darwin-curproc.c
166  */
167 #define CFS_CURPROC_COMM_MAX (sizeof ((struct proc *)0)->p_comm)
168 /*
169  * XNU has no capabilities
170  */
171 typedef int cfs_kernel_cap_t;
172
173 #endif /* _XNU_LIBCFS_H */