Whamcloud - gitweb
ae960e8fedd72a1413a1a1cb13d7c968c7ae4cbd
[fs/lustre-release.git] / libcfs / 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  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __LIBCFS_LINUX_LIBCFS_H__
38 #define __LIBCFS_LINUX_LIBCFS_H__
39
40 #ifndef __LIBCFS_LIBCFS_H__
41 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
42 #endif
43
44 #ifdef HAVE_ASM_TYPES_H
45 #include <asm/types.h>
46 #else
47 #include <libcfs/types.h>
48 #endif
49
50 #include <stdarg.h>
51 #include <libcfs/linux/linux-time.h>
52 #include <libcfs/linux/linux-mem.h>
53 #include <libcfs/linux/linux-prim.h>
54 #include <libcfs/linux/linux-lock.h>
55 #include <libcfs/linux/linux-fs.h>
56 #include <libcfs/linux/linux-tcpip.h>
57
58
59 #ifdef __KERNEL__
60 # include <linux/types.h>
61 # include <linux/time.h>
62 # include <asm/timex.h>
63 #else
64 # include <sys/types.h>
65 # include <sys/time.h>
66 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
67 typedef unsigned long long cycles_t;
68 #endif
69
70 #ifndef __KERNEL__
71 /* Userpace byte flipping */
72 # include <endian.h>
73 # include <byteswap.h>
74 # define __swab16(x) bswap_16(x)
75 # define __swab32(x) bswap_32(x)
76 # define __swab64(x) bswap_64(x)
77 # define __swab16s(x) do {*(x) = bswap_16(*(x));} while (0)
78 # define __swab32s(x) do {*(x) = bswap_32(*(x));} while (0)
79 # define __swab64s(x) do {*(x) = bswap_64(*(x));} while (0)
80 # if __BYTE_ORDER == __LITTLE_ENDIAN
81 #  define le16_to_cpu(x) (x)
82 #  define cpu_to_le16(x) (x)
83 #  define le32_to_cpu(x) (x)
84 #  define cpu_to_le32(x) (x)
85 #  define le64_to_cpu(x) (x)
86 #  define cpu_to_le64(x) (x)
87
88 #  define be16_to_cpu(x) bswap_16(x)
89 #  define cpu_to_be16(x) bswap_16(x)
90 #  define be32_to_cpu(x) bswap_32(x)
91 #  define cpu_to_be32(x) bswap_32(x)
92 #  define be64_to_cpu(x) bswap_64(x)
93 #  define cpu_to_be64(x) bswap_64(x)
94
95 # else
96 #  if __BYTE_ORDER == __BIG_ENDIAN
97 #   define le16_to_cpu(x) bswap_16(x)
98 #   define cpu_to_le16(x) bswap_16(x)
99 #   define le32_to_cpu(x) bswap_32(x)
100 #   define cpu_to_le32(x) bswap_32(x)
101 #   define le64_to_cpu(x) bswap_64(x)
102 #   define cpu_to_le64(x) bswap_64(x)
103
104 #   define be16_to_cpu(x) (x)
105 #   define cpu_to_be16(x) (x)
106 #   define be32_to_cpu(x) (x)
107 #   define cpu_to_be32(x) (x)
108 #   define be64_to_cpu(x) (x)
109 #   define cpu_to_be64(x) (x)
110
111 #  else
112 #   error "Unknown byte order"
113 #  endif /* __BIG_ENDIAN */
114 # endif /* __LITTLE_ENDIAN */
115 #endif /* ! __KERNEL__ */
116
117 struct ptldebug_header {
118         __u32 ph_len;
119         __u32 ph_flags;
120         __u32 ph_subsys;
121         __u32 ph_mask;
122         __u32 ph_cpu_id;
123         __u32 ph_sec;
124         __u64 ph_usec;
125         __u32 ph_stack;
126         __u32 ph_pid;
127         __u32 ph_extern_pid;
128         __u32 ph_line_num;
129 } __attribute__((packed));
130
131 #ifdef __KERNEL__
132 # include <linux/sched.h> /* THREAD_SIZE */
133 #else
134 # ifndef THREAD_SIZE /* x86_64 has THREAD_SIZE in userspace */
135 #  define THREAD_SIZE 8192
136 # endif
137 #endif
138
139 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
140
141 #if defined(__KERNEL__) && !defined(__x86_64__)
142 # ifdef  __ia64__
143 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
144                           ((unsigned long)__builtin_dwarf_cfa() &       \
145                            (THREAD_SIZE - 1)))
146 # else
147 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
148                           ((unsigned long)__builtin_frame_address(0) &  \
149                            (THREAD_SIZE - 1)))
150 # endif /* __ia64__ */
151
152 #define __CHECK_STACK(file, func, line)                                 \
153 do {                                                                    \
154         unsigned long _stack = CDEBUG_STACK();                           \
155                                                                         \
156         if (_stack > 3*THREAD_SIZE/4 && _stack > libcfs_stack) {        \
157                 libcfs_stack = _stack;                                  \
158                 libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_WARNING,      \
159                                  file, func, line,                      \
160                                  "maximum lustre stack %lu\n", _stack); \
161               /*panic("LBUG");*/                                        \
162         }                                                               \
163 } while (0)
164 #define CHECK_STACK()     __CHECK_STACK(__FILE__, __func__, __LINE__)
165 #else /* !__KERNEL__ */
166 #define __CHECK_STACK(X, Y, Z) do { } while(0)
167 #define CHECK_STACK() do { } while(0)
168 #define CDEBUG_STACK() (0L)
169 #endif /* __KERNEL__ */
170
171 /* initial pid  */
172 #define LUSTRE_LNET_PID          12345
173
174 #define ENTRY_NESTING_SUPPORT (1)
175 #define ENTRY_NESTING   do {;} while (0)
176 #define EXIT_NESTING   do {;} while (0)
177 #define __current_nesting_level() (0)
178
179 /*
180  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
181  *
182  * Implementation is in linux-curproc.c
183  */
184 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
185
186 #if defined(__KERNEL__)
187 #include <linux/capability.h>
188 typedef kernel_cap_t cfs_kernel_cap_t;
189 #else
190 typedef __u32 cfs_kernel_cap_t;
191 #endif
192
193 #if defined(__KERNEL__)
194 /*
195  * No stack-back-tracing in Linux for now.
196  */
197 struct cfs_stack_trace {
198 };
199
200 #ifndef WITH_WATCHDOG
201 #define WITH_WATCHDOG
202 #endif
203
204 #endif
205
206 #endif /* _LINUX_LIBCFS_H */