summaryrefslogtreecommitdiff
path: root/monitor/analyze.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-08-06 14:22:58 -0700
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2021-08-09 15:01:29 -0700
commit7dc659cde02ae3aa97609a8edbe9c507b369e710 (patch)
tree852f11f9ade448825aa114181fc5db4724cd39bc /monitor/analyze.c
parent52c7d16865a78d83d0c6abd0f81de9ff5ecaa71a (diff)
downloadbluez-7dc659cde02ae3aa97609a8edbe9c507b369e710.tar.gz
monitor: Fix not accouting for multiple outstanding packets
Analyze code was not accounting for the fact that multiple outstanding packets could be pending which will cause the last_tx to be overwritten but its latency would be calculated against the very first packet complete.
Diffstat (limited to 'monitor/analyze.c')
-rw-r--r--monitor/analyze.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/monitor/analyze.c b/monitor/analyze.c
index d504c8d84..aae153f94 100644
--- a/monitor/analyze.c
+++ b/monitor/analyze.c
@@ -62,8 +62,7 @@ struct hci_conn {
unsigned long tx_num;
unsigned long tx_num_comp;
size_t tx_bytes;
- struct timeval last_tx;
- struct timeval last_tx_comp;
+ struct queue *tx_queue;
struct timeval tx_lat_min;
struct timeval tx_lat_max;
struct timeval tx_lat_med;
@@ -121,6 +120,7 @@ static void conn_destroy(void *data)
printf(" %u octets TX max packet size\n", conn->tx_pkt_max);
printf(" %u octets TX median packet size\n", conn->tx_pkt_med);
+ queue_destroy(conn->tx_queue, free);
free(conn);
}
@@ -133,6 +133,7 @@ static struct hci_conn *conn_alloc(struct hci_dev *dev, uint16_t handle,
conn->handle = handle;
conn->type = type;
+ conn->tx_queue = queue_new();
return conn;
}
@@ -372,6 +373,7 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv,
uint16_t count = get_le16(data + 2);
struct hci_conn *conn;
struct timeval res;
+ struct timeval *last_tx;
data += 4;
size -= 4;
@@ -381,10 +383,10 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv,
continue;
conn->tx_num_comp += count;
- conn->last_tx_comp = *tv;
- if (timerisset(&conn->last_tx)) {
- timersub(&conn->last_tx_comp, &conn->last_tx, &res);
+ last_tx = queue_pop_head(conn->tx_queue);
+ if (last_tx) {
+ timersub(tv, last_tx, &res);
if ((!timerisset(&conn->tx_lat_min) ||
timercmp(&res, &conn->tx_lat_min, <)) &&
@@ -414,7 +416,7 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv,
} else
conn->tx_lat_med = res;
- timerclear(&conn->last_tx);
+ free(last_tx);
}
}
}
@@ -489,8 +491,12 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out,
return;
if (out) {
+ struct timeval *last_tx;
+
conn->tx_num++;
- conn->last_tx = *tv;
+ last_tx = new0(struct timeval, 1);
+ memcpy(last_tx, tv, sizeof(*tv));
+ queue_push_tail(conn->tx_queue, last_tx);
conn->tx_bytes += size;
if (!conn->tx_pkt_min || size < conn->tx_pkt_min)