-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see [sun.com URL with a
- * copy of GPLv2].
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2013, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#ifndef __LIBCFS_LINUX_KP30_H__
#define __LIBCFS_LINUX_KP30_H__
-#ifndef __LIBCFS_KP30_H__
-#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
-#endif
-#ifdef __KERNEL__
-#ifndef AUTOCONF_INCLUDED
-# include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/stat.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/unistd.h>
+#include <linux/kmod.h>
+#include <linux/notifier.h>
+#include <linux/fs.h>
+#include <linux/miscdevice.h>
+#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 <asm/atomic.h>
+#include <asm/uaccess.h>
+#include <linux/rwsem.h>
+#include <linux/proc_fs.h>
+#include <linux/file.h>
+#include <linux/smp.h>
+#include <linux/ctype.h>
+#include <linux/compiler.h>
+#ifdef HAVE_MM_INLINE
+# include <linux/mm_inline.h>
#endif
-# include <linux/kernel.h>
-# include <linux/mm.h>
-# include <linux/string.h>
-# include <linux/stat.h>
-# include <linux/init.h>
-# include <linux/errno.h>
-# include <linux/unistd.h>
-# include <asm/system.h>
-# include <linux/kmod.h>
-# include <linux/notifier.h>
-# include <linux/fs.h>
-# include <linux/miscdevice.h>
-# 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 <linux/smp_lock.h>
-# include <asm/atomic.h>
-# include <asm/uaccess.h>
-# include <linux/rwsem.h>
-# include <linux/proc_fs.h>
-# include <linux/file.h>
-# include <linux/smp.h>
-# include <linux/ctype.h>
-# include <linux/compiler.h>
-# ifdef HAVE_MM_INLINE
-# include <linux/mm_inline.h>
-# endif
-# if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
-# include <linux/kallsyms.h>
-# include <linux/moduleparam.h>
-# endif
+#include <linux/kallsyms.h>
+#include <linux/moduleparam.h>
+#include <linux/scatterlist.h>
#include <libcfs/linux/portals_compat25.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
-#define cfs_get_work_data(type,field,data) (data)
-#else
-
-#ifdef HAVE_3ARGS_INIT_WORK
-
-#define prepare_work(wq,cb,cbdata) \
-do { \
- INIT_WORK((wq), (void *)(cb), (void *)(cbdata)); \
-} while (0)
-
-#define cfs_get_work_data(type,field,data) (data)
-
-#else
-
-#define prepare_work(wq,cb,cbdata) \
-do { \
- INIT_WORK((wq), (void *)(cb)); \
-} while (0)
-
#define cfs_get_work_data(type,field,data) container_of(data,type,field)
-#endif
-
+#define cfs_num_online_cpus() num_online_cpus()
#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
-#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) */
-
#ifdef CONFIG_SMP
#define LASSERT_SPIN_LOCKED(lock) LASSERT(spin_is_locked(lock))
+#define LINVRNT_SPIN_LOCKED(lock) LINVRNT(spin_is_locked(lock))
#else
-#define LASSERT_SPIN_LOCKED(lock) do {} while(0)
+#define LASSERT_SPIN_LOCKED(lock) do {(void)sizeof(lock);} while(0)
+#define LINVRNT_SPIN_LOCKED(lock) do {(void)sizeof(lock);} while(0)
#endif
+
#define LASSERT_SEM_LOCKED(sem) LASSERT(down_trylock(sem) != 0)
+#define LASSERT_MUTEX_LOCKED(x) LASSERT(mutex_is_locked(x))
#define LIBCFS_PANIC(msg) panic(msg)
/* ------------------------------------------------------------------- */
-#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_MODULE_USE try_module_get(THIS_MODULE)
#define PORTAL_MODULE_UNUSE module_put(THIS_MODULE)
-#endif
/******************************************************************************/
/* Module parameter support */
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-# define CFS_MODULE_PARM(name, t, type, perm, desc) \
- MODULE_PARM(name, t);\
- MODULE_PARM_DESC(name, desc)
-
-#else
-# define CFS_MODULE_PARM(name, t, type, perm, desc) \
+#define CFS_MODULE_PARM(name, t, type, perm, desc) \
module_param(name, type, perm);\
MODULE_PARM_DESC(name, desc)
-#endif
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
-# define CFS_SYSFS_MODULE_PARM 0 /* no sysfs module parameters */
-#else
-# define CFS_SYSFS_MODULE_PARM 1 /* module parameters accessible via sysfs */
-#endif
+#define CFS_SYSFS_MODULE_PARM 1 /* module parameters accessible via sysfs */
+
/******************************************************************************/
#if (__GNUC__)
# define printf(format, b...) CDEBUG(D_OTHER, format , ## b)
# define time(a) CURRENT_TIME
-#ifndef num_possible_cpus
-#define num_possible_cpus() NR_CPUS
-#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
-#define i_size_read(a) ((a)->i_size)
-#endif
-
-#else /* !__KERNEL__ */
-# include <stdio.h>
-# include <stdlib.h>
-#if defined(__CYGWIN__)
-# include <cygwin-ioctl.h>
-#else
-# include <stdint.h>
-#endif
-# include <unistd.h>
-# include <time.h>
-# include <limits.h>
-# include <errno.h>
-# include <sys/ioctl.h> /* for _IOWR */
-#ifndef _IOWR
-#include "ioctl.h"
-#endif
-
-# define CFS_MODULE_PARM(name, t, type, perm, desc)
-#define PORTAL_SYMBOL_GET(x) inter_module_get(#x)
-#define PORTAL_SYMBOL_PUT(x) inter_module_put(#x)
-
-#endif /* End of !__KERNEL__ */
+# define cfs_num_possible_cpus() num_possible_cpus()
+# define cfs_num_present_cpus() num_present_cpus()
/******************************************************************************/
/* Light-weight trace
# if !KLWT_SUPPORT
typedef struct _lwt_page {
- struct list_head lwtp_list;
- struct page *lwtp_page;
- lwt_event_t *lwtp_events;
+ cfs_list_t lwtp_list;
+ struct page *lwtp_page;
+ lwt_event_t *lwtp_events;
} lwt_page_t;
typedef struct {
#define LWTSTR(n) #n
#define LWTWHERE(f,l) f ":" LWTSTR(l)
-#define LWT_EVENTS_PER_PAGE (CFS_PAGE_SIZE / sizeof (lwt_event_t))
+#define LWT_EVENTS_PER_PAGE (PAGE_CACHE_SIZE / sizeof(lwt_event_t))
#define LWT_EVENT(p1, p2, p3, p4) \
do { \
\
if (cpu->lwtc_current_index >= LWT_EVENTS_PER_PAGE) { \
cpu->lwtc_current_page = \
- list_entry (p->lwtp_list.next, \
- lwt_page_t, lwtp_list); \
+ cfs_list_entry (p->lwtp_list.next, \
+ lwt_page_t, lwtp_list); \
cpu->lwtc_current_index = 0; \
} \
\
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,
+extern int lwt_snapshot (cfs_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 */
/* this is a bit chunky */
-#if defined(__KERNEL__)
- #define _LWORDSIZE BITS_PER_LONG
-#else
- #define _LWORDSIZE __WORDSIZE
-#endif
+#define _LWORDSIZE BITS_PER_LONG
-#if (defined(__x86_64__) && (defined(__KERNEL__) || defined(CRAY_XT3))) || defined(HAVE_U64_LONG_LONG)
-/* x86_64 defines __u64 as "long" in userspace, but "long long" in the kernel */
-# define LPU64 "%Lu"
-# define LPD64 "%Ld"
-# define LPX64 "%#Lx"
-# define LPF64 "L"
-#elif (_LWORDSIZE == 32)
-# define LPU64 "%Lu"
-# define LPD64 "%Ld"
-# define LPX64 "%#Lx"
+#if (defined(__KERNEL__) && defined(HAVE_KERN__U64_LONG_LONG)) || \
+ (!defined(__KERNEL__) && defined(HAVE_USER__U64_LONG_LONG))
+# define LPU64 "%llu"
+# define LPD64 "%lld"
+# define LPX64 "%#llx"
+# define LPX64i "%llx"
+# define LPO64 "%#llo"
# define LPF64 "L"
-#elif (_LWORDSIZE == 64)
+#else
# define LPU64 "%lu"
# define LPD64 "%ld"
# define LPX64 "%#lx"
+# define LPX64i "%lx"
+# define LPO64 "%#lo"
# define LPF64 "l"
#endif
-#ifdef HAVE_SIZE_T_LONG
-# define LPSZ "%lu"
-#else
-# define LPSZ "%u"
-#endif
+/*
+ * long_ptr_t & ulong_ptr_t, same to "long" for gcc
+ */
+# define LPLU "%lu"
+# define LPLD "%ld"
+# define LPLX "%#lx"
-#ifdef HAVE_SSIZE_T_LONG
-# define LPSSZ "%ld"
-#else
-# define LPSSZ "%d"
-#endif
+/*
+ * pid_t
+ */
+# define LPPID "%d"
#ifndef LPU64
# error "No word size defined"
#undef _LWORDSIZE
+#define cfs_smp_processor_id() smp_processor_id()
+
+#ifndef get_cpu
+# ifdef CONFIG_PREEMPT
+# define cfs_get_cpu() ({ preempt_disable(); smp_processor_id(); })
+# define cfs_put_cpu() preempt_enable()
+# else
+# define cfs_get_cpu() smp_processor_id()
+# define cfs_put_cpu()
+# endif
+#else
+# define cfs_get_cpu() get_cpu()
+# define cfs_put_cpu() put_cpu()
+#endif /* get_cpu & put_cpu */
+
+#ifdef HAVE_SYSCTL_CTLNAME
+#define INIT_CTL_NAME(a) .ctl_name = a,
+#define INIT_STRATEGY(a) .strategy = a,
+#else
+#define INIT_CTL_NAME(a)
+#define INIT_STRATEGY(a)
+#endif
+
#endif