Skip to content

Commit 0a16173

Browse files
author
Tomasz Bursztyka
committed
net: buf: Change NET_BUF_DEBUG to NET_BUF_LOG and add a level option
It will be thus possible to enable only the error logging, or the other sys_log levels. Change-Id: I0c0ed789f7cfbb4811320e8f8249151288274873 Signed-off-by: Tomasz Bursztyka <[email protected]>
1 parent 6158dfd commit 0a16173

File tree

9 files changed

+37
-25
lines changed

9 files changed

+37
-25
lines changed

include/net/buf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ struct net_buf_pool {
526526
*
527527
* @return New buffer or NULL if out of buffers.
528528
*/
529-
#if defined(CONFIG_NET_BUF_DEBUG)
529+
#if defined(CONFIG_NET_BUF_LOG)
530530
struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, int32_t timeout,
531531
const char *func, int line);
532532
#define net_buf_alloc(_pool, _timeout) \
@@ -548,7 +548,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout);
548548
*
549549
* @return New buffer or NULL if the FIFO is empty.
550550
*/
551-
#if defined(CONFIG_NET_BUF_DEBUG)
551+
#if defined(CONFIG_NET_BUF_LOG)
552552
struct net_buf *net_buf_get_debug(struct k_fifo *fifo, int32_t timeout,
553553
const char *func, int line);
554554
#define net_buf_get(_fifo, _timeout) \
@@ -602,7 +602,7 @@ void net_buf_put(struct k_fifo *fifo, struct net_buf *buf);
602602
*
603603
* @param buf A valid pointer on a buffer
604604
*/
605-
#if defined(CONFIG_NET_BUF_DEBUG)
605+
#if defined(CONFIG_NET_BUF_LOG)
606606
void net_buf_unref_debug(struct net_buf *buf, const char *func, int line);
607607
#define net_buf_unref(_buf) \
608608
net_buf_unref_debug(_buf, __func__, __LINE__)

samples/net/ieee802154/cc2520/prj.conf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ CONFIG_NET_DEBUG_ICMPV6=y
3333
CONFIG_NET_DEBUG_CONN=y
3434
CONFIG_NET_STATISTICS=y
3535

36-
#CONFIG_NET_BUF_DEBUG=y
37-
3836
CONFIG_NET_L2_IEEE802154=y
3937
CONFIG_NET_DEBUG_L2_IEEE802154=y
4038
CONFIG_NET_L2_IEEE802154_ORFD=y

samples/net/ieee802154/qemu/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ CONFIG_NET_DEBUG_IF=y
3030
CONFIG_NET_DEBUG_ICMPV6=y
3131
CONFIG_NET_DEBUG_CONN=y
3232
CONFIG_NET_STATISTICS=y
33-
#CONFIG_NET_BUF_DEBUG=y
3433

3534
CONFIG_NET_L2_IEEE802154=y
3635
CONFIG_NET_DEBUG_L2_IEEE802154=y

samples/net/mbedtls_sslclient/prj_galileo.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ CONFIG_IP_BUF_TX_SIZE=4
1616

1717
#CONFIG_NETWORKING_WITH_LOGGING=y
1818
#CONFIG_NETWORK_IP_STACK_DEBUG_NET_BUF=y
19-
#CONFIG_NET_BUF_DEBUG=y
2019
#CONFIG_NETWORK_IP_STACK_DEBUG_CONTEXT=y
2120
#CONFIG_NETWORK_IP_STACK_DEBUG_TCP_PSOCK=y
2221

subsys/net/Kconfig

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,33 @@ config NET_BUF
2525
This option enables support for generic network protocol
2626
buffers.
2727

28-
config NET_BUF_DEBUG
29-
bool "Network buffer debugging"
28+
config NET_BUF_LOG
29+
bool "Network buffer logging"
3030
depends on NET_BUF
3131
select STDOUT_CONSOLE
3232
select SYS_LOG
3333
default n
3434
help
35-
Enable debug logs and checks for the generic network buffers.
35+
Enable logs and checks for the generic network buffers.
3636

37-
config NET_BUF_SIMPLE_DEBUG
37+
config SYS_LOG_NET_BUF_LEVEL
38+
int
39+
prompt "Network buffer Logging level"
40+
depends on NET_BUF_LOG
41+
default 1
42+
range 0 4
43+
help
44+
Sets log level for network buffers.
45+
Levels are:
46+
0 OFF, do not write
47+
1 ERROR, only write SYS_LOG_ERR
48+
2 WARNING, write SYS_LOG_WRN in adition to previous level
49+
3 INFO, write SYS_LOG_INF in adition to previous levels
50+
4 DEBUG, write SYS_LOG_DBG in adition to previous levels
51+
52+
config NET_BUF_SIMPLE_LOG
3853
bool "Network buffer memory debugging"
39-
depends on NET_BUF_DEBUG
54+
depends on NET_BUF_LOG
4055
select STDOUT_CONSOLE
4156
select SYS_LOG
4257
default n

subsys/net/buf.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
#include <net/buf.h>
2626

27-
#if defined(CONFIG_NET_BUF_DEBUG)
27+
#if defined(CONFIG_NET_BUF_LOG)
2828
#define SYS_LOG_DOMAIN "net/buf"
29-
#define SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
29+
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_NET_BUF_LEVEL
3030
#include <logging/sys_log.h>
3131

3232
#define NET_BUF_DBG(fmt, ...) SYS_LOG_DBG("(%p) " fmt, k_current_get(), \
@@ -44,7 +44,7 @@
4444
#define NET_BUF_WARN(fmt, ...)
4545
#define NET_BUF_INFO(fmt, ...)
4646
#define NET_BUF_ASSERT(cond)
47-
#endif /* CONFIG_NET_BUF_DEBUG */
47+
#endif /* CONFIG_NET_BUF_LOG */
4848

4949
/* Helpers to access the storage array, since we don't have access to its
5050
* type at this point anymore.
@@ -68,7 +68,7 @@ static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool,
6868
return buf;
6969
}
7070

71-
#if defined(CONFIG_NET_BUF_DEBUG)
71+
#if defined(CONFIG_NET_BUF_LOG)
7272
struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, int32_t timeout,
7373
const char *func, int line)
7474
#else
@@ -114,7 +114,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout)
114114

115115
irq_unlock(key);
116116

117-
#if defined(CONFIG_NET_BUF_DEBUG)
117+
#if defined(CONFIG_NET_BUF_LOG) && SYS_LOG_LEVEL >= SYS_LOG_LEVEL_WARNING
118118
if (timeout == K_FOREVER) {
119119
buf = k_lifo_get(&pool->free, K_NO_WAIT);
120120
if (!buf) {
@@ -145,7 +145,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout)
145145
return buf;
146146
}
147147

148-
#if defined(CONFIG_NET_BUF_DEBUG)
148+
#if defined(CONFIG_NET_BUF_LOG)
149149
struct net_buf *net_buf_get_debug(struct k_fifo *fifo, int32_t timeout,
150150
const char *func, int line)
151151
#else
@@ -202,7 +202,7 @@ void net_buf_put(struct k_fifo *fifo, struct net_buf *buf)
202202
k_fifo_put_list(fifo, buf, tail);
203203
}
204204

205-
#if defined(CONFIG_NET_BUF_DEBUG)
205+
#if defined(CONFIG_NET_BUF_LOG)
206206
void net_buf_unref_debug(struct net_buf *buf, const char *func, int line)
207207
#else
208208
void net_buf_unref(struct net_buf *buf)
@@ -213,7 +213,7 @@ void net_buf_unref(struct net_buf *buf)
213213
while (buf) {
214214
struct net_buf *frags = buf->frags;
215215

216-
#if defined(CONFIG_NET_BUF_DEBUG)
216+
#if defined(CONFIG_NET_BUF_LOG)
217217
if (!buf->ref) {
218218
NET_BUF_ERR("%s():%d: buf %p double free", func, line,
219219
buf);
@@ -324,7 +324,7 @@ struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag)
324324
return next_frag;
325325
}
326326

327-
#if defined(CONFIG_NET_BUF_SIMPLE_DEBUG)
327+
#if defined(CONFIG_NET_BUF_SIMPLE_LOG)
328328
#define NET_BUF_SIMPLE_DBG(fmt, ...) NET_BUF_DBG(fmt, ##__VA_ARGS__)
329329
#define NET_BUF_SIMPLE_ERR(fmt, ...) NET_BUF_ERR(fmt, ##__VA_ARGS__)
330330
#define NET_BUF_SIMPLE_WARN(fmt, ...) NET_BUF_WARN(fmt, ##__VA_ARGS__)
@@ -336,7 +336,7 @@ struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag)
336336
#define NET_BUF_SIMPLE_WARN(fmt, ...)
337337
#define NET_BUF_SIMPLE_INFO(fmt, ...)
338338
#define NET_BUF_SIMPLE_ASSERT(cond)
339-
#endif /* CONFIG_NET_BUF_SIMPLE_DEBUG */
339+
#endif /* CONFIG_NET_BUF_SIMPLE_LOG */
340340

341341
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len)
342342
{

tests/net/6lo/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ CONFIG_SYS_LOG_SHOW_COLOR=y
1616
CONFIG_NET_DEBUG_IF=y
1717
CONFIG_NET_DEBUG_CORE=y
1818
CONFIG_NET_6LO_DEBUG=n
19-
CONFIG_NET_BUF_DEBUG=n
2019
CONFIG_NET_DEBUG_NET_BUF=n
2120

2221
CONFIG_NET_6LO_CONTEXT=y

tests/net/buf/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
CONFIG_NET_BUF=y
2-
#CONFIG_NET_BUF_DEBUG=y
2+
#CONFIG_NET_BUF_LOG=y
3+
#CONFIG_SYS_LOG_NET_BUF_LEVEL=4
34
CONFIG_ZTEST=y

tests/net/nbuf/prj.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
CONFIG_NETWORKING=y
22
CONFIG_NET_IPV6=y
33
CONFIG_NET_BUF=y
4-
#CONFIG_NET_BUF_DEBUG=y
4+
#CONFIG_NET_BUF_LOG=y
5+
#CONFIG_SYS_LOG_NET_BUF_LEVEL=4
56
CONFIG_MAIN_STACK_SIZE=2048
67
CONFIG_NET_NBUF_RX_COUNT=4
78
CONFIG_NET_NBUF_TX_COUNT=4

0 commit comments

Comments
 (0)