From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.71 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796316176; b=qU0DvtOMGh/Gi482e3tgGm/UiGUm8q6R1APRI2MyZiSnqk2z86Jll882IVDWVUzj3Uk+ zDLPIEH/AwnpIk0t4UNN/eHjzIsmoXgalda/L0h3gz/uFniP+UJskyvMLAkeMC/+cFVuG sh5q5HN8rfoWncp99hoX98AKhp5c4mD4G07llgEw67VZV9jbw0d7H668Vm/CpPvPBcx3n zYvbVnpN48tVr/HITmTaedRKJ7pQtXyymb2RhLtnz8ZreN/7ICFSd9tT4Wlb2Cfk3POoN h/aSI5QKugrWCxOM/kD+xQnzHvqXe0q7quAWnzeK9lB0iM2NtcHMLPstlUpqilFCZzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796316176; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Received:Date:Mime-Version:X-Mailer:Message-ID: Subject:From:To:Cc:Content-Type:Content-Transfer-Encoding; bh=pWThLjs0DTBD3uXjlg+EiFYKiTVVimnQtK27mKEGWls=; b=Y7Lvr+/5gStLnbm5qBgUjgMlj+wfo8ByuTjaEvahSQZvb4TH6aAB2XWcF20ZLQNg1oz+ OlB95LzjO/VsQsvKpG3hFaB5FHfT+ZuoQ0E5fI9x5/CI8jVkzZFqVIPngWvyAsBaiCgs3 TfMFRjpqkgGpAbWnxTB8Ox/laqJnDt+1mZkXEMyI9Z82F9j4ujQDo+HoAwRdKcm33/ETF 2+f6ZsQnh7k11dc5OLXkEEdMoL8meIhI20b5rHlG0qn8BheSjiFRgNSmG/ZukmkDxXkj5 3OKAesVttem85gMGig4xYfjRf60ovu8Avnq24voVP1JG+4XpFeFSKULO0f5t9P+rUKA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--nauta.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bX8SQvUB; arc=none smtp.remote-ip=209.85.128.71 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13291606A334 for ; Thu, 3 Dec 2026 16:42:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 13291606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--nauta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=bX8SQvUB Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a1fdde384cso108318365e9.3 for ; Thu, 03 Dec 2026 08:42:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796316173; x=1796920973; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:mime-version:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=pWThLjs0DTBD3uXjlg+EiFYKiTVVimnQtK27mKEGWls=; b=bX8SQvUBspKVm6PeROMahoNbRwSxCaiYUtrDuo9CvbYhboMElUfwO6CnZttkMJG0u3 CiEs0jEYGGu8nNFJtVqi4qv60B9+y5Q19Y0k5J1inhksVilZY5V/1PntgQfQTRhsPmCy y3Jvv41G3i8O6cu1MSYbluUVR0ZiwN1cU4yU9pFbc7hJIRyZwuvBbymwaZZ3n5Mzcne8 7QVNz6AL/U2rx5cbMfKQri1ki6xEOtW0U/j4JZasYzuWLiauBQusAg4CcBZ4OOXrKVnp 8Sp+G8pgupqmXlOEBd4tWA7gNoHnAwtKj2UpwEWVlkxdbzdlCQeIXSiI2zwpTvznk0bM HaWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796316173; x=1796920973; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:mime-version:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=pWThLjs0DTBD3uXjlg+EiFYKiTVVimnQtK27mKEGWls=; b=FQVfQIBV5OnZeXXXp2MIUgvhDvQktPxyVBSOYnvUzjYXCfUEYbc5p4wIm6WHxsE0nN HBTUVLC1eyYC3ihzcr6r9MZd2AQAYS21k3ZmMRUgrUZRWicFC11jSJNg2VDCB62SKSag jFJpeF3DKQ7njp/SOS3Q3pk3cfGv1xIR3V0f96fXgkgYX9EtfZEj4Zy0AKbPHJ4SW+vk 6E96MliTeOoC3fd6zzbQsX4myAr52yCtr5VI2HOpJKpwkhygs1bqLZEV8yCi1Vf4PMOa fvT+tMIbBugVZS+WrthpzbAe+72ufi9Gy5W18MFeVm2An1ITwEpqvPQNnvMxWelPdjc/ Bl1A== X-Gm-Message-State: APuU4Z+IDvJjdIUI6IdZcwALeFOMkPH5l+t9X8e3kkDEMvUHCuyqQBlz lvyiCp94w/KP3/BfGkuaCUZS61hLU51Oeznisk++gqJEE0a2t0jnNHJkq6/FRJjxaGuHu8LmUnI d5qdlm4OsmKzTs0lYywmJ47DDA0npOA97u/ocaq1V8d+VU0mI2s3S536U0uL+PP4hZmpw3YhcRs LkV0L2CDKFzLiD3DJ4gBJKQt58758YCn4szObQLPJ5a8M= X-Received: from wmbje17.prod.google.com ([2002:a05:600c:1f91:b0:4bb:5e69:8177]) (user=nauta job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1548:b0:4bb:7347:d5df with SMTP id 5b1f17b1804b1-4bb88814405mr908598405e9.13.1796316173311; Thu, 03 Dec 2026 08:42:53 -0800 (PST) Date: Thu, 3 Dec 2026 16:42:24 +0000 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog Message-ID: <20261203164225.3278460-1-nauta@google.com> Subject: [PATCH BlueZ v2] midi: Fix stall when timestampHigh is zero From: Alessandro Parilli To: linux-bluetooth@vger.kernel.org Cc: Alessandro Parilli Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable append_timestamp_high_maybe() busy-waits until the high 6 bits of the 13-bit millisecond timestamp become non-zero. This was added by commit c29241fe129f ("midi: Fix random empty timestamp_high value") to avoid sending a header byte of 0x80, at the time the parser in this file treated a timestampHigh of 0 as "header not read yet". Commit 220f102c8db9 ("profiles/midi: Fix zero timestampHigh") fixed the parser, and the BLE MIDI specification allows a timestampHigh of 0 (the header is 0b10hhhhhh), so the workaround is no longer needed. It is also costly: the high bits are 0 for the first 128 ms of every 8.192 s timestamp period, so any packet started in that window makes bluetoothd spin in its main loop for up to 128 ms, sending and reading nothing. With MIDI clock (24 ppqn) sent to a synth over BLE this shows up every 8.192 s: a btmon capture at 100 BPM (one clock message every 25 ms) shows the outgoing ATT writes stopping for 135-152 ms each period, followed by a single packet carrying the 3 clock messages that queued up. Clock-following devices drift behind each time. Write the header from the current time once instead. Fixes: c29241fe129f ("midi: Fix random empty timestamp_high value") --- v2: explain why the loop was added (c29241fe129f) and why it is no longer needed since 220f102c8db9; add a Fixes: tag. No code change. profiles/midi/libmidi.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/profiles/midi/libmidi.c b/profiles/midi/libmidi.c index 349f5f7..d90f522 100644 --- a/profiles/midi/libmidi.c +++ b/profiles/midi/libmidi.c @@ -58,20 +58,18 @@ inline static uint8_t sysex_get(const snd_seq_event_t *= ev, size_t i) =20 inline static void append_timestamp_high_maybe(struct midi_write_parser *p= arser) { - uint8_t timestamp_high =3D 0x80; - if (midi_write_has_data(parser)) return; =20 - /* Make sure timesampt_high is assigned a non-zero value */ - do { - /* convert =C2=B5s to ms */ - parser->rtime =3D g_get_monotonic_time() / 1000; - timestamp_high |=3D (parser->rtime & 0x1F80) >> 7; - } while (timestamp_high =3D=3D 0x80); + /* convert =C2=B5s to ms */ + parser->rtime =3D g_get_monotonic_time() / 1000; =20 - /* set timestampHigh */ - buffer_append_byte(&parser->midi_stream, timestamp_high); + /* + * set timestampHigh: the header byte is 10hhhhhh and a timestampHigh + * of 0 (header 0x80) is valid. + */ + buffer_append_byte(&parser->midi_stream, + 0x80 | ((parser->rtime & 0x1F80) >> 7)); } =20 inline static void append_timestamp_low(struct midi_write_parser *parser) --=20 2.56.1.911.g883d8bcb20-goog