Whamcloud - gitweb
1e823432a3b1e81f0af1a47c9949c15cf375964c
[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 <libcfs/linux/linux-mem.h>
12 #include <libcfs/linux/linux-time.h>
13 #include <libcfs/linux/linux-prim.h>
14 #include <libcfs/linux/linux-lock.h>
15 #include <libcfs/linux/linux-fs.h>
16
17 #ifdef HAVE_ASM_TYPES_H
18 #include <asm/types.h>
19 #else
20 /* this is actually coming from within lustre, a layering violation.
21  * we may not even need it, as libuptlctl (the dependency for which it
22  * is needed in liblustre building on catamount, bug 6923) shows no
23  * apparent need to be included in liblustre AFAICS.  The change of
24  * include to lustre/types.h only makes this explicit instead of implicit.
25  * To be resolved.  For now, make it CRAY_PORTALS only, to avoid breaking
26  * non-b1_4 branches that don't have this file.
27  */
28 # if CRAY_PORTALS
29 #  include <lustre/types.h>
30 # else
31 #  include "types.h"
32 # endif
33 #endif
34
35
36 #ifdef __KERNEL__
37 # include <linux/types.h>
38 # include <linux/time.h>
39 # include <asm/timex.h>
40 #else
41 # include <sys/types.h>
42 # include <sys/time.h>
43 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
44 typedef unsigned long long cycles_t;
45 #endif
46
47 #ifndef __KERNEL__
48 /* Userpace byte flipping */
49 # include <endian.h>
50 # include <byteswap.h>
51 # define __swab16(x) bswap_16(x)
52 # define __swab32(x) bswap_32(x)
53 # define __swab64(x) bswap_64(x)
54 # define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
55 # define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
56 # define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
57 # if __BYTE_ORDER == __LITTLE_ENDIAN
58 #  define le16_to_cpu(x) (x)
59 #  define cpu_to_le16(x) (x)
60 #  define le32_to_cpu(x) (x)
61 #  define cpu_to_le32(x) (x)
62 #  define le64_to_cpu(x) (x)
63 #  define cpu_to_le64(x) (x)
64 # else
65 #  if __BYTE_ORDER == __BIG_ENDIAN
66 #   define le16_to_cpu(x) bswap_16(x)
67 #   define cpu_to_le16(x) bswap_16(x)
68 #   define le32_to_cpu(x) bswap_32(x)
69 #   define cpu_to_le32(x) bswap_32(x)
70 #   define le64_to_cpu(x) bswap_64(x)
71 #   define cpu_to_le64(x) bswap_64(x)
72 #  else
73 #   error "Unknown byte order"
74 #  endif /* __BIG_ENDIAN */
75 # endif /* __LITTLE_ENDIAN */
76 #endif /* ! __KERNEL__ */
77
78 struct ptldebug_header {
79         __u32 ph_len;
80         __u32 ph_flags;
81         __u32 ph_subsys;
82         __u32 ph_mask;
83         __u32 ph_cpu_id;
84         __u32 ph_sec;
85         __u64 ph_usec;
86         __u32 ph_stack;
87         __u32 ph_pid;
88         __u32 ph_extern_pid;
89         __u32 ph_line_num;
90 } __attribute__((packed));
91
92 #ifdef __KERNEL__
93 # include <linux/sched.h> /* THREAD_SIZE */
94 #else
95 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
96 #  define THREAD_SIZE 8192
97 # endif
98 #endif
99
100 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
101
102 #ifdef __KERNEL__
103 # ifdef  __ia64__
104 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
105                         ((unsigned long)__builtin_dwarf_cfa() &            \
106                          (THREAD_SIZE - 1)))
107 # else
108 #  define CDEBUG_STACK (THREAD_SIZE -                                      \
109                         ((unsigned long)__builtin_frame_address(0) &       \
110                          (THREAD_SIZE - 1)))
111 # endif /* __ia64__ */
112
113 #define CHECK_STACK(stack)                                                    \
114         do {                                                                  \
115                 if ((stack) > 3*THREAD_SIZE/4 && (stack) > portal_stack) {    \
116                         portals_debug_msg(DEBUG_SUBSYSTEM, D_WARNING,         \
117                                           __FILE__, __FUNCTION__, __LINE__,   \
118                                           (stack),"maximum lustre stack %u\n",\
119                                           portal_stack = (stack));            \
120                       /*panic("LBUG");*/                                      \
121                 }                                                             \
122         } while (0)
123 #else /* !__KERNEL__ */
124 #define CHECK_STACK(stack) do { } while(0)
125 #define CDEBUG_STACK (0L)
126 #endif /* __KERNEL__ */
127
128 /* initial pid  */
129 # if CRAY_PORTALS
130 /*
131  * 1) ptl_pid_t in cray portals is only 16 bits, not 32 bits, therefore this
132  *    is too big.
133  *
134  * 2) the implementation of ernal in cray portals further restricts the pid
135  *    space that may be used to 0 <= pid <= 255 (an 8 bit value).  Returns
136  *    an error at nal init time for any pid outside this range.  Other nals
137  *    in cray portals don't have this restriction.
138  * */
139 #define LUSTRE_PTL_PID          9
140 # else
141 #define LUSTRE_PTL_PID          12345
142 # endif
143
144 #define ENTRY_NESTING_SUPPORT (0)
145 #define ENTRY_NESTING   do {;} while (0)
146 #define EXIT_NESTING   do {;} while (0)
147 #define __current_nesting_level() (0)
148
149 /*
150  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
151  *
152  * Implementation is in linux-curproc.c
153  */
154 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
155
156 #if defined(__KERNEL__)
157 #include <linux/capability.h>
158 typedef kernel_cap_t cfs_kernel_cap_t;
159 #else
160 typedef __u32 cfs_kernel_cap_t;
161 #endif
162
163 #endif /* _LINUX_LIBCFS_H */