Skip to content

Commit

Permalink
Merge branch 'feature/add_rx_buff_statistic_v5.2' into 'release/v5.2'
Browse files Browse the repository at this point in the history
feat(802.15.4): IEEE802.15.4 add rx buffer statistic (v5.2)

See merge request espressif/esp-idf!35641
  • Loading branch information
chshu committed Dec 24, 2024
2 parents baef4f2 + ed5f9ba commit 1408102
Show file tree
Hide file tree
Showing 10 changed files with 524 additions and 14 deletions.
28 changes: 21 additions & 7 deletions components/ieee802154/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,31 @@ menu "IEEE 802.15.4"
Enabling this option allows different kinds of IEEE802154 debug output.
All IEEE802154 debug features increase the size of the final binary.

config IEEE802154_RX_BUFFER_STATISTIC
bool "Rx buffer statistic"
depends on IEEE802154_DEBUG
default n
help
Enabling this option to count IEEE802154 rx buffer when allocating or freeing.

config IEEE802154_ASSERT
bool "Enrich the assert information with IEEE802154 state and event"
bool "Enrich the assert information"
depends on IEEE802154_DEBUG
select IEEE802154_RECORD
default n
help
Enabling this option to print more information when assert.

config IEEE802154_RECORD
bool "Record the information with IEEE802154 state and event"
depends on IEEE802154_DEBUG
default n
help
Enabling this option to add some probe codes in the driver, and these informations
will be printed when assert.
Enabling this option to add some probe codes in the driver, and record these information.

config IEEE802154_RECORD_EVENT
bool "Enable record event information for debugging"
depends on IEEE802154_DEBUG
depends on IEEE802154_RECORD
default n
help
Enabling this option to record event, when assert, the recorded event will be printed.
Expand All @@ -122,7 +136,7 @@ menu "IEEE 802.15.4"

config IEEE802154_RECORD_STATE
bool "Enable record state information for debugging"
depends on IEEE802154_DEBUG
depends on IEEE802154_RECORD
default n
help
Enabling this option to record state, when assert, the recorded state will be printed.
Expand All @@ -137,7 +151,7 @@ menu "IEEE 802.15.4"

config IEEE802154_RECORD_CMD
bool "Enable record command information for debugging"
depends on IEEE802154_DEBUG
depends on IEEE802154_RECORD
default n
help
Enabling this option to record the command, when assert, the recorded
Expand All @@ -153,7 +167,7 @@ menu "IEEE 802.15.4"

config IEEE802154_RECORD_ABORT
bool "Enable record abort information for debugging"
depends on IEEE802154_DEBUG
depends on IEEE802154_RECORD
default n
help
Enabling this option to record the abort, when assert, the recorded
Expand Down
50 changes: 47 additions & 3 deletions components/ieee802154/driver/esp_ieee802154_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ static char *ieee80154_tx_abort_reason_string[] = {

#endif // CONFIG_IEEE802154_RECORD_EVENT

#if CONFIG_IEEE802154_ASSERT
void ieee802154_assert_print(void)
#if CONFIG_IEEE802154_RECORD
void ieee802154_record_print(void)
{
#if CONFIG_IEEE802154_RECORD_EVENT
ESP_EARLY_LOGW(IEEE802154_TAG, "Print the record event, current event index: %d", g_ieee802154_probe.event_index);
Expand Down Expand Up @@ -235,7 +235,7 @@ void ieee802154_assert_print(void)
ESP_EARLY_LOGW(IEEE802154_TAG,"Print the record abort done.");
#endif // CONFIG_IEEE802154_RECORD_ABORT
}
#endif // CONFIG_IEEE802154_ASSERT
#endif // CONFIG_IEEE802154_RECORD

#if CONFIG_IEEE802154_TXRX_STATISTIC
static ieee802154_txrx_statistic_t s_ieee802154_txrx_statistic;
Expand Down Expand Up @@ -370,4 +370,48 @@ void ieee802154_txrx_statistic_print(void)

#endif // CONFIG_IEEE802154_TXRX_STATISTIC

#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
#define IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL 10
#define IEEE802154_RX_BUFFER_GET_USED_LEVEL(a) (((a) * IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL) / (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1))
static uint16_t s_rx_buffer_used_nums = 0;
static uint64_t s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1];

void ieee802154_rx_buffer_statistic_is_free(bool is_free)
{
if (is_free) {
s_rx_buffer_used_nums--;
} else {
s_rx_buffer_used_nums++;
// (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1) means buffer full.
if (s_rx_buffer_used_nums > (CONFIG_IEEE802154_RX_BUFFER_SIZE + 1)) {
s_rx_buffer_used_nums = CONFIG_IEEE802154_RX_BUFFER_SIZE + 1;
}
s_rx_buffer_used_water_level[IEEE802154_RX_BUFFER_GET_USED_LEVEL(s_rx_buffer_used_nums)]++;
}
}

void ieee802154_rx_buffer_statistic_clear(void)
{
memset((void*)s_rx_buffer_used_water_level, 0, sizeof(uint64_t)*(IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1));
}

void ieee802154_rx_buffer_statistic_print(void)
{
uint64_t total_times = 0;
for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL + 1); i++) {
total_times += s_rx_buffer_used_water_level[i];
}
ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+");
ESP_LOGW(IEEE802154_TAG, "|%25s|%-25u|", "rx buff total size:", CONFIG_IEEE802154_RX_BUFFER_SIZE);
ESP_LOGW(IEEE802154_TAG, "|%25s|%-25llu|", "buffer alloc times:", total_times);
ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+");
for (uint8_t i = 0; i < (IEEE802154_RX_BUFFER_USED_TOTAL_LEVEL); i++) {
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);
}
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);
ESP_LOGW(IEEE802154_TAG, "+-------------------------+-------------------------+");
}

#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC

#endif // CONFIG_IEEE802154_DEBUG
3 changes: 3 additions & 0 deletions components/ieee802154/driver/esp_ieee802154_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static pending_tx_t s_pending_tx = { 0 };
static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *frame_info)
{
// If the RX done packet is written in the stub buffer, drop it silently.
IEEE802154_RX_BUFFER_STAT_IS_FREE(false);
if (s_rx_index != CONFIG_IEEE802154_RX_BUFFER_SIZE) {
// Otherwise, post it to the upper layer.
// Ignore bit8 for the frame length, due to the max frame length is 127 based 802.15.4 spec.
Expand All @@ -99,6 +100,7 @@ static void ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *
static void ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info)
{
if (ack && ack_frame_info) {
IEEE802154_RX_BUFFER_STAT_IS_FREE(false);
if (s_rx_index == CONFIG_IEEE802154_RX_BUFFER_SIZE) {
esp_ieee802154_transmit_failed(frame, ESP_IEEE802154_TX_ERR_NO_ACK);
} else {
Expand All @@ -118,6 +120,7 @@ esp_err_t ieee802154_receive_handle_done(const uint8_t *data)
return ESP_FAIL;
}
s_rx_frame_info[size / IEEE802154_RX_FRAME_SIZE].process = false;
IEEE802154_RX_BUFFER_STAT_IS_FREE(true);
return ESP_OK;
}

Expand Down
21 changes: 20 additions & 1 deletion components/ieee802154/esp_ieee802154.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -416,3 +416,22 @@ void esp_ieee802154_txrx_statistic_print(void)
ieee802154_txrx_statistic_print();
}
#endif // CONFIG_IEEE802154_TXRX_STATISTIC

#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC
void esp_ieee802154_rx_buffer_statistic_clear(void)
{
ieee802154_rx_buffer_statistic_clear();
}

void esp_ieee802154_rx_buffer_statistic_print(void)
{
ieee802154_rx_buffer_statistic_print();
}
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC

#if CONFIG_IEEE802154_RECORD
void esp_ieee802154_record_print(void)
{
ieee802154_record_print();
}
#endif // CONFIG_IEEE802154_RECORD
23 changes: 23 additions & 0 deletions components/ieee802154/include/esp_ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,29 @@ void esp_ieee802154_txrx_statistic_clear(void);
void esp_ieee802154_txrx_statistic_print(void);
#endif // CONFIG_IEEE802154_TXRX_STATISTIC

#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC

/**
* @brief Print the current IEEE802.15.4 rx buffer statistic.
*
*/
void esp_ieee802154_rx_buffer_statistic_clear(void);

/**
* @brief Clear the current IEEE802.15.4 rx buffer statistic.
*
*/
void esp_ieee802154_rx_buffer_statistic_print(void);
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC

#if CONFIG_IEEE802154_RECORD

/**
* @brief Print the current IEEE802.15.4 event/command/state record.
*
*/
void esp_ieee802154_record_print(void);
#endif // CONFIG_IEEE802154_RECORD
#ifdef __cplusplus
}
#endif
41 changes: 38 additions & 3 deletions components/ieee802154/private_include/esp_ieee802154_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,27 @@ typedef struct {

extern ieee802154_probe_info_t g_ieee802154_probe;

#if CONFIG_IEEE802154_ASSERT
#if CONFIG_IEEE802154_RECORD
/**
* @brief This function print rich information, which is useful for debug.
* Only can be used when `IEEE802154_ASSERT` is enabled.
*
*/
void ieee802154_assert_print(void);
void ieee802154_record_print(void);
#endif

#if CONFIG_IEEE802154_ASSERT

#if CONFIG_IEEE802154_RECORD
#define IEEE802154_ASSERT(a) do { \
if(unlikely(!(a))) { \
ieee802154_assert_print(); \
ieee802154_record_print(); \
assert(a); \
} \
} while (0)
#else
#error "CONFIG_IEEE802154_RECORD must be enabled when CONFIG_IEEE802154_ASSERT enabled"
#endif
#else // CONFIG_IEEE802154_ASSERT
#define IEEE802154_ASSERT(a) assert(a)
#endif // CONFIG_IEEE802154_ASSERT
Expand Down Expand Up @@ -249,6 +257,33 @@ void ieee802154_tx_break_coex_nums_update(void);
#define IEEE802154_TX_BREAK_COEX_NUMS_UPDATE()
#endif // CONFIG_IEEE802154_TXRX_STATISTIC

#if CONFIG_IEEE802154_RX_BUFFER_STATISTIC

/**
* @brief Count the rx buffer used.
*
* @param[in] is_free True for rx buffer frees and false for rx buffer allocates.
*
*/
void ieee802154_rx_buffer_statistic_is_free(bool is_free);

/**
* @brief Clear the current IEEE802.15.4 rx buffer statistic.
*
*/
void ieee802154_rx_buffer_statistic_clear(void);

/**
* @brief Print the current IEEE802.15.4 rx buffer statistic.
*
*/
void ieee802154_rx_buffer_statistic_print(void);

#define IEEE802154_RX_BUFFER_STAT_IS_FREE(a) ieee802154_rx_buffer_statistic_is_free(a)
#else
#define IEEE802154_RX_BUFFER_STAT_IS_FREE(a)
#endif // CONFIG_IEEE802154_RX_BUFFER_STATISTIC

// TODO: replace etm code using common interface

#define IEEE802154_ETM_CHANNEL0 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRCS "ieee802154_debug.c"
INCLUDE_DIRS "."
REQUIRES ieee802154 console esp_phy)
Loading

0 comments on commit 1408102

Please sign in to comment.