From: Rob Clark Subject: [PATCH] drm: add DRM_ERROR_RATELIMITED Date: Thu, 21 Nov 2013 14:29:51 -0500 Message-ID: <1385062191-30854-1-git-send-email-robdclark@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail-qc0-f169.google.com (mail-qc0-f169.google.com [209.85.216.169]) by gabe.freedesktop.org (Postfix) with ESMTP id 81E1AFCD83 for ; Thu, 21 Nov 2013 11:29:59 -0800 (PST) Received: by mail-qc0-f169.google.com with SMTP id u18so159734qcx.14 for ; Thu, 21 Nov 2013 11:29:59 -0800 (PST) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org For error traces in situations that can run away, it is nice to have a rate-limited version of DRM_ERROR() to avoid massing log flooding. Signed-off-by: Rob Clark --- include/drm/drmP.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 0a372b2..dd6699e 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -56,6 +56,7 @@ #include #include #include +#include #if defined(__alpha__) || defined(__powerpc__) #include /* For pte_wrprotect */ #endif @@ -180,6 +181,22 @@ int drm_err(const char *func, const char *format, ...); #define DRM_ERROR(fmt, ...) \ drm_err(__func__, fmt, ##__VA_ARGS__) +/** + * Rate limited error output. Like DRM_ERROR() but won't flood the log. + * + * \param fmt printf() like format string. + * \param arg arguments + */ +#define DRM_ERROR_RATELIMITED(fmt, ...) \ +({ \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + \ + if (__ratelimit(&_rs)) \ + drm_err(__func__, fmt, ##__VA_ARGS__); \ +}) + #define DRM_INFO(fmt, ...) \ printk(KERN_INFO "[" DRM_NAME "] " fmt, ##__VA_ARGS__) -- 1.8.4.2