Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3418568lqp; Tue, 26 Mar 2024 08:39:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU3wgBkO8x6r4uITuJCgMfCtE9dwOxA4mCZ69eiXm+lUwTnDQgyT+fdgHI7w5f1jCquK0GBLEz7HCrh9+TIv4lmdBgpeN09PujT3JHyWg== X-Google-Smtp-Source: AGHT+IEIt8FJL7YctlwT10aGWByurSaYcMuu5kkoO+6rVqGWd6xYWLUO6DH9dw6mWwB64YAf2XV4 X-Received: by 2002:a50:9354:0:b0:56b:989d:bdce with SMTP id n20-20020a509354000000b0056b989dbdcemr6916761eda.24.1711467552513; Tue, 26 Mar 2024 08:39:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711467552; cv=pass; d=google.com; s=arc-20160816; b=YGomVakuU0Ua1m6pQr1d/hmlkcDLlBySeVdXO6nlJunBGkqVmw+bf6qs8KtuTXiJ0R kdNx5yhPPP32UmjTEX5nXpsHVtf4h+T2R+WmJux3fzwS4YcD6WD0R+GqHMFOBiW+Ofhs vbQYEAQ06wY7Qfmdi2karvzmTZCzY58fMukyo+9ADW0DjaurbE6Hkl7dyHQVCw9wSGOg mFmJJLtPblhcNMFFeXYV5Q2sZPdyouOc/ZWef2xwPsAPJJmdSU2BmarmkCNg9kYhKq96 guYH6cNwvKcD4pY7ohhXgsknmKGwzX7GNHACZjCZtvSwlssSFaRu70cYolIkYDfh/+R5 +ayg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=NdW5IYEdhdPJN9JvhsmEKb8jj3fZA3AkNx8BkvH5wGU=; fh=0IsR9ktt/JJTrT3kGRWDobjv5NSaWfDTzIPyTsjticE=; b=pogRNRuKMhbKfpZGsfh0l0fS39/EHwfa9kdxe9ZKXZLXpn3Ismv0yf2sPQi21oma7H sdOsG/9H4oVjt87fPGq6vOAvjRHjjYSqdep2VgA+GouYFidjNqXlneuS29pqTJwEfOoi vSvMTH9V1mcIKMTa8Da+WqS9sPtVI2dIGKkL2NJjVEba/iPSG8qfHxsYfpqvZNq1JK54 H8pgxprfrb+NpPlkN3JyFYwi8r8j0xd0XVafXkKaVNUYxQ6H+2jg/G2TubsnWvjbKh+s hzKK+mRYUUJSe2+8L29Wdnbifs0eTlAcF8m7lpPQ2BQRvgU+p7F9xeFuouNyTPPdWdCC pRMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PAKpz88M; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-2789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2789-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h12-20020a0564020e8c00b005688b0fe67esi3727793eda.259.2024.03.26.08.39.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 08:39:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-2789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PAKpz88M; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-2789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2789-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 198F81F67A7E for ; Tue, 26 Mar 2024 15:39:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DC5613C9CB; Tue, 26 Mar 2024 15:34:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PAKpz88M" X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D55713C919 for ; Tue, 26 Mar 2024 15:34:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711467242; cv=none; b=NEIwEgIG/ncey30o+QA8Hj7C6LUuYGJNVf45//bOs69UVk77wYZ99ze1FUPM2ljI+9d8LTNDQW0TMnEgpF5VPUrzSSNZ7GCPrDTE0klMwQNLljwTtymdmgsSELFWDwzq07waXvzGljq3NpdP4IGLO0RH8Jy4CTVUga3H8QGy+xA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711467242; c=relaxed/simple; bh=fylGhHFqGGhA/IdFXG9bDjDOmCKG8nXTMSp197cNV+E=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=AgeaO+5z2iq13FP9NjRWddBbRfL4+/tvwxJLH7a/3EQ5WYGgWf/H7jA54xPgOBT7EpXf7LPcl/ipDy/Im/gC/uOVHnmkMlpyMNioo0Vm4WkDJeMetWXPv+qoAfKEdsxhD5FCYbHiZrMCdV5ls65yGHmHAXE/ixsXhwfUyBQ4YLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PAKpz88M; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d6ee81bcd4so6624341fa.2 for ; Tue, 26 Mar 2024 08:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711467239; x=1712072039; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NdW5IYEdhdPJN9JvhsmEKb8jj3fZA3AkNx8BkvH5wGU=; b=PAKpz88MRxnF5t82FnsTHMfJF754FJrhmrTY1Hcl+ZpYZsimIiDmTIIdya56SKRIEh DI9z9pZSojPpnJwY4akBmlIvKrvBimu50B4fFky0sCI6cy+HM4gIH5Trx3vzPESHaIuO rI8OqasESnDHS+OmhEaK2MANIs2zxHeQtKwxmjglGC0m8uvwo9RufZ8JehrrJ94RLtek 3oLZHFYeruJ/WOmOmD9rmrWryrDOQBNmuoDOXatl9vawzNzIUnujGQnXYU/utF4jNmhA 3K/qsZPB9ako9/EScSMtBI7auy2PtlMxxIjbSLo05TcZTbqLM90Z+IwjxcQAvB4chPHP 8nug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711467239; x=1712072039; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NdW5IYEdhdPJN9JvhsmEKb8jj3fZA3AkNx8BkvH5wGU=; b=WNyQf5HS5TjPxZSpY3RUK6uXr61p4lnS/ifE+IDHuoWaDNDz7ZgQfbl59+ezlfH/uO auDNYPFengZfbzFsZ7CQ23ySU2Eghe3YFm65t5ET2csoLHIXgM1Rk1NSTMoaXbpdKfs2 ji718h+a4YFSphqFAyB9HHVPYqcAQQOEu1CZcs/6wGSTJU8FJTccDrQuRz7nKP8iHsYE zcAHv8eAARF0NpksUZO8VDfz16wn+tdcIO0L41414CVT2sbFdvQcGtaWOSuFFQGLBFY8 8dTMAWfQFHx0816cMcGMb7ohUMfmjRhTPMERt8F4NmYRUuuun2YzAoJ3mj5cqa6Z5rif QebA== X-Gm-Message-State: AOJu0YxNu+Pbd6VqGR23Wuenn3+x5czyORhhIF5iNI3mKCQMEi7jZdXg wuRzE5vNbGqpvOC2jicI+IzBdHjEnkKQtNm8q7/qUG7f7w+2iiq8//phy/rnNi8yGSFg/KITmDd PMRxPCwxILy/APT0pYcSHxXO5S1lNhwwQ X-Received: by 2002:a2e:9797:0:b0:2d6:c2dc:3396 with SMTP id y23-20020a2e9797000000b002d6c2dc3396mr5430951lji.30.1711467238306; Tue, 26 Mar 2024 08:33:58 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240325144031.335354-1-vlad.pruteanu@nxp.com> <20240325144031.335354-2-vlad.pruteanu@nxp.com> In-Reply-To: From: Luiz Augusto von Dentz Date: Tue, 26 Mar 2024 11:33:45 -0400 Message-ID: Subject: Re: [EXT] Re: [PATCH BlueZ 1/1] client/player: Fix transport.send command's transfer of packets To: Vlad Pruteanu Cc: "linux-bluetooth@vger.kernel.org" , Mihai-Octavian Urzica , Silviu Florian Barbulescu , Iulia Tanasescu , Andrei Istodorescu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Vlad, On Tue, Mar 26, 2024 at 11:21=E2=80=AFAM Vlad Pruteanu wrote: > > Hello Luiz, > > > > -----Original Message----- > > From: Luiz Augusto von Dentz > > Sent: Monday, March 25, 2024 6:04 PM > > To: Vlad Pruteanu > > Cc: linux-bluetooth@vger.kernel.org; Mihai-Octavian Urzica > octavian.urzica@nxp.com>; Silviu Florian Barbulescu > > ; Iulia Tanasescu ; > > Andrei Istodorescu > > Subject: [EXT] Re: [PATCH BlueZ 1/1] client/player: Fix transport.send > > command's transfer of packets > > > > Caution: This is an external email. Please take care when clicking link= s or > > opening attachments. When in doubt, report the message using the 'Repor= t > > this email' button > > > > > > Hi Vlad, > > > > On Mon, Mar 25, 2024 at 10:40=E2=80=AFAM Vlad Pruteanu > > wrote: > > > > > > The transport.send command sends a number num of packets at intervals > > > specified by the transport latency reported by the CIS Establsihed ev= ent. > > > Num is defined as qos.ucast.out.latency * 1000 / qos.ucast.out.interv= al. > > > Since this latency could be smaller than the SDU interval for some pr= esets, > > > the resulting num would be 0, causing the file transfer to stop after= the > > > first packet. Instead, one packet should be sent at SDU interval dist= ance > > > apart. > > > > Please add some output samples showing the wrong interval ends up being > > used. > > > Below you can find what I consider to a relevant excerpt taken from btmon= log: > ... > < HCI Command: LE Set Connected Isochronous Group Parameters (0x08|0x0062= ) > CIG ID: 0x00 > Central to Peripheral SDU Interval: 10000 us (0x002710) > Peripheral to Central SDU Interval: 10000 us (0x002710) > SCA: 201 - 500 ppm (0x00) > Packing: Sequential (0x00) > Framing: Unframed (0x00) > Central to Peripheral Maximum Latency: 10 ms (0x000a) > Peripheral to Central Maximum Latency: 10 ms (0x000a) > Number of CIS: 1 > CIS ID: 0x00 > Central to Peripheral Maximum SDU Size: 40 > Peripheral to Central Maximum SDU Size: 0 > Central to Peripheral PHY: LE 2M (0x02) > Peripheral to Central PHY: LE 2M (0x02) > Central to Peripheral Retransmission attempts: 0x02 > Peripheral to Central Retransmission attempts: 0x00 > ... > > HCI Event: Command Complete (0x0e) > LE Set Connected Isochronous Group Parameters (0x08|0x0062) ncmd 1 > Status: Success (0x00) > CIG ID: 0x00 > Number of Handles: 1 > Connection Handle #0: 144 > ... > < HCI Command: LE Create Connected Isochronous Stream (0x08|0x0064) > Number of CIS: 1 > CIS Handle: 144 > ACL Handle: 128 > ... > > HCI Event: LE Meta Event (0x3e) > LE Connected Isochronous Stream Established (0x19) > Status: Success (0x00) > Connection Handle: 144 > CIG Synchronization Delay: 1992 us (0x0007c8) > CIS Synchronization Delay: 1992 us (0x0007c8) > Central to Peripheral Latency: 1992 us (0x0007c8) > Peripheral to Central Latency: 1992 us (0x0007c8) > Central to Peripheral PHY: LE 2M (0x02) > Peripheral to Central PHY: LE 2M (0x02) > Number of Subevents: 3 > Central to Peripheral Burst Number: 1 > Peripheral to Central Burst Number: 0 > Central to Peripheral Flush Timeout: 1 > Peripheral to Central Flush Timeout: 1 > Central to Peripheral MTU: 40 > Peripheral to Central MTU: 0 > ISO Interval: 10.00 msec (0x0008) > ... > bluetoothd[349393]: < ISO Data TX: Handle 144 flags 0x02 > > HCI Event: Number of Completed Packets (0x13) > Num handles: 1 > Handle: 144 Address: A0:CD:F3:78:04:0A (Murata Manufacturing Co.,= Ltd.) > Count: 1 > #470: len 44 (27 Kb/s) > Latency: 13 msec (13-13 msec ~13 msec) > > The Maximum Latency is correctly set to 10ms in the LE Set Connected Isoc= hronous Group Parameters command, and the controller reports the final late= ncy as being 1992 us. This is the value that (after conversion to ms) qos.u= cast.out.latency takes in the current implementation. num is defined as num= =3D (qos.ucast.out.latency * 1000 / qos.ucast.out.interval), with interval= being the ISO interval, 10000us and therefore num will be 0 in this case. = As you can see the first packet is always sent, but after that none can be = seen. Instead, the Host should send 1 packet every time this function is ca= lled. The timer related change below ensures that this function is triggere= d at every SDU interval. So, in the end, the Host will send 1 packet every = SDU interval. > > > --- > > > client/player.c | 34 +++++++++++++++++++++++++++------- > > > 1 file changed, 27 insertions(+), 7 deletions(-) > > > > > > diff --git a/client/player.c b/client/player.c > > > index 1f56bfd27..f579d9904 100644 > > > --- a/client/player.c > > > +++ b/client/player.c > > > @@ -34,6 +34,7 @@ > > > > > > #include "lib/bluetooth.h" > > > #include "lib/uuid.h" > > > +#include "lib/iso.h" > > > > > > #include "profiles/audio/a2dp-codecs.h" > > > #include "src/shared/lc3.h" > > > @@ -5007,7 +5008,6 @@ static bool transport_timer_read(struct io *io, > > void *user_data) > > > struct bt_iso_qos qos; > > > socklen_t len; > > > int ret, fd; > > > - uint32_t num; > > > uint64_t exp; > > > > > > if (transport->fd < 0) > > > @@ -5031,10 +5031,7 @@ static bool transport_timer_read(struct io *io= , > > void *user_data) > > > return false; > > > } > > > > > > - /* num of packets =3D latency (ms) / interval (us) */ > > > - num =3D (qos.ucast.out.latency * 1000 / qos.ucast.out.interva= l); > > > - > > > - ret =3D transport_send_seq(transport, transport->fd, num); > > > + ret =3D transport_send_seq(transport, transport->fd, 1); > > > if (ret < 0) { > > > bt_shell_printf("Unable to send: %s (%d)\n", > > > strerror(-ret), ret); > > > @@ -5052,6 +5049,8 @@ static bool transport_timer_read(struct io *io, > > void *user_data) > > > static int transport_send(struct transport *transport, int fd, > > > struct bt_iso_qos *qos) > > > { > > > + struct sockaddr_iso addr; > > > + socklen_t optlen; > > > struct itimerspec ts; > > > int timer_fd; > > > > > > @@ -5068,9 +5067,30 @@ static int transport_send(struct transport > > *transport, int fd, > > > return -errno; > > > > > > memset(&ts, 0, sizeof(ts)); > > > - ts.it_value.tv_nsec =3D qos->ucast.out.latency * 1000000; > > > - ts.it_interval.tv_nsec =3D qos->ucast.out.latency * 1000000; > > > > > > + /* Need to know if the transport on which data is sent is > > > + * broadcast or unicast so that the correct qos structure > > > + * can be accessed. At this point in code there no other > > > + * way of knowing this besides checking the peer address. > > > + * Broadcast will use BDADDR_ANY, while Unicast will use > > > + * the connected peer's actual address. > > > + */ > > > + memset(&addr, 0, sizeof(addr)); > > > + optlen =3D sizeof(addr); > > > + > > > + if (getpeername(transport->sk, &addr, &optlen) < 0) > > > + return -errno; > > > > The description seems to be suggesting there is a rounding error, but > > the code below only deals with the fact we didn't use proper fields > > for broadcast, so is it really fixing what is the patch description or > > something else? > > > The main change that I made here is the value of the interval for the tim= er. > Before, it used to be set to qos.ucast.out.latency and I propose to chang= e > it to qos.ucast.out.interval, so that the Host will send 1SDU packet on > every ISO Interval. I included the ucast/bcast qos update since I was > already updating this line of code. That is, I didn't want to send the pa= tch > with "qos->ucast.out.interval" without differentiating between bcast and > ucast since it would've been wrong. Hmm if I recall correctly this code used to be sending a packet per interval but we run into problems because the interval is rather short and OS itself would take time to transfer the packet from userspace to socket and then to driver, etc, so I suggest we round up the value if it ends up being 0. > > > + if (!(bacmp(&addr.iso_bdaddr, BDADDR_ANY))) { > > > + /* Interval is measured in us, multiply by 1000 to ge= t ns */ > > > + ts.it_value.tv_nsec =3D qos->bcast.out.interval * 100= 0; > > > + ts.it_interval.tv_nsec =3D qos->bcast.out.interval * = 1000; > > > + } else { > > > + /* Interval is measured in us, multiply by 1000 to ge= t ns */ > > > + ts.it_value.tv_nsec =3D qos->ucast.out.interval * 100= 0; > > > + ts.it_interval.tv_nsec =3D qos->ucast.out.interval * = 1000; > > > + > > > + } > > > if (timerfd_settime(timer_fd, TFD_TIMER_ABSTIME, &ts, NULL) <= 0) > > > return -errno; > > > > > > -- > > > 2.39.2 > > > > > > > > > -- > > Luiz Augusto von Dentz --=20 Luiz Augusto von Dentz