浏览代码

qcacmn: Rate limit logs based on elapsed time

QDF_TRACE_RATE_LIMITED() currently rate limits by only printing every
rate'th call to the function from the same location. Instead, prevent
logging messages more than some constant 'k' times per second. This
means any subsequent calls to the API from the same location within 1/k
seconds will be dropped.

Change-Id: I31a3f48f68fb6bc67f59f3157a635345943d3331
CRs-Fixed: 2205794
Dustin Brown 7 年之前
父节点
当前提交
9a94c9a29d
共有 4 个文件被更改,包括 31 次插入17 次删除
  1. 0 2
      hif/inc/hif.h
  2. 10 2
      hif/src/hif_debug.h
  3. 2 6
      hif/src/sdio/hif_sdio_dev.c
  4. 19 7
      qdf/linux/src/i_qdf_trace.h

+ 0 - 2
hif/inc/hif.h

@@ -52,8 +52,6 @@ extern "C" {
 typedef void __iomem *A_target_id_t;
 typedef void *hif_handle_t;
 
-#define HIF_DBG_PRINT_RATE 1000
-
 #define HIF_TYPE_AR6002   2
 #define HIF_TYPE_AR6003   3
 #define HIF_TYPE_AR6004   5

+ 10 - 2
hif/src/hif_debug.h

@@ -1,9 +1,8 @@
 /*
- * Copyright (c) 2014, 2016 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014, 2016, 2018 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
- *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
  * above copyright notice and this permission notice appear in all
@@ -23,6 +22,15 @@
 #define __HIF_DEBUG_H__
 #include "qdf_trace.h"
 
+#define __hif_log_rl(level, format, args...) \
+	QDF_TRACE_RATE_LIMITED(QDF_MODULE_ID_HIF, level, FL(format), ## args)
+
+#define hif_alert_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_FATAL, params)
+#define hif_err_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_ERROR, params)
+#define hif_warn_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_WARN, params)
+#define hif_info_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_INFO, params)
+#define hif_debug_rl(params...) __hif_log_rl(QDF_TRACE_LEVEL_DEBUG, params)
+
 #define HIF_ERROR(args ...) \
 	QDF_TRACE(QDF_MODULE_ID_HIF, QDF_TRACE_LEVEL_ERROR, ## args)
 #define HIF_WARN(args ...) \

+ 2 - 6
hif/src/sdio/hif_sdio_dev.c

@@ -1,9 +1,8 @@
 /*
- * Copyright (c) 2013-2017 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2018 The Linux Foundation. All rights reserved.
  *
  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
  *
- *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
  * above copyright notice and this permission notice appear in all
@@ -190,10 +189,7 @@ HTC_PACKET *hif_dev_alloc_rx_buffer(struct hif_sdio_device *pdev)
 	headsize = sizeof(HTC_PACKET);
 	netbuf = qdf_nbuf_alloc(NULL, bufsize + headsize, 0, 4, false);
 	if (netbuf == NULL) {
-		QDF_TRACE_RATE_LIMITED(HIF_DBG_PRINT_RATE, QDF_MODULE_ID_HIF,
-				       QDF_TRACE_LEVEL_ERROR,
-				       "(%s)Allocate netbuf failed\n",
-				       __func__);
+		hif_err_rl("Allocate netbuf failed");
 		return NULL;
 	}
 	packet = (HTC_PACKET *) qdf_nbuf_data(netbuf);

+ 19 - 7
qdf/linux/src/i_qdf_trace.h

@@ -58,14 +58,26 @@
 #define QDF_TRACE qdf_trace_msg
 #define QDF_VTRACE qdf_vtrace_msg
 #define QDF_TRACE_HEX_DUMP qdf_trace_hex_dump
-#define QDF_TRACE_RATE_LIMITED(rate, module, level, format, ...)\
+#define QDF_MAX_LOGS_PER_SEC 2
+/**
+ * QDF_TRACE_RATE_LIMITED() - rate limited version of QDF_TRACE
+ * @params: parameters to pass through to QDF_TRACE
+ *
+ * This API prevents logging a message more than QDF_MAX_LOGS_PER_SEC times per
+ * second. This means any subsequent calls to this API from the same location
+ * within 1/QDF_MAX_LOGS_PER_SEC seconds will be dropped.
+ *
+ * Return: None
+ */
+#define QDF_TRACE_RATE_LIMITED(params...)\
 	do {\
-		static int rate_limit;\
-		rate_limit++;\
-		if (rate)\
-			if (0 == (rate_limit % rate))\
-				qdf_trace_msg(module, level, format,\
-						##__VA_ARGS__);\
+		static ulong __last_ticks;\
+		ulong __ticks = jiffies;\
+		if (time_after(__ticks,\
+			       __last_ticks + HZ / QDF_MAX_LOGS_PER_SEC)) {\
+			QDF_TRACE(params);\
+			__last_ticks = __ticks;\
+		} \
 	} while (0)
 #else
 #define QDF_TRACE(arg ...)