2024-04-16 10:25:40

by Vlad Pruteanu

[permalink] [raw]
Subject: [PATCH 0/1] Bluetooth: hci_event: Fix setting of broadcast qos interval and latency

The latency parameter of the broadcast qos is calculated wrongly.

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G

For framed PDUs:
Transport_Latency_BIG = BIG_Sync_Delay + PTO x (NSE / BN -
IRC) * ISO_Interval + ISO_Interval + SDU_Interval

For unframed PDUs:
Transport_Latency = BIG_Sync_Delay + (PTO x (NSE / BN - IRC) +
1) x ISO_Interval - SDU_Interval

For broadcast sink the latency should be taken directly from the
BIG Sync Established event and for the source it should be taken
from the Create BIG Complete event.

The interval parameter of the broadcast qos reffers to the SDU
Interval and shouldn't be set based on the latency. The Host will
read this value from the BASE.

Vlad Pruteanu (1):
Bluetooth: hci_event: Fix setting of broadcast qos interval and
latency

net/bluetooth/hci_event.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

--
2.40.1



2024-04-16 10:26:40

by Vlad Pruteanu

[permalink] [raw]
Subject: [PATCH 1/1] Bluetooth: hci_event: Fix setting of broadcast qos interval and latency

The latency parameter of the broadcast qos is calculated wrongly.

BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G

For framed PDUs:
Transport_Latency_BIG = BIG_Sync_Delay + PTO x (NSE / BN -
IRC) * ISO_Interval + ISO_Interval + SDU_Interval

For unframed PDUs:
Transport_Latency = BIG_Sync_Delay + (PTO x (NSE / BN - IRC) +
1) x ISO_Interval - SDU_Interval

For broadcast sink the latency should be taken directly from the
BIG Sync Established event and for the source it should be taken
from the Create BIG Complete event.

The interval parameter of the broadcast qos reffers to the SDU
Interval and shouldn't be set based on the latency. The Host will
read this value from the BASE.

Signed-off-by: Vlad Pruteanu <[email protected]>
---
net/bluetooth/hci_event.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 868ffccff773..dff4bedc3e9b 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -6983,6 +6983,8 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data,

if (!ev->status) {
conn->state = BT_CONNECTED;
+ conn->iso_qos.bcast.out.latency =
+ DIV_ROUND_CLOSEST(get_unaligned_le24(ev->transport_delay), 1000);
set_bit(HCI_CONN_BIG_CREATED, &conn->flags);
rcu_read_unlock();
hci_debugfs_create_conn(conn);
@@ -7029,7 +7031,6 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,

for (i = 0; i < ev->num_bis; i++) {
u16 handle = le16_to_cpu(ev->bis[i]);
- __le32 interval;

bis = hci_conn_hash_lookup_handle(hdev, handle);
if (!bis) {
@@ -7044,11 +7045,10 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
set_bit(HCI_CONN_PA_SYNC, &bis->flags);

bis->iso_qos.bcast.big = ev->handle;
- memset(&interval, 0, sizeof(interval));
- memcpy(&interval, ev->latency, sizeof(ev->latency));
- bis->iso_qos.bcast.in.interval = le32_to_cpu(interval);
- /* Convert ISO Interval (1.25 ms slots) to latency (ms) */
- bis->iso_qos.bcast.in.latency = le16_to_cpu(ev->interval) * 125 / 100;
+ /* Convert Transport Latency (us) to Latency (msec) */
+ bis->iso_qos.bcast.in.latency =
+ DIV_ROUND_CLOSEST(get_unaligned_le24(ev->latency),
+ 1000);
bis->iso_qos.bcast.in.sdu = le16_to_cpu(ev->max_pdu);

if (!ev->status) {
--
2.40.1


2024-04-16 10:57:19

by bluez.test.bot

[permalink] [raw]
Subject: RE: Bluetooth: hci_event: Fix setting of broadcast qos interval and latency

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=845006

---Test result---

Test Summary:
CheckPatch PASS 0.60 seconds
GitLint PASS 0.28 seconds
SubjectPrefix PASS 0.10 seconds
BuildKernel PASS 30.90 seconds
CheckAllWarning PASS 33.73 seconds
CheckSparse WARNING 42.95 seconds
CheckSmatch FAIL 37.49 seconds
BuildKernel32 PASS 29.91 seconds
TestRunnerSetup PASS 538.69 seconds
TestRunner_l2cap-tester PASS 18.36 seconds
TestRunner_iso-tester FAIL 33.38 seconds
TestRunner_bnep-tester PASS 4.67 seconds
TestRunner_mgmt-tester FAIL 109.90 seconds
TestRunner_rfcomm-tester PASS 7.27 seconds
TestRunner_sco-tester PASS 15.03 seconds
TestRunner_ioctl-tester PASS 7.70 seconds
TestRunner_mesh-tester FAIL 5.87 seconds
TestRunner_smp-tester PASS 6.72 seconds
TestRunner_userchan-tester PASS 4.83 seconds
IncrementalBuild PASS 28.16 seconds

Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:

Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: net/bluetooth/hci_core.o] Error 139
make[4]: *** Deleting file 'net/bluetooth/hci_core.o'
make[3]: *** [scripts/Makefile.build:485: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: net] Error 2
make[2]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bcm203x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bcm203x.o'
make[4]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bpa10x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bpa10x.o'
make[3]: *** [scripts/Makefile.build:485: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: drivers] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1919: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
Total: 122, Passed: 121 (99.2%), Failed: 1, Not Run: 0

Failed Test Cases
ISO Connect2 Suspend - Success Failed 6.244 seconds
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 492, Passed: 489 (99.4%), Failed: 1, Not Run: 2

Failed Test Cases
LL Privacy - Set Device Flag 1 (Device Privacy) Failed 0.130 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 9 (90.0%), Failed: 1, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1 Failed 0.095 seconds


---
Regards,
Linux Bluetooth

2024-04-16 14:32:19

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH 1/1] Bluetooth: hci_event: Fix setting of broadcast qos interval and latency

Hi Vlad,

On Tue, Apr 16, 2024 at 6:25 AM Vlad Pruteanu <[email protected]> wrote:
>
> The latency parameter of the broadcast qos is calculated wrongly.
>
> BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 6, Part G
>
> For framed PDUs:
> Transport_Latency_BIG = BIG_Sync_Delay + PTO x (NSE / BN -
> IRC) * ISO_Interval + ISO_Interval + SDU_Interval
>
> For unframed PDUs:
> Transport_Latency = BIG_Sync_Delay + (PTO x (NSE / BN - IRC) +
> 1) x ISO_Interval - SDU_Interval
>
> For broadcast sink the latency should be taken directly from the
> BIG Sync Established event and for the source it should be taken
> from the Create BIG Complete event.
>
> The interval parameter of the broadcast qos reffers to the SDU
> Interval and shouldn't be set based on the latency. The Host will
> read this value from the BASE.
>
> Signed-off-by: Vlad Pruteanu <[email protected]>
> ---
> net/bluetooth/hci_event.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
> index 868ffccff773..dff4bedc3e9b 100644
> --- a/net/bluetooth/hci_event.c
> +++ b/net/bluetooth/hci_event.c
> @@ -6983,6 +6983,8 @@ static void hci_le_create_big_complete_evt(struct hci_dev *hdev, void *data,
>
> if (!ev->status) {
> conn->state = BT_CONNECTED;
> + conn->iso_qos.bcast.out.latency =
> + DIV_ROUND_CLOSEST(get_unaligned_le24(ev->transport_delay), 1000);

You should probably add comments quoting the spec, also you quoted in
the description that framed vs unframed but then the code does not
attempt to differentiate, so perhaps that is not really important and
then we can remove it, the important part is what shall be used as
transport latency.

> set_bit(HCI_CONN_BIG_CREATED, &conn->flags);
> rcu_read_unlock();
> hci_debugfs_create_conn(conn);
> @@ -7029,7 +7031,6 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
>
> for (i = 0; i < ev->num_bis; i++) {
> u16 handle = le16_to_cpu(ev->bis[i]);
> - __le32 interval;
>
> bis = hci_conn_hash_lookup_handle(hdev, handle);
> if (!bis) {
> @@ -7044,11 +7045,10 @@ static void hci_le_big_sync_established_evt(struct hci_dev *hdev, void *data,
> set_bit(HCI_CONN_PA_SYNC, &bis->flags);
>
> bis->iso_qos.bcast.big = ev->handle;
> - memset(&interval, 0, sizeof(interval));
> - memcpy(&interval, ev->latency, sizeof(ev->latency));
> - bis->iso_qos.bcast.in.interval = le32_to_cpu(interval);
> - /* Convert ISO Interval (1.25 ms slots) to latency (ms) */
> - bis->iso_qos.bcast.in.latency = le16_to_cpu(ev->interval) * 125 / 100;
> + /* Convert Transport Latency (us) to Latency (msec) */
> + bis->iso_qos.bcast.in.latency =
> + DIV_ROUND_CLOSEST(get_unaligned_le24(ev->latency),
> + 1000);

Ditto as above.

> bis->iso_qos.bcast.in.sdu = le16_to_cpu(ev->max_pdu);
>
> if (!ev->status) {
> --
> 2.40.1
>


--
Luiz Augusto von Dentz