Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[fs/lustre-release.git] / lnet / include / libcfs / kp30.h
similarity index 54%
rename from lnet/include/linux/kp30.h
rename to lnet/include/libcfs/kp30.h
index e590514..cdd1bff 100644 (file)
@@ -1,58 +1,19 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  */
-#ifndef _KP30_INCLUDED
-#define _KP30_INCLUDED
+#ifndef __LIBCFS_KP30_H__
+#define __LIBCFS_KP30_H__
 
-#include <linux/libcfs.h>
 #define PORTAL_DEBUG
+#include <libcfs/libcfs.h>
 
-#ifdef __KERNEL__
-# include <linux/vmalloc.h>
-# include <linux/time.h>
-# include <linux/slab.h>
-# include <linux/interrupt.h>
-# include <linux/highmem.h>
-# include <linux/module.h>
-# include <linux/version.h>
-# include <portals/p30.h>
-# include <linux/smp_lock.h>
-# include <asm/atomic.h>
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-#define schedule_work schedule_task
-#define prepare_work(wq,cb,cbdata)                                            \
-do {                                                                          \
-        INIT_TQUEUE((wq), 0, 0);                                              \
-        PREPARE_TQUEUE((wq), (cb), (cbdata));                                 \
-} while (0)
-
-#define PageUptodate Page_Uptodate
-#define our_recalc_sigpending(current) recalc_sigpending(current)
-#define num_online_cpus() smp_num_cpus
-static inline void our_cond_resched(void)
-{
-        if (current->need_resched)
-               schedule ();
-}
-#define work_struct_t       struct tq_struct
+#include <libcfs/arch/kp30.h>
 
-#else
-
-#define prepare_work(wq,cb,cbdata)                                            \
-do {                                                                          \
-        INIT_WORK((wq), (void *)(cb), (void *)(cbdata));                      \
-} while (0)
-#define wait_on_page wait_on_page_locked
-#define our_recalc_sigpending(current) recalc_sigpending()
-#define strtok(a,b) strpbrk(a, b)
-static inline void our_cond_resched(void)
-{
-        cond_resched();
-}
-#define work_struct_t      struct work_struct
+#ifdef __KERNEL__
 
-#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
+# ifndef DEBUG_SUBSYSTEM
+#  define DEBUG_SUBSYSTEM S_UNDEFINED
+# endif
 
 #ifdef PORTAL_DEBUG
 extern void kportal_assertion_failed(char *expr, char *file, const char *func,
@@ -74,32 +35,7 @@ extern void kportal_assertion_failed(char *expr, char *file, const char *func,
 #define LASSERTF(cond, fmt...) do { } while (0)
 #endif
 
-#ifdef CONFIG_SMP
-#define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
-#else
-#define LASSERT_SPIN_LOCKED(lock) do {} while(0)
-#endif
-
-#ifdef __arch_um__
-#define LBUG_WITH_LOC(file, func, line)                                 \
-do {                                                                    \
-        CEMERG("LBUG - trying to dump log to /tmp/lustre-log\n");       \
-        portals_debug_dumplog();                                        \
-        portals_run_lbug_upcall(file, func, line);                      \
-        panic("LBUG");                                                  \
-} while (0)
-#else
-#define LBUG_WITH_LOC(file, func, line)                                 \
-do {                                                                    \
-        CEMERG("LBUG\n");                                               \
-        portals_debug_dumpstack(NULL);                                  \
-        portals_debug_dumplog();                                        \
-        portals_run_lbug_upcall(file, func, line);                      \
-        set_task_state(current, TASK_UNINTERRUPTIBLE);                  \
-        schedule();                                                     \
-} while (0)
-#endif /* __arch_um__ */
-
+/* LBUG_WITH_LOC defined in portals/<os>/kp30.h */
 #define LBUG() LBUG_WITH_LOC(__FILE__, __FUNCTION__, __LINE__)
 
 /*
@@ -127,11 +63,11 @@ do {                                                                          \
 #define PORTAL_ALLOC_GFP(ptr, size, mask)                                 \
 do {                                                                      \
         LASSERT(!in_interrupt() ||                                        \
-               (size <= PORTAL_VMALLOC_SIZE && mask == GFP_ATOMIC));      \
+               (size <= PORTAL_VMALLOC_SIZE && mask == CFS_ALLOC_ATOMIC));\
         if ((size) > PORTAL_VMALLOC_SIZE)                                 \
-                (ptr) = vmalloc(size);                                    \
+                (ptr) = cfs_alloc_large(size);                            \
         else                                                              \
-                (ptr) = kmalloc((size), (mask));                          \
+                (ptr) = cfs_alloc((size), (mask));                        \
         if ((ptr) == NULL) {                                              \
                 CERROR("PORTALS: out of memory at %s:%d (tried to alloc '"\
                        #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));\
@@ -139,17 +75,18 @@ do {                                                                      \
                        atomic_read(&portal_kmemory));                     \
         } else {                                                          \
                 portal_kmem_inc((ptr), (size));                           \
-                memset((ptr), 0, (size));                                 \
+                if (!((mask) & CFS_ALLOC_ZERO))                           \
+                       memset((ptr), 0, (size));                          \
         }                                                                 \
         CDEBUG(D_MALLOC, "kmalloced '" #ptr "': %d at %p (tot %d).\n",    \
                (int)(size), (ptr), atomic_read (&portal_kmemory));        \
 } while (0)
 
 #define PORTAL_ALLOC(ptr, size) \
-        PORTAL_ALLOC_GFP(ptr, size, GFP_NOFS)
+        PORTAL_ALLOC_GFP(ptr, size, CFS_ALLOC_IO)
 
 #define PORTAL_ALLOC_ATOMIC(ptr, size) \
-        PORTAL_ALLOC_GFP(ptr, size, GFP_ATOMIC)
+        PORTAL_ALLOC_GFP(ptr, size, CFS_ALLOC_ATOMIC)
 
 #define PORTAL_FREE(ptr, size)                                          \
 do {                                                                    \
@@ -160,39 +97,14 @@ do {                                                                    \
                 break;                                                  \
         }                                                               \
         if (s > PORTAL_VMALLOC_SIZE)                                    \
-                vfree(ptr);                                             \
+                cfs_free_large(ptr);                                    \
         else                                                            \
-                kfree(ptr);                                             \
+                cfs_free(ptr);                                          \
         portal_kmem_dec((ptr), s);                                      \
         CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n",     \
                s, (ptr), atomic_read(&portal_kmemory));                 \
 } while (0)
 
-/* ------------------------------------------------------------------- */
-
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-
-#define PORTAL_SYMBOL_REGISTER(x) inter_module_register(#x, THIS_MODULE, &x)
-#define PORTAL_SYMBOL_UNREGISTER(x) inter_module_unregister(#x)
-
-#define PORTAL_SYMBOL_GET(x) ((typeof(&x))inter_module_get(#x))
-#define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
-
-#define PORTAL_MODULE_USE       MOD_INC_USE_COUNT
-#define PORTAL_MODULE_UNUSE     MOD_DEC_USE_COUNT
-#else
-
-#define PORTAL_SYMBOL_REGISTER(x)
-#define PORTAL_SYMBOL_UNREGISTER(x)
-
-#define PORTAL_SYMBOL_GET(x) symbol_get(x)
-#define PORTAL_SYMBOL_PUT(x) symbol_put(x)
-
-#define PORTAL_MODULE_USE       try_module_get(THIS_MODULE)
-#define PORTAL_MODULE_UNUSE     module_put(THIS_MODULE)
-
-#endif
-
 /******************************************************************************/
 
 #ifdef PORTALS_PROFILING
@@ -243,7 +155,9 @@ extern struct prof_ent prof_ents[MAX_PROFS];
 #endif /* PORTALS_PROFILING */
 
 /* debug.c */
-void portals_debug_dumpstack(struct task_struct *tsk);
+extern spinlock_t stack_backtrace_lock;
+
+void portals_debug_dumpstack(cfs_task_t *tsk);
 void portals_run_upcall(char **argv);
 void portals_run_lbug_upcall(char * file, const char *fn, const int line);
 void portals_debug_dumplog(void);
@@ -254,44 +168,20 @@ int portals_debug_mark_buffer(char *text);
 int portals_debug_set_daemon(unsigned int cmd, unsigned int length,
                              char *file, unsigned int size);
 __s32 portals_debug_copy_to_user(char *buf, unsigned long len);
-#if (__GNUC__)
 /* Use the special GNU C __attribute__ hack to have the compiler check the
  * printf style argument string against the actual argument count and
  * types.
  */
-#ifdef printf
-# warning printf has been defined as a macro...
-# undef printf
-#endif
 void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
                        const int line, unsigned long stack,
                        char *format, ...)
         __attribute__ ((format (printf, 7, 8)));
-#else
-void portals_debug_msg(int subsys, int mask, char *file, const char *fn,
-                       const int line, unsigned long stack,
-                       const char *format, ...);
-#endif /* __GNUC__ */
 void portals_debug_set_level(unsigned int debug_level);
 
-# define fprintf(a, format, b...) CDEBUG(D_OTHER, format , ## b)
-# define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
-# define time(a) CURRENT_TIME
-
 extern void kportal_daemonize (char *name);
 extern void kportal_blockallsigs (void);
 
 #else  /* !__KERNEL__ */
-# include <stdio.h>
-# include <stdlib.h>
-#ifndef __CYGWIN__
-# include <stdint.h>
-#else
-# include <cygwin-ioctl.h>
-#endif
-# include <unistd.h>
-# include <time.h>
-# include <limits.h>
 # ifndef DEBUG_SUBSYSTEM
 #  define DEBUG_SUBSYSTEM S_UNDEFINED
 # endif
@@ -324,6 +214,22 @@ void portals_debug_dumplog(void);
 #define CERROR(format, a...) CDEBUG(D_ERROR, format, ## a)
 #endif
 
+/*
+ * compile-time assertions. @cond has to be constant expression.
+ * ISO C Standard:
+ *
+ *        6.8.4.2  The switch statement
+ *
+ *       ....
+ *
+ *       [#3] The expression of each case label shall be  an  integer
+ *       constant   expression  and  no  two  of  the  case  constant
+ *       expressions in the same switch statement shall have the same
+ *       value  after  conversion...
+ *
+ */
+#define CLASSERT(cond) ({ switch(42) { case (cond): case 0: break; } })
+
 /* support decl needed both by kernel and liblustre */
 char *portals_nid2str(int nal, ptl_nid_t nid, char *str);
 char *portals_id2str(int nal, ptl_process_id_t nid, char *str);
@@ -332,119 +238,19 @@ char *portals_id2str(int nal, ptl_process_id_t nid, char *str);
 # define CURRENT_TIME time(0)
 #endif
 
-/******************************************************************************/
-/* Light-weight trace
- * Support for temporary event tracing with minimal Heisenberg effect. */
-#define LWT_SUPPORT  0
-
-#define LWT_MEMORY   (16<<20)
-
-#if !KLWT_SUPPORT
-# if defined(__KERNEL__)
-#  if !defined(BITS_PER_LONG)
-#   error "BITS_PER_LONG not defined"
-#  endif
-# elif !defined(__WORDSIZE)
-#  error "__WORDSIZE not defined"
-# else
-#  define BITS_PER_LONG __WORDSIZE
-# endif
-
-/* kernel hasn't defined this? */
-typedef struct {
-        long long   lwte_when;
-        char       *lwte_where;
-        void       *lwte_task;
-        long        lwte_p1;
-        long        lwte_p2;
-        long        lwte_p3;
-        long        lwte_p4;
-# if BITS_PER_LONG > 32
-        long        lwte_pad;
-# endif
-} lwt_event_t;
-#endif /* !KLWT_SUPPORT */
-
-#if LWT_SUPPORT
-# ifdef __KERNEL__
-#  if !KLWT_SUPPORT
-
-typedef struct _lwt_page {
-        struct list_head     lwtp_list;
-        struct page         *lwtp_page;
-        lwt_event_t         *lwtp_events;
-} lwt_page_t;
-
-typedef struct {
-        int                lwtc_current_index;
-        lwt_page_t        *lwtc_current_page;
-} lwt_cpu_t;
-
-extern int       lwt_enabled;
-extern lwt_cpu_t lwt_cpus[];
-
-/* Note that we _don't_ define LWT_EVENT at all if LWT_SUPPORT isn't set.
- * This stuff is meant for finding specific problems; it never stays in
- * production code... */
-
-#define LWTSTR(n)       #n
-#define LWTWHERE(f,l)   f ":" LWTSTR(l)
-#define LWT_EVENTS_PER_PAGE (PAGE_SIZE / sizeof (lwt_event_t))
-
-#define LWT_EVENT(p1, p2, p3, p4)                                       \
-do {                                                                    \
-        unsigned long    flags;                                         \
-        lwt_cpu_t       *cpu;                                           \
-        lwt_page_t      *p;                                             \
-        lwt_event_t     *e;                                             \
-                                                                        \
-        if (lwt_enabled) {                                              \
-                local_irq_save (flags);                                 \
-                                                                        \
-                cpu = &lwt_cpus[smp_processor_id()];                    \
-                p = cpu->lwtc_current_page;                             \
-                e = &p->lwtp_events[cpu->lwtc_current_index++];         \
-                                                                        \
-                if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) {   \
-                        cpu->lwtc_current_page =                        \
-                                list_entry (p->lwtp_list.next,          \
-                                            lwt_page_t, lwtp_list);     \
-                        cpu->lwtc_current_index = 0;                    \
-                }                                                       \
-                                                                        \
-                e->lwte_when  = get_cycles();                           \
-                e->lwte_where = LWTWHERE(__FILE__,__LINE__);            \
-                e->lwte_task  = current;                                \
-                e->lwte_p1    = (long)(p1);                             \
-                e->lwte_p2    = (long)(p2);                             \
-                e->lwte_p3    = (long)(p3);                             \
-                e->lwte_p4    = (long)(p4);                             \
-                                                                        \
-                local_irq_restore (flags);                              \
-        }                                                               \
-} while (0)
-
-#endif /* !KLWT_SUPPORT */
-
-extern int  lwt_init (void);
-extern void lwt_fini (void);
-extern int  lwt_lookup_string (int *size, char *knlptr,
-                               char *usrptr, int usrsize);
-extern int  lwt_control (int enable, int clear);
-extern int  lwt_snapshot (cycles_t *now, int *ncpu, int *total_size,
-                          void *user_ptr, int user_size);
-# else  /* __KERNEL__ */
-#  define LWT_EVENT(p1,p2,p3,p4)     /* no userland implementation yet */
-# endif /* __KERNEL__ */
-#endif /* LWT_SUPPORT */
+/* --------------------------------------------------------------------
+ * Light-weight trace
+ * Support for temporary event tracing with minimal Heisenberg effect.
+ * All stuff about lwt are put in arch/kp30.h
+ * -------------------------------------------------------------------- */
 
 struct portals_device_userstate
 {
         int          pdu_memhog_pages;
-        struct page *pdu_memhog_root_page;
+        cfs_page_t   *pdu_memhog_root_page;
 };
 
-#include <linux/portals_lib.h>
+#include <libcfs/portals_lib.h>
 
 /*
  * USER LEVEL STUFF BELOW
@@ -569,77 +375,30 @@ static inline int portal_ioctl_pack(struct portal_ioctl_data *data, char **pbuf,
 
         return 0;
 }
-#else
-#include <asm/uaccess.h>
-
-/* buffer MUST be at least the size of portal_ioctl_hdr */
-static inline int portal_ioctl_getdata(char *buf, char *end, void *arg)
-{
-        struct portal_ioctl_hdr *hdr;
-        struct portal_ioctl_data *data;
-        int err;
-        ENTRY;
-
-        hdr = (struct portal_ioctl_hdr *)buf;
-        data = (struct portal_ioctl_data *)buf;
-
-        err = copy_from_user(buf, (void *)arg, sizeof(*hdr));
-        if (err)
-                RETURN(err);
 
-        if (hdr->ioc_version != PORTAL_IOCTL_VERSION) {
-                CERROR("PORTALS: version mismatch kernel vs application\n");
-                RETURN(-EINVAL);
-        }
-
-        if (hdr->ioc_len + buf >= end) {
-                CERROR("PORTALS: user buffer exceeds kernel buffer\n");
-                RETURN(-EINVAL);
-        }
-
-
-        if (hdr->ioc_len < sizeof(struct portal_ioctl_data)) {
-                CERROR("PORTALS: user buffer too small for ioctl\n");
-                RETURN(-EINVAL);
-        }
-
-        err = copy_from_user(buf, (void *)arg, hdr->ioc_len);
-        if (err)
-                RETURN(err);
-
-        if (portal_ioctl_is_invalid(data)) {
-                CERROR("PORTALS: ioctl not correctly formatted\n");
-                RETURN(-EINVAL);
-        }
-
-        if (data->ioc_inllen1)
-                data->ioc_inlbuf1 = &data->ioc_bulk[0];
+#else
 
-        if (data->ioc_inllen2)
-                data->ioc_inlbuf2 = &data->ioc_bulk[0] +
-                        size_round(data->ioc_inllen1);
+extern inline int portal_ioctl_getdata(char *buf, char *end, void *arg);
 
-        RETURN(0);
-}
 #endif
 
 /* ioctls for manipulating snapshots 30- */
 #define IOC_PORTAL_TYPE                   'e'
 #define IOC_PORTAL_MIN_NR                 30
 
-#define IOC_PORTAL_PING                    _IOWR('e', 30, long)
+#define IOC_PORTAL_PING                    _IOWR('e', 30, IOCTL_PORTAL_TYPE)
 
-#define IOC_PORTAL_CLEAR_DEBUG             _IOWR('e', 32, long)
-#define IOC_PORTAL_MARK_DEBUG              _IOWR('e', 33, long)
-#define IOC_PORTAL_PANIC                   _IOWR('e', 34, long)
-#define IOC_PORTAL_NAL_CMD                 _IOWR('e', 35, long)
-#define IOC_PORTAL_GET_NID                 _IOWR('e', 36, long)
-#define IOC_PORTAL_FAIL_NID                _IOWR('e', 37, long)
+#define IOC_PORTAL_CLEAR_DEBUG             _IOWR('e', 32, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_MARK_DEBUG              _IOWR('e', 33, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_PANIC                   _IOWR('e', 34, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_NAL_CMD                 _IOWR('e', 35, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_GET_NID                 _IOWR('e', 36, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_FAIL_NID                _IOWR('e', 37, IOCTL_PORTAL_TYPE)
 
-#define IOC_PORTAL_LWT_CONTROL             _IOWR('e', 39, long)
-#define IOC_PORTAL_LWT_SNAPSHOT            _IOWR('e', 40, long)
-#define IOC_PORTAL_LWT_LOOKUP_STRING       _IOWR('e', 41, long)
-#define IOC_PORTAL_MEMHOG                  _IOWR('e', 42, long)
+#define IOC_PORTAL_LWT_CONTROL             _IOWR('e', 39, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_LWT_SNAPSHOT            _IOWR('e', 40, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_LWT_LOOKUP_STRING       _IOWR('e', 41, IOCTL_PORTAL_TYPE)
+#define IOC_PORTAL_MEMHOG                  _IOWR('e', 42, IOCTL_PORTAL_TYPE)
 #define IOC_PORTAL_MAX_NR                             42
 
 enum {
@@ -694,49 +453,6 @@ enum cfg_record_type {
 
 typedef int (*cfg_record_cb_t)(enum cfg_record_type, int len, void *data);
 
-#ifdef __CYGWIN__
-# ifndef BITS_PER_LONG
-#  if (~0UL) == 0xffffffffUL
-#   define BITS_PER_LONG 32
-#  else
-#   define BITS_PER_LONG 64
-#  endif
-# endif
-#endif
-
-#if BITS_PER_LONG > 32
-# define LI_POISON ((int)0x5a5a5a5a5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a5a5a5a5a)
-#else
-# define LI_POISON ((int)0x5a5a5a5a)
-# define LL_POISON ((long)0x5a5a5a5a)
-# define LP_POISON ((void *)(long)0x5a5a5a5a)
-#endif
-
-#if defined(__x86_64__)
-# define LPU64 "%Lu"
-# define LPD64 "%Ld"
-# define LPX64 "%#Lx"
-# define LPSZ  "%lu"
-# define LPSSZ "%ld"
-#elif (BITS_PER_LONG == 32 || __WORDSIZE == 32)
-# define LPU64 "%Lu"
-# define LPD64 "%Ld"
-# define LPX64 "%#Lx"
-# define LPSZ  "%u"
-# define LPSSZ "%d"
-#elif (BITS_PER_LONG == 64 || __WORDSIZE == 64)
-# define LPU64 "%lu"
-# define LPD64 "%ld"
-# define LPX64 "%#lx"
-# define LPSZ  "%lu"
-# define LPSSZ "%ld"
-#endif
-#ifndef LPU64
-# error "No word size defined"
-#endif
-
 /* lustre_id output helper macros */
 #define DLID4   "%lu/%lu/%lu/%lu"
 
@@ -745,5 +461,5 @@ typedef int (*cfg_record_cb_t)(enum cfg_record_type, int len, void *data);
     (unsigned long)(id)->li_fid.lf_group,      \
     (unsigned long)(id)->li_stc.u.e3s.l3s_ino, \
     (unsigned long)(id)->li_stc.u.e3s.l3s_gen
-                
+
 #endif