Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/external/bsd/drm2/include/linux Kludge up <linux/ratelim...
details: https://anonhg.NetBSD.org/src/rev/578fabf4d10f
branches: trunk
changeset: 1027862:578fabf4d10f
user: riastradh <riastradh%NetBSD.org@localhost>
date: Sun Dec 19 00:59:17 2021 +0000
description:
Kludge up <linux/ratelimit.h> with ppsratecheck.
diffstat:
sys/external/bsd/drm2/include/linux/ratelimit.h | 44 ++++++++++++++++++++++++-
1 files changed, 43 insertions(+), 1 deletions(-)
diffs (56 lines):
diff -r 84fd81c9fb6f -r 578fabf4d10f sys/external/bsd/drm2/include/linux/ratelimit.h
--- a/sys/external/bsd/drm2/include/linux/ratelimit.h Sun Dec 19 00:59:10 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/ratelimit.h Sun Dec 19 00:59:17 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ratelimit.h,v 1.2 2014/03/18 18:20:43 riastradh Exp $ */
+/* $NetBSD: ratelimit.h,v 1.3 2021/12/19 00:59:17 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -32,4 +32,46 @@
#ifndef _LINUX_RATELIMIT_H_
#define _LINUX_RATELIMIT_H_
+#include <sys/atomic.h>
+#include <sys/stdbool.h>
+#include <sys/time.h>
+
+struct linux_ratelimit {
+ volatile unsigned rl_lock;
+ struct timeval rl_lasttime;
+ int rl_curpps;
+ unsigned rl_maxpps;
+};
+
+/*
+ * XXX Assumes hz=100 so this works in static initializers, and/or
+ * hopes the caller just uses DEFAULT_RATELIMIT_INTERVAL and doesn't
+ * mention hz.
+ */
+#define DEFAULT_RATELIMIT_INTERVAL (5*100)
+#define DEFAULT_RATELIMIT_BURST 10
+
+#define DEFINE_RATELIMIT_STATE(n, i, b) \
+ struct linux_ratelimit n = { \
+ .rl_lock = 0, \
+ .rl_lasttime = { .tv_sec = 0, .tv_usec = 0 }, \
+ .rl_curpps = 0, \
+ .rl_maxpps = (b)/((i)/100), \
+ }
+
+static inline bool
+__ratelimit(struct linux_ratelimit *r)
+{
+ int ok;
+
+ if (atomic_cas_uint(&r->rl_lock, 0, 1))
+ return false;
+ membar_enter();
+ ok = ppsratecheck(&r->rl_lasttime, &r->rl_curpps, r->rl_maxpps);
+ membar_exit();
+ r->rl_lock = 0;
+
+ return ok;
+}
+
#endif /* _LINUX_RATELIMIT_H_ */
Home |
Main Index |
Thread Index |
Old Index