net: buf: change avail_count variable to atomic type

using CONFIG_NET_BUF_POOL_USAGE monitor avail_count,
this variable should be protect.
Protecting it by using atomic variable

Signed-off-by: Ehud Naim <ehudn@marvell.com>
This commit is contained in:
Ehud Naim 2020-10-27 22:56:01 +02:00 committed by Jukka Rissanen
commit c58c8b1257
5 changed files with 11 additions and 11 deletions

View file

@ -818,7 +818,7 @@ struct net_buf_pool {
#if defined(CONFIG_NET_BUF_POOL_USAGE) #if defined(CONFIG_NET_BUF_POOL_USAGE)
/** Amount of available buffers in the pool. */ /** Amount of available buffers in the pool. */
int16_t avail_count; atomic_t avail_count;
/** Total size of the pool. */ /** Total size of the pool. */
const uint16_t pool_size; const uint16_t pool_size;
@ -844,7 +844,7 @@ struct net_buf_pool {
.free = Z_LIFO_INITIALIZER(_pool.free), \ .free = Z_LIFO_INITIALIZER(_pool.free), \
.buf_count = _count, \ .buf_count = _count, \
.uninit_count = _count, \ .uninit_count = _count, \
.avail_count = _count, \ .avail_count = ATOMIC_INIT(_count), \
.name = STRINGIFY(_pool), \ .name = STRINGIFY(_pool), \
.destroy = _destroy, \ .destroy = _destroy, \
.alloc = _alloc, \ .alloc = _alloc, \

View file

@ -141,7 +141,7 @@ close_client:
net_pkt_get_info(&rx, &tx, &rx_data, &tx_data); net_pkt_get_info(&rx, &tx, &rx_data, &tx_data);
printf("rx buf: %d, tx buf: %d\n", printf("rx buf: %d, tx buf: %d\n",
rx_data->avail_count, tx_data->avail_count); atomic_get(&rx_data->avail_count), atomic_get(&tx_data->avail_count));
#endif #endif
} }

View file

@ -346,8 +346,8 @@ success:
net_buf_reset(buf); net_buf_reset(buf);
#if defined(CONFIG_NET_BUF_POOL_USAGE) #if defined(CONFIG_NET_BUF_POOL_USAGE)
pool->avail_count--; atomic_dec(&pool->avail_count);
__ASSERT_NO_MSG(pool->avail_count >= 0); __ASSERT_NO_MSG(atomic_get(&pool->avail_count) >= 0);
#endif #endif
return buf; return buf;
} }
@ -552,8 +552,8 @@ void net_buf_unref(struct net_buf *buf)
pool = net_buf_pool_get(buf->pool_id); pool = net_buf_pool_get(buf->pool_id);
#if defined(CONFIG_NET_BUF_POOL_USAGE) #if defined(CONFIG_NET_BUF_POOL_USAGE)
pool->avail_count++; atomic_inc(&pool->avail_count);
__ASSERT_NO_MSG(pool->avail_count <= pool->buf_count); __ASSERT_NO_MSG(atomic_get(&pool->avail_count) <= pool->buf_count);
#endif #endif
if (pool->destroy) { if (pool->destroy) {

View file

@ -286,7 +286,7 @@ const char *net_pkt_pool2str(struct net_buf_pool *pool)
static inline int16_t get_frees(struct net_buf_pool *pool) static inline int16_t get_frees(struct net_buf_pool *pool)
{ {
#if defined(CONFIG_NET_BUF_POOL_USAGE) #if defined(CONFIG_NET_BUF_POOL_USAGE)
return pool->avail_count; return atomic_get(&pool->avail_count);
#else #else
return 0; return 0;
#endif #endif

View file

@ -3226,7 +3226,7 @@ static void context_info(struct net_context *context, void *user_data)
#if defined(CONFIG_NET_BUF_POOL_USAGE) #if defined(CONFIG_NET_BUF_POOL_USAGE)
PR("%p\t%d\t%d\tEDATA (%s)\n", PR("%p\t%d\t%d\tEDATA (%s)\n",
pool, pool->buf_count, pool, pool->buf_count,
pool->avail_count, pool->name); atomic_get(&pool->avail_count), pool->name);
#else #else
PR("%p\t%d\tEDATA\n", pool, pool->buf_count); PR("%p\t%d\tEDATA\n", pool, pool->buf_count);
#endif #endif
@ -3265,11 +3265,11 @@ static int cmd_net_mem(const struct shell *shell, size_t argc, char *argv[])
PR("%p\t%d\t%d\tRX DATA (%s)\n", PR("%p\t%d\t%d\tRX DATA (%s)\n",
rx_data, rx_data->buf_count, rx_data, rx_data->buf_count,
rx_data->avail_count, rx_data->name); atomic_get(&rx_data->avail_count), rx_data->name);
PR("%p\t%d\t%d\tTX DATA (%s)\n", PR("%p\t%d\t%d\tTX DATA (%s)\n",
tx_data, tx_data->buf_count, tx_data, tx_data->buf_count,
tx_data->avail_count, tx_data->name); atomic_get(&tx_data->avail_count), tx_data->name);
#else #else
PR("Address\t\tTotal\tName\n"); PR("Address\t\tTotal\tName\n");