From owner-svn-src-head@freebsd.org Thu Mar 23 16:23:56 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8B9ABD1A292; Thu, 23 Mar 2017 16:23:56 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 664B8185D; Thu, 23 Mar 2017 16:23:56 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2NGNtab094867; Thu, 23 Mar 2017 16:23:55 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2NGNttr094863; Thu, 23 Mar 2017 16:23:55 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201703231623.v2NGNttr094863@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Thu, 23 Mar 2017 16:23:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315864 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Mar 2017 16:23:56 -0000 Author: hselasky Date: Thu Mar 23 16:23:55 2017 New Revision: 315864 URL: https://svnweb.freebsd.org/changeset/base/315864 Log: Use ppsratecheck() for ratelimiting in the LinuxKPI. Suggested by: cem @ MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/device.h head/sys/compat/linuxkpi/common/include/linux/kernel.h head/sys/compat/linuxkpi/common/src/linux_compat.c Modified: head/sys/compat/linuxkpi/common/include/linux/device.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/device.h Thu Mar 23 16:01:51 2017 (r315863) +++ head/sys/compat/linuxkpi/common/include/linux/device.h Thu Mar 23 16:23:55 2017 (r315864) @@ -145,13 +145,13 @@ show_class_attr_string(struct class *cla 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) Modified: head/sys/compat/linuxkpi/common/include/linux/kernel.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/kernel.h Thu Mar 23 16:01:51 2017 (r315863) +++ head/sys/compat/linuxkpi/common/include/linux/kernel.h Thu Mar 23 16:23:55 2017 (r315864) @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -225,7 +226,7 @@ scnprintf(char *buf, size_t size, const #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_ */ Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Mar 23 16:01:51 2017 (r315863) +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Thu Mar 23 16:23:55 2017 (r315864) @@ -1484,20 +1484,6 @@ __unregister_chrdev(unsigned int major, 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) {