Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1240826ybb; Fri, 20 Mar 2020 16:20:17 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtmHCJLDJBmy5o2IXYQD1hpHH9VK7/+NoqbLLrQhCc3d4Pm1vuRehbm28HvQtCRw0Z7U9pl X-Received: by 2002:a9d:754e:: with SMTP id b14mr677102otl.293.1584746417176; Fri, 20 Mar 2020 16:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584746417; cv=none; d=google.com; s=arc-20160816; b=rv9heKdv9BW4gMAKFm1GWa7HSmvjZWJWhXKdi29CJvfAZ2toDOBwD6c6nC443KITCv q0Es+QpM3PwOBPmhQT2B2z/g1nAiCK8yfxmGTXwxNS7ktZLWEij8PrmIG5zUu1p1MqeG 4G7Tba59cSE2qyNeVCz565dBDAKiwwppHKfARk4gTBUIA34xHrvI8CK+V7RTnemaeFxv uxThpqWx7+Y7VZM5AWq986sTNrH5EX8EJi/lzOOcz0vtrK3sW8grp6GZAKy7tzRDQWeb 8KMemq21qKel+QswQ/7YuXVkE3USZoWdjmPdG0Rv7VI+TVhmqERML7egYKEmP25gNnjB bZAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JBbo2a0i4CpeeOBbaJAqxpqZkTg0B0uov6ptYoUJLXE=; b=TPplcBXM9LZaf5QTTA4ciucYW4LeRfUPpafaptmGhfjwKCHT2XShUmrQN18QFtgsC/ ZA5SZpR1gbUeSACwGZ+LlE67y9lXNxrF9QxDFC715cMT2/MRqzksH/6rX+dBGCBBIGD9 DPAZBxtw+sDGEsyoyTZlEhGNEvYk1QKfAUxUbXYdxc2qJJbbsiY0PrHcqweHiiIlF2CM mJCaQ/K0yHm+THILhR2iyuq4EK7IIuHOhGG00a85nAdEugN82T/suzRgdgapYSlZyQEo WDCQau1RLVdN9PT29tCb78AvPeJtPkQ2TMdCzj3aWKvkNknERsM2WLui2o07/IpBxmDX vvlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nTUt91ZE; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g8si3728420otg.126.2020.03.20.16.20.04; Fri, 20 Mar 2020 16:20:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nTUt91ZE; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727338AbgCTXTh (ORCPT + 99 others); Fri, 20 Mar 2020 19:19:37 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40999 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727334AbgCTXTh (ORCPT ); Fri, 20 Mar 2020 19:19:37 -0400 Received: by mail-pl1-f193.google.com with SMTP id t16so3136588plr.8 for ; Fri, 20 Mar 2020 16:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JBbo2a0i4CpeeOBbaJAqxpqZkTg0B0uov6ptYoUJLXE=; b=nTUt91ZEzn7KN+96nvAiwT5uJeEgtaFB6p/zLnXCPviaemLK3N6Rz9SbujG3zDvQxL i6iAKg68I+a+vYC5sGqSFLolNRnM+C9KLwK529/DTaVJH+grA8EA1PJP+20OGWW825rD yyIL+wuvLu/wj1YBafS8dlzz3teE8iQhI5ccE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JBbo2a0i4CpeeOBbaJAqxpqZkTg0B0uov6ptYoUJLXE=; b=KMPsn+oNXKuY0Rfk6eevVkR/KUJINrWhGy56LyvdSPxAQj3NGplKWzofXTIjv/Yf+n CfiM5/9j11dUIIFDH+Zu22w6rZTeLt0hpw794MHwYAVvDKfWDlZCM/FXgUxlFNQLEams QxEkexIy+GVDoIwpGWN7Xx7zisiKoW8ph2bIWJSsLhE599wiRhSYdYm+l21qELrkbNgB 5KlsXiZ6jxALHTyEmvK1WFRvEpZNg27SuQxNtRPwhKocX23CPfYsxQqNAiJ34Jf++Kec TVCQwG40wMVkPRdAELGst8q5v0CtTjs/P76ca9iFauaOPc5bmJZfSTMT7ePBzIsYnT1v 8mzw== X-Gm-Message-State: ANhLgQ130P1TSbRHRlRosbdu2NC3g1bpBUxfE85ee87VyzOZP1hp4wra Kf5w5VlK73d3qZ+5q8UDtmuNZg== X-Received: by 2002:a17:902:9a45:: with SMTP id x5mr10286830plv.296.1584746376114; Fri, 20 Mar 2020 16:19:36 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:e09a:8d06:a338:aafb]) by smtp.gmail.com with ESMTPSA id q26sm6530773pff.63.2020.03.20.16.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Mar 2020 16:19:35 -0700 (PDT) From: Abhishek Pandit-Subedi To: marcel@holtmann.org, linux-bluetooth@vger.kernel.org Cc: chromeos-bluetooth-upstreaming@chromium.org, Abhishek Pandit-Subedi , "David S. Miller" , Johan Hedberg , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jakub Kicinski Subject: [PATCH v2 1/1] Bluetooth: Prioritize SCO traffic Date: Fri, 20 Mar 2020 16:19:28 -0700 Message-Id: <20200320161922.v2.1.I17e2220fd0c0822c76a15ef89b882fb4cfe3fe89@changeid> X-Mailer: git-send-email 2.25.1.696.g5e7596f4ac-goog In-Reply-To: <20200320231928.137720-1-abhishekpandit@chromium.org> References: <20200320231928.137720-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When scheduling TX packets, send all SCO/eSCO packets first, check for pending SCO/eSCO packets after every ACL/LE packet and send them if any are pending. This is done to make sure that we can meet SCO deadlines on slow interfaces like UART. If we were to queue up multiple ACL packets without checking for a SCO packet, we might miss the SCO timing. For example: The time it takes to send a maximum size ACL packet (1024 bytes): t = 10/8 * 1024 bytes * 8 bits/byte * 1 packet / baudrate where 10/8 is uart overhead due to start/stop bits per byte Replace t = 3.75ms (SCO deadline), which gives us a baudrate of 2730666. At a baudrate of 3000000, if we didn't check for SCO packets within 1024 bytes, we would miss the 3.75ms timing window. Signed-off-by: Abhishek Pandit-Subedi --- Changes in v2: * Refactor to check for SCO/eSCO after each ACL/LE packet sent * Enabled SCO priority all the time and removed the sched_limit variable net/bluetooth/hci_core.c | 111 +++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 50 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index dbd2ad3a26ed..a29177e1a9d0 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -4239,6 +4239,60 @@ static void __check_timeout(struct hci_dev *hdev, unsigned int cnt) } } +/* Schedule SCO */ +static void hci_sched_sco(struct hci_dev *hdev) +{ + struct hci_conn *conn; + struct sk_buff *skb; + int quote; + + BT_DBG("%s", hdev->name); + + if (!hci_conn_num(hdev, SCO_LINK)) + return; + + while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) { + while (quote-- && (skb = skb_dequeue(&conn->data_q))) { + BT_DBG("skb %p len %d", skb, skb->len); + hci_send_frame(hdev, skb); + + conn->sent++; + if (conn->sent == ~0) + conn->sent = 0; + } + } +} + +static void hci_sched_esco(struct hci_dev *hdev) +{ + struct hci_conn *conn; + struct sk_buff *skb; + int quote; + + BT_DBG("%s", hdev->name); + + if (!hci_conn_num(hdev, ESCO_LINK)) + return; + + while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, + "e))) { + while (quote-- && (skb = skb_dequeue(&conn->data_q))) { + BT_DBG("skb %p len %d", skb, skb->len); + hci_send_frame(hdev, skb); + + conn->sent++; + if (conn->sent == ~0) + conn->sent = 0; + } + } +} + +static void hci_sched_sync(struct hci_dev *hdev) +{ + hci_sched_sco(hdev); + hci_sched_esco(hdev); +} + static void hci_sched_acl_pkt(struct hci_dev *hdev) { unsigned int cnt = hdev->acl_cnt; @@ -4270,6 +4324,9 @@ static void hci_sched_acl_pkt(struct hci_dev *hdev) hdev->acl_cnt--; chan->sent++; chan->conn->sent++; + + /* Send pending SCO packets right away */ + hci_sched_sync(hdev); } } @@ -4354,54 +4411,6 @@ static void hci_sched_acl(struct hci_dev *hdev) } } -/* Schedule SCO */ -static void hci_sched_sco(struct hci_dev *hdev) -{ - struct hci_conn *conn; - struct sk_buff *skb; - int quote; - - BT_DBG("%s", hdev->name); - - if (!hci_conn_num(hdev, SCO_LINK)) - return; - - while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) { - while (quote-- && (skb = skb_dequeue(&conn->data_q))) { - BT_DBG("skb %p len %d", skb, skb->len); - hci_send_frame(hdev, skb); - - conn->sent++; - if (conn->sent == ~0) - conn->sent = 0; - } - } -} - -static void hci_sched_esco(struct hci_dev *hdev) -{ - struct hci_conn *conn; - struct sk_buff *skb; - int quote; - - BT_DBG("%s", hdev->name); - - if (!hci_conn_num(hdev, ESCO_LINK)) - return; - - while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, - "e))) { - while (quote-- && (skb = skb_dequeue(&conn->data_q))) { - BT_DBG("skb %p len %d", skb, skb->len); - hci_send_frame(hdev, skb); - - conn->sent++; - if (conn->sent == ~0) - conn->sent = 0; - } - } -} - static void hci_sched_le(struct hci_dev *hdev) { struct hci_chan *chan; @@ -4436,6 +4445,9 @@ static void hci_sched_le(struct hci_dev *hdev) cnt--; chan->sent++; chan->conn->sent++; + + /* Send pending SCO packets right away */ + hci_sched_sync(hdev); } } @@ -4458,9 +4470,8 @@ static void hci_tx_work(struct work_struct *work) if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { /* Schedule queues and send stuff to HCI driver */ + hci_sched_sync(hdev); hci_sched_acl(hdev); - hci_sched_sco(hdev); - hci_sched_esco(hdev); hci_sched_le(hdev); } -- 2.25.1.696.g5e7596f4ac-goog