Whamcloud - gitweb
0aac9194156a51040dee579f97616dd06ac92c90
[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 #include <stdarg.h>
12 #include <libcfs/linux/linux-mem.h>
13 #include <libcfs/linux/linux-time.h>
14 #include <libcfs/linux/linux-prim.h>
15 #include <libcfs/linux/linux-lock.h>
16 #include <libcfs/linux/linux-fs.h>
17 #include <libcfs/linux/linux-tcpip.h>
18
19 #ifdef HAVE_ASM_TYPES_H
20 #include <asm/types.h>
21 #else
22 #include <libcfs/types.h>
23 #endif
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 # else
55 #  if __BYTE_ORDER == __BIG_ENDIAN
56 #   define le16_to_cpu(x) bswap_16(x)
57 #   define cpu_to_le16(x) bswap_16(x)
58 #   define le32_to_cpu(x) bswap_32(x)
59 #   define cpu_to_le32(x) bswap_32(x)
60 #   define le64_to_cpu(x) bswap_64(x)
61 #   define cpu_to_le64(x) bswap_64(x)
62 #  else
63 #   error "Unknown byte order"
64 #  endif /* __BIG_ENDIAN */
65 # endif /* __LITTLE_ENDIAN */
66 #endif /* ! __KERNEL__ */
67
68 struct ptldebug_header {
69         __u32 ph_len;
70         __u32 ph_flags;
71         __u32 ph_subsys;
72         __u32 ph_mask;
73         __u32 ph_cpu_id;
74         __u32 ph_sec;
75         __u64 ph_usec;
76         __u32 ph_stack;
77         __u32 ph_pid;
78         __u32 ph_extern_pid;
79         __u32 ph_line_num;
80 } __attribute__((packed));
81
82 #ifdef __KERNEL__
83 # include <linux/sched.h> /* THREAD_SIZE */
84 #else
85 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
86 #  define THREAD_SIZE 8192
87 # endif
88 #endif
89
90 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
91
92 #if defined(__KERNEL__) && !defined(__x86_64__)
93 # ifdef  __ia64__
94 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
95                           ((unsigned long)__builtin_dwarf_cfa() &       \
96                            (THREAD_SIZE - 1)))
97 # else
98 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
99                           ((unsigned long)__builtin_frame_address(0) &  \
100                            (THREAD_SIZE - 1)))
101 # endif /* __ia64__ */
102
103 #define __CHECK_STACK(file, func, line)                                 \
104 do {                                                                    \
105         unsigned long _stack = CDEBUG_STACK();                          \
106                                                                         \
107         if (_stack > 3*THREAD_SIZE/4 && _stack > libcfs_stack) {        \
108                 libcfs_stack = _stack;                                  \
109                 libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_WARNING,      \
110                                  file, func, line,                      \
111                                  "maximum lustre stack %lu\n", _stack); \
112               /*panic("LBUG");*/                                        \
113         }                                                               \
114 } while (0)
115 #define CHECK_STACK()     __CHECK_STACK(__FILE__, __func__, __LINE__)
116 #else /* !__KERNEL__ */
117 #define __CHECK_STACK(X, Y, Z) do { } while(0)
118 #define CHECK_STACK() do { } while(0)
119 #define CDEBUG_STACK() (0L)
120 #endif /* __KERNEL__ */
121
122 /* initial pid  */
123 #define LUSTRE_LNET_PID          12345
124
125 #define ENTRY_NESTING_SUPPORT (1)
126 #define ENTRY_NESTING   do {;} while (0)
127 #define EXIT_NESTING   do {;} while (0)
128 #define __current_nesting_level() (0)
129
130 /*
131  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
132  *
133  * Implementation is in linux-curproc.c
134  */
135 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
136
137 #if defined(__KERNEL__)
138 #include <linux/capability.h>
139 typedef kernel_cap_t cfs_kernel_cap_t;
140 #else
141 typedef __u32 cfs_kernel_cap_t;
142 #endif
143
144 #if defined(__KERNEL__)
145 /*
146  * No stack-back-tracing in Linux for now.
147  */
148 struct cfs_stack_trace {
149 };
150
151 #ifndef WITH_WATCHDOG
152 #define WITH_WATCHDOG
153 #endif
154
155 #endif
156
157 #endif /* _LINUX_LIBCFS_H */