2021-03-10 16:13:16

by Vincent MAILHOL

[permalink] [raw]
Subject: [RFC PATCH v2 0/1] Allow drivers to modify dql.min_limit value

Abstract: would like to directly set dql.min_limit value inside a
driver to improve BQL performances of a CAN USB driver.

CAN packets have a small PDU: for classical CAN maximum size is
roughly 16 bytes (8 for payload and 8 for arbitration, CRC and
others).

I am writing an CAN driver for an USB interface. To compensate the
extra latency introduced by the USB, I want to group several CAN
frames and do one USB bulk send. To this purpose, I implemented BQL in
my driver.

However, the BQL algorithms can take time to adjust, especially if
there are small bursts.

The best way I found is to directly modify the dql.min_limit and set
it to some empirical values. This way, even during small burst events
I can have a good throughput. Slightly increasing the dql.min_limit
has no measurable impact on the latency as long as frames fit in the
same USB packet (i.e. BQL overheard is negligible compared to USB
overhead).

The BQL was not designed for USB nor was it designed for CAN's small
PDUs which probably explains why I am the first one to ever have
thought of using dql.min_limit within the driver.

The code I wrote looks like:

> #ifdef CONFIG_BQL
> netdev_get_tx_queue(netdev, 0)->dql.min_limit = <some empirical value>;
> #endif

Using #ifdef to set up some variables is not a best practice. I am
sending this RFC to see if we can add a function to set this
dql.min_limit in a more pretty way.

For your reference, this RFQ is a follow-up of a discussion on the
linux-can mailing list:
https://lore.kernel.org/linux-can/[email protected]/

Thank you for your comments.

Yours sincerely,
Vincent

** Changelog **

RFC v1 -> RFC v2
- Fix incorect #ifdef use.
Reference: https://lore.kernel.org/linux-can/[email protected]/

Link to RFC v1:
https://lore.kernel.org/linux-can/[email protected]/T/#t


Vincent Mailhol (1):
dql: add dql_set_min_limit()

include/linux/netdevice.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

--
2.26.2


2021-03-10 16:15:12

by Vincent MAILHOL

[permalink] [raw]
Subject: [RFC PATCH v2 1/1] netdev: add netdev_queue_set_dql_min_limit()

Add a function to set the dynamic queue limit minimum value.

This function is to be used by network drivers which are able to
prove, at least through empirical tests on several environment (with
other applications, heavy context switching, virtualization...), that
they constantly reach better performances with a specific predefined
dql.min_limit value with no noticeable latency impact.

Signed-off-by: Vincent Mailhol <[email protected]>
---

include/linux/netdevice.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ddf4cfc12615..7fceea9a202d 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -3389,6 +3389,23 @@ netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
}

+/**
+ * netdev_queue_set_dql_min_limit - set dql minimum limit
+ * @dev_queue: pointer to transmit queue
+ * @min_limit: dql minimum limit
+ *
+ * Forces xmit_more() to return true until the minimum threshold
+ * defined by @min_limit is reached. Warning: to be use with care,
+ * misuse will impact the latency.
+ */
+static inline void netdev_queue_set_dql_min_limit(struct netdev_queue *q,
+ unsigned int min_limit)
+{
+#ifdef CONFIG_BQL
+ q->dql.min_limit = min_limit;
+#endif
+}
+
/**
* netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
* @dev_queue: pointer to transmit queue
--
2.26.2