⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kp30.h

📁 非常经典的一个分布式系统
💻 H
📖 第 1 页 / 共 2 页
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: */#ifndef __LIBCFS_KP30_H__#define __LIBCFS_KP30_H__/* Controlled via configure key *//* #define LIBCFS_DEBUG */#include <libcfs/libcfs.h>#include <lnet/types.h>#if defined(__linux__)#include <libcfs/linux/kp30.h>#elif defined(__APPLE__)#include <libcfs/darwin/kp30.h>#elif defined(__WINNT__)#include <libcfs/winnt/kp30.h>#else#error Unsupported operating system#endif#ifndef DEBUG_SUBSYSTEM# define DEBUG_SUBSYSTEM S_UNDEFINED#endif#ifdef __KERNEL__#ifdef LIBCFS_DEBUG/* * When this is on, LASSERT macro includes check for assignment used instead * of equality check, but doesn't have unlikely(). Turn this on from time to * time to make test-builds. This shouldn't be on for production release. */#define LASSERT_CHECKED (0)#if LASSERT_CHECKED/* * Assertion. * * Strange construction with empty "then" clause is used to trigger compiler * warnings on the assertions of the form LASSERT(a = b); * * "warning: suggest parentheses around assignment used as truth value" * * requires -Wall. Unfortunately this rules out use of likely/unlikely. */#define LASSERT(cond)                                           \({                                                              \        if (cond)                                               \                ;                                               \        else                                                    \                libcfs_assertion_failed( #cond , __FILE__,      \                        __FUNCTION__, __LINE__);                \})#define LASSERTF(cond, fmt, a...)                                       \({                                                                      \         if (cond)                                                      \                 ;                                                      \         else {                                                         \                 libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG,       \                                  __FILE__, __FUNCTION__,__LINE__,      \                                  "ASSERTION(" #cond ") failed:" fmt,   \                                  ## a);                                \                 LBUG();                                                \         }                                                              \})/* LASSERT_CHECKED */#else#define LASSERT(cond)                                           \({                                                              \        if (unlikely(!(cond)))                                  \                libcfs_assertion_failed(#cond , __FILE__,       \                        __FUNCTION__, __LINE__);                \})#define LASSERTF(cond, fmt, a...)                                       \({                                                                      \        if (unlikely(!(cond))) {                                        \                libcfs_debug_msg(NULL, DEBUG_SUBSYSTEM, D_EMERG,        \                                 __FILE__, __FUNCTION__,__LINE__,       \                                 "ASSERTION(" #cond ") failed:" fmt,    \                                 ## a);                                 \                LBUG();                                                 \        }                                                               \})/* LASSERT_CHECKED */#endif/* LIBCFS_DEBUG */#else#define LASSERT(e) ((void)(0))#define LASSERTF(cond, fmt...) ((void)(0))#endif /* LIBCFS_DEBUG */void lbug_with_loc(char *file, const char *func, const int line)        __attribute__((noreturn));#define LBUG() lbug_with_loc(__FILE__, __FUNCTION__, __LINE__)extern atomic_t libcfs_kmemory;/* * Memory */#ifdef LIBCFS_DEBUG# define libcfs_kmem_inc(ptr, size)             \do {                                            \        atomic_add(size, &libcfs_kmemory);      \} while (0)# define libcfs_kmem_dec(ptr, size) do {        \        atomic_sub(size, &libcfs_kmemory);      \} while (0)#else# define libcfs_kmem_inc(ptr, size) do {} while (0)# define libcfs_kmem_dec(ptr, size) do {} while (0)#endif /* LIBCFS_DEBUG */#define LIBCFS_VMALLOC_SIZE        16384#define LIBCFS_ALLOC_GFP(ptr, size, mask)                                 \do {                                                                      \        LASSERT(!in_interrupt() ||                                        \               (size <= LIBCFS_VMALLOC_SIZE && mask == CFS_ALLOC_ATOMIC));\        if (unlikely((size) > LIBCFS_VMALLOC_SIZE))                     \                (ptr) = cfs_alloc_large(size);                            \        else                                                              \                (ptr) = cfs_alloc((size), (mask));                        \        if (unlikely((ptr) == NULL)) {                                  \                CERROR("LNET: out of memory at %s:%d (tried to alloc '"   \                       #ptr "' = %d)\n", __FILE__, __LINE__, (int)(size));\                CERROR("LNET: %d total bytes allocated by lnet\n",        \                       atomic_read(&libcfs_kmemory));                     \        } else {                                                          \                libcfs_kmem_inc((ptr), (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 (&libcfs_kmemory));        \} while (0)#define LIBCFS_ALLOC(ptr, size) \        LIBCFS_ALLOC_GFP(ptr, size, CFS_ALLOC_IO)#define LIBCFS_ALLOC_ATOMIC(ptr, size) \        LIBCFS_ALLOC_GFP(ptr, size, CFS_ALLOC_ATOMIC)#define LIBCFS_FREE(ptr, size)                                          \do {                                                                    \        int s = (size);                                                 \        if (unlikely((ptr) == NULL)) {                                  \                CERROR("LIBCFS: free NULL '" #ptr "' (%d bytes) at "    \                       "%s:%d\n", s, __FILE__, __LINE__);               \                break;                                                  \        }                                                               \        if (unlikely(s > LIBCFS_VMALLOC_SIZE))                          \                cfs_free_large(ptr);                                    \        else                                                            \                cfs_free(ptr);                                          \        libcfs_kmem_dec((ptr), s);                                      \        CDEBUG(D_MALLOC, "kfreed '" #ptr "': %d at %p (tot %d).\n",     \               s, (ptr), atomic_read(&libcfs_kmemory));                 \} while (0)/******************************************************************************//* htonl hack - either this, or compile with -O2. Stupid byteorder/generic.h */#if defined(__GNUC__) && (__GNUC__ >= 2) && !defined(__OPTIMIZE__)#define ___htonl(x) __cpu_to_be32(x)#define ___htons(x) __cpu_to_be16(x)#define ___ntohl(x) __be32_to_cpu(x)#define ___ntohs(x) __be16_to_cpu(x)#define htonl(x) ___htonl(x)#define ntohl(x) ___ntohl(x)#define htons(x) ___htons(x)#define ntohs(x) ___ntohs(x)#endifvoid libcfs_debug_dumpstack(cfs_task_t *tsk);void libcfs_run_upcall(char **argv);void libcfs_run_lbug_upcall(char * file, const char *fn, const int line);void libcfs_debug_dumplog(void);int libcfs_debug_init(unsigned long bufsize);int libcfs_debug_cleanup(void);int libcfs_debug_clear_buffer(void);int libcfs_debug_mark_buffer(char *text);void libcfs_debug_set_level(unsigned int debug_level);#else  /* !__KERNEL__ */# ifdef LIBCFS_DEBUG#  undef NDEBUG#  include <assert.h>#  define LASSERT(e)     assert(e)#  define LASSERTF(cond, args...)                                              \do {                                                                           \          if (!(cond))                                                         \                CERROR(args);                                                  \          assert(cond);                                                        \} while (0)#  define LBUG()   assert(0)# else#  define LASSERT(e) ((void)(0))#  define LASSERTF(cond, args...) do { } while (0)#  define LBUG()   ((void)(0))# endif /* LIBCFS_DEBUG */# define printk(format, args...) printf (format, ## args)# ifdef CRAY_XT3                                /* buggy calloc! */#  define LIBCFS_ALLOC(ptr, size)               \   do {                                         \        (ptr) = malloc(size);                   \        memset(ptr, 0, size);                   \   } while (0)# else#  define LIBCFS_ALLOC(ptr, size) do { (ptr) = calloc(1,size); } while (0)# endif# define LIBCFS_FREE(a, b) do { free(a); } while (0)void libcfs_debug_dumplog(void);int libcfs_debug_init(unsigned long bufsize);int libcfs_debug_cleanup(void);/* * Generic compiler-dependent macros required for kernel * build go below this comment. Actual compiler/compiler version * specific implementations come from the above header files */#define likely(x)	__builtin_expect(!!(x), 1)#define unlikely(x)	__builtin_expect(!!(x), 0)/* !__KERNEL__ */#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 */int         libcfs_isknown_lnd(int type);char       *libcfs_lnd2modname(int type);char       *libcfs_lnd2str(int type);int         libcfs_str2lnd(char *str);char       *libcfs_net2str(__u32 net);char       *libcfs_nid2str(lnet_nid_t nid);__u32       libcfs_str2net(char *str);lnet_nid_t  libcfs_str2nid(char *str);int         libcfs_str2anynid(lnet_nid_t *nid, char *str);char       *libcfs_id2str(lnet_process_id_t id);void        libcfs_setnet0alias(int type);/* how an LNET NID encodes net:address */#define LNET_NIDADDR(nid)      ((__u32)((nid) & 0xffffffff))#define LNET_NIDNET(nid)       ((__u32)(((nid) >> 32)) & 0xffffffff)#define LNET_MKNID(net,addr)   ((((__u64)(net))<<32)|((__u64)(addr)))/* how net encodes type:number */#define LNET_NETNUM(net)       ((net) & 0xffff)#define LNET_NETTYP(net)       (((net) >> 16) & 0xffff)#define LNET_MKNET(typ,num)    ((((__u32)(typ))<<16)|((__u32)(num)))/* implication */#define ergo(a, b) (!(a) || (b))/* logical equivalence */#define equi(a, b) (!!(a) == !!(b))#ifndef CURRENT_TIME# define CURRENT_TIME time(0)#endif/* -------------------------------------------------------------------- * Light-weight trace * Support for temporary event tracing with minimal Heisenberg effect. * All stuff about lwt are put in arch/kp30.h * -------------------------------------------------------------------- */struct libcfs_device_userstate{        int           ldu_memhog_pages;        cfs_page_t   *ldu_memhog_root_page;};/* what used to be in portals_lib.h */#ifndef MIN# define MIN(a,b) (((a)<(b)) ? (a): (b))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -