Whamcloud - gitweb
c873c2fc2fdd82dc6401c56cbea00f8564537d80
[fs/lustre-release.git] / lnet / include / libcfs / linux / libcfs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4 #ifndef __LIBCFS_LINUX_LIBCFS_H__
5 #define __LIBCFS_LINUX_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 #ifdef HAVE_ASM_TYPES_H
12 #include <asm/types.h>
13 #else
14 #include <libcfs/types.h>
15 #endif
16
17 #include <stdarg.h>
18 #include <libcfs/linux/linux-time.h>
19 #include <libcfs/linux/linux-mem.h>
20 #include <libcfs/linux/linux-prim.h>
21 #include <libcfs/linux/linux-lock.h>
22 #include <libcfs/linux/linux-fs.h>
23 #include <libcfs/linux/linux-tcpip.h>
24
25
26 #ifdef __KERNEL__
27 # include <linux/types.h>
28 # include <linux/time.h>
29 # include <asm/timex.h>
30 #else
31 # include <sys/types.h>
32 # include <sys/time.h>
33 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
34 typedef unsigned long long cycles_t;
35 #endif
36
37 #ifndef __KERNEL__
38 /* Userpace byte flipping */
39 # include <endian.h>
40 # include <byteswap.h>
41 # define __swab16(x) bswap_16(x)
42 # define __swab32(x) bswap_32(x)
43 # define __swab64(x) bswap_64(x)
44 # define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
45 # define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
46 # define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
47 # if __BYTE_ORDER == __LITTLE_ENDIAN
48 #  define le16_to_cpu(x) (x)
49 #  define cpu_to_le16(x) (x)
50 #  define le32_to_cpu(x) (x)
51 #  define cpu_to_le32(x) (x)
52 #  define le64_to_cpu(x) (x)
53 #  define cpu_to_le64(x) (x)
54
55 #  define be16_to_cpu(x) bswap_16(x)
56 #  define cpu_to_be16(x) bswap_16(x)
57 #  define be32_to_cpu(x) bswap_32(x)
58 #  define cpu_to_be32(x) bswap_32(x)
59 #  define be64_to_cpu(x) bswap_64(x)
60 #  define cpu_to_be64(x) bswap_64(x)
61
62 # else
63 #  if __BYTE_ORDER == __BIG_ENDIAN
64 #   define le16_to_cpu(x) bswap_16(x)
65 #   define cpu_to_le16(x) bswap_16(x)
66 #   define le32_to_cpu(x) bswap_32(x)
67 #   define cpu_to_le32(x) bswap_32(x)
68 #   define le64_to_cpu(x) bswap_64(x)
69 #   define cpu_to_le64(x) bswap_64(x)
70
71 #   define be16_to_cpu(x) (x)
72 #   define cpu_to_be16(x) (x)
73 #   define be32_to_cpu(x) (x)
74 #   define cpu_to_be32(x) (x)
75 #   define be64_to_cpu(x) (x)
76 #   define cpu_to_be64(x) (x)
77
78 #  else
79 #   error "Unknown byte order"
80 #  endif /* __BIG_ENDIAN */
81 # endif /* __LITTLE_ENDIAN */
82 #endif /* ! __KERNEL__ */
83
84 struct ptldebug_header {
85         __u32 ph_len;
86         __u32 ph_flags;
87         __u32 ph_subsys;
88         __u32 ph_mask;
89         __u32 ph_cpu_id;
90         __u32 ph_sec;
91         __u64 ph_usec;
92         __u32 ph_stack;
93         __u32 ph_pid;
94         __u32 ph_extern_pid;
95         __u32 ph_line_num;
96 } __attribute__((packed));
97
98 #ifdef __KERNEL__
99 # include <linux/sched.h> /* THREAD_SIZE */
100 #else
101 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
102 #  define THREAD_SIZE 8192
103 # endif
104 #endif
105
106 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
107
108 #if defined(__KERNEL__) && !defined(__x86_64__)
109 # ifdef  __ia64__
110 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
111                           ((unsigned long)__builtin_dwarf_cfa() &       \
112                            (THREAD_SIZE - 1)))
113 # else
114 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
115                           ((unsigned long)__builtin_frame_address(0) &  \
116                            (THREAD_SIZE - 1)))
117 # endif /* __ia64__ */
118
119 #define __CHECK_STACK(file, func, line)                                 \
120 do {                                                                    \
121         unsigned long _stack = CDEBUG_STACK();                          \
122                                                                         \
123         if (_stack > 3*THREAD_SIZE/4 && _stack > libcfs_stack) {        \
124                 libcfs_stack = _stack;                                  \
125                 libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_WARNING,      \
126                                  file, func, line,                      \
127                                  "maximum lustre stack %lu\n", _stack); \
128               /*panic("LBUG");*/                                        \
129         }                                                               \
130 } while (0)
131 #define CHECK_STACK()     __CHECK_STACK(__FILE__, __func__, __LINE__)
132 #else /* !__KERNEL__ */
133 #define __CHECK_STACK(X, Y, Z) do { } while(0)
134 #define CHECK_STACK() do { } while(0)
135 #define CDEBUG_STACK() (0L)
136 #endif /* __KERNEL__ */
137
138 /* initial pid  */
139 #define LUSTRE_LNET_PID          12345
140
141 #define ENTRY_NESTING_SUPPORT (1)
142 #define ENTRY_NESTING   do {;} while (0)
143 #define EXIT_NESTING   do {;} while (0)
144 #define __current_nesting_level() (0)
145
146 /*
147  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
148  *
149  * Implementation is in linux-curproc.c
150  */
151 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
152
153 #if defined(__KERNEL__)
154 #include <linux/capability.h>
155 typedef kernel_cap_t cfs_kernel_cap_t;
156 #else
157 typedef __u32 cfs_kernel_cap_t;
158 #endif
159
160 #if defined(__KERNEL__)
161 /*
162  * No stack-back-tracing in Linux for now.
163  */
164 struct cfs_stack_trace {
165 };
166
167 #ifndef WITH_WATCHDOG
168 #define WITH_WATCHDOG
169 #endif
170
171 #endif
172
173 #endif /* _LINUX_LIBCFS_H */