Skip to content

Commit

Permalink
Statistics for data request latencies (ARMmbed#2629)
Browse files Browse the repository at this point in the history
* Adaptation layer TX latency statistics

* MAC data request TX latency statistics

* Updated change log
  • Loading branch information
Jarkko Paso authored May 14, 2021
1 parent 3f7eae6 commit 3aeb2af
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Adaptation layer removes oldest packets first when stack needs to release memory or reduce traffic

### Changes
*
* Statistics for MAC data request latencies. Separated to adaptation layer and MAC queueing delays.

### Bug fixes
* Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
Expand Down
1 change: 1 addition & 0 deletions nanostack/mac_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ typedef struct mac_statistics_s {
uint32_t mac_retry_count; /**< MAC TX retry count. */
uint32_t mac_cca_attempts_count; /**< MAC CCA attempts count. */
uint32_t mac_failed_cca_count; /**< MAC failed CCA count. */
uint32_t mac_tx_latency_max; /**< MAC data request max latency. */
} mac_statistics_t;

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions nanostack/nwk_stats_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ typedef struct nwk_stats_t {
uint16_t adapt_layer_tx_queue_size; /**< Adaptation layer direct TX queue size. */
uint16_t adapt_layer_tx_queue_peak; /**< Adaptation layer direct TX queue size peak. */
uint32_t adapt_layer_tx_congestion_drop; /**< Adaptation layer direct TX randon early detection drop packet. */
uint16_t adapt_layer_tx_latency_max; /**< Adaptation layer latency between TX request and TX ready in seconds (MAX). */
} nwk_stats_t;

/**
Expand Down
14 changes: 12 additions & 2 deletions source/6LoWPAN/adaptation_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,13 @@ int8_t lowpan_adaptation_interface_tx(protocol_interface_info_entry_t *cur, buff
if (!interface_ptr) {
goto tx_error_handler;
}

// Set TX start timestamp
if (!buf->adaptation_timestamp) {
buf->adaptation_timestamp = protocol_core_monotonic_time;
if (!buf->adaptation_timestamp) {
buf->adaptation_timestamp--;
}
}
uint8_t traffic_class = buf->options.traffic_class >> IP_TCLASS_DSCP_SHIFT;

if (traffic_class == IP_DSCP_EF) {
Expand Down Expand Up @@ -1549,9 +1555,13 @@ int8_t lowpan_adaptation_interface_tx_confirm(protocol_interface_info_entry_t *c
tr_error("No data request for this confirmation %u", confirm->msduHandle);
return -1;
}
//Check status for
buffer_t *buf = tx_ptr->buf;

// Update adaptation layer latency for unicast packets. Given as seconds.
if (buf->link_specific.ieee802_15_4.requestAck && buf->adaptation_timestamp) {
protocol_stats_update(STATS_AL_TX_LATENCY, ((protocol_core_monotonic_time - buf->adaptation_timestamp) + 5) / 10);
}

//Indirect data expiration
if (confirm->status == MLME_TRANSACTION_EXPIRED && !active_direct_confirm) {
if (buf->link_specific.ieee802_15_4.indirectTTL > 7000) {
Expand Down
1 change: 1 addition & 0 deletions source/Core/include/ns_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ typedef struct buffer {
bool rpl_instance_known: 1;
bool ip_routed_up: 1;
uint8_t rpl_flag_error;
uint32_t adaptation_timestamp; /*!< Timestamp when buffer pushed to adaptation interface. Unit 100ms */
//uint8_t bc_sending_superframe; /*FHSS uses this randomly chosen superframe to send this packet (if broadcast)*/
//uint8_t fhss_channel_retries_left;
//uint8_t ip_transmission_prev_seq; /*!< XXX: this stores the data packet seq. number, which is needed for re-transmission. */
Expand Down
1 change: 1 addition & 0 deletions source/MAC/IEEE802_15_4/mac_data_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ typedef struct mac_pre_build_frame {
uint16_t blacklist_period_ms;
uint16_t initial_tx_channel;
uint32_t tx_time;
uint32_t request_start_time_us;
bool upper_layer_request: 1;
bool mac_allocated_payload_ptr: 1;
bool asynch_request: 1;
Expand Down
7 changes: 7 additions & 0 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
buffer->tx_request_restart_cnt = rf_mac_setup->tx_failure_restart_max;
//check that header + payload length is not bigger than MAC MTU

buffer->request_start_time_us = mac_mcps_sap_get_phy_timestamp(rf_mac_setup);

if (data_req->InDirectTx) {
mac_indirect_queue_write(rf_mac_setup, buffer);
} else {
Expand Down Expand Up @@ -1630,6 +1632,11 @@ static void mcps_data_confirm_handle(protocol_interface_rf_mac_setup_s *rf_ptr,
confirm.timestamp = 0;
}

if (buffer->fcf_dsn.ackRequested) {
// Update latency for unicast packets. Given as milliseconds.
sw_mac_stats_update(rf_ptr, STAT_MAC_TX_LATENCY, ((mac_mcps_sap_get_phy_timestamp(rf_ptr) - buffer->request_start_time_us) + 500) / 1000);
}

if (buffer->upper_layer_request) {
//Check tunnel
mcps_sap_prebuild_frame_buffer_free(buffer);
Expand Down
5 changes: 5 additions & 0 deletions source/MAC/IEEE802_15_4/sw_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,11 @@ void sw_mac_stats_update(protocol_interface_rf_mac_setup_s *setup, mac_stats_typ
case STAT_MAC_TX_CCA_FAIL:
setup->mac_statistics->mac_failed_cca_count++;
break;
case STAT_MAC_TX_LATENCY:
if (update_val > setup->mac_statistics->mac_tx_latency_max) {
setup->mac_statistics->mac_tx_latency_max = update_val;
}
break;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions source/MAC/IEEE802_15_4/sw_mac_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef enum {
STAT_MAC_TX_RETRY,
STAT_MAC_TX_CCA_ATT,
STAT_MAC_TX_CCA_FAIL,
STAT_MAC_TX_LATENCY
} mac_stats_type_t;

typedef enum arm_nwk_timer_id {
Expand Down
3 changes: 2 additions & 1 deletion source/NWK_INTERFACE/Include/protocol_stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ typedef enum {
STATS_ETX_1ST_PARENT,
STATS_ETX_2ND_PARENT,
STATS_AL_TX_QUEUE_SIZE,
STATS_AL_TX_CONGESTION_DROP
STATS_AL_TX_CONGESTION_DROP,
STATS_AL_TX_LATENCY

} nwk_stats_type_t;

Expand Down
5 changes: 5 additions & 0 deletions source/NWK_INTERFACE/protocol_stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ void protocol_stats_update(nwk_stats_type_t type, uint16_t update_val)
case STATS_AL_TX_CONGESTION_DROP:
nwk_stats_ptr->adapt_layer_tx_congestion_drop++;
break;
case STATS_AL_TX_LATENCY:
if (update_val > nwk_stats_ptr->adapt_layer_tx_latency_max) {
nwk_stats_ptr->adapt_layer_tx_latency_max = update_val;
}
break;
}
}
}
Expand Down

0 comments on commit 3aeb2af

Please sign in to comment.