net: Add a way to see who is trying to alloc/dealloc a net_buf
Change-Id: Ib7813bc5809f85f27aa4fe06583b64461741466a Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
606c3701ab
commit
2f5b1d1570
|
@ -46,6 +46,11 @@
|
|||
#include "contiki/ip/uip.h"
|
||||
#include "contiki/packetbuf.h"
|
||||
|
||||
#if defined(CONFIG_NETWORKING_WITH_LOGGING)
|
||||
#undef DEBUG_NET_BUFS
|
||||
#define DEBUG_NET_BUFS
|
||||
#endif
|
||||
|
||||
struct net_context;
|
||||
|
||||
/*! The default MTU is 1280 (minimum IPv6 packet size) + LL header
|
||||
|
@ -172,7 +177,13 @@ struct net_buf {
|
|||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
/* Get buffer from the available buffers pool */
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
#define net_buf_get(context) net_buf_get_debug(context, __FUNCTION__, __LINE__)
|
||||
struct net_buf *net_buf_get_debug(struct net_context *context, const char *caller, int line);
|
||||
#else
|
||||
struct net_buf *net_buf_get(struct net_context *context);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Get buffer from pool but also reserve headroom for
|
||||
|
@ -185,7 +196,13 @@ struct net_buf *net_buf_get(struct net_context *context);
|
|||
*
|
||||
* @return Network buffer if successful, NULL otherwise.
|
||||
*/
|
||||
/* Same as net_buf_get, but also reserve headroom for potential headers */
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
#define net_buf_get_reserve(res) net_buf_get_reserve_debug(res,__FUNCTION__,__LINE__)
|
||||
struct net_buf *net_buf_get_reserve_debug(uint16_t reserve_head, const char *caller, int line);
|
||||
#else
|
||||
struct net_buf *net_buf_get_reserve(uint16_t reserve_head);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Place buffer back into the available buffers pool.
|
||||
|
@ -197,7 +214,13 @@ struct net_buf *net_buf_get_reserve(uint16_t reserve_head);
|
|||
* @param buf Network buffer to release.
|
||||
*
|
||||
*/
|
||||
/* Place buffer back into the available buffers pool */
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
#define net_buf_put(buf) net_buf_put_debug(buf, __FUNCTION__, __LINE__)
|
||||
void net_buf_put_debug(struct net_buf *buf, const char *caller, int line);
|
||||
#else
|
||||
void net_buf_put(struct net_buf *buf);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Prepare data to be added at the end of the buffer.
|
||||
|
|
|
@ -53,13 +53,21 @@ extern struct net_tuple *net_context_get_tuple(struct net_context *context);
|
|||
static struct net_buf buffers[NUM_BUFS];
|
||||
static struct nano_fifo free_bufs;
|
||||
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
struct net_buf *net_buf_get_reserve_debug(uint16_t reserve_head, const char *caller, int line)
|
||||
#else
|
||||
struct net_buf *net_buf_get_reserve(uint16_t reserve_head)
|
||||
#endif
|
||||
{
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = nano_fifo_get(&free_bufs);
|
||||
if (!buf) {
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
NET_ERR("Failed to get free buffer (%s():%d)\n", caller, line);
|
||||
#else
|
||||
NET_ERR("Failed to get free buffer\n");
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -71,7 +79,11 @@ struct net_buf *net_buf_get_reserve(uint16_t reserve_head)
|
|||
return buf;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
struct net_buf *net_buf_get_debug(struct net_context *context, const char *caller, int line)
|
||||
#else
|
||||
struct net_buf *net_buf_get(struct net_context *context)
|
||||
#endif
|
||||
{
|
||||
struct net_buf *buf;
|
||||
struct net_tuple *tuple;
|
||||
|
@ -94,7 +106,11 @@ struct net_buf *net_buf_get(struct net_context *context)
|
|||
break;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
buf = net_buf_get_reserve_debug(reserve, caller, line);
|
||||
#else
|
||||
buf = net_buf_get_reserve(reserve);
|
||||
#endif
|
||||
if (!buf) {
|
||||
return buf;
|
||||
}
|
||||
|
@ -104,9 +120,17 @@ struct net_buf *net_buf_get(struct net_context *context)
|
|||
return buf;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
void net_buf_put_debug(struct net_buf *buf, const char *caller, int line)
|
||||
#else
|
||||
void net_buf_put(struct net_buf *buf)
|
||||
#endif
|
||||
{
|
||||
#ifdef DEBUG_NET_BUFS
|
||||
NET_DBG("buf %p (%s():%d)\n", buf, caller, line);
|
||||
#else
|
||||
NET_DBG("buf %p\n", buf);
|
||||
#endif
|
||||
|
||||
nano_fifo_put(&free_bufs, buf);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue