Use ppsratecheck() for ratelimiting in the LinuxKPI.

Suggested by:		cem @
MFC after:		1 week
Sponsored by:		Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2017-03-23 16:23:55 +00:00
parent d2f312e0e7
commit 8f7eee5a63
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=315864
3 changed files with 14 additions and 18 deletions

View File

@ -145,13 +145,13 @@ show_class_attr_string(struct class *class,
device_printf((dev)->bsddev, fmt, ##__VA_ARGS__)
#define dev_err_ratelimited(dev, ...) do { \
static time_t __ratelimited; \
static linux_ratelimit_t __ratelimited; \
if (linux_ratelimited(&__ratelimited)) \
dev_err(dev, __VA_ARGS__); \
} while (0)
#define dev_warn_ratelimited(dev, ...) do { \
static time_t __ratelimited; \
static linux_ratelimit_t __ratelimited; \
if (linux_ratelimited(&__ratelimited)) \
dev_warn(dev, __VA_ARGS__); \
} while (0)

View File

@ -41,6 +41,7 @@
#include <sys/smp.h>
#include <sys/stddef.h>
#include <sys/syslog.h>
#include <sys/time.h>
#include <linux/bitops.h>
#include <linux/compiler.h>
@ -225,7 +226,7 @@ scnprintf(char *buf, size_t size, const char *fmt, ...)
#define pr_cont(fmt, ...) \
printk(KERN_CONT fmt, ##__VA_ARGS__)
#define pr_warn_ratelimited(...) do { \
static time_t __ratelimited; \
static linux_ratelimit_t __ratelimited; \
if (linux_ratelimited(&__ratelimited)) \
pr_warning(__VA_ARGS__); \
} while (0)
@ -423,6 +424,15 @@ abs64(int64_t x)
return (x < 0 ? -x : x);
}
extern bool linux_ratelimited(time_t *);
typedef struct linux_ratelimit {
struct timeval lasttime;
int counter;
} linux_ratelimit_t;
static inline bool
linux_ratelimited(linux_ratelimit_t *rl)
{
return (ppsratecheck(&rl->lasttime, &rl->counter, 1));
}
#endif /* _LINUX_KERNEL_H_ */

View File

@ -1484,20 +1484,6 @@ __unregister_chrdev(unsigned int major, unsigned int baseminor,
bool linux_cpu_has_clflush;
#endif
bool
linux_ratelimited(time_t *ptime)
{
/* make sure uptime is not zero by OR'ing bit 31 */
time_t curr = time_uptime | (1U << 31);
/* check if one or more seconds have passed */
if (*ptime != curr) {
*ptime = curr;
return (1);
}
return (0);
}
static void
linux_compat_init(void *arg)
{