Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1034282lqg; Sat, 2 Mar 2024 12:08:01 -0800 (PST) X-Forwarded-Encrypted: i=4; AJvYcCVTnMY0ARJ2N1lBsH1rw6TdjJ82JO5iTknxEs8W/ojMefOrMUzRqFk6ILciZvOEEeWHTnc4g0lqUlinUmt/Fh7ubBZZbkFNwd2PoAq/fQ== X-Google-Smtp-Source: AGHT+IER1ZRoaD3nOExHTfbRP4JuYfhP1HWGfdWUJN2WYFMhr+B/kzmIVKzDmRn7Gngle0pMZFYn X-Received: by 2002:a05:6a20:e545:b0:1a1:2cba:baf0 with SMTP id nf5-20020a056a20e54500b001a12cbabaf0mr7405890pzb.25.1709410081433; Sat, 02 Mar 2024 12:08:01 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1709410081; cv=pass; d=google.com; s=arc-20160816; b=0huzyAUYRyT4mOhtO1eaf1bvNJIkDWT7AmwGb+L5NrYZfuxTnoKeVa3SYt52GSip5C zSNzPj0LwVKETfnQywsqiGo12lw9kJpAJRO9T3GRmWzXxJPchWGaqBSxpYz3wckT2JuN iKLyyksXFxvz+5TAP9Es8OG/FH7Bm/hoaN8I7/1Gnyj3GTI4AY8MTjRrkqe82ouCcFIO YugUclGq4dGvIVnhodXd9n56OM2TxCINzEKAZROnjpSZXlMF5E/lFcawlbscZ3qSO3zO 6OrjA7hCRXjtyAQI0YgoA242w/arvXJg6bYrr4zncjW0B1ppaiD2qy669xtZdXmUO/gj i1Kg== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=An/mj6d1gOGyrMkwQ6JKMbWIX5kfocAe+0oQz/NspZ0=; fh=ExGhjNQEFJgRqHmYATVc5UXZbS7abAmaHDitrfHKOuE=; b=EtN71JmsJmg91FpbGZZqk64H07sUInjIi7Auf4o2nx5/m0jHcck6gUCK+yYbk2lWol 3YIZkx8XY6kahsGKPmnmSz6LKeg35S9X0NWQxeMBaRJCxLdCYvKXtlGWqqo5x/sPSGch e93rs+OqKIZzwPycS0fiz97tpRU7COH+NfjhvO/cJpU/5gJT5Qc+DVji0vFQJRY8b+Br Ate0n+SCXnGAi0PRL0wucYyl/GThgVx9wDfgY5pz3O/5nSyhkRHbQb5kp5V9kXE/x1jy ctp2UnaOc4gsnBFfufe6WLnEmeq+CIec8e44z/X1lvNfd27HgIAjMoL3lA1prl+7ReyL 8tlA==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@iki.fi header.s=meesny header.b=dPUXuXgH; arc=pass (i=2 spf=pass spfdomain=iki.fi dkim=pass dkdomain=iki.fi); spf=pass (google.com: domain of linux-bluetooth+bounces-2254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2254-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c27-20020a631c1b000000b005d7bf204e26si5930516pgc.899.2024.03.02.12.08.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 12:08:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-2254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@iki.fi header.s=meesny header.b=dPUXuXgH; arc=pass (i=2 spf=pass spfdomain=iki.fi dkim=pass dkdomain=iki.fi); spf=pass (google.com: domain of linux-bluetooth+bounces-2254-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-2254-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 197AD283340 for ; Sat, 2 Mar 2024 20:08:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9274740866; Sat, 2 Mar 2024 20:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="dPUXuXgH" X-Original-To: linux-bluetooth@vger.kernel.org Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B28C8405CB for ; Sat, 2 Mar 2024 20:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410072; cv=pass; b=gwQuHO8vB9QyBXIPm0CFfApLBNZfiD0UcPFDYXTslA+hrjrKFOwqzDaXXj2mD2t+cdpV5sa9jpur3q9YuLVeIuHHLdKZZEGqI9woOp1T7G3KlqzFy47w/rSkk1AFdW23nJOV18LgXQNY7HS4xd8eiJrEhIs8SpWr9Ej/KykT9dA= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410072; c=relaxed/simple; bh=ROFbXOLH3jHR0dXu+krzdnYD20zsq9MJmvsRKJnOHu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tvHeueacD0sl+0nWFnH8MdOzJB82Dw9npAiATDWZuCi9FcG7V46TFIyqFLyvmC+p8tgMrgMhS8sUe1t6SJXEyTiC5Grjba9ERYfMNbe4Muxms42bYsjB7h33JmHiWr9115ScnU5cMGJUs2QCJHK6pVdOmgUoazxY70W4NZ5zQFA= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=dPUXuXgH; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Received: from monolith.lan (unknown [193.138.7.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4TnGGW4mM4z100r; Sat, 2 Mar 2024 22:07:47 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=An/mj6d1gOGyrMkwQ6JKMbWIX5kfocAe+0oQz/NspZ0=; b=dPUXuXgHFtwegrRPFvBOzVhuNi1j8CYgK1uL7955JVaXtX8WBCJkRslEgOhZNETc6M9TI/ P4Sg5/oUSq8dyMSiz3e5NwLM7HqXLZXNPQ2mNLMPDKWnuAbkbyDY44s6oVHWR5ySqgW0t+ qWHFHklwCgd57EXSnCqdJ40iK0pfctA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=An/mj6d1gOGyrMkwQ6JKMbWIX5kfocAe+0oQz/NspZ0=; b=Qa89ptPTpHMlMKVyI+O2KLD3a0OLPboUDvsnJdg8DyFHgvfQqJZTm5aEGWXmZw23Wnwf1F M2EDTIAI9J8PxzbrsNYRU3ajjLHFFUdI2cYHsKTcCs6AB/mKNuUH4YJCMrq6ek7kuUGqcX rqFZFvGgbTYlZnVIi54sDvVaERZAMiQ= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1709410068; a=rsa-sha256; cv=none; b=CTp9sGCG4dXnaOCRt3svo8RezEruSHEr8zfAVBpiK7uaojqHX6By37ao8CvGD3zUU0m8dI PBTD1zVX0FmqYANMOQtaX6Ipke9sh6box3LxOt5jnT+4aeKkolXTyyVXs4sVRvcEuOVfC9 ij+Owx0FanCnBiRjiL+6wYU1UDEsFzQ= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH 1/3] Bluetooth: add support for skb TX timestamping Date: Sat, 2 Mar 2024 22:07:36 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Support enabling TX timestamping for some skbs, and track them until packet completion. Generate SCM_TSTAMP_SCHED when sending to driver, and SCM_TSTAMP_SND at packet completion. Make the default situation with no TX timestamping more efficient by only counting packets in the queue when there is nothing to track. When there is something to track, we need to make clones, since the driver may modify sent skbs. Signed-off-by: Pauli Virtanen --- include/net/bluetooth/hci_core.h | 12 +++++ net/bluetooth/hci_conn.c | 78 ++++++++++++++++++++++++++++++++ net/bluetooth/hci_core.c | 5 ++ net/bluetooth/hci_event.c | 4 ++ 4 files changed, 99 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 56fb42df44a3..51b556612a6b 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -267,6 +267,12 @@ struct adv_info { struct delayed_work rpa_expired_cb; }; +struct tx_comp_queue { + struct sk_buff_head queue; + unsigned int extra; + unsigned int tracked; +}; + #define HCI_MAX_ADV_INSTANCES 5 #define HCI_DEFAULT_ADV_DURATION 2 @@ -763,6 +769,8 @@ struct hci_conn { struct sk_buff_head data_q; struct list_head chan_list; + struct tx_comp_queue tx_comp_queue; + struct delayed_work disc_work; struct delayed_work auto_accept_work; struct delayed_work idle_work; @@ -1546,6 +1554,10 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); void hci_conn_failed(struct hci_conn *conn, u8 status); u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle); +void hci_conn_tx_comp_queue(struct hci_conn *conn, struct sk_buff *skb); +void hci_conn_tx_comp_dequeue(struct hci_conn *conn); +void hci_tx_timestamp(struct sk_buff *skb, const struct sockcm_cookie *sockc); + /* * hci_conn_get() and hci_conn_put() are used to control the life-time of an * "hci_conn" object. They do not guarantee that the hci_conn object is running, diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 3ad74f76983b..f44d4b8fa0c6 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -973,6 +974,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, } skb_queue_head_init(&conn->data_q); + skb_queue_head_init(&conn->tx_comp_queue.queue); INIT_LIST_HEAD(&conn->chan_list); INIT_LIST_HEAD(&conn->link_list); @@ -1117,6 +1119,7 @@ void hci_conn_del(struct hci_conn *conn) } skb_queue_purge(&conn->data_q); + skb_queue_purge(&conn->tx_comp_queue.queue); /* Remove the connection from the list and cleanup its remaining * state. This is a separate function since for some cases like @@ -2928,3 +2931,78 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason) return hci_cmd_sync_queue_once(hdev, abort_conn_sync, conn, NULL); } + +void hci_tx_timestamp(struct sk_buff *skb, const struct sockcm_cookie *sockc) +{ + /* This shall be called on a single skb of those generated by user + * sendmsg(), and only when the sendmsg() does not return error to + * user. This is required for keeping the tskey that increments here in + * sync with possible sendmsg() counting by user. + */ + + if (!skb || !sockc) + return; + + skb_setup_tx_timestamp(skb, sockc->tsflags); +} + +void hci_conn_tx_comp_queue(struct hci_conn *conn, struct sk_buff *skb) +{ + struct tx_comp_queue *comp = &conn->tx_comp_queue; + bool track = false; + + if (skb->sk) { + if (skb_shinfo(skb)->tx_flags & SKBTX_SCHED_TSTAMP) + __skb_tstamp_tx(skb, NULL, NULL, skb->sk, + SCM_TSTAMP_SCHED); + + if (skb_shinfo(skb)->tx_flags & SKBTX_SW_TSTAMP) + track = true; + } + + /* If nothing is tracked, just count extra skbs at the queue head */ + if (!track && !comp->tracked) { + comp->extra++; + return; + } + + if (track) { + skb = skb_clone_sk(skb); + if (!skb) + return; + + comp->tracked++; + } else { + skb = skb_clone(skb, GFP_KERNEL); + if (!skb) + return; + } + + skb_queue_tail(&comp->queue, skb); +} + +void hci_conn_tx_comp_dequeue(struct hci_conn *conn) +{ + struct tx_comp_queue *comp = &conn->tx_comp_queue; + struct sk_buff *skb; + + /* If there are tracked skbs, the counted extra go before dequeuing real + * skbs, to keep ordering. When nothing is tracked, the ordering doesn't + * matter so dequeue real skbs first to get rid of them ASAP. + */ + if (comp->extra && (comp->tracked || skb_queue_empty(&comp->queue))) { + comp->extra--; + return; + } + + skb = skb_dequeue(&comp->queue); + if (!skb) + return; + + if (skb->sk) { + comp->tracked--; + skb_tstamp_tx(skb, NULL); + } + + kfree_skb(skb); +} diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index df3aa41e376d..f4af6e99d798 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3715,6 +3715,8 @@ static void hci_sched_acl_pkt(struct hci_dev *hdev) hci_conn_enter_active_mode(chan->conn, bt_cb(skb)->force_active); + hci_conn_tx_comp_queue(chan->conn, skb); + hci_send_frame(hdev, skb); hdev->acl_last_tx = jiffies; @@ -3876,6 +3878,9 @@ static void hci_sched_iso(struct hci_dev *hdev) while (*cnt && (conn = hci_low_sent(hdev, ISO_LINK, "e))) { while (quote-- && (skb = skb_dequeue(&conn->data_q))) { BT_DBG("skb %p len %d", skb, skb->len); + + hci_conn_tx_comp_queue(conn, skb); + hci_send_frame(hdev, skb); conn->sent++; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index bffd2c7ff608..f56211d8ff7a 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4438,6 +4438,7 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data, struct hci_comp_pkts_info *info = &ev->handles[i]; struct hci_conn *conn; __u16 handle, count; + unsigned int i; handle = __le16_to_cpu(info->handle); count = __le16_to_cpu(info->count); @@ -4448,6 +4449,9 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data, conn->sent -= count; + for (i = 0; i < count; ++i) + hci_conn_tx_comp_dequeue(conn); + switch (conn->type) { case ACL_LINK: hdev->acl_cnt += count; -- 2.44.0