lib: net_buf: support counting max used buf
Support counting the max used net_buf when CONFIG_NET_BUF_POOL_USAGE is defined. Signed-off-by: Maochen Wang <maochen.wang@nxp.com>
This commit is contained in:
parent
05a5688b34
commit
f36e2e0664
2 changed files with 6 additions and 0 deletions
|
|
@ -1098,6 +1098,9 @@ struct net_buf_pool {
|
|||
/** Total size of the pool. */
|
||||
const uint16_t pool_size;
|
||||
|
||||
/** Maximum count of used buffers. */
|
||||
uint16_t max_used;
|
||||
|
||||
/** Name of the pool. Used when printing pool information. */
|
||||
const char *name;
|
||||
#endif /* CONFIG_NET_BUF_POOL_USAGE */
|
||||
|
|
@ -1115,6 +1118,7 @@ struct net_buf_pool {
|
|||
/** @cond INTERNAL_HIDDEN */
|
||||
#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \
|
||||
IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \
|
||||
IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.max_used = 0,)) \
|
||||
IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),))
|
||||
|
||||
#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \
|
||||
|
|
|
|||
|
|
@ -344,6 +344,8 @@ success:
|
|||
#if defined(CONFIG_NET_BUF_POOL_USAGE)
|
||||
atomic_dec(&pool->avail_count);
|
||||
__ASSERT_NO_MSG(atomic_get(&pool->avail_count) >= 0);
|
||||
pool->max_used = MAX(pool->max_used,
|
||||
pool->buf_count - atomic_get(&pool->avail_count));
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue