From patchwork Fri Jul 28 22:42:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 707609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B2F3EB64DD for ; Fri, 28 Jul 2023 22:42:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229619AbjG1Wmx (ORCPT ); Fri, 28 Jul 2023 18:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233689AbjG1Wmw (ORCPT ); Fri, 28 Jul 2023 18:42:52 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC8BF421C for ; Fri, 28 Jul 2023 15:42:50 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686bea20652so2602767b3a.1 for ; Fri, 28 Jul 2023 15:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690584169; x=1691188969; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=rq9DNo6BbiRVT3oUxKhpF5wOAp2niXJWIqnAPpJQ0q0=; b=eKM99BWChToTsXK05Fd2yXYk1oH6ZQ+FQznMNUVtWv1csZGfm+R4R8yrDhTXacMy13 GGIurqa5fZdKA6aMIa9gPTJLBf3M5k91PYF4xOpFh0UJLcoF8fbcc1V+c/QebQQ7DExS LjhRdyqk1R4e3wJBi+KYG+8YUw0jr4XhMv7vVE0avRnwrznQCp+Amn+vA1PEUNYZEKKw YOIRNYm/nROeIvnhDNG4GoDxQAoGBjCq+QDJOEjxQenslKwSFKyFlplqFEi1um+B6LUW O2faO6z8SP5b0FWwbKvbDZadR7UdF7VSXj5fF5OSXkrzLfAJD3vHU1HQWqEC1mYho8mo 8Jdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690584169; x=1691188969; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rq9DNo6BbiRVT3oUxKhpF5wOAp2niXJWIqnAPpJQ0q0=; b=fwqDsj7zpHSYBtfBJQ8kW4R5TbZnD3vbYo8GSQwEqiJOT/jbwgcO25slksmEC0dFDz h0pMwWvMh1RpI2TmoNTe+Z/J5Q8LDNy5s0aHwjRjCQwPKuJ/2n0AF9h58IzRMduhSrpV 5BMU5/0OO4BaugjinhHq5L527qcVRzTnZ9eqauSMMGqtQWpi6CgGIe3HDNSUasK5mR71 RFRjLWKKkRLAePuJ4gqSM1MOuuRvfVYOJm0fghs9gqicmuyY82A50KZRPZYYRSnCDBgr cqxNxV7D8R36tS8FMExQN//Ylqiks9P6RkTFg+da1wpUgrmO0/LHYpNKp6Wlpfl8CzgB iI9A== X-Gm-Message-State: ABy/qLaHc0j0ku4pi9QY0MjY3XmgNk8kqAcrUH7LHX0W24SqlnBiflnH vxWmN//iMG4EmQmro37omvO870xYTxQ= X-Google-Smtp-Source: APBJJlE0aG7IiWntIizrg2L7LSrBiiQQFojxccgVMxehfMh+5UfhkCKnS3kRuJ+3AKrG1P3B3qnCCw== X-Received: by 2002:a05:6a00:10d5:b0:682:7d8a:f891 with SMTP id d21-20020a056a0010d500b006827d8af891mr3974180pfu.20.1690584169526; Fri, 28 Jul 2023 15:42:49 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b0068703879d3esm2731041pfu.113.2023.07.28.15.42.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:42:48 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v5 1/7] monitor: Use gnuplot to plot graph of Latency-Packets Date: Fri, 28 Jul 2023 15:42:41 -0700 Message-ID: <20230728224247.102057-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This make use of gnuplot when using -a/--analyze to plot a graph of Latency-Packets: Found BR-ACL connection with handle 256 Address: XX:XX:XX:XX:XX:XX (Sony Home Entertainment&Sound Products Inc) 60 RX packets 22548 TX packets 22547 TX completed packets 3 msec min latency 73 msec max latency 11 msec median latency 6 octets TX min packet size 850 octets TX max packet size 847 octets TX median packet size 10000 +-+----------------------------------------------------------------+ +| ++ | +| ||+ Packets +-----+ | +| ||| | 1000 +-| |||++ | +| ||||| + | +| |||||++| | +| ||||||||+++ | 100 +-| ||||||||||| + | +| |||||||||||+++ + | +| |||||||||||||| | | +| ++ ||||||||||||||++|+ | | || |||||||||||||||||++ | 10 +-| || |||||||||||||||||||+ | +| || |||||||||||||||||||| + | +| || ++||||||||||||||||||||++|++++ + | | || ||||||||||||||||||||||||||||| | | 1 +-| ||+||||||||||||||||||||||||||||| + + | + | ++----------------------------------------------------------------+ + + + + + + + + + 0 10 20 30 40 50 60 70 80 Latency (ms) --- monitor/analyze.c | 98 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 11 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index a20ba98b0be4..991373dbb348 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "lib/bluetooth.h" @@ -28,6 +29,9 @@ #include "monitor/packet.h" #include "monitor/analyze.h" +#define TIMEVAL_MSEC(_tv) \ + (long long)((_tv)->tv_sec * 1000 + (_tv)->tv_usec / 1000) + struct hci_dev { uint16_t index; uint8_t type; @@ -69,12 +73,18 @@ struct hci_conn { struct timeval tx_lat_min; struct timeval tx_lat_max; struct timeval tx_lat_med; + struct queue *plot; uint16_t tx_pkt_min; uint16_t tx_pkt_max; uint16_t tx_pkt_med; struct queue *chan_list; }; +struct plot { + long long x_msec; + size_t y_count; +}; + struct l2cap_chan { uint16_t cid; uint16_t psm; @@ -135,6 +145,47 @@ static struct l2cap_chan *chan_lookup(struct hci_conn *conn, uint16_t cid, return chan; } +static void tmp_write(void *data, void *user_data) +{ + struct plot *plot = data; + FILE *tmp = user_data; + + fprintf(tmp, "%lld %zu\n", plot->x_msec, plot->y_count); +} + +static void plot_draw(struct queue *queue) +{ + const char *filename = "analyze.tmp"; + FILE *gplot = popen("gnuplot", "w"); + FILE *tmp; + + if (!gplot) + return; + + if (queue_isempty(queue)) + goto done; + + tmp = fopen(filename, "w"); + if (!tmp) + goto done; + + queue_foreach(queue, tmp_write, tmp); + + fprintf(gplot, "set terminal dumb enhanced ansi\n"); + fprintf(gplot, "set xlabel 'Latency (ms)'\n"); + fprintf(gplot, "set tics out nomirror\n"); + fprintf(gplot, "set log y\n"); + fprintf(gplot, "set yrange [0.5:*]\n"); + fprintf(gplot, "plot './%s' using 1:2 t 'Packets' w impulses\n", + filename); + fflush(gplot); + + fclose(tmp); +done: + pclose(gplot); + unlink(filename); +} + static void conn_destroy(void *data) { struct hci_conn *conn = data; @@ -172,21 +223,17 @@ static void conn_destroy(void *data) print_field("%lu RX packets", conn->rx_num); print_field("%lu TX packets", conn->tx_num); print_field("%lu TX completed packets", conn->tx_num_comp); - print_field("%lld msec min latency", - (long long) - (conn->tx_lat_min.tv_sec * 1000 + - conn->tx_lat_min.tv_usec / 1000)); - print_field("%lld msec max latency", - (long long) - (conn->tx_lat_max.tv_sec * 1000 + - conn->tx_lat_max.tv_usec / 1000)); + print_field("%lld msec min latency", TIMEVAL_MSEC(&conn->tx_lat_min)); + print_field("%lld msec max latency", TIMEVAL_MSEC(&conn->tx_lat_max)); print_field("%lld msec median latency", - (long long) - (conn->tx_lat_med.tv_sec * 1000 + - conn->tx_lat_med.tv_usec / 1000)); + TIMEVAL_MSEC(&conn->tx_lat_med)); print_field("%u octets TX min packet size", conn->tx_pkt_min); print_field("%u octets TX max packet size", conn->tx_pkt_max); print_field("%u octets TX median packet size", conn->tx_pkt_med); + + plot_draw(conn->plot); + + queue_destroy(conn->plot, free); queue_destroy(conn->chan_list, chan_destroy); queue_destroy(conn->tx_queue, free); @@ -203,6 +250,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(); + conn->plot = queue_new(); conn->chan_list = queue_new(); @@ -447,6 +495,32 @@ static void evt_cmd_complete(struct hci_dev *dev, struct timeval *tv, } } +static bool match_plot_latency(const void *data, const void *user_data) +{ + const struct plot *plot = data; + const struct timeval *latency = user_data; + + return TIMEVAL_MSEC(latency) == plot->x_msec; +} + +static void plot_add(struct queue *queue, struct timeval *latency, + uint16_t count) +{ + struct plot *plot; + + plot = queue_find(queue, match_plot_latency, latency); + if (plot) { + plot->y_count += count; + return; + } + + plot = new0(struct plot, 1); + plot->x_msec = TIMEVAL_MSEC(latency); + plot->y_count = count; + + queue_push_tail(queue, plot); +} + static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, const void *data, uint16_t size) { @@ -504,6 +578,8 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, } else conn->tx_lat_med = res; + plot_add(conn->plot, &res, count); + free(last_tx); } } From patchwork Fri Jul 28 22:42:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 708601 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04BBAC41513 for ; Fri, 28 Jul 2023 22:42:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232862AbjG1Wmy (ORCPT ); Fri, 28 Jul 2023 18:42:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjG1Wmx (ORCPT ); Fri, 28 Jul 2023 18:42:53 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAC32421C for ; Fri, 28 Jul 2023 15:42:52 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-68706d67ed9so1373296b3a.2 for ; Fri, 28 Jul 2023 15:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690584171; x=1691188971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Gq/xN/8W0GSGo1Vn6uul++xq/XHjSuMSQtXh1disr3g=; b=kMiv8/InQzceLzTcJ08BFpwazOjY0KYd3CMsnU81eOY7Tf7y/HhgoLh6ovRcWk7Y2U H2CmjxOHobhZ6h2kGWj/EYM0tCc5HApF5qwqNnxbXox4Es0g1SFuJPld4mDNuBiDfaQV oO97p3Ln1PFAlhOoIx45pGJXiUi7HfSV7jOuW/JcoeWzfiHpJjSw76Iahd9o5M40fDfk l3Rtb0xbpeulZSJmRsHV1Thhtav92t4+VqK43IuZ7hyrSyZZSJt/yVwcoTsajp8U5iOW R8Vu7d5CkeeHgXLu0Bq+62nPc/zqJHv+jieKUfNQXBnz0Cgak3HKCUJMJL3IMlkNtlTd gfnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690584171; x=1691188971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gq/xN/8W0GSGo1Vn6uul++xq/XHjSuMSQtXh1disr3g=; b=AayxOZgv2aD5hogjf7t7h4ePAiPPhVMjW4+4OxlrbaPWYfTe0YJjcjqZzeHZZm3xAs ZmCznkbNmvZPa8m8gB+vzWXMubCbiUCmCmAhIak2+sEqcZGEiMBPhgZ05BCPkG6EILYH mKjfSFyV1tQfUaq3sVdcZJesoxIQHt4UncgDPIuKRPRw0rwOJVRcdonpw/55g9xIjHe6 caHqBAutHf/PNxzOIQLeFc8OjHYdiMt0KOV6pEtn2Ulv6cpJDvAVH3WdSrgjS/i/s/E4 4rDFEYxo8Wg7fHHcWXiTz+YrD0E0gJnTkUSCy9VDkozVmQfEMVZrIHM/503x2KW8R1lS Nv7Q== X-Gm-Message-State: ABy/qLYr2jS9f9xc4lr1GwiyfX7uT+MI5nvCzWsTKDMqu86lPCeCiVTq fZDSF5QRupwd5ByKhpnT8lRBRJcKunc= X-Google-Smtp-Source: APBJJlHpuqHdsdkC1z+RrPMKXyDrGJhHtAmVGxTM5yM7hVVIZPmXta59ytyjM8ACQ7E2NuunQv/eEQ== X-Received: by 2002:a05:6a21:778c:b0:131:dd92:4805 with SMTP id bd12-20020a056a21778c00b00131dd924805mr3234600pzc.57.1690584171327; Fri, 28 Jul 2023 15:42:51 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b0068703879d3esm2731041pfu.113.2023.07.28.15.42.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:42:49 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v5 2/7] monitor: Update documentation Date: Fri, 28 Jul 2023 15:42:42 -0700 Message-ID: <20230728224247.102057-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728224247.102057-1-luiz.dentz@gmail.com> References: <20230728224247.102057-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This updates the documentation to mention gnuplot usage. --- monitor/btmon.rst | 4 +++- monitor/main.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/monitor/btmon.rst b/monitor/btmon.rst index 0ab13eb2eb5c..82f9381c151d 100644 --- a/monitor/btmon.rst +++ b/monitor/btmon.rst @@ -33,7 +33,9 @@ OPTIONS -w FILE, --write FILE Save traces in btsnoop format to *FILE*. -a FILE, --analyze FILE Analyze traces in btsnoop format from *FILE*. It displays the devices found in the *FILE* with - its packets by type. + its packets by type. If gnuplot is installed on + the system it also attempts to plot packet latency + graph. -s SOCKET, --server SOCKET Start monitor server socket. -p PRIORITY, --priority PRIORITY Show only priority or lower for user log. diff --git a/monitor/main.c b/monitor/main.c index decf7cc467f2..fa56fcb29f38 100644 --- a/monitor/main.c +++ b/monitor/main.c @@ -51,6 +51,9 @@ static void usage(void) "\t-r, --read Read traces in btsnoop format\n" "\t-w, --write Save traces in btsnoop format\n" "\t-a, --analyze Analyze traces in btsnoop format\n" + "\t If gnuplot is installed on the\n" + "\t system it will also attempt to plot\n" + "\t packet latency graph.\n" "\t-s, --server Start monitor server socket\n" "\t-p, --priority Show only priority or lower\n" "\t-i, --index Show only specified controller\n" From patchwork Fri Jul 28 22:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 707608 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97FB1C001DE for ; Fri, 28 Jul 2023 22:42:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233689AbjG1Wm4 (ORCPT ); Fri, 28 Jul 2023 18:42:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjG1Wmz (ORCPT ); Fri, 28 Jul 2023 18:42:55 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 754FE421C for ; Fri, 28 Jul 2023 15:42:54 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-686f090310dso2458803b3a.0 for ; Fri, 28 Jul 2023 15:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690584173; x=1691188973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dvlh7azK0k6mHhSmylrvFhEeH7R3U1pM9PhXU1dT/zA=; b=QvhSum4AOtA0p91ZdxvKeinusRmV07P1pbf7Nk7IiAifjL5t0zEV4QevvE0IfrA2gu rKCLEclotJzgzNnIgNXO9QziQAwytdax1h75MLvzELwwvNhDLs3y+c/PVso9gUWXqFAS QsVVgVL4+FRUFrXx9O5J7Fp/152WvWeKJN9Z3+Mrz+MZOtosxw+TEd9pbhocSgeh2rmf O9N7SuNoZoVHP91SNQKLC/+4hRr2AQ050fCvykVP2hR5oeqkNclW/8/ocWuqw5loWYnA k8OSfuph+dPNHcmVHf3+tzcvadVY3WIER6zgDSIEUg3qlIONS1h/jDU/T2fTWsi8Nll5 hWeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690584173; x=1691188973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dvlh7azK0k6mHhSmylrvFhEeH7R3U1pM9PhXU1dT/zA=; b=ZzfxO0JRLNaXOtrkOnRjaKxE32tn96YCHqXxoi+rv1eYB/TGanrNraO+cJMdEDX05Q bImlSsfVX47t6vGH4geezXe2tUPMlBkYronqbMWgGI7nNtqpIM3ilG+TzYzcamDmtz4R ALEC0V72xSjip9SESpKW9+taUL4JpWyhNEI5VcqQuyQjQ8YBumzeWqMSe+CJweBrctcN oqLSUni0DULsueh0/gyj+priyEqV3Hw5jXyBqAkUb4eS3StT7Eo7YID6UIPnD/RPBVn8 +5QyTiGGnIK3552GMMqJBz8ENs6Q3h4+8iNa9GqFzadVSrjDC8NHWggv+n/fQzxsU9+N noHQ== X-Gm-Message-State: ABy/qLaKoqHbUNPCZRLM52w5pl5OZvB+NVhcYbv8ktlG4KKhbvfykN6C 5qk9b8/Jqqi6iWjKbArkxqZKFis3+ts= X-Google-Smtp-Source: APBJJlEKC/1jf+2LebI3WaEsIk2bgGLWf84L7b5tRZbBAlRFIex+FgfcFxWkLgY672E7FM2mYh8jLQ== X-Received: by 2002:a05:6a20:6a0f:b0:130:45cc:9ae7 with SMTP id p15-20020a056a206a0f00b0013045cc9ae7mr3998991pzk.38.1690584173196; Fri, 28 Jul 2023 15:42:53 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b0068703879d3esm2731041pfu.113.2023.07.28.15.42.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:42:51 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v5 3/7] monitor: Consolidate code around latency calculation Date: Fri, 28 Jul 2023 15:42:43 -0700 Message-ID: <20230728224247.102057-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728224247.102057-1-luiz.dentz@gmail.com> References: <20230728224247.102057-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This move latency calculations to a helper function called packet_latency_add so it can get reused by the likes of l2cap.c and analyze.c --- monitor/analyze.c | 44 ++++++----------------------------- monitor/l2cap.c | 36 ++++------------------------- monitor/packet.c | 59 +++++++++++++++++++++++++---------------------- monitor/packet.h | 12 +++++++--- 4 files changed, 51 insertions(+), 100 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index 991373dbb348..ddaaf6942035 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -70,9 +70,7 @@ struct hci_conn { unsigned long tx_num_comp; size_t tx_bytes; struct queue *tx_queue; - struct timeval tx_lat_min; - struct timeval tx_lat_max; - struct timeval tx_lat_med; + struct packet_latency tx_l; struct queue *plot; uint16_t tx_pkt_min; uint16_t tx_pkt_max; @@ -223,13 +221,11 @@ static void conn_destroy(void *data) print_field("%lu RX packets", conn->rx_num); print_field("%lu TX packets", conn->tx_num); print_field("%lu TX completed packets", conn->tx_num_comp); - print_field("%lld msec min latency", TIMEVAL_MSEC(&conn->tx_lat_min)); - print_field("%lld msec max latency", TIMEVAL_MSEC(&conn->tx_lat_max)); - print_field("%lld msec median latency", - TIMEVAL_MSEC(&conn->tx_lat_med)); - print_field("%u octets TX min packet size", conn->tx_pkt_min); - print_field("%u octets TX max packet size", conn->tx_pkt_max); - print_field("%u octets TX median packet size", conn->tx_pkt_med); + print_field("%lld-%lld msec (~%lld msec) TX Latency", + TV_MSEC(conn->tx_l.min), TV_MSEC(conn->tx_l.max), + TV_MSEC(conn->tx_l.med)); + print_field("%u-%u octets (~%u octets) TX packet size", + conn->tx_pkt_min, conn->tx_pkt_max, conn->tx_pkt_med); plot_draw(conn->plot); @@ -550,33 +546,7 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, if (last_tx) { timersub(tv, last_tx, &res); - if ((!timerisset(&conn->tx_lat_min) || - timercmp(&res, &conn->tx_lat_min, <)) && - res.tv_sec >= 0 && res.tv_usec >= 0) - conn->tx_lat_min = res; - - if (!timerisset(&conn->tx_lat_max) || - timercmp(&res, &conn->tx_lat_max, >)) - conn->tx_lat_max = res; - - if (timerisset(&conn->tx_lat_med)) { - struct timeval tmp; - - timeradd(&conn->tx_lat_med, &res, &tmp); - - tmp.tv_sec /= 2; - tmp.tv_usec /= 2; - if (tmp.tv_sec % 2) { - tmp.tv_usec += 500000; - if (tmp.tv_usec >= 1000000) { - tmp.tv_sec++; - tmp.tv_usec -= 1000000; - } - } - - conn->tx_lat_med = tmp; - } else - conn->tx_lat_med = res; + packet_latency_add(&conn->tx_l, &res); plot_add(conn->plot, &res, count); diff --git a/monitor/l2cap.c b/monitor/l2cap.c index 8258475d26dc..8f3d8e65b510 100644 --- a/monitor/l2cap.c +++ b/monitor/l2cap.c @@ -100,9 +100,7 @@ struct chan_data { uint8_t ext_ctrl; uint8_t seq_num; uint16_t sdu; - struct timeval tx_min; - struct timeval tx_max; - struct timeval tx_med; + struct packet_latency tx_l; }; static struct chan_data chan_list[MAX_CHAN]; @@ -2798,8 +2796,6 @@ void l2cap_packet(uint16_t index, bool in, uint16_t handle, uint8_t flags, } } -#define TV_MSEC(_tv) (long long)((_tv)->tv_sec * 1000 + (_tv)->tv_usec / 1000) - void l2cap_dequeue_frame(struct timeval *delta, struct packet_conn_data *conn) { struct l2cap_frame *frame; @@ -2813,39 +2809,15 @@ void l2cap_dequeue_frame(struct timeval *delta, struct packet_conn_data *conn) if (!chan) return; - if ((!timerisset(&chan->tx_min) || timercmp(delta, &chan->tx_min, <)) - && delta->tv_sec >= 0 && delta->tv_usec >= 0) - chan->tx_min = *delta; - - if (!timerisset(&chan->tx_max) || timercmp(delta, &chan->tx_max, >)) - chan->tx_max = *delta; - - if (timerisset(&chan->tx_med)) { - struct timeval tmp; - - timeradd(&chan->tx_med, delta, &tmp); - - tmp.tv_sec /= 2; - tmp.tv_usec /= 2; - if (tmp.tv_sec % 2) { - tmp.tv_usec += 500000; - if (tmp.tv_usec >= 1000000) { - tmp.tv_sec++; - tmp.tv_usec -= 1000000; - } - } - - chan->tx_med = tmp; - } else - chan->tx_med = *delta; + packet_latency_add(&chan->tx_l, delta); print_field("Channel: %d [PSM %d mode %s (0x%02x)] {chan %d}", frame->cid, frame->psm, mode2str(frame->mode), frame->mode, frame->chan); print_field("Channel Latency: %lld msec (%lld-%lld msec ~%lld msec)", - TV_MSEC(delta), TV_MSEC(&chan->tx_min), - TV_MSEC(&chan->tx_max), TV_MSEC(&chan->tx_med)); + TV_MSEC(*delta), TV_MSEC(chan->tx_l.min), + TV_MSEC(chan->tx_l.max), TV_MSEC(chan->tx_l.med)); free(frame); } diff --git a/monitor/packet.c b/monitor/packet.c index f581a8e7233d..b905080edc60 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -10336,7 +10336,34 @@ static void role_change_evt(struct timeval *tv, uint16_t index, print_role(evt->role); } -#define TV_MSEC(_tv) (long long)(_tv.tv_sec * 1000 + _tv.tv_usec / 1000) +void packet_latency_add(struct packet_latency *latency, struct timeval *delta) +{ + if ((!timerisset(&latency->min) || timercmp(delta, &latency->min, <)) + && delta->tv_sec >= 0 && delta->tv_usec >= 0) + latency->min = *delta; + + if (!timerisset(&latency->max) || timercmp(delta, &latency->max, >)) + latency->max = *delta; + + if (timerisset(&latency->med)) { + struct timeval tmp; + + timeradd(&latency->med, delta, &tmp); + + tmp.tv_sec /= 2; + tmp.tv_usec /= 2; + if (tmp.tv_sec % 2) { + tmp.tv_usec += 500000; + if (tmp.tv_usec >= 1000000) { + tmp.tv_sec++; + tmp.tv_usec -= 1000000; + } + } + + latency->med = tmp; + } else + latency->med = *delta; +} static void packet_dequeue_tx(struct timeval *tv, uint16_t handle) { @@ -10354,35 +10381,11 @@ static void packet_dequeue_tx(struct timeval *tv, uint16_t handle) timersub(tv, tx, &delta); - if ((!timerisset(&conn->tx_min) || timercmp(&delta, &conn->tx_min, <)) - && delta.tv_sec >= 0 && delta.tv_usec >= 0) - conn->tx_min = delta; - - if (!timerisset(&conn->tx_max) || timercmp(&delta, &conn->tx_max, >)) - conn->tx_max = delta; - - if (timerisset(&conn->tx_med)) { - struct timeval tmp; - - timeradd(&conn->tx_med, &delta, &tmp); - - tmp.tv_sec /= 2; - tmp.tv_usec /= 2; - if (tmp.tv_sec % 2) { - tmp.tv_usec += 500000; - if (tmp.tv_usec >= 1000000) { - tmp.tv_sec++; - tmp.tv_usec -= 1000000; - } - } - - conn->tx_med = tmp; - } else - conn->tx_med = delta; + packet_latency_add(&conn->tx_l, &delta); print_field("Latency: %lld msec (%lld-%lld msec ~%lld msec)", - TV_MSEC(delta), TV_MSEC(conn->tx_min), - TV_MSEC(conn->tx_max), TV_MSEC(conn->tx_med)); + TV_MSEC(delta), TV_MSEC(conn->tx_l.min), + TV_MSEC(conn->tx_l.max), TV_MSEC(conn->tx_l.med)); l2cap_dequeue_frame(&delta, conn); diff --git a/monitor/packet.h b/monitor/packet.h index 88f4c8241ff6..12cb68d508f8 100644 --- a/monitor/packet.h +++ b/monitor/packet.h @@ -23,6 +23,13 @@ #define PACKET_FILTER_SHOW_A2DP_STREAM (1 << 6) #define PACKET_FILTER_SHOW_MGMT_SOCKET (1 << 7) #define PACKET_FILTER_SHOW_ISO_DATA (1 << 8) +#define TV_MSEC(_tv) (long long)((_tv).tv_sec * 1000 + (_tv).tv_usec / 1000) + +struct packet_latency { + struct timeval min; + struct timeval max; + struct timeval med; +}; struct packet_conn_data { uint16_t index; @@ -33,14 +40,13 @@ struct packet_conn_data { uint8_t dst_type; struct queue *tx_q; struct queue *chan_q; - struct timeval tx_min; - struct timeval tx_max; - struct timeval tx_med; + struct packet_latency tx_l; void *data; void (*destroy)(void *data); }; struct packet_conn_data *packet_get_conn_data(uint16_t handle); +void packet_latency_add(struct packet_latency *latency, struct timeval *delta); bool packet_has_filter(unsigned long filter); void packet_set_filter(unsigned long filter); From patchwork Fri Jul 28 22:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 708600 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3542EB64DD for ; Fri, 28 Jul 2023 22:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229495AbjG1Wm6 (ORCPT ); Fri, 28 Jul 2023 18:42:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233478AbjG1Wm4 (ORCPT ); Fri, 28 Jul 2023 18:42:56 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 108384495 for ; Fri, 28 Jul 2023 15:42:56 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686be28e1a8so1858206b3a.0 for ; Fri, 28 Jul 2023 15:42:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690584175; x=1691188975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kp/DcLh5WO3tRYY+x0GV4ZFX6NbomSTB3aO/vJlAm5w=; b=TQqL+5Uq9RycNTJVfTHIiusD5SytAfByhkBxSMSbCD33OVJ6ADXsFFjUQoCj55gyRQ rTELET/8ktt+2XEu/pMmB2s1aoMpOJQfQiX05FEJgmXu5SIF+wU2BFBNtWa2mQxa2WZv aRQM1zYMV9lwKC6Lmbvcr0s5lZ4/Wp6qwRgoT9w42QUqLnLP9n3G4lXK3Xl1AuZYihe/ Pzq/UBUBKEtWbngTh+9m3XtbUQAT19RccBe6qhaWyZBj3ruMR/O/FqT3CJURT5YUTXGA jDfc6b7z4+tS7tSrxNvn2EuayYXDOXbbo/Bghr3ApMd5fXlZwt4vWuE+0JMge7oed8Sx q6Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690584175; x=1691188975; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kp/DcLh5WO3tRYY+x0GV4ZFX6NbomSTB3aO/vJlAm5w=; b=fqpHyn7310V+ZeyO+6nOfI0mdjGdkuBvwr4YHIelY68zA5+nKVa6K4x/CimlmdMNzu 87WuLo7w9HtPeQljzcBsOPvs+KeLtMQsjS4s3wMCVuzrl/AEykj3WQJQD5ppp5nNWlgp 4wvXw3AiW72ZsCFOgOe3kTnsg+9TK7lCYcVKBr9FWv0rea8vUs6oWkyf70fruQ24Frw0 RQlt8cOWtxHS2jAn9P8gCWR4KxWSJ42heghlLpMSbIeSif5jIx3zX/EMzTh/6w5rTmTo 2JKEy/V0nGJt4WjQGLjP5p1XGIXb8gi9PsG6Y1SfmiVjs6PdIJommh7QUOpxvDCh8awf MPEw== X-Gm-Message-State: ABy/qLaZq0SVeGDhEzV4cvNSXPaT1o4nRFOsV/wsprY36wf2ix24Pmqo Ye/brc6ztcOsjiPsh74pAFkKWfFzV7w= X-Google-Smtp-Source: APBJJlHXpPDWO/O6iDuodBuVAFJBSEgxzsS4wfMehqP+40thaYC5PNGFrmJpdJhKNWWjbaENgzoKcA== X-Received: by 2002:a05:6a00:8c9:b0:682:a6bd:e952 with SMTP id s9-20020a056a0008c900b00682a6bde952mr3348102pfu.6.1690584174834; Fri, 28 Jul 2023 15:42:54 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b0068703879d3esm2731041pfu.113.2023.07.28.15.42.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:42:53 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v5 4/7] monitor: Fix not dequeing TX packet properly Date: Fri, 28 Jul 2023 15:42:44 -0700 Message-ID: <20230728224247.102057-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728224247.102057-1-luiz.dentz@gmail.com> References: <20230728224247.102057-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz num_completed_packets_evt contain a count for how many packets have been completed per handle. --- monitor/packet.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index b905080edc60..badc9b9c7785 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -10406,6 +10406,7 @@ static void num_completed_packets_evt(struct timeval *tv, uint16_t index, for (i = 0; i < evt->num_handles; i++) { uint16_t handle; uint16_t count; + int j; if (!util_iov_pull_le16(&iov, &handle)) break; @@ -10415,9 +10416,10 @@ static void num_completed_packets_evt(struct timeval *tv, uint16_t index, if (!util_iov_pull_le16(&iov, &count)) break; - print_field("Count: %d", le16_to_cpu(evt->count)); + print_field("Count: %d", count); - packet_dequeue_tx(tv, handle); + for (j = 0; j < count; j++) + packet_dequeue_tx(tv, handle); } if (iov.iov_len) From patchwork Fri Jul 28 22:42:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 707607 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65F6CC001DF for ; Fri, 28 Jul 2023 22:43:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233741AbjG1Wm7 (ORCPT ); Fri, 28 Jul 2023 18:42:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231880AbjG1Wm6 (ORCPT ); Fri, 28 Jul 2023 18:42:58 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF746421C for ; Fri, 28 Jul 2023 15:42:57 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-686e29b058cso2012029b3a.1 for ; Fri, 28 Jul 2023 15:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690584176; x=1691188976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AqtPrNOzG2zgD66FN9kCCGXtJuxydbI9dQmkP+yzwmg=; b=D/c/EuE0Q0PYZO2uGGIAEMmqGMEVtza8aDkdb2Yxp1hyS+xAl8grmUaNy9SrQYphlv RNPkaWOOLedy3ntJBm/ETHnRWs7Kt8wMTJqbTDm90UqmSWhcD12tM6XVXHAoi4/abMX+ fL7uR5zWS8KTglW8if9D7c7qRwPBKXxnnKPNXHVVg/wYaQpdtrR5iiSidzThtDrzk9Cb NOik+TPa8pmLett2rVHKBih8r058VwvwQdvXzhcz80xTQFM4/rRzJ9K2j5ZGj9fxfJVA DxxWZYdRUHyLLpCO0y/jG2V9D2tN571Fs/fud7n9SlMJZmDkgRtCjYzl2EAK1kFu1ivt gA4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690584176; x=1691188976; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AqtPrNOzG2zgD66FN9kCCGXtJuxydbI9dQmkP+yzwmg=; b=JR74wiiGy4sq5i1PMslOJwlVEFL925tSYUK7BJAZcR6PUxg/KGZRoWdVq25NvQO224 3ec0ly7fWVdeTmuEK6JL6u7/LYfjv94GVo0g2PMtqdi1Bn+OwdBlx7q0J4sRUEktj7Ff yTGabG9y+IlqnWW6/+bc4gim16L8vl12wU7N+hu1dar0CMDtSh0yEK7SFSkGMlcwlk/Z nqVq3SXmWEM3X8o4qHA0ljZthDVC3Rs/AJijsvy2HOJDWeRG6Mz6QCwF7xt+yiANOLJ4 OL8Dj3onxVsNIvt2u92agVBnp1zJJxLssrno/aM6L+KWQQ/pzuHiynd0TI555IFzxuu7 KX/g== X-Gm-Message-State: ABy/qLaVMOnX/6D8uZLsvm2ENhiWaLicnu9sMetL+I5dfpdCkRsrkj8r yqi8/MFzUFdPuGaJbUoaytdPEN3lswo= X-Google-Smtp-Source: APBJJlFOcvCHIzVeQdjcKdfzWvhLiTq5XCGU2i2ZcIGp00iLFDNPezHs5/oSFOAGKIn+AJKUajYWEA== X-Received: by 2002:a05:6a00:1955:b0:686:bc23:e20a with SMTP id s21-20020a056a00195500b00686bc23e20amr3459914pfk.21.1690584176535; Fri, 28 Jul 2023 15:42:56 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b0068703879d3esm2731041pfu.113.2023.07.28.15.42.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:42:55 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v5 5/7] monitor: Fix not calculating latency for ISO/SCO packets Date: Fri, 28 Jul 2023 15:42:45 -0700 Message-ID: <20230728224247.102057-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728224247.102057-1-luiz.dentz@gmail.com> References: <20230728224247.102057-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz ISO/SCO packets latency was not being calculated because no connection was assigned to them. --- monitor/packet.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/monitor/packet.c b/monitor/packet.c index badc9b9c7785..b5a4fb1671b1 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -10607,6 +10607,10 @@ static void sync_conn_complete_evt(struct timeval *tv, uint16_t index, print_field("RX packet length: %d", le16_to_cpu(evt->rx_pkt_len)); print_field("TX packet length: %d", le16_to_cpu(evt->tx_pkt_len)); print_air_mode(evt->air_mode); + + if (evt->status == 0x00) + assign_handle(index, le16_to_cpu(evt->handle), evt->link_type, + (void *)evt->bdaddr, BDADDR_BREDR); } static void sync_conn_changed_evt(struct timeval *tv, uint16_t index, @@ -11566,6 +11570,10 @@ static void le_cis_established_evt(struct timeval *tv, uint16_t index, print_field("Central to Peripheral MTU: %u", le16_to_cpu(evt->c_mtu)); print_field("Peripheral to Central MTU: %u", le16_to_cpu(evt->p_mtu)); print_slot_125("ISO Interval", evt->interval); + + if (!evt->status) + assign_handle(index, le16_to_cpu(evt->conn_handle), 0x05, + NULL, BDADDR_LE_PUBLIC); } static void le_req_cis_evt(struct timeval *tv, uint16_t index, @@ -11604,6 +11612,14 @@ static void le_big_complete_evt(struct timeval *tv, uint16_t index, print_slot_125("ISO Interval", evt->interval); print_list(evt->bis_handle, size, evt->num_bis, sizeof(*evt->bis_handle), print_bis_handle); + + if (!evt->status) { + int i; + + for (i = 0; i < evt->num_bis; i++) + assign_handle(index, le16_to_cpu(evt->bis_handle[i]), + 0x05, NULL, BDADDR_LE_PUBLIC); + } } static void le_big_terminate_evt(struct timeval *tv, uint16_t index, @@ -11631,6 +11647,14 @@ static void le_big_sync_estabilished_evt(struct timeval *tv, uint16_t index, print_slot_125("ISO Interval", evt->interval); print_list(evt->bis, size, evt->num_bis, sizeof(*evt->bis), print_bis_handle); + + if (!evt->status) { + int i; + + for (i = 0; i < evt->num_bis; i++) + assign_handle(index, le16_to_cpu(evt->bis[i]), + 0x05, NULL, BDADDR_LE_PUBLIC); + } } static void le_big_sync_lost_evt(struct timeval *tv, uint16_t index, From patchwork Fri Jul 28 22:42:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 708599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F4CFEB64DD for ; Fri, 28 Jul 2023 22:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233926AbjG1WnC (ORCPT ); Fri, 28 Jul 2023 18:43:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233968AbjG1WnB (ORCPT ); Fri, 28 Jul 2023 18:43:01 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F105449E for ; Fri, 28 Jul 2023 15:42:59 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-686b9964ae2so1911604b3a.3 for ; Fri, 28 Jul 2023 15:42:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690584178; x=1691188978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=g1Cxubman+YQUXa8gTY/9HAG3R/1Rik0Xg7kE1cKTME=; b=A58J/rIjlHGf0zstdvGHXA4U0nYgMH0hvIsSA4tgTc6uspkAX2SkcwpBbzuHUjlXLN JHy5LmEToPHhiOV1uswiPTdy+I/Mdmel4tohL5Gad52Sr00BlZOxsx08a2wQPwm7YTqe D7qFukcN5+v/GSJ3Fn88/aHMJCeogSEqC3V1V398mn8/gEGNPYWBW/2qepZbIGZ7Dlkr 64FXVswFBEkhyyyUGdwl+6J80i50/ZdoVtW4zddte9N8vGHoMLH32GAnCRbdR51UIwop CouJ2rw0jnyyScrbHxsvQtnpCh3p3vFjVIgeRWfkkO4T6QPl3ttBjul0ufUymPZ3qpSC nFBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690584178; x=1691188978; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g1Cxubman+YQUXa8gTY/9HAG3R/1Rik0Xg7kE1cKTME=; b=YK5yEOWo/8E+Q1x7RdR+zQcRt8xysvzm0aobINaqPPL4WNTM0XFkG3awRmgyY5DAUg J7wth77M3yqcgkJvppn+qHVfdTStLZNF3W/n+PLQsi9usZTqVLEclNVXFJRQvWDjTpXu c4P7NCr5pkex1g2i+x3NM33Vmv2JDXxtt4vaIgmPY05r2OLw9t+NHvrRPzKDNkwOhAfV i+A3ONu38R0zTrm/7djIpMtTAmckirE9G/8afAbY4U8I5wVsD5wKsBtMSdWf3hX9gLuI lYK5tyj6UnM1dIruY5pTO5RGnCJ0CwWABJxDAfSXaawwJp2sC8C6cbR1m6O85fwA6PT4 m7Kg== X-Gm-Message-State: ABy/qLaELkD1Tl3dd64Z4t+1rWI5AssjYZaSkJyXunE0dL+/qJq6QYsT t+zE3STcoblAFOIqxALRrW/P0tXL3bs= X-Google-Smtp-Source: APBJJlHsFLro6tLLtrHrAVWg+ou4Rk7pSB8y8tgRsTWgu0Ae4WknISpHBdqm4IdZszTyJJ6GvmT1NQ== X-Received: by 2002:a05:6a20:840b:b0:137:514a:9835 with SMTP id c11-20020a056a20840b00b00137514a9835mr3565822pzd.9.1690584178265; Fri, 28 Jul 2023 15:42:58 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b0068703879d3esm2731041pfu.113.2023.07.28.15.42.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:42:57 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v5 6/7] monitor/analyze: Fix not dequeing TX packet properly Date: Fri, 28 Jul 2023 15:42:46 -0700 Message-ID: <20230728224247.102057-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728224247.102057-1-luiz.dentz@gmail.com> References: <20230728224247.102057-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz num_completed_packets_evt contain a count for how many packets have been completed per handle. --- monitor/analyze.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index ddaaf6942035..c8192ffa7d2a 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -532,6 +532,7 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, struct hci_conn *conn; struct timeval res; struct timeval *last_tx; + int j; data += 4; size -= 4; @@ -542,15 +543,17 @@ static void evt_num_completed_packets(struct hci_dev *dev, struct timeval *tv, conn->tx_num_comp += count; - last_tx = queue_pop_head(conn->tx_queue); - if (last_tx) { - timersub(tv, last_tx, &res); + for (j = 0; j < count; j++) { + last_tx = queue_pop_head(conn->tx_queue); + if (last_tx) { + timersub(tv, last_tx, &res); - packet_latency_add(&conn->tx_l, &res); + packet_latency_add(&conn->tx_l, &res); - plot_add(conn->plot, &res, count); + plot_add(conn->plot, &res, count); - free(last_tx); + free(last_tx); + } } } } From patchwork Fri Jul 28 22:42:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 707606 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7A26C001DF for ; Fri, 28 Jul 2023 22:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234309AbjG1WnG (ORCPT ); Fri, 28 Jul 2023 18:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233968AbjG1WnF (ORCPT ); Fri, 28 Jul 2023 18:43:05 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81A1E44B1 for ; Fri, 28 Jul 2023 15:43:01 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6862842a028so1937632b3a.0 for ; Fri, 28 Jul 2023 15:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690584180; x=1691188980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=mvKrKUkOuXPlRJMRwTzdHt7gSh8VQHDYyBf1xu4Gs/w=; b=etcd/fdzTnfzQyn3HCGQlYPGRD+dz8hMrL5ze33HT7dmRbJ9Cu5tMtM/r/ntz2ZzeF d3sMwKQ+vG8dlZKenT8gZAkBBkhQRBgsRwnl04R/R87eHJL/9aI40NNx13u3KX6aEnAR eG41b4uQKF/cfJhNq9YALD5QxG3uKjw2Zc61uqmZCe7sVjZ+z8GE3HSR5jbfdJn2NdwT aN6kmxPqMOi7yO4s0UFP5KwOvpyZ5a0qANyfP01be5zcc4AGCETFMrRUGH7TerinxD0Y qsOXdM/GGOemT6B0Ls2zWwyp9F4JB8ox3bkaoqT2U34dsEageXge17A2h7MtXJpv+dou 8Kmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690584180; x=1691188980; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mvKrKUkOuXPlRJMRwTzdHt7gSh8VQHDYyBf1xu4Gs/w=; b=YV3VuFPPILT1KNLAyy2Tj7pEg7ZkOomrATE89jVSZmfe8P7Pdr6R9c6uQojP9bO1fi YQM+KFLIF5FD91ookCwZf/O+w70RgAUBWU25sPFmk/B4EytizS6m8AFgD/qm+N0scqdq np74+1iAaIQS9wJuJSgtYPpDpqlCgAuae/G1DR59uthiRIA2PqBI89Ybze7lui2Ywx5D wWyzloYcYuyJmrvLyNK0nDhr+CGFeqdz4MeMY32tf6y8eJfDxb1o09hKqmUYV6Fb8IDv /0iND7+6vm2XFg4L/PnVfBP1IHvGA0mC6mXm38HySifFKbpqzIQXRs0EK43OOqKBQI5f Aq1A== X-Gm-Message-State: ABy/qLbM6YsSvv0zMRL5gyxijf7TBDNLTsG2ZVNuPuLu32H38RxvNZMc /hZ2xQvqaBUoZogVivMYqK+Yd/oDTr0= X-Google-Smtp-Source: APBJJlFwZ6/WCr8raXPzEhGZMCBpf5L0YEM3fKRSsAyucVyeeSi5QEMGpp9yo6NV2HG723SDalcMmw== X-Received: by 2002:a05:6a00:1953:b0:687:189c:4e3d with SMTP id s19-20020a056a00195300b00687189c4e3dmr1699520pfk.10.1690584179930; Fri, 28 Jul 2023 15:42:59 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-236-201-58.hsd1.or.comcast.net. [71.236.201.58]) by smtp.gmail.com with ESMTPSA id x41-20020a056a000be900b0068703879d3esm2731041pfu.113.2023.07.28.15.42.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 15:42:58 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v5 7/7] monitor/analyze: Fix not calculating latency for ISO/SCO packets Date: Fri, 28 Jul 2023 15:42:47 -0700 Message-ID: <20230728224247.102057-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230728224247.102057-1-luiz.dentz@gmail.com> References: <20230728224247.102057-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz ISO/SCO packets latency was not being calculated because no connection was being assigned to them. --- monitor/analyze.c | 56 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/monitor/analyze.c b/monitor/analyze.c index c8192ffa7d2a..b4a7cf726ac9 100644 --- a/monitor/analyze.c +++ b/monitor/analyze.c @@ -652,10 +652,28 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out, } } -static void sco_pkt(struct timeval *tv, uint16_t index, +static void conn_pkt_tx(struct hci_conn *conn, struct timeval *tv, + uint16_t size) +{ + struct timeval *last_tx; + + 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) + conn->tx_pkt_min = size; + if (!conn->tx_pkt_max || size > conn->tx_pkt_max) + conn->tx_pkt_max = size; +} + +static void sco_pkt(struct timeval *tv, uint16_t index, bool out, const void *data, uint16_t size) { + const struct bt_hci_acl_hdr *hdr = data; struct hci_dev *dev; + struct hci_conn *conn; dev = dev_lookup(index); if (!dev) @@ -663,6 +681,18 @@ static void sco_pkt(struct timeval *tv, uint16_t index, dev->num_hci++; dev->num_sco++; + + conn = conn_lookup_type(dev, le16_to_cpu(hdr->handle) & 0x0fff, + CONN_BR_SCO); + if (!conn) + return; + + if (out) { + conn->tx_num++; + conn_pkt_tx(conn, tv, size - sizeof(*hdr)); + } else { + conn->rx_num++; + } } static void info_index(struct timeval *tv, uint16_t index, @@ -726,9 +756,11 @@ static void ctrl_msg(struct timeval *tv, uint16_t index, dev->ctrl_msg++; } -static void iso_pkt(struct timeval *tv, uint16_t index, +static void iso_pkt(struct timeval *tv, uint16_t index, bool out, const void *data, uint16_t size) { + const struct bt_hci_iso_hdr *hdr = data; + struct hci_conn *conn; struct hci_dev *dev; dev = dev_lookup(index); @@ -737,6 +769,18 @@ static void iso_pkt(struct timeval *tv, uint16_t index, dev->num_hci++; dev->num_iso++; + + conn = conn_lookup_type(dev, le16_to_cpu(hdr->handle) & 0x0fff, + CONN_LE_ISO); + if (!conn) + return; + + if (out) { + conn->tx_num++; + conn_pkt_tx(conn, tv, size - sizeof(*hdr)); + } else { + conn->rx_num++; + } } static void unknown_opcode(struct timeval *tv, uint16_t index, @@ -804,8 +848,10 @@ void analyze_trace(const char *path) acl_pkt(&tv, index, false, buf, pktlen); break; case BTSNOOP_OPCODE_SCO_TX_PKT: + sco_pkt(&tv, index, true, buf, pktlen); + break; case BTSNOOP_OPCODE_SCO_RX_PKT: - sco_pkt(&tv, index, buf, pktlen); + sco_pkt(&tv, index, false, buf, pktlen); break; case BTSNOOP_OPCODE_OPEN_INDEX: case BTSNOOP_OPCODE_CLOSE_INDEX: @@ -829,8 +875,10 @@ void analyze_trace(const char *path) ctrl_msg(&tv, index, buf, pktlen); break; case BTSNOOP_OPCODE_ISO_TX_PKT: + iso_pkt(&tv, index, true, buf, pktlen); + break; case BTSNOOP_OPCODE_ISO_RX_PKT: - iso_pkt(&tv, index, buf, pktlen); + iso_pkt(&tv, index, false, buf, pktlen); break; default: unknown_opcode(&tv, index, buf, pktlen);