Skip to content

Commit f36e2e0

Browse files
MaochenWang1kartben
authored andcommitted
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 <[email protected]>
1 parent 05a5688 commit f36e2e0

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/zephyr/net_buf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,9 @@ struct net_buf_pool {
10981098
/** Total size of the pool. */
10991099
const uint16_t pool_size;
11001100

1101+
/** Maximum count of used buffers. */
1102+
uint16_t max_used;
1103+
11011104
/** Name of the pool. Used when printing pool information. */
11021105
const char *name;
11031106
#endif /* CONFIG_NET_BUF_POOL_USAGE */
@@ -1115,6 +1118,7 @@ struct net_buf_pool {
11151118
/** @cond INTERNAL_HIDDEN */
11161119
#define NET_BUF_POOL_USAGE_INIT(_pool, _count) \
11171120
IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.avail_count = ATOMIC_INIT(_count),)) \
1121+
IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.max_used = 0,)) \
11181122
IF_ENABLED(CONFIG_NET_BUF_POOL_USAGE, (.name = STRINGIFY(_pool),))
11191123

11201124
#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _ud_size, _destroy) \

lib/net_buf/buf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
344344
#if defined(CONFIG_NET_BUF_POOL_USAGE)
345345
atomic_dec(&pool->avail_count);
346346
__ASSERT_NO_MSG(atomic_get(&pool->avail_count) >= 0);
347+
pool->max_used = MAX(pool->max_used,
348+
pool->buf_count - atomic_get(&pool->avail_count));
347349
#endif
348350
return buf;
349351
}

0 commit comments

Comments
 (0)