can: c_can: cache frames to operate as a true FIFO
Subsystems (3)
cover can: c_can: cache frames to operate as a true FIFO
Performance tests of the c_can driver led to the patch that gives the series its name. We have also added a patch for ethtool support and a patch to remove a variable that is no longer used.
Dario Binacchi (3):
can: c_can: remove the rxmasked unused variable
can: c_can: add ethtool support
can: c_can: cache frames to operate as a true FIFO
drivers/net/can/c_can/Makefile | 3 +
drivers/net/can/c_can/c_can.h | 6 +-
drivers/net/can/c_can/c_can_ethtool.c | 46 +++++++++++++
.../net/can/c_can/{c_can.c => c_can_main.c} | 65 +++++++++++++++----
4 files changed, 107 insertions(+), 13 deletions(-)
create mode 100644 drivers/net/can/c_can/c_can_ethtool.c
rename drivers/net/can/c_can/{c_can.c => c_can_main.c} (95%)Signature · 1 line
2.17.1
PATCH 1/3 can: c_can: remove the rxmasked unused variable
Initialized by c_can_chip_config() it's never used.
---
drivers/net/can/c_can/c_can.c | 1 - drivers/net/can/c_can/c_can.h | 1 - 2 files changed, 2 deletions(-)
drivers/net/can/c_can/c_can.c +0 -1
@@ -599,7 +599,6 @@ static int c_can_chip_config(struct net_device *dev)/* Clear all internal status */ atomic_set (&priv->tx_active,0 ); - priv->rxmasked =0 ; priv->tx_dir =0 ;/* set bittiming params */
drivers/net/can/c_can/c_can.h +0 -1
@@ -205,7 +205,6 @@ struct c_can_priv {struct c_can_raminit raminit_sys;/* RAMINIT via syscon regmap */ void (*raminit)(const struct c_can_priv *priv,bool enable);u32 comm_rcv_high; -u32 rxmasked;u32 dlc[]; };
Signature · 1 line
2.17.1
Marc Kleine-Budde
maintainerRe: [PATCH 1/3] can: c_can: remove the rxmasked unused variable
Quoted 3 lines · Dario Binacchi
Initialized by
c_can_chip_config()it's never used.Signed-off-by Dario Binacchi <[email protected]>
applied to linux-can-next/testing
thanks,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 2/3 can: c_can: add ethtool support
In reply to Dario BinacchiWith commit 132f2d45fb23 ("can: c_can: add support to 64 message objects") the number of message objects used for reception / transmission depends on FIFO size.
The ethtools API support allows you to retrieve this info. Driver info has been added too.
---
drivers/net/can/c_can/Makefile | 3 ++
drivers/net/can/c_can/c_can.h | 2 +
drivers/net/can/c_can/c_can_ethtool.c | 46 +++++++++++++++++++
.../net/can/c_can/{c_can.c => c_can_main.c} | 1 +
4 files changed, 52 insertions(+)
create mode 100644 drivers/net/can/c_can/c_can_ethtool.c
rename drivers/net/can/c_can/{c_can.c => c_can_main.c} (99%)drivers/net/can/c_can/Makefile +3 -0
@@ -4,5 +4,8 @@ # obj-$(CONFIG_CAN_C_CAN) += c_can.o + +c_can-objs := c_can_main.o c_can_ethtool.o + obj-$(CONFIG_CAN_C_CAN_PLATFORM) += c_can_platform.o obj-$(CONFIG_CAN_C_CAN_PCI) += c_can_pci.o
drivers/net/can/c_can/c_can.h +2 -0
@@ -218,4 +218,6 @@ int c_can_power_up(struct net_device *dev);int c_can_power_down (struct net_device *dev);#endif +void c_can_set_ethtool_ops (struct net_device *dev); +#endif /* C_CAN_H */
drivers/net/can/c_can/c_can_ethtool.c new file +46 -0
46 lines not on this page · raw message
drivers/net/can/c_can/c_can_main.c renamed from drivers/net/can/c_can/c_can.c +1 -0
@@ -1334,6 +1334,7 @@ int register_c_can_dev(struct net_device *dev) dev->flags |=IFF_ECHO ;/* we support local echo */ dev->netdev_ops = &c_can_netdev_ops; +c_can_set_ethtool_ops (dev); err =register_candev (dev);if (!err)
Signature · 1 line
2.17.1
Marc Kleine-Budde
maintainerRe: [PATCH 2/3] can: c_can: add ethtool support
drivers/net/can/c_can/c_can_ethtool.c line 41
Quoted 10 lines · Dario Binacchi
With commit
132f2d45fb23("can:c_can: add support to 64 message objects") the number of message objects used for reception / transmission depends on FIFO size.
The ethtools API support allows you to retrieve this info. Driver info has been added too.drivers/net/can/c_can/c_can_ethtool.c new file +4
-0+static const struct ethtool_ops c_can_ethtool_ops = { + .get_drvinfo = c_can_get_drvinfo, + .get_channels = c_can_get_channels, +};
I think you're filling the wrong information here. I think channels is for independent RX/TX channels. I think you want to implement get_ringparam.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH 3/3 can: c_can: cache frames to operate as a true FIFO
In reply to Dario BinacchiAs reported by a comment in the c_can_start_xmit() this was not a FIFO. C/D_CAN controller sends out the buffers prioritized so that the lowest buffer number wins.
What did c_can_start_xmit() do if it found tx_active = 0x80000000 ? It waited until the only frame of the FIFO was actually transmitted by the controller. Only one message in the FIFO but we had to wait for it to empty completely to ensure that the messages were transmitted in the order in which they were loaded.
By storing the frames in the FIFO without requiring its transmission, we will be able to use the full size of the FIFO even in cases such as the one described above. The transmission interrupt will trigger their transmission only when all the messages previously loaded but stored in less priority positions of the buffers have been transmitted.
---
drivers/net/can/c_can/c_can.h | 3 ++ drivers/net/can/c_can/c_can_main.c | 63 ++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 11 deletions(-)
drivers/net/can/c_can/c_can.h +3 -0
@@ -191,6 +191,9 @@ struct c_can_priv {unsigned int msg_obj_tx_last;u32 msg_obj_rx_mask;atomic_t tx_active; +atomic_t tx_cached; +spinlock_t tx_cached_lock; +atomic_t tx_avail;atomic_t sie_pending;unsigned long tx_dir;int last_status;
drivers/net/can/c_can/c_can_main.c +52 -11
109 lines not on this page · raw message
Signature · 1 line
2.17.1
Marc Kleine-Budde
maintainerQuoted 10 lines · Dario Binacchi
As reported by a comment in the
c_can_start_xmit()this was not a FIFO. C/D_CAN controller sends out the buffers prioritized so that the lowest buffer number wins.What did
c_can_start_xmit()do if it foundtx_active=0x80000000? It waited until the only frame of the FIFO was actually transmitted by the controller. Only one message in the FIFO but we had to wait for it to empty completely to ensure that the messages were transmitted in the order in which they were loaded.
Quoted 5 lines
By storing the frames in the FIFO without requiring its transmission, we will be able to use the full size of the FIFO even in cases such as the one described above. The transmission interrupt will trigger their transmission only when all the messages previously loaded but stored in less priority positions of the buffers have been transmitted.
The algorithm you implemented looks a bit too complicated to me. Let me sketch the algorithm that's implemented by several other drivers.
- have a power of two number of TX objects
- add a number of objects to struct priv (tx_num)
(or make it a define, if the number of tx objects is compile time fixed)
- add two "unsigned int" variables to your struct priv,
one "tx_head", one "tx_tail"
- the hard_start_xmit() writes to priv->tx_head & (priv->tx_num - 1)
- increment tx_head
- stop the tx_queue if there is no space or if the object with the lowest prio has been written
- in TX complete IRQ, handle priv->tx_tail object
- increment tx_tail
- wake queue if there is space but don't wake if we wait for the lowest prio object to be TX completed.
Special care needs to be taken to implement that lock-less and race free. I suggest to look the the mcp251xfd driver.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Marc Kleine-Budde
maintainerQuoted 34 lines · Marc Kleine-Budde
Quoted 10 lines · Dario Binacchi
As reported by a comment in the
c_can_start_xmit()this was not a FIFO. C/D_CAN controller sends out the buffers prioritized so that the lowest buffer number wins.What did
c_can_start_xmit()do if it foundtx_active=0x80000000? It waited until the only frame of the FIFO was actually transmitted by the controller. Only one message in the FIFO but we had to wait for it to empty completely to ensure that the messages were transmitted in the order in which they were loaded.Quoted 5 lines
By storing the frames in the FIFO without requiring its transmission, we will be able to use the full size of the FIFO even in cases such as the one described above. The transmission interrupt will trigger their transmission only when all the messages previously loaded but stored in less priority positions of the buffers have been transmitted.
The algorithm you implemented looks a bit too complicated to me. Let me sketch the algorithm that's implemented by several other drivers.
- have a power of two number of TX objects
- add a number of objects to struct priv (tx_num)
(or make it a define, if the number of tx objects is compile time fixed)
- add two "unsigned int" variables to your struct priv,
one "tx_head", one "tx_tail"
- thehard_start_xmit()writes topriv->tx_head& (priv->tx_num- 1)
- incrementtx_head
- stop thetx_queueif there is no space or if the object with the lowest prio has been written
- in TX complete IRQ, handlepriv->tx_tailobject
- incrementtx_tail
- wake queue if there is space but don't wake if we wait for the lowest prio object to be TX completed.
Quoted 2 lines
Special care needs to be taken to implement that lock-less and race free. I suggest to look the the mcp251xfd driver.
After converting the driver to the above outlined implementation it should be more straight forward to add the caching you implemented.
regards,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Marc,
Quoted 38 lines
Il 10/05/2021 14:36 Marc Kleine-Budde <[email protected]> ha scritto:
Quoted 34 lines · Marc Kleine-Budde
Quoted 10 lines · Dario Binacchi
As reported by a comment in the
c_can_start_xmit()this was not a FIFO. C/D_CAN controller sends out the buffers prioritized so that the lowest buffer number wins.What did
c_can_start_xmit()do if it foundtx_active=0x80000000? It waited until the only frame of the FIFO was actually transmitted by the controller. Only one message in the FIFO but we had to wait for it to empty completely to ensure that the messages were transmitted in the order in which they were loaded.Quoted 5 lines
By storing the frames in the FIFO without requiring its transmission, we will be able to use the full size of the FIFO even in cases such as the one described above. The transmission interrupt will trigger their transmission only when all the messages previously loaded but stored in less priority positions of the buffers have been transmitted.
The algorithm you implemented looks a bit too complicated to me. Let me sketch the algorithm that's implemented by several other drivers.
- have a power of two number of TX objects
- add a number of objects to struct priv (tx_num)
(or make it a define, if the number of tx objects is compile time fixed)
- add two "unsigned int" variables to your struct priv,
one "tx_head", one "tx_tail"
- thehard_start_xmit()writes topriv->tx_head& (priv->tx_num- 1)
- incrementtx_head
- stop thetx_queueif there is no space or if the object with the lowest prio has been written
- in TX complete IRQ, handlepriv->tx_tailobject
- incrementtx_tail
- wake queue if there is space but don't wake if we wait for the lowest prio object to be TX completed.
Quoted 6 lines
Quoted 2 lines
Special care needs to be taken to implement that lock-less and race free. I suggest to look the the mcp251xfd driver.
After converting the driver to the above outlined implementation it should be more straight forward to add the caching you implemented.
I took some time to think about your suggestions.
The submitted patch was developed trying to improve the CAN transmission using the current driver design for minimize the creation of bugs.
If I'm not missing something you suggest me to change the driver design as a pre-condition to apply an updated version of my patch. IMHO this would increase the possibility of generating bugs, even for parts of the code that are considered stable. If the algorithm I have implemented is a bit too complicated, let's try to simplify it starting from the submitted patch.
Waiting for your reply, thanks and regards
Dario
Quoted 8 lines
regards,
MarcSignature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |