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
2018-03-13 17:02:05 -07:00
提交者 nshrivas
父節點 88de1dba44
當前提交 9a94c9a29d
共有 4 個檔案被更改,包括 31 行新增17 行删除

查看文件

@@ -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

查看文件

@@ -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 ...) \

查看文件

@@ -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);

查看文件

@@ -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 ...)