Skip to content

Commit 2c786a4

Browse files
committed
Merge branch 'feature/add_rx_buff_statistic_v5.3' into 'release/v5.3'
feat(802.15.4): IEEE802.15.4 add rx buffer statistic (v5.3) See merge request espressif/esp-idf!35640
2 parents 1dcb5a0 + 53b3a21 commit 2c786a4

File tree

13 files changed

+532
-15
lines changed

13 files changed

+532
-15
lines changed

components/ieee802154/Kconfig

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,31 @@ menu "IEEE 802.15.4"
9797
Enabling this option allows different kinds of IEEE802154 debug output.
9898
All IEEE802154 debug features increase the size of the final binary.
9999

100+
config IEEE802154_RX_BUFFER_STATISTIC
101+
bool "Rx buffer statistic"
102+
depends on IEEE802154_DEBUG
103+
default n
104+
help
105+
Enabling this option to count IEEE802154 rx buffer when allocating or freeing.
106+
100107
config IEEE802154_ASSERT
101-
bool "Enrich the assert information with IEEE802154 state and event"
108+
bool "Enrich the assert information"
109+
depends on IEEE802154_DEBUG
110+
select IEEE802154_RECORD
111+
default n
112+
help
113+
Enabling this option to print more information when assert.
114+
115+
config IEEE802154_RECORD
116+
bool "Record the information with IEEE802154 state and event"
102117
depends on IEEE802154_DEBUG
103118
default n
104119
help
105-
Enabling this option to add some probe codes in the driver, and these informations
106-
will be printed when assert.
120+
Enabling this option to add some probe codes in the driver, and record these information.
107121

108122
config IEEE802154_RECORD_EVENT
109123
bool "Enable record event information for debugging"
110-
depends on IEEE802154_DEBUG
124+
depends on IEEE802154_RECORD
111125
default n
112126
help
113127
Enabling this option to record event, when assert, the recorded event will be printed.
@@ -122,7 +136,7 @@ menu "IEEE 802.15.4"
122136

123137
config IEEE802154_RECORD_STATE
124138
bool "Enable record state information for debugging"
125-
depends on IEEE802154_DEBUG
139+
depends on IEEE802154_RECORD
126140
default n
127141
help
128142
Enabling this option to record state, when assert, the recorded state will be printed.
@@ -137,7 +151,7 @@ menu "IEEE 802.15.4"
137151

138152
config IEEE802154_RECORD_CMD
139153
bool "Enable record command information for debugging"
140-
depends on IEEE802154_DEBUG
154+
depends on IEEE802154_RECORD
141155
default n
142156
help
143157
Enabling this option to record the command, when assert, the recorded
@@ -153,7 +167,7 @@ menu "IEEE 802.15.4"
153167

154168
config IEEE802154_RECORD_ABORT
155169
bool "Enable record abort information for debugging"
156-
depends on IEEE802154_DEBUG
170+
depends on IEEE802154_RECORD
157171
default n
158172
help
159173
Enabling this option to record the abort, when assert, the recorded

components/ieee802154/driver/esp_ieee802154_debug.c

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ static char *ieee80154_tx_abort_reason_string[] = {
171171

172172
#endif // CONFIG_IEEE802154_RECORD_EVENT
173173

174-
#if CONFIG_IEEE802154_ASSERT
175-
void ieee802154_assert_print(void)
174+
#if CONFIG_IEEE802154_RECORD
175+
void ieee802154_record_print(void)
176176
{
177177
#if CONFIG_IEEE802154_RECORD_EVENT
178178
ESP_EARLY_LOGW(IEEE802154_TAG, "Print the record event, current event index: %d", g_ieee802154_probe.event_index);
@@ -235,7 +235,7 @@ void ieee802154_assert_print(void)
235235
ESP_EARLY_LOGW(IEEE802154_TAG,"Print the record abort done.");
236236
#endif // CONFIG_IEEE802154_RECORD_ABORT
237237
}
238-
#endif // CONFIG_IEEE802154_ASSERT
238+
#endif // CONFIG_IEEE802154_RECORD
239239

240240
#if CONFIG_IEEE802154_TXRX_STATISTIC
241241
static ieee802154_txrx_statistic_t s_ieee802154_txrx_statistic;
@@ -370,4 +370,48 @@ void ieee802154_txrx_statistic_print(void)
370370

371371
#endif // CONFIG_IEEE802154_TXRX_STATISTIC
372372

373+
#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
374+
#define IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL 10
375+
#define IEEE802154_RX_BUFFER_GET_USED_LEVEL(a) (((a) * IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL) / (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1))
376+
static uint16_t s_rx_buffer_used_nums = 0;
377+
static uint64_t s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1];
378+
379+
void ieee802154_rx_buffer_statistic_is_free(bool is_free)
380+
{
381+
if (is_free) {
382+
s_rx_buffer_used_nums--;
383+
} else {
384+
s_rx_buffer_used_nums++;
385+
// (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1) means buffer full.
386+
if (s_rx_buffer_used_nums > (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1)) {
387+
s_rx_buffer_used_nums = CONFIG_IEEE802154_RX_BUFFER_SIZE + 1;
388+
}
389+
s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_GET_USED_LEVEL(s_rx_buffer_used_nums)]++;
390+
}
391+
}
392+
393+
void ieee802154_rx_buffer_statistic_clear(void)
394+
{
395+
memset((void*)s_rx_buffer_used_water_level, 0, sizeof(uint64_t)*(IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1));
396+
}
397+
398+
void ieee802154_rx_buffer_statistic_print(void)
399+
{
400+
uint64_t total_times = 0;
401+
for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1); i++) {
402+
total_times += s_rx_buffer_used_water_level[i];
403+
}
404+
ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+");
405+
ESP_LOGW(IEEE802154_TAG, "|%25s|%-25u|", "rx buff total size:", CONFIG_IEEE802154_RX_BUFFER_SIZE);
406+
ESP_LOGW(IEEE802154_TAG, "|%25s|%-25llu|", "buffer alloc times:", total_times);
407+
ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+");
408+
for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL); i++) {
409+
ESP_LOGW(IEEE802154_TAG, "|%4d%%%5s%4d%%%10s|%-15llu%9.2f%%|", ((i) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), "~", ((i + 1) * 100 / IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL), " used:", s_rx_buffer_used_water_level[i], ((float)s_rx_buffer_used_water_level[i] / (float)total_times)*100);
410+
}
411+
ESP_LOGW(IEEE802154_TAG, "|%25s|%-15llu%9.2f%%|", "full used:", s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL], ((float)s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL] / (float)total_times)*100);
412+
ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+");
413+
}
414+
415+
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC
416+
373417
#endif // CONFIG_IEEE802154_DEBUG

components/ieee802154/driver/esp_ieee802154_dev.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static pending_tx_t s_pending_tx = { 0 };
8787
static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *frame_info)
8888
{
8989
// If the RX done packet is written in the stub buffer, drop it silently.
90+
IEEE802154_RX_BUFFER_STAT_IS_FREE(false);
9091
if (s_rx_index != CONFIG_IEEE802154_RX_BUFFER_SIZE) {
9192
// Otherwise, post it to the upper layer.
9293
// Ignore bit8 for the frame length, due to the max frame length is 127 based 802.15.4 spec.
@@ -99,6 +100,7 @@ static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *
99100
static void ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info)
100101
{
101102
if (ack && ack_frame_info) {
103+
IEEE802154_RX_BUFFER_STAT_IS_FREE(false);
102104
if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) {
103105
esp_ieee802154_transmit_failed(frame, ESP_IEEE802154_TX_ERR_NO_ACK);
104106
} else {
@@ -118,6 +120,7 @@ esp_err_t ieee802154_receive_handle_done(const uint8_t *data)
118120
return ESP_FAIL;
119121
}
120122
s_rx_frame_info[size / IEEE802154_RX_FRAME_SIZE].process = false;
123+
IEEE802154_RX_BUFFER_STAT_IS_FREE(true);
121124
return ESP_OK;
122125
}
123126

components/ieee802154/esp_ieee802154.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -416,3 +416,22 @@ void esp_ieee802154_txrx_statistic_print(void)
416416
ieee802154_txrx_statistic_print();
417417
}
418418
#endif // CONFIG_IEEE802154_TXRX_STATISTIC
419+
420+
#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
421+
void esp_ieee802154_rx_buffer_statistic_clear(void)
422+
{
423+
ieee802154_rx_buffer_statistic_clear();
424+
}
425+
426+
void esp_ieee802154_rx_buffer_statistic_print(void)
427+
{
428+
ieee802154_rx_buffer_statistic_print();
429+
}
430+
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC
431+
432+
#if CONFIG_IEEE802154_RECORD
433+
void esp_ieee802154_record_print(void)
434+
{
435+
ieee802154_record_print();
436+
}
437+
#endif // CONFIG_IEEE802154_RECORD

components/ieee802154/include/esp_ieee802154.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,29 @@ void esp_ieee802154_txrx_statistic_clear(void);
623623
void esp_ieee802154_txrx_statistic_print(void);
624624
#endif // CONFIG_IEEE802154_TXRX_STATISTIC
625625

626+
#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
627+
628+
/**
629+
* @brief Print the current IEEE802.15.4 rx buffer statistic.
630+
*
631+
*/
632+
void esp_ieee802154_rx_buffer_statistic_clear(void);
633+
634+
/**
635+
* @brief Clear the current IEEE802.15.4 rx buffer statistic.
636+
*
637+
*/
638+
void esp_ieee802154_rx_buffer_statistic_print(void);
639+
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC
640+
641+
#if CONFIG_IEEE802154_RECORD
642+
643+
/**
644+
* @brief Print the current IEEE802.15.4 event/command/state record.
645+
*
646+
*/
647+
void esp_ieee802154_record_print(void);
648+
#endif // CONFIG_IEEE802154_RECORD
626649
#ifdef __cplusplus
627650
}
628651
#endif

components/ieee802154/private_include/esp_ieee802154_util.h

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,27 @@ typedef struct {
168168

169169
extern ieee802154_probe_info_t g_ieee802154_probe;
170170

171-
#if CONFIG_IEEE802154_ASSERT
171+
#if CONFIG_IEEE802154_RECORD
172172
/**
173173
* @brief This function print rich information, which is useful for debug.
174174
* Only can be used when `IEEE802154_ASSERT` is enabled.
175175
*
176176
*/
177-
void ieee802154_assert_print(void);
177+
void ieee802154_record_print(void);
178+
#endif
179+
180+
#if CONFIG_IEEE802154_ASSERT
181+
182+
#if CONFIG_IEEE802154_RECORD
178183
#define IEEE802154_ASSERT(a) do { \
179184
if(unlikely(!(a))) { \
180-
ieee802154_assert_print(); \
185+
ieee802154_record_print(); \
181186
assert(a); \
182187
} \
183188
} while (0)
189+
#else
190+
#error "CONFIG_IEEE802154_RECORD must be enabled when CONFIG_IEEE802154_ASSERT enabled"
191+
#endif
184192
#else // CONFIG_IEEE802154_ASSERT
185193
#define IEEE802154_ASSERT(a) assert(a)
186194
#endif // CONFIG_IEEE802154_ASSERT
@@ -249,6 +257,33 @@ void ieee802154_tx_break_coex_nums_update(void);
249257
#define IEEE802154_TX_BREAK_COEX_NUMS_UPDATE()
250258
#endif // CONFIG_IEEE802154_TXRX_STATISTIC
251259

260+
#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
261+
262+
/**
263+
* @brief Count the rx buffer used.
264+
*
265+
* @param[in] is_free True for rx buffer frees and false for rx buffer allocates.
266+
*
267+
*/
268+
void ieee802154_rx_buffer_statistic_is_free(bool is_free);
269+
270+
/**
271+
* @brief Clear the current IEEE802.15.4 rx buffer statistic.
272+
*
273+
*/
274+
void ieee802154_rx_buffer_statistic_clear(void);
275+
276+
/**
277+
* @brief Print the current IEEE802.15.4 rx buffer statistic.
278+
*
279+
*/
280+
void ieee802154_rx_buffer_statistic_print(void);
281+
282+
#define IEEE802154_RX_BUFFER_STAT_IS_FREE(a) ieee802154_rx_buffer_statistic_is_free(a)
283+
#else
284+
#define IEEE802154_RX_BUFFER_STAT_IS_FREE(a)
285+
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC
286+
252287
// TODO: replace etm code using common interface
253288

254289
#define IEEE802154_ETM_CHANNEL0 0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
idf_component_register(SRCS "ieee802154_debug.c"
2+
INCLUDE_DIRS "."
3+
REQUIRES ieee802154 console esp_phy)

0 commit comments

Comments
 (0)