qcacmn: Log memory stats in host driver

Add logs in driver to log current memory footprint
in init functions. Add wlan_mem_stats to sysfs node
in both perf and defconfig builds.
The stats are included under MCL feature
DCONFIG_WLAN_SYSFS_MEM_STATS.

Change-Id: I79c6d418a5762cddf52ab3bc0b0c93993fa7fd84
CRs-Fixed: 2635192
This commit is contained in:
Nisha Menon
2020-01-21 16:54:12 -08:00
committed by nshrivas
parent b725ee6291
commit 0bbaedb23c
5 changed files with 122 additions and 56 deletions

View File

@@ -10684,6 +10684,11 @@ dp_soc_attach(struct cdp_ctrl_objmgr_psoc *ctrl_psoc,
dp_soc_set_interrupt_mode(soc); dp_soc_set_interrupt_mode(soc);
dp_soc_set_def_pdev(soc); dp_soc_set_def_pdev(soc);
dp_info("Mem stats: DMA = %u HEAP = %u SKB = %u",
qdf_dma_mem_stats_read(),
qdf_heap_mem_stats_read(),
qdf_skb_mem_stats_read());
return soc; return soc;
fail5: fail5:
dp_soc_srng_free(soc); dp_soc_srng_free(soc);
@@ -10876,6 +10881,11 @@ void *dp_soc_init(struct dp_soc *soc, HTC_HANDLE htc_handle,
/* initialize work queue for stats processing */ /* initialize work queue for stats processing */
qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc); qdf_create_work(0, &soc->htt_stats.work, htt_t2h_stats_handler, soc);
dp_info("Mem stats: DMA = %u HEAP = %u SKB = %u",
qdf_dma_mem_stats_read(),
qdf_heap_mem_stats_read(),
qdf_skb_mem_stats_read());
return soc; return soc;
fail6: fail6:
htt_soc_htc_dealloc(soc->htt_handle); htt_soc_htc_dealloc(soc->htt_handle);
@@ -12429,6 +12439,11 @@ static inline QDF_STATUS dp_pdev_init(struct cdp_soc_t *txrx_soc,
dp_init_tso_stats(pdev); dp_init_tso_stats(pdev);
dp_tx_ppdu_stats_attach(pdev); dp_tx_ppdu_stats_attach(pdev);
dp_info("Mem stats: DMA = %u HEAP = %u SKB = %u",
qdf_dma_mem_stats_read(),
qdf_heap_mem_stats_read(),
qdf_skb_mem_stats_read());
return QDF_STATUS_SUCCESS; return QDF_STATUS_SUCCESS;
fail9: fail9:
dp_ipa_uc_detach(soc, pdev); dp_ipa_uc_detach(soc, pdev);

View File

@@ -555,8 +555,6 @@ int qdf_mem_multi_page_link(qdf_device_t osdev,
struct qdf_mem_multi_page_t *pages, struct qdf_mem_multi_page_t *pages,
uint32_t elem_size, uint32_t elem_count, uint8_t cacheable); uint32_t elem_size, uint32_t elem_count, uint8_t cacheable);
#ifdef WLAN_DEBUGFS
/** /**
* qdf_mem_kmalloc_inc() - increment kmalloc allocated bytes count * qdf_mem_kmalloc_inc() - increment kmalloc allocated bytes count
* @size: number of bytes to increment by * @size: number of bytes to increment by
@@ -573,13 +571,7 @@ void qdf_mem_kmalloc_inc(qdf_size_t size);
*/ */
void qdf_mem_kmalloc_dec(qdf_size_t size); void qdf_mem_kmalloc_dec(qdf_size_t size);
#else #ifdef CONFIG_WLAN_SYSFS_MEM_STATS
static inline void qdf_mem_kmalloc_inc(qdf_size_t size) { }
static inline void qdf_mem_kmalloc_dec(qdf_size_t size) { }
#endif /* WLAN_DEBUGFS */
/** /**
* qdf_mem_skb_inc() - increment total skb allocation size * qdf_mem_skb_inc() - increment total skb allocation size
* @size: size to be added * @size: size to be added
@@ -596,6 +588,16 @@ void qdf_mem_skb_inc(qdf_size_t size);
*/ */
void qdf_mem_skb_dec(qdf_size_t size); void qdf_mem_skb_dec(qdf_size_t size);
#else
static inline void qdf_mem_skb_inc(qdf_size_t size)
{
}
static inline void qdf_mem_skb_dec(qdf_size_t size)
{
}
#endif /* CONFIG_WLAN_SYSFS_MEM_STATS */
/** /**
* qdf_mem_map_table_alloc() - Allocate shared memory info structure * qdf_mem_map_table_alloc() - Allocate shared memory info structure
* @num: number of required storage * @num: number of required storage
@@ -846,4 +848,28 @@ static inline void qdf_mem_shared_mem_free(qdf_device_t osdev,
qdf_mem_free(shared_mem); qdf_mem_free(shared_mem);
} }
/**
* qdf_dma_mem_stats_read() - Return the DMA memory allocated in
* host driver
*
* Return: None
*/
int32_t qdf_dma_mem_stats_read(void);
/**
* qdf_heap_mem_stats_read() - Return the heap memory allocated
* in host driver
*
* Return: None
*/
int32_t qdf_heap_mem_stats_read(void);
/**
* qdf_skb_mem_stats_read() - Return the SKB memory allocated in
* host driver
*
* Return: None
*/
int32_t qdf_skb_mem_stats_read(void);
#endif /* __QDF_MEMORY_H */ #endif /* __QDF_MEMORY_H */

View File

@@ -1620,7 +1620,12 @@ static inline qdf_nbuf_t
qdf_nbuf_alloc_fl(qdf_device_t osdev, qdf_size_t size, int reserve, int align, qdf_nbuf_alloc_fl(qdf_device_t osdev, qdf_size_t size, int reserve, int align,
int prio, const char *func, uint32_t line) int prio, const char *func, uint32_t line)
{ {
return __qdf_nbuf_alloc(osdev, size, reserve, align, prio, func, line); qdf_nbuf_t nbuf;
nbuf = __qdf_nbuf_alloc(osdev, size, reserve, align, prio, func, line);
if (qdf_likely(nbuf))
qdf_mem_skb_inc(nbuf->truesize);
return nbuf;
} }
static inline void qdf_nbuf_free(qdf_nbuf_t buf) static inline void qdf_nbuf_free(qdf_nbuf_t buf)

View File

@@ -59,6 +59,18 @@ static bool is_initial_mem_debug_disabled;
#define QDF_MEM_WARN_THRESHOLD 300 /* ms */ #define QDF_MEM_WARN_THRESHOLD 300 /* ms */
#define QDF_DEBUG_STRING_SIZE 512 #define QDF_DEBUG_STRING_SIZE 512
/**
* struct __qdf_mem_stat - qdf memory statistics
* @kmalloc: total kmalloc allocations
* @dma: total dma allocations
* @skb: total skb allocations
*/
static struct __qdf_mem_stat {
qdf_atomic_t kmalloc;
qdf_atomic_t dma;
qdf_atomic_t skb;
} qdf_mem_stat;
#ifdef MEMORY_DEBUG #ifdef MEMORY_DEBUG
#include "qdf_debug_domain.h" #include "qdf_debug_domain.h"
@@ -292,54 +304,11 @@ u_int8_t prealloc_disabled = 1;
qdf_declare_param(prealloc_disabled, byte); qdf_declare_param(prealloc_disabled, byte);
qdf_export_symbol(prealloc_disabled); qdf_export_symbol(prealloc_disabled);
/**
* struct __qdf_mem_stat - qdf memory statistics
* @kmalloc: total kmalloc allocations
* @dma: total dma allocations
* @skb: total skb allocations
*/
static struct __qdf_mem_stat {
qdf_atomic_t kmalloc;
qdf_atomic_t dma;
qdf_atomic_t skb;
} qdf_mem_stat;
void qdf_mem_skb_inc(qdf_size_t size)
{
qdf_atomic_add(size, &qdf_mem_stat.skb);
}
void qdf_mem_skb_dec(qdf_size_t size)
{
qdf_atomic_sub(size, &qdf_mem_stat.skb);
}
#if defined WLAN_DEBUGFS #if defined WLAN_DEBUGFS
/* Debugfs root directory for qdf_mem */ /* Debugfs root directory for qdf_mem */
static struct dentry *qdf_mem_debugfs_root; static struct dentry *qdf_mem_debugfs_root;
void qdf_mem_kmalloc_inc(qdf_size_t size)
{
qdf_atomic_add(size, &qdf_mem_stat.kmalloc);
}
void qdf_mem_kmalloc_dec(qdf_size_t size)
{
qdf_atomic_sub(size, &qdf_mem_stat.kmalloc);
}
static void qdf_mem_dma_inc(qdf_size_t size)
{
qdf_atomic_add(size, &qdf_mem_stat.dma);
}
static inline void qdf_mem_dma_dec(qdf_size_t size)
{
qdf_atomic_sub(size, &qdf_mem_stat.dma);
}
#ifdef MEMORY_DEBUG #ifdef MEMORY_DEBUG
static int qdf_err_printer(void *priv, const char *fmt, ...) static int qdf_err_printer(void *priv, const char *fmt, ...)
{ {
@@ -841,9 +810,6 @@ static QDF_STATUS qdf_mem_debugfs_init(void)
#else /* WLAN_DEBUGFS */ #else /* WLAN_DEBUGFS */
static inline void qdf_mem_dma_inc(qdf_size_t size) {}
static inline void qdf_mem_dma_dec(qdf_size_t size) {}
static QDF_STATUS qdf_mem_debugfs_init(void) static QDF_STATUS qdf_mem_debugfs_init(void)
{ {
return QDF_STATUS_E_NOSUPPORT; return QDF_STATUS_E_NOSUPPORT;
@@ -863,6 +829,38 @@ static QDF_STATUS qdf_mem_debug_debugfs_exit(void)
#endif /* WLAN_DEBUGFS */ #endif /* WLAN_DEBUGFS */
void qdf_mem_kmalloc_inc(qdf_size_t size)
{
qdf_atomic_add(size, &qdf_mem_stat.kmalloc);
}
static void qdf_mem_dma_inc(qdf_size_t size)
{
qdf_atomic_add(size, &qdf_mem_stat.dma);
}
#ifdef CONFIG_WLAN_SYSFS_MEM_STATS
void qdf_mem_skb_inc(qdf_size_t size)
{
qdf_atomic_add(size, &qdf_mem_stat.skb);
}
void qdf_mem_skb_dec(qdf_size_t size)
{
qdf_atomic_sub(size, &qdf_mem_stat.skb);
}
#endif
void qdf_mem_kmalloc_dec(qdf_size_t size)
{
qdf_atomic_sub(size, &qdf_mem_stat.kmalloc);
}
static inline void qdf_mem_dma_dec(qdf_size_t size)
{
qdf_atomic_sub(size, &qdf_mem_stat.dma);
}
/** /**
* __qdf_mempool_init() - Create and initialize memory pool * __qdf_mempool_init() - Create and initialize memory pool
* *
@@ -2302,3 +2300,24 @@ void qdf_ether_addr_copy(void *dst_addr, const void *src_addr)
} }
qdf_export_symbol(qdf_ether_addr_copy); qdf_export_symbol(qdf_ether_addr_copy);
int32_t qdf_dma_mem_stats_read(void)
{
return qdf_atomic_read(&qdf_mem_stat.dma);
}
qdf_export_symbol(qdf_dma_mem_stats_read);
int32_t qdf_heap_mem_stats_read(void)
{
return qdf_atomic_read(&qdf_mem_stat.kmalloc);
}
qdf_export_symbol(qdf_heap_mem_stats_read);
int32_t qdf_skb_mem_stats_read(void)
{
return qdf_atomic_read(&qdf_mem_stat.skb);
}
qdf_export_symbol(qdf_skb_mem_stats_read);

View File

@@ -551,6 +551,7 @@ void __qdf_nbuf_free(struct sk_buff *skb)
return; return;
qdf_nbuf_count_dec(skb); qdf_nbuf_count_dec(skb);
qdf_mem_skb_dec(skb->truesize);
if (nbuf_free_cb) if (nbuf_free_cb)
nbuf_free_cb(skb); nbuf_free_cb(skb);
else else