Add more Linux defines. Improve some existing ones.
Obtained from: kmacy @ MFC after: 1 week Sponsored by: Mellanox Technologies
This commit is contained in:
parent
04a471587e
commit
abb14a540f
@ -2,7 +2,7 @@
|
|||||||
* Copyright (c) 2010 Isilon Systems, Inc.
|
* Copyright (c) 2010 Isilon Systems, Inc.
|
||||||
* Copyright (c) 2010 iX Systems, Inc.
|
* Copyright (c) 2010 iX Systems, Inc.
|
||||||
* Copyright (c) 2010 Panasas, Inc.
|
* Copyright (c) 2010 Panasas, Inc.
|
||||||
* Copyright (c) 2013-2015 Mellanox Technologies, Ltd.
|
* Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
|
||||||
* Copyright (c) 2015 François Tigeot
|
* Copyright (c) 2015 François Tigeot
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@ -50,14 +50,17 @@
|
|||||||
#define __cond_lock(x,c) (c)
|
#define __cond_lock(x,c) (c)
|
||||||
#define __bitwise
|
#define __bitwise
|
||||||
#define __devinitdata
|
#define __devinitdata
|
||||||
|
#define __deprecated
|
||||||
#define __init
|
#define __init
|
||||||
#define __devinit
|
#define __devinit
|
||||||
#define __devexit
|
#define __devexit
|
||||||
#define __exit
|
#define __exit
|
||||||
|
#define __rcu
|
||||||
#define __stringify(x) #x
|
#define __stringify(x) #x
|
||||||
#define __attribute_const__ __attribute__((__const__))
|
#define __attribute_const__ __attribute__((__const__))
|
||||||
#undef __always_inline
|
#undef __always_inline
|
||||||
#define __always_inline inline
|
#define __always_inline inline
|
||||||
|
#define ____cacheline_aligned __aligned(CACHE_LINE_SIZE)
|
||||||
|
|
||||||
#define likely(x) __builtin_expect(!!(x), 1)
|
#define likely(x) __builtin_expect(!!(x), 1)
|
||||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
@ -72,6 +75,9 @@
|
|||||||
|
|
||||||
#define barrier() __asm__ __volatile__("": : :"memory")
|
#define barrier() __asm__ __volatile__("": : :"memory")
|
||||||
|
|
||||||
|
#define ___PASTE(a,b) a##b
|
||||||
|
#define __PASTE(a,b) ___PASTE(a,b)
|
||||||
|
|
||||||
#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
|
#define ACCESS_ONCE(x) (*(volatile __typeof(x) *)&(x))
|
||||||
|
|
||||||
#define WRITE_ONCE(x,v) do { \
|
#define WRITE_ONCE(x,v) do { \
|
||||||
@ -87,5 +93,9 @@
|
|||||||
barrier(); \
|
barrier(); \
|
||||||
__var; \
|
__var; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define lockless_dereference(p) READ_ONCE(p)
|
||||||
|
|
||||||
|
#define _AT(T,X) ((T)(X))
|
||||||
|
|
||||||
#endif /* _LINUX_COMPILER_H_ */
|
#endif /* _LINUX_COMPILER_H_ */
|
||||||
|
@ -62,11 +62,59 @@
|
|||||||
#define KERN_INFO "<6>"
|
#define KERN_INFO "<6>"
|
||||||
#define KERN_DEBUG "<7>"
|
#define KERN_DEBUG "<7>"
|
||||||
|
|
||||||
|
#define U8_MAX ((u8)~0U)
|
||||||
|
#define S8_MAX ((s8)(U8_MAX >> 1))
|
||||||
|
#define S8_MIN ((s8)(-S8_MAX - 1))
|
||||||
|
#define U16_MAX ((u16)~0U)
|
||||||
|
#define S16_MAX ((s16)(U16_MAX >> 1))
|
||||||
|
#define S16_MIN ((s16)(-S16_MAX - 1))
|
||||||
|
#define U32_MAX ((u32)~0U)
|
||||||
|
#define S32_MAX ((s32)(U32_MAX >> 1))
|
||||||
|
#define S32_MIN ((s32)(-S32_MAX - 1))
|
||||||
|
#define U64_MAX ((u64)~0ULL)
|
||||||
|
#define S64_MAX ((s64)(U64_MAX >> 1))
|
||||||
|
#define S64_MIN ((s64)(-S64_MAX - 1))
|
||||||
|
|
||||||
|
#define S8_C(x) x
|
||||||
|
#define U8_C(x) x ## U
|
||||||
|
#define S16_C(x) x
|
||||||
|
#define U16_C(x) x ## U
|
||||||
|
#define S32_C(x) x
|
||||||
|
#define U32_C(x) x ## U
|
||||||
|
#define S64_C(x) x ## LL
|
||||||
|
#define U64_C(x) x ## ULL
|
||||||
|
|
||||||
#define BUILD_BUG_ON(x) CTASSERT(!(x))
|
#define BUILD_BUG_ON(x) CTASSERT(!(x))
|
||||||
|
|
||||||
#define BUG() panic("BUG")
|
#define BUG() panic("BUG at %s:%d", __FILE__, __LINE__)
|
||||||
#define BUG_ON(condition) do { if (condition) BUG(); } while(0)
|
#define BUG_ON(cond) do { \
|
||||||
#define WARN_ON BUG_ON
|
if (cond) { \
|
||||||
|
panic("BUG ON %s failed at %s:%d", \
|
||||||
|
__stringify(cond), __FILE__, __LINE__); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define WARN_ON(cond) ({ \
|
||||||
|
bool __ret = (cond); \
|
||||||
|
if (__ret) { \
|
||||||
|
printf("WARNING %s failed at %s:%d\n", \
|
||||||
|
__stringify(cond), __FILE__, __LINE__); \
|
||||||
|
} \
|
||||||
|
unlikely(__ret); \
|
||||||
|
})
|
||||||
|
|
||||||
|
#define WARN_ON_SMP(cond) WARN_ON(cond)
|
||||||
|
|
||||||
|
#define WARN_ON_ONCE(cond) ({ \
|
||||||
|
static bool __warn_on_once; \
|
||||||
|
bool __ret = (cond); \
|
||||||
|
if (__ret && !__warn_on_once) { \
|
||||||
|
__warn_on_once = 1; \
|
||||||
|
printf("WARNING %s failed at %s:%d\n", \
|
||||||
|
__stringify(cond), __FILE__, __LINE__); \
|
||||||
|
} \
|
||||||
|
unlikely(__ret); \
|
||||||
|
})
|
||||||
|
|
||||||
#undef ALIGN
|
#undef ALIGN
|
||||||
#define ALIGN(x, y) roundup2((x), (y))
|
#define ALIGN(x, y) roundup2((x), (y))
|
||||||
@ -116,7 +164,7 @@
|
|||||||
#define log_once(level,...) do { \
|
#define log_once(level,...) do { \
|
||||||
static bool __log_once; \
|
static bool __log_once; \
|
||||||
\
|
\
|
||||||
if (!__log_once) { \
|
if (unlikely(!__log_once)) { \
|
||||||
__log_once = true; \
|
__log_once = true; \
|
||||||
log(level, __VA_ARGS__); \
|
log(level, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
@ -132,7 +180,10 @@
|
|||||||
log(LOG_ERR, pr_fmt(fmt), ##__VA_ARGS__)
|
log(LOG_ERR, pr_fmt(fmt), ##__VA_ARGS__)
|
||||||
#define pr_warning(fmt, ...) \
|
#define pr_warning(fmt, ...) \
|
||||||
log(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
|
log(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
|
||||||
#define pr_warn pr_warning
|
#define pr_warn(...) \
|
||||||
|
pr_warning(__VA_ARGS__)
|
||||||
|
#define pr_warn_once(fmt, ...) \
|
||||||
|
log_once(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
|
||||||
#define pr_notice(fmt, ...) \
|
#define pr_notice(fmt, ...) \
|
||||||
log(LOG_NOTICE, pr_fmt(fmt), ##__VA_ARGS__)
|
log(LOG_NOTICE, pr_fmt(fmt), ##__VA_ARGS__)
|
||||||
#define pr_info(fmt, ...) \
|
#define pr_info(fmt, ...) \
|
||||||
@ -143,11 +194,20 @@
|
|||||||
printk(KERN_CONT fmt, ##__VA_ARGS__)
|
printk(KERN_CONT fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
#ifndef WARN
|
#ifndef WARN
|
||||||
#define WARN(condition, format...) ({ \
|
#define WARN(condition, ...) ({ \
|
||||||
int __ret_warn_on = !!(condition); \
|
bool __ret_warn_on = (condition); \
|
||||||
if (unlikely(__ret_warn_on)) \
|
if (unlikely(__ret_warn_on)) \
|
||||||
pr_warning(format); \
|
pr_warning(__VA_ARGS__); \
|
||||||
unlikely(__ret_warn_on); \
|
unlikely(__ret_warn_on); \
|
||||||
|
})
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef WARN_ONCE
|
||||||
|
#define WARN_ONCE(condition, ...) ({ \
|
||||||
|
bool __ret_warn_on = (condition); \
|
||||||
|
if (unlikely(__ret_warn_on)) \
|
||||||
|
pr_warn_once(__VA_ARGS__); \
|
||||||
|
unlikely(__ret_warn_on); \
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -171,11 +231,19 @@
|
|||||||
#define min3(a, b, c) min(a, min(b,c))
|
#define min3(a, b, c) min(a, min(b,c))
|
||||||
#define max3(a, b, c) max(a, max(b,c))
|
#define max3(a, b, c) max(a, max(b,c))
|
||||||
|
|
||||||
#define min_t(type, _x, _y) ((type)(_x) < (type)(_y) ? (type)(_x) : (type)(_y))
|
#define min_t(type, x, y) ({ \
|
||||||
#define max_t(type, _x, _y) ((type)(_x) > (type)(_y) ? (type)(_x) : (type)(_y))
|
type __min1 = (x); \
|
||||||
|
type __min2 = (y); \
|
||||||
|
__min1 < __min2 ? __min1 : __min2; })
|
||||||
|
|
||||||
|
#define max_t(type, x, y) ({ \
|
||||||
|
type __max1 = (x); \
|
||||||
|
type __max2 = (y); \
|
||||||
|
__max1 > __max2 ? __max1 : __max2; })
|
||||||
|
|
||||||
#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
|
#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max)
|
||||||
#define clamp(x, lo, hi) min( max(x,lo), hi)
|
#define clamp(x, lo, hi) min( max(x,lo), hi)
|
||||||
|
#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This looks more complex than it should be. But we need to
|
* This looks more complex than it should be. But we need to
|
||||||
@ -190,6 +258,7 @@
|
|||||||
#define smp_processor_id() PCPU_GET(cpuid)
|
#define smp_processor_id() PCPU_GET(cpuid)
|
||||||
#define num_possible_cpus() mp_ncpus
|
#define num_possible_cpus() mp_ncpus
|
||||||
#define num_online_cpus() mp_ncpus
|
#define num_online_cpus() mp_ncpus
|
||||||
|
#define cpu_has_clflush (1)
|
||||||
|
|
||||||
typedef struct pm_message {
|
typedef struct pm_message {
|
||||||
int event;
|
int event;
|
||||||
@ -204,6 +273,13 @@ typedef struct pm_message {
|
|||||||
|
|
||||||
#define DIV_ROUND_CLOSEST(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
|
#define DIV_ROUND_CLOSEST(x, divisor) (((x) + ((divisor) / 2)) / (divisor))
|
||||||
|
|
||||||
|
#define DIV_ROUND_CLOSEST_ULL(x, divisor) ({ \
|
||||||
|
__typeof(divisor) __d = (divisor); \
|
||||||
|
unsigned long long __ret = (x) + (__d) / 2; \
|
||||||
|
__ret /= __d; \
|
||||||
|
__ret; \
|
||||||
|
})
|
||||||
|
|
||||||
static inline uintmax_t
|
static inline uintmax_t
|
||||||
mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor)
|
mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user