kernel.h revision 340003
11553Srgrimes/*-
2230051Skevlo * Copyright (c) 2010 Isilon Systems, Inc.
31553Srgrimes * Copyright (c) 2010 iX Systems, Inc.
41553Srgrimes * Copyright (c) 2010 Panasas, Inc.
51553Srgrimes * Copyright (c) 2013-2016 Mellanox Technologies, Ltd.
61553Srgrimes * Copyright (c) 2014-2015 Fran��ois Tigeot
71553Srgrimes * All rights reserved.
81553Srgrimes *
91553Srgrimes * Redistribution and use in source and binary forms, with or without
101553Srgrimes * modification, are permitted provided that the following conditions
111553Srgrimes * are met:
121553Srgrimes * 1. Redistributions of source code must retain the above copyright
131553Srgrimes *    notice unmodified, this list of conditions, and the following
141553Srgrimes *    disclaimer.
151553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161553Srgrimes *    notice, this list of conditions and the following disclaimer in the
171553Srgrimes *    documentation and/or other materials provided with the distribution.
181553Srgrimes *
191553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
201553Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
211553Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
221553Srgrimes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
231553Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
241553Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251553Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261553Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271553Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
281553Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291553Srgrimes *
301553Srgrimes * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/kernel.h 340003 2018-11-01 15:50:57Z hselasky $
3129451Scharnier */
321553Srgrimes#ifndef	_LINUX_KERNEL_H_
3329451Scharnier#define	_LINUX_KERNEL_H_
3429451Scharnier
3550479Speter#include <sys/cdefs.h>
361553Srgrimes#include <sys/types.h>
371553Srgrimes#include <sys/systm.h>
381553Srgrimes#include <sys/param.h>
391553Srgrimes#include <sys/libkern.h>
401553Srgrimes#include <sys/stat.h>
411553Srgrimes#include <sys/smp.h>
421553Srgrimes#include <sys/stddef.h>
431553Srgrimes#include <sys/syslog.h>
4429451Scharnier#include <sys/time.h>
4529451Scharnier
46269825Simp#include <linux/bitops.h>
471553Srgrimes#include <linux/compiler.h>
4820458Sjoerg#include <linux/errno.h>
4969004Simp#include <linux/sched.h>
5016073Sphk#include <linux/types.h>
511553Srgrimes#include <linux/jiffies.h>
5230638Speter#include <linux/log2.h>
531553Srgrimes
5461640Speter#include <asm/byteorder.h>
5561640Speter#include <asm/uaccess.h>
5661640Speter
5769135Speter#include <machine/stdarg.h>
5861640Speter
5961640Speter#define KERN_CONT       ""
6072684Speter#define	KERN_EMERG	"<0>"
6161640Speter#define	KERN_ALERT	"<1>"
6229451Scharnier#define	KERN_CRIT	"<2>"
63269825Simp#define	KERN_ERR	"<3>"
64269825Simp#define	KERN_WARNING	"<4>"
65269825Simp#define	KERN_NOTICE	"<5>"
66269825Simp#define	KERN_INFO	"<6>"
67269825Simp#define	KERN_DEBUG	"<7>"
68269825Simp
69269825Simp#define	U8_MAX		((u8)~0U)
70269825Simp#define	S8_MAX		((s8)(U8_MAX >> 1))
71269825Simp#define	S8_MIN		((s8)(-S8_MAX - 1))
72269825Simp#define	U16_MAX		((u16)~0U)
731553Srgrimes#define	S16_MAX		((s16)(U16_MAX >> 1))
741553Srgrimes#define	S16_MIN		((s16)(-S16_MAX - 1))
751553Srgrimes#define	U32_MAX		((u32)~0U)
7645744Speter#define	S32_MAX		((s32)(U32_MAX >> 1))
7761640Speter#define	S32_MIN		((s32)(-S32_MAX - 1))
781553Srgrimes#define	U64_MAX		((u64)~0ULL)
7961640Speter#define	S64_MAX		((s64)(U64_MAX >> 1))
801553Srgrimes#define	S64_MIN		((s64)(-S64_MAX - 1))
81110895Sru
821553Srgrimes#define	S8_C(x)  x
831553Srgrimes#define	U8_C(x)  x ## U
841553Srgrimes#define	S16_C(x) x
851553Srgrimes#define	U16_C(x) x ## U
861553Srgrimes#define	S32_C(x) x
871553Srgrimes#define	U32_C(x) x ## U
881553Srgrimes#define	S64_C(x) x ## LL
891553Srgrimes#define	U64_C(x) x ## ULL
901553Srgrimes
9145744Speter#define	BUILD_BUG()			do { CTASSERT(0); } while (0)
9261640Speter#define	BUILD_BUG_ON(x)			CTASSERT(!(x))
931553Srgrimes#define	BUILD_BUG_ON_MSG(x, msg)	BUILD_BUG_ON(x)
9461640Speter#define	BUILD_BUG_ON_NOT_POWER_OF_2(x)	BUILD_BUG_ON(!powerof2(x))
951553Srgrimes#define	BUILD_BUG_ON_INVALID(expr)	while (0) { (void)(expr); }
96159362Sdelphij
97205880Sru#define	BUG()			panic("BUG at %s:%d", __FILE__, __LINE__)
98205880Sru#define	BUG_ON(cond)		do {				\
99110895Sru	if (cond) {						\
1001553Srgrimes		panic("BUG ON %s failed at %s:%d",		\
1011553Srgrimes		    __stringify(cond), __FILE__, __LINE__);	\
1021553Srgrimes	}							\
1031553Srgrimes} while (0)
104207260Simp
1051553Srgrimes#define	WARN_ON(cond) ({					\
106207260Simp      bool __ret = (cond);					\
107207260Simp      if (__ret) {						\
1081553Srgrimes		printf("WARNING %s failed at %s:%d\n",		\
109207260Simp		    __stringify(cond), __FILE__, __LINE__);	\
1101553Srgrimes      }								\
1111553Srgrimes      unlikely(__ret);						\
11255614Speter})
1131553Srgrimes
11455614Speter#define	WARN_ON_SMP(cond)	WARN_ON(cond)
11555614Speter
11655614Speter#define	WARN_ON_ONCE(cond) ({					\
11755614Speter      static bool __warn_on_once;				\
11829451Scharnier      bool __ret = (cond);					\
11929451Scharnier      if (__ret && !__warn_on_once) {				\
120207260Simp		__warn_on_once = 1;				\
121207260Simp		printf("WARNING %s failed at %s:%d\n",		\
12212772Speter		    __stringify(cond), __FILE__, __LINE__);	\
123207260Simp      }								\
124207260Simp      unlikely(__ret);						\
125207260Simp})
126207260Simp
127207260Simp#define	oops_in_progress	SCHEDULER_STOPPED()
128207260Simp
129207260Simp#undef	ALIGN
130207260Simp#define	ALIGN(x, y)		roundup2((x), (y))
131207260Simp#undef PTR_ALIGN
132207260Simp#define	PTR_ALIGN(p, a)		((__typeof(p))ALIGN((uintptr_t)(p), (a)))
133207260Simp#define	DIV_ROUND_UP(x, n)	howmany(x, n)
134207260Simp#define	__KERNEL_DIV_ROUND_UP(x, n)	howmany(x, n)
13599923Sbde#define	DIV_ROUND_UP_ULL(x, n)	DIV_ROUND_UP((unsigned long long)(x), (n))
13699923Sbde#define	FIELD_SIZEOF(t, f)	sizeof(((t *)0)->f)
13799923Sbde
138113951Sdes#define	printk(...)		printf(__VA_ARGS__)
139218544Simp#define	vprintk(f, a)		vprintf(f, a)
140218544Simp
141185186Sthompsaextern void linux_dump_stack(void);
142185186Sthompsa#define	dump_stack()		linux_dump_stack()
143185186Sthompsa
144185186Sthompsastruct va_format {
145185186Sthompsa	const char *fmt;
146185186Sthompsa	va_list *va;
1471553Srgrimes};
1481553Srgrimes
14999923Sbdestatic inline int
15020395Sbdevscnprintf(char *buf, size_t size, const char *fmt, va_list args)
15152653Smarcel{
15252653Smarcel	ssize_t ssize = size;
153230044Skevlo	int i;
1541553Srgrimes
1551553Srgrimes	i = vsnprintf(buf, size, fmt, args);
1561553Srgrimes
1571553Srgrimes	return ((i >= ssize) ? (ssize - 1) : i);
1585325Sgibbs}
1595325Sgibbs
1605325Sgibbsstatic inline int
1611553Srgrimesscnprintf(char *buf, size_t size, const char *fmt, ...)
16269135Speter{
16369135Speter	va_list args;
1641553Srgrimes	int i;
1651553Srgrimes
1666803Sgibbs	va_start(args, fmt);
1676803Sgibbs	i = vscnprintf(buf, size, fmt, args);
168207260Simp	va_end(args);
169207260Simp
170207260Simp	return (i);
1711553Srgrimes}
1721553Srgrimes
1731553Srgrimes/*
1741553Srgrimes * The "pr_debug()" and "pr_devel()" macros should produce zero code
1751553Srgrimes * unless DEBUG is defined:
1761553Srgrimes */
17713400Speter#ifdef DEBUG
178153888Sru#define pr_debug(fmt, ...) \
17934619Seivind	log(LOG_DEBUG, fmt, ##__VA_ARGS__)
180153888Sru#define pr_devel(fmt, ...) \
181153888Sru	log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__)
182153888Sru#else
183153888Sru#define pr_debug(fmt, ...) \
184153888Sru	({ if (0) log(LOG_DEBUG, fmt, ##__VA_ARGS__); 0; })
185153888Sru#define pr_devel(fmt, ...) \
186163640Simp	({ if (0) log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__); 0; })
187153888Sru#endif
188153888Sru
189163638Simp#ifndef pr_fmt
190153888Sru#define pr_fmt(fmt) fmt
19161640Speter#endif
19261640Speter
19361640Speter/*
19483594Speter * Print a one-time message (analogous to WARN_ONCE() et al):
19583594Speter */
19683594Speter#define printk_once(...) do {			\
19765091Speter	static bool __print_once;		\
19861640Speter						\
199163638Simp	if (!__print_once) {			\
200163638Simp		__print_once = true;		\
201163638Simp		printk(__VA_ARGS__);		\
202163638Simp	}					\
203230044Skevlo} while (0)
20461640Speter
205229403Sed/*
20661640Speter * Log a one-time message (analogous to WARN_ONCE() et al):
207229403Sed */
20861640Speter#define log_once(level,...) do {		\
20961640Speter	static bool __log_once;			\
210229403Sed						\
21161640Speter	if (unlikely(!__log_once)) {		\
21261640Speter		__log_once = true;		\
21361640Speter		log(level, __VA_ARGS__);	\
21461640Speter	}					\
21561640Speter} while (0)
21661640Speter
21761640Speter#define pr_emerg(fmt, ...) \
21861640Speter	log(LOG_EMERG, pr_fmt(fmt), ##__VA_ARGS__)
21961640Speter#define pr_alert(fmt, ...) \
22061640Speter	log(LOG_ALERT, pr_fmt(fmt), ##__VA_ARGS__)
22161640Speter#define pr_crit(fmt, ...) \
22261640Speter	log(LOG_CRIT, pr_fmt(fmt), ##__VA_ARGS__)
22361640Speter#define pr_err(fmt, ...) \
22461640Speter	log(LOG_ERR, pr_fmt(fmt), ##__VA_ARGS__)
22561640Speter#define pr_warning(fmt, ...) \
22661640Speter	log(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
22761640Speter#define pr_warn(...) \
22861640Speter	pr_warning(__VA_ARGS__)
22961652Speter#define pr_warn_once(fmt, ...) \
23061640Speter	log_once(LOG_WARNING, pr_fmt(fmt), ##__VA_ARGS__)
23161640Speter#define pr_notice(fmt, ...) \
232163640Simp	log(LOG_NOTICE, pr_fmt(fmt), ##__VA_ARGS__)
23361640Speter#define pr_info(fmt, ...) \
23461640Speter	log(LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
23561640Speter#define pr_info_once(fmt, ...) \
23661640Speter	log_once(LOG_INFO, pr_fmt(fmt), ##__VA_ARGS__)
237153888Sru#define pr_cont(fmt, ...) \
23882393Speter	printk(KERN_CONT fmt, ##__VA_ARGS__)
239153888Sru#define	pr_warn_ratelimited(...) do {		\
240153888Sru	static linux_ratelimit_t __ratelimited;	\
241153888Sru	if (linux_ratelimited(&__ratelimited))	\
242153888Sru		pr_warning(__VA_ARGS__);	\
243153888Sru} while (0)
244153888Sru
245153888Sru#ifndef WARN
246153888Sru#define	WARN(condition, ...) ({			\
247153888Sru	bool __ret_warn_on = (condition);	\
248153888Sru	if (unlikely(__ret_warn_on))		\
24982393Speter		pr_warning(__VA_ARGS__);	\
25082393Speter	unlikely(__ret_warn_on);		\
25182393Speter})
25282393Speter#endif
25382393Speter
25482393Speter#ifndef WARN_ONCE
25582393Speter#define	WARN_ONCE(condition, ...) ({		\
25682393Speter	bool __ret_warn_on = (condition);	\
25782393Speter	if (unlikely(__ret_warn_on))		\
25882393Speter		pr_warn_once(__VA_ARGS__);	\
25983594Speter	unlikely(__ret_warn_on);		\
26083594Speter})
26183594Speter#endif
26282393Speter
26382393Speter#define container_of(ptr, type, member)				\
26482393Speter({								\
265230044Skevlo	const __typeof(((type *)0)->member) *__p = (ptr);	\
26682393Speter	(type *)((uintptr_t)__p - offsetof(type, member));	\
267229403Sed})
26882393Speter
269229403Sed#define	ARRAY_SIZE(x)	(sizeof(x) / sizeof((x)[0]))
27082393Speter
27182393Speter#define	u64_to_user_ptr(val)	((void *)(uintptr_t)(val))
272229403Sed
27382393Speterstatic inline unsigned long long
27482393Spetersimple_strtoull(const char *cp, char **endp, unsigned int base)
27582393Speter{
27682393Speter	return (strtouq(cp, endp, base));
27782393Speter}
27882393Speter
27982393Speterstatic inline long long
28082393Spetersimple_strtoll(const char *cp, char **endp, unsigned int base)
28182393Speter{
28282393Speter	return (strtoq(cp, endp, base));
28382393Speter}
28482393Speter
28582393Speterstatic inline unsigned long
28682393Spetersimple_strtoul(const char *cp, char **endp, unsigned int base)
28782393Speter{
28882393Speter	return (strtoul(cp, endp, base));
28982393Speter}
29082393Speter
29182393Speterstatic inline long
29282393Spetersimple_strtol(const char *cp, char **endp, unsigned int base)
29382393Speter{
29482393Speter	return (strtol(cp, endp, base));
29582393Speter}
29682393Speter
29782393Speterstatic inline int
29882393Speterkstrtoul(const char *cp, unsigned int base, unsigned long *res)
29982393Speter{
3001553Srgrimes	char *end;
3011553Srgrimes
302129119Scognet	*res = strtoul(cp, &end, base);
303129073Scognet
3041553Srgrimes	/* skip newline character, if any */
305162936Sru	if (*end == '\n')
3061553Srgrimes		end++;
307152811Sru	if (*cp == 0 || *end != 0)
30861640Speter		return (-EINVAL);
30961640Speter	return (0);
310152811Sru}
311219819Sjeff
312269825Simpstatic inline int
313269825Simpkstrtol(const char *cp, unsigned int base, long *res)
3141553Srgrimes{
3151553Srgrimes	char *end;
31629451Scharnier
31729451Scharnier	*res = strtol(cp, &end, base);
3181553Srgrimes
3191553Srgrimes	/* skip newline character, if any */
320162936Sru	if (*end == '\n')
321269825Simp		end++;
322152862Sru	if (*cp == 0 || *end != 0)
3238857Srgrimes		return (-EINVAL);
3246803Sgibbs	return (0);
32554490Speter}
326219819Sjeff
3271553Srgrimesstatic inline int
3281553Srgrimeskstrtoint(const char *cp, unsigned int base, int *res)
3291553Srgrimes{
3301553Srgrimes	char *end;
3311553Srgrimes	long temp;
332129073Scognet
3331553Srgrimes	*res = temp = strtol(cp, &end, base);
3341553Srgrimes
33552098Speter	/* skip newline character, if any */
3361566Srgrimes	if (*end == '\n')
33752098Speter		end++;
33852098Speter	if (*cp == 0 || *end != 0)
3391566Srgrimes		return (-EINVAL);
3401566Srgrimes	if (temp != (int)temp)
341162936Sru		return (-ERANGE);
342269825Simp	return (0);
343269825Simp}
344269825Simp
345162936Srustatic inline int
346162936Srukstrtouint(const char *cp, unsigned int base, unsigned int *res)
347162936Sru{
348162936Sru	char *end;
349162936Sru	unsigned long temp;
350162936Sru
3511553Srgrimes	*res = temp = strtoul(cp, &end, base);
352269825Simp
353269825Simp	/* skip newline character, if any */
354269825Simp	if (*end == '\n')
355269825Simp		end++;
356269825Simp	if (*cp == 0 || *end != 0)
357152811Sru		return (-EINVAL);
358152862Sru	if (temp != (unsigned int)temp)
359152862Sru		return (-ERANGE);
3601553Srgrimes	return (0);
36173199Speter}
3624571Sgibbs
3636803Sgibbsstatic inline int
36472684Speterkstrtou32(const char *cp, unsigned int base, u32 *res)
365269825Simp{
3664571Sgibbs	char *end;
3674571Sgibbs	unsigned long temp;
3685325Sgibbs
36991002Speter	*res = temp = strtoul(cp, &end, base);
370269825Simp
3711553Srgrimes	/* skip newline character, if any */
372219819Sjeff	if (*end == '\n')
373269825Simp		end++;
3741553Srgrimes	if (*cp == 0 || *end != 0)
375269825Simp		return (-EINVAL);
376269825Simp	if (temp != (u32)temp)
377214654Sobrien		return (-ERANGE);
378269825Simp	return (0);
379269825Simp}
380269825Simp
381269825Simpstatic inline int
382269825Simpkstrtobool(const char *s, bool *res)
383269825Simp{
384152862Sru	int len;
385269825Simp
386269825Simp	if (s == NULL || (len = strlen(s)) == 0 || res == NULL)
387269825Simp		return (-EINVAL);
388269825Simp
389276280Sian	/* skip newline character, if any */
390269825Simp	if (s[len - 1] == '\n')
391269825Simp		len--;
392269825Simp
3934571Sgibbs	if (len == 1 && strchr("yY1", s[0]) != NULL)
394269825Simp		*res = true;
395269825Simp	else if (len == 1 && strchr("nN0", s[0]) != NULL)
396269825Simp		*res = false;
3974571Sgibbs	else if (strncasecmp("on", s, len) == 0)
398269825Simp		*res = true;
399269825Simp	else if (strncasecmp("off", s, len) == 0)
400269825Simp		*res = false;
401269825Simp	else
402269825Simp		return (-EINVAL);
403269825Simp
404269825Simp	return (0);
405269825Simp}
4065325Sgibbs
407269825Simpstatic inline int
408269825Simpkstrtobool_from_user(const char __user *s, size_t count, bool *res)
409269825Simp{
4101553Srgrimes	char buf[8] = {};
411269825Simp
412269825Simp	if (count > (sizeof(buf) - 1))
413269825Simp		count = (sizeof(buf) - 1);
414269825Simp
415269825Simp	if (copy_from_user(buf, s, count))
416269825Simp		return (-EFAULT);
417269825Simp
41854490Speter	return (kstrtobool(buf, res));
419269825Simp}
420269825Simp
421269825Simp#define min(x, y)	((x) < (y) ? (x) : (y))
422269825Simp#define max(x, y)	((x) > (y) ? (x) : (y))
423269825Simp
424269825Simp#define min3(a, b, c)	min(a, min(b,c))
425269825Simp#define max3(a, b, c)	max(a, max(b,c))
426219819Sjeff
427269825Simp#define	min_t(type, x, y) ({			\
428269825Simp	type __min1 = (x);			\
429269825Simp	type __min2 = (y);			\
430269825Simp	__min1 < __min2 ? __min1 : __min2; })
431269825Simp
432269825Simp#define	max_t(type, x, y) ({			\
433269825Simp	type __max1 = (x);			\
434152811Sru	type __max2 = (y);			\
435269825Simp	__max1 > __max2 ? __max1 : __max2; })
436269825Simp
437269825Simp#define clamp_t(type, _x, min, max)	min_t(type, max_t(type, _x, min), max)
438269825Simp#define clamp(x, lo, hi)		min( max(x,lo), hi)
439269825Simp#define	clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi)
440269825Simp
441269825Simp/*
442269825Simp * This looks more complex than it should be. But we need to
443269825Simp * get the type for the ~ right in round_down (it needs to be
444269825Simp * as wide as the result!), and we want to evaluate the macro
445269825Simp * arguments just once each.
446269825Simp */
447269825Simp#define __round_mask(x, y) ((__typeof__(x))((y)-1))
448269825Simp#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
449269825Simp#define round_down(x, y) ((x) & ~__round_mask(x, y))
450269825Simp
451269825Simp#define	smp_processor_id()	PCPU_GET(cpuid)
452269825Simp#define	num_possible_cpus()	mp_ncpus
453269825Simp#define	num_online_cpus()	mp_ncpus
454269825Simp
455269825Simp#if defined(__i386__) || defined(__amd64__)
456269825Simpextern bool linux_cpu_has_clflush;
457269825Simp#define	cpu_has_clflush		linux_cpu_has_clflush
458269825Simp#endif
459269825Simp
460269825Simptypedef struct pm_message {
461269825Simp	int event;
462269825Simp} pm_message_t;
463269825Simp
464269825Simp/* Swap values of a and b */
465269825Simp#define swap(a, b) do {			\
466269825Simp	typeof(a) _swap_tmp = a;	\
467269825Simp	a = b;				\
468269825Simp	b = _swap_tmp;			\
469269825Simp} while (0)
470269825Simp
471269825Simp#define	DIV_ROUND_CLOSEST(x, divisor)	(((x) + ((divisor) / 2)) / (divisor))
472269825Simp
473276280Sian#define	DIV_ROUND_CLOSEST_ULL(x, divisor) ({		\
474276280Sian	__typeof(divisor) __d = (divisor);		\
475276280Sian	unsigned long long __ret = (x) + (__d) / 2;	\
476276280Sian	__ret /= __d;					\
477269825Simp	__ret;						\
478269825Simp})
479269825Simp
480276280Sianstatic inline uintmax_t
481276280Sianmult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor)
482276280Sian{
483269825Simp	uintmax_t q = (x / divisor);
484276280Sian	uintmax_t r = (x % divisor);
485276280Sian
486269825Simp	return ((q * multiplier) + ((r * multiplier) / divisor));
487276280Sian}
48830796Sjoerg
489276280Sianstatic inline int64_t
490269825Simpabs64(int64_t x)
491269825Simp{
492269825Simp	return (x < 0 ? -x : x);
493269825Simp}
494269825Simp
495269825Simptypedef struct linux_ratelimit {
496269825Simp	struct timeval lasttime;
497269825Simp	int counter;
498269825Simp} linux_ratelimit_t;
499269825Simp
500269825Simpstatic inline bool
501269825Simplinux_ratelimited(linux_ratelimit_t *rl)
502269825Simp{
503269825Simp	return (ppsratecheck(&rl->lasttime, &rl->counter, 1));
504269825Simp}
505269825Simp
506269825Simp#endif	/* _LINUX_KERNEL_H_ */
507269825Simp