Skip to content

Commit 3aeb2af

Browse files
author
Jarkko Paso
authored
Statistics for data request latencies (ARMmbed#2629)
* Adaptation layer TX latency statistics * MAC data request TX latency statistics * Updated change log
1 parent 3f7eae6 commit 3aeb2af

File tree

11 files changed

+37
-4
lines changed

11 files changed

+37
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Adaptation layer removes oldest packets first when stack needs to release memory or reduce traffic
99

1010
### Changes
11-
*
11+
* Statistics for MAC data request latencies. Separated to adaptation layer and MAC queueing delays.
1212

1313
### Bug fixes
1414
* Added ignoring of retry messages from RADIUS server when waiting EAP-TLS

nanostack/mac_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ typedef struct mac_statistics_s {
325325
uint32_t mac_retry_count; /**< MAC TX retry count. */
326326
uint32_t mac_cca_attempts_count; /**< MAC CCA attempts count. */
327327
uint32_t mac_failed_cca_count; /**< MAC failed CCA count. */
328+
uint32_t mac_tx_latency_max; /**< MAC data request max latency. */
328329
} mac_statistics_t;
329330

330331
#ifdef __cplusplus

nanostack/nwk_stats_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef struct nwk_stats_t {
7474
uint16_t adapt_layer_tx_queue_size; /**< Adaptation layer direct TX queue size. */
7575
uint16_t adapt_layer_tx_queue_peak; /**< Adaptation layer direct TX queue size peak. */
7676
uint32_t adapt_layer_tx_congestion_drop; /**< Adaptation layer direct TX randon early detection drop packet. */
77+
uint16_t adapt_layer_tx_latency_max; /**< Adaptation layer latency between TX request and TX ready in seconds (MAX). */
7778
} nwk_stats_t;
7879

7980
/**

source/6LoWPAN/adaptation_interface.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,13 @@ int8_t lowpan_adaptation_interface_tx(protocol_interface_info_entry_t *cur, buff
13091309
if (!interface_ptr) {
13101310
goto tx_error_handler;
13111311
}
1312-
1312+
// Set TX start timestamp
1313+
if (!buf->adaptation_timestamp) {
1314+
buf->adaptation_timestamp = protocol_core_monotonic_time;
1315+
if (!buf->adaptation_timestamp) {
1316+
buf->adaptation_timestamp--;
1317+
}
1318+
}
13131319
uint8_t traffic_class = buf->options.traffic_class >> IP_TCLASS_DSCP_SHIFT;
13141320

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

1560+
// Update adaptation layer latency for unicast packets. Given as seconds.
1561+
if (buf->link_specific.ieee802_15_4.requestAck && buf->adaptation_timestamp) {
1562+
protocol_stats_update(STATS_AL_TX_LATENCY, ((protocol_core_monotonic_time - buf->adaptation_timestamp) + 5) / 10);
1563+
}
1564+
15551565
//Indirect data expiration
15561566
if (confirm->status == MLME_TRANSACTION_EXPIRED && !active_direct_confirm) {
15571567
if (buf->link_specific.ieee802_15_4.indirectTTL > 7000) {

source/Core/include/ns_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ typedef struct buffer {
218218
bool rpl_instance_known: 1;
219219
bool ip_routed_up: 1;
220220
uint8_t rpl_flag_error;
221+
uint32_t adaptation_timestamp; /*!< Timestamp when buffer pushed to adaptation interface. Unit 100ms */
221222
//uint8_t bc_sending_superframe; /*FHSS uses this randomly chosen superframe to send this packet (if broadcast)*/
222223
//uint8_t fhss_channel_retries_left;
223224
//uint8_t ip_transmission_prev_seq; /*!< XXX: this stores the data packet seq. number, which is needed for re-transmission. */

source/MAC/IEEE802_15_4/mac_data_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ typedef struct mac_pre_build_frame {
100100
uint16_t blacklist_period_ms;
101101
uint16_t initial_tx_channel;
102102
uint32_t tx_time;
103+
uint32_t request_start_time_us;
103104
bool upper_layer_request: 1;
104105
bool mac_allocated_payload_ptr: 1;
105106
bool asynch_request: 1;

source/MAC/IEEE802_15_4/mac_mcps_sap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
383383
buffer->tx_request_restart_cnt = rf_mac_setup->tx_failure_restart_max;
384384
//check that header + payload length is not bigger than MAC MTU
385385

386+
buffer->request_start_time_us = mac_mcps_sap_get_phy_timestamp(rf_mac_setup);
387+
386388
if (data_req->InDirectTx) {
387389
mac_indirect_queue_write(rf_mac_setup, buffer);
388390
} else {
@@ -1630,6 +1632,11 @@ static void mcps_data_confirm_handle(protocol_interface_rf_mac_setup_s *rf_ptr,
16301632
confirm.timestamp = 0;
16311633
}
16321634

1635+
if (buffer->fcf_dsn.ackRequested) {
1636+
// Update latency for unicast packets. Given as milliseconds.
1637+
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);
1638+
}
1639+
16331640
if (buffer->upper_layer_request) {
16341641
//Check tunnel
16351642
mcps_sap_prebuild_frame_buffer_free(buffer);

source/MAC/IEEE802_15_4/sw_mac.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ void sw_mac_stats_update(protocol_interface_rf_mac_setup_s *setup, mac_stats_typ
765765
case STAT_MAC_TX_CCA_FAIL:
766766
setup->mac_statistics->mac_failed_cca_count++;
767767
break;
768+
case STAT_MAC_TX_LATENCY:
769+
if (update_val > setup->mac_statistics->mac_tx_latency_max) {
770+
setup->mac_statistics->mac_tx_latency_max = update_val;
771+
}
772+
break;
768773
}
769774
}
770775
}

source/MAC/IEEE802_15_4/sw_mac_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef enum {
3535
STAT_MAC_TX_RETRY,
3636
STAT_MAC_TX_CCA_ATT,
3737
STAT_MAC_TX_CCA_FAIL,
38+
STAT_MAC_TX_LATENCY
3839
} mac_stats_type_t;
3940

4041
typedef enum arm_nwk_timer_id {

source/NWK_INTERFACE/Include/protocol_stats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ typedef enum {
4545
STATS_ETX_1ST_PARENT,
4646
STATS_ETX_2ND_PARENT,
4747
STATS_AL_TX_QUEUE_SIZE,
48-
STATS_AL_TX_CONGESTION_DROP
48+
STATS_AL_TX_CONGESTION_DROP,
49+
STATS_AL_TX_LATENCY
4950

5051
} nwk_stats_type_t;
5152

source/NWK_INTERFACE/protocol_stats.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ void protocol_stats_update(nwk_stats_type_t type, uint16_t update_val)
155155
case STATS_AL_TX_CONGESTION_DROP:
156156
nwk_stats_ptr->adapt_layer_tx_congestion_drop++;
157157
break;
158+
case STATS_AL_TX_LATENCY:
159+
if (update_val > nwk_stats_ptr->adapt_layer_tx_latency_max) {
160+
nwk_stats_ptr->adapt_layer_tx_latency_max = update_val;
161+
}
162+
break;
158163
}
159164
}
160165
}

0 commit comments

Comments
 (0)