Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4032787ybb; Mon, 23 Mar 2020 12:11:19 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuPHI8RrCvsPIEztVCC7KtPySwe6redpGejv0xlVbUeXTGaeEmZxTnQqkB03xuNGbdIBCEi X-Received: by 2002:aca:5f09:: with SMTP id t9mr689070oib.5.1584990679136; Mon, 23 Mar 2020 12:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584990679; cv=none; d=google.com; s=arc-20160816; b=BAAj2ONnugOkNqybEU11O09Fyz3WUkTYn4ssfK0R89avrnN1ENXFKS0tfCC+8o2rYB WCBr+pNhnVosNxvDLZAXIsPY/rpxdafm9xoFsmBN94fZmM7Q4tOOLDcNYfkc9cTbqUOr yjZ49urJGhQBRe5+7TXQChzWKqTCCNmmnAOf91zNlqbKcDbKF9xTZUPE8glnSkrXbFga N8MzuYvqot7GGRoMRjYtg2qlnbcXRae3caF2NSIyuW3k/oBEI+5+AZB0cFRI1LT78Mn/ GJJhMxzW140ktI+Anf/AjKHKUMKCWVQLwrinUOglTgVg2koqAi1EMOzfldtwNLa6h28D aCFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1tp3bC93e0nUfPggrmvnMYoBNQ6UWOR58w4LV4ZhNS0=; b=Gfp8RYyoavEL6E+RQIZHkUdEoYmhjJsn7FOwv+U+zosiZyDDAnOqdJQgsAIyrSsu0L Hvns3qU7DxDNvVm8QC7xuhwzGx/gEasNXn+04hCu3TtAH7Yqu7g19Moe3Th2Eh68An7F vZ7AK+amwKMgPhFljhFxaJVd4sMhOlWht1+wSAqCfrUHLYT45DZyU/7tUwB8hEdtyONe vBsXIyg3H7Tqaegq9OeLQYgujKV8VBfuusdpyJmQcaa4pCjTn6hsCSmlKArgNveXFPb7 Rg8/yZIYyNGqoEz85xu54ARojsRlnqucXyO/EKNzqba9ufC876GNeP6ncf43YPcuee3F 6XFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QZFAJNVn; 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 t28si366961ooc.16.2020.03.23.12.10.56; Mon, 23 Mar 2020 12:11:19 -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=QZFAJNVn; 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 S1727658AbgCWTKz (ORCPT + 99 others); Mon, 23 Mar 2020 15:10:55 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:34218 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727324AbgCWTKy (ORCPT ); Mon, 23 Mar 2020 15:10:54 -0400 Received: by mail-vs1-f67.google.com with SMTP id t10so9571329vsp.1 for ; Mon, 23 Mar 2020 12:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1tp3bC93e0nUfPggrmvnMYoBNQ6UWOR58w4LV4ZhNS0=; b=QZFAJNVnkEz6tJ6FzoGWo4cS0Tr0c2wT3Gyl8gMiNmkTeIqbKiWYsC2rYDsKnGt2e8 t0G0SzWlbvcpkKDxM0HH2DVdv5P7T3kTpraFDN528g94nBDdv0LJS3W0wP8SJBTPgyTD qgcvi04yAeh1TRoLfUD0Y6hp2xFWkCWWHiQaI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1tp3bC93e0nUfPggrmvnMYoBNQ6UWOR58w4LV4ZhNS0=; b=TY06HQs2eOtOnHffhK3b15G0t851TIxI3D6FO9vU6IwmibAxgTSBH8vsaQExdo6bsB asjHVbn9dkejHuWCKzWjJ7UAbmS+M1X9GQZbDTlNHylXinULyXkf+cKelsYZkn6SMdNI P4EvBBE92oQTSKsXKaeeMgKMwX/4mhpeCMZwBvZMroZpgLic3gM0VcL1vP5QXyjDGPgt Gn7kIaYVh2MUQwUv3XAU3jCeN9CKs5DTxdKZpEiI+sAgRWqOVQF+7oja+j6HI0tE8xud iTr6lBbbjf5hR2Jz6tcFoyJYErVWRD8MAr2oAF4oWToRKIh1aYO7KWO+HWVm/AXmPhrU 7aJg== X-Gm-Message-State: ANhLgQ2LwUFofh/kvIHiralcsdXmdGIdAL5Qk/gWSfRHrS3JmPcq+TMT V8ujDqW/HD/ylUqCczZ3cNTE2zjt/dUwTUr+Zw7xZw== X-Received: by 2002:a67:c01e:: with SMTP id v30mr17629845vsi.71.1584990652351; Mon, 23 Mar 2020 12:10:52 -0700 (PDT) MIME-Version: 1.0 References: <20200320231928.137720-1-abhishekpandit@chromium.org> <20200320161922.v2.1.I17e2220fd0c0822c76a15ef89b882fb4cfe3fe89@changeid> In-Reply-To: From: Abhishek Pandit-Subedi Date: Mon, 23 Mar 2020 12:10:40 -0700 Message-ID: Subject: Re: [PATCH v2 1/1] Bluetooth: Prioritize SCO traffic To: Marcel Holtmann Cc: Bluetooth Kernel Mailing List , ChromeOS Bluetooth Upstreaming , "David S. Miller" , Johan Hedberg , netdev , LKML , Jakub Kicinski Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Mon, Mar 23, 2020 at 11:58 AM Marcel Holtmann wrote: > > Hi Abhishek, > > > 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); > > +} > > + > > scrap this function. It has almost zero benefit. Done. > > > 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); > > hci_sched_esco(); > hci_sched_sco(); > > > } > > } > > > > @@ -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); > > Same as above. Just call the two functions. Done > > > } > > } > > > > @@ -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); > > I would actually just move _le up after _acl and then keep _sco and _esco at the bottom. The calls here are just for the case there are no ACL nor LE packets. Then we would send at least 1 ACL/LE packet before SCO even if there were SCO pending when we entered this function. I think it is still better to keep SCO/eSCO at the top. > > Regards > > Marcel >