public inbox for linux-can@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Fabio Baltieri <fabio.baltieri@gmail.com>
Cc: linux-can@vger.kernel.org
Subject: Re: [RFC PATCH] can: add tx/rx led trigger support
Date: Wed, 11 Apr 2012 08:14:57 +0200	[thread overview]
Message-ID: <4F852161.90706@hartkopp.net> (raw)
In-Reply-To: <1334093965-2692-1-git-send-email-fabio.baltieri@gmail.com>

Hi Fabio,

at first i REALLY LIKE blinkenlights :-)

According to your implementation i have some remarks:

On 10.04.2012 23:39, Fabio Baltieri wrote:

> diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
> index 5d2efe7..76eb70c 100644
> --- a/include/linux/can/dev.h
> +++ b/include/linux/can/dev.h
> @@ -16,6 +16,8 @@
>  #include <linux/can.h>
>  #include <linux/can/netlink.h>
>  #include <linux/can/error.h>
> +#include <linux/timer.h>
> +#include <linux/leds.h>
>  
>  /*
>   * CAN mode
> @@ -52,6 +54,13 @@ struct can_priv {
>  
>  	unsigned int echo_skb_max;
>  	struct sk_buff **echo_skb;
> +
> +#ifdef CONFIG_CAN_LEDS
> +	struct timer_list tx_off_timer, rx_off_timer;
> +	struct led_trigger *tx_led, *rx_led;
> +	char tx_led_name[32], rx_led_name[32];
> +	atomic_t led_discard_count;
> +#endif
>  };


Why don't you add struct led_trigger directly here, as it makes the two
kzalloc calls in  can_led_init() obsolete?

Struct can_priv is allocated anyway and therefore you do not take care of the
removal of your privately allocated memory.

Now looking into the tx path LEDs as an example:

> +/* This is used to ignore devices not based on the can-dev framework */
> +static int rtnl_link_kind_is(struct net_device *netdev, const char *kind)
> +{
> +	if (netdev->rtnl_link_ops &&
> +		strncmp(kind, netdev->rtnl_link_ops->kind, strlen(kind)) == 0)
> +		return 1;
> +	else
> +		return 0;
> +}


You do this costly compare with *each* tx/rx CAN frame in the hot path.

Not very nice :-(

> +
> +void can_led_tx(struct net_device *netdev, int loop)
> +{
> +	struct can_priv *priv = netdev_priv(netdev);
> +
> +	if (!rtnl_link_kind_is(netdev, "can"))
> +		return;


See here.

> +
> +	if (unlikely(!priv->tx_led))
> +		return;
> +
> +	if (!timer_pending(&priv->tx_off_timer)) {
> +		led_trigger_event(priv->tx_led, LED_FULL);
> +
> +		mod_timer(&priv->tx_off_timer,
> +			jiffies + msecs_to_jiffies(led_off_delay));
> +	}
> +
> +	if (loop)
> +		atomic_dec(&priv->led_discard_count);
> +}
> +


As you pointed out that only CAN devices are supported that use the can-dev
infrastructure you do some costly checks one layer above (in net/can) instead
of implementing it on the driver layer (in drivers/net/can).

The only correct trigger for a tx-LED can be retrieved from the TX done
interrupt in the interrupt function like here:

http://lxr.linux.no/#linux+v3.3.1/drivers/net/can/sja1000/sja1000.c#L507

where the echo skb is sent back to the system.

This makes sure, that the tx-LED is only triggered, when there was a really
successful transmission on the CAN bus.

I wonder if it makes more sense to add the LED trigger stuff into
drivers/net/can/dev.c ?!?

Of course the correct calling points to trigger the rx/tx-LEDs need to be
implemented inside *each* driver at the correct position.

And we should probably add a new CAN netlink command here

	http://lxr.linux.no/#linux+v3.3.1/drivers/net/can/dev.c#L577

to configure the LED timer per interface: 0 -> LEDs off (==default)

The question would be, if this code

> +	if (!timer_pending(&priv->tx_off_timer)) {
> +		led_trigger_event(priv->tx_led, LED_FULL);
> +
> +		mod_timer(&priv->tx_off_timer,
> +			jiffies + msecs_to_jiffies(led_off_delay));
> +	}


is ready to be used in hard IRQ context?

If not we may use a construct with a tasklet that can be triggered from hard
IRQ context, like here:

	http://lxr.linux.no/#linux+v3.3.1/net/can/bcm.c#L356

I think this part

> +
> +	if (loop)
> +		atomic_dec(&priv->led_discard_count);
> +}

is becoming obsolete anyway then, right?

Regards,
Oliver


  reply	other threads:[~2012-04-11  6:14 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-10 21:39 [RFC PATCH] can: add tx/rx led trigger support Fabio Baltieri
2012-04-11  6:14 ` Oliver Hartkopp [this message]
2012-04-11 17:58   ` Fabio Baltieri
2012-04-11 18:29     ` Oliver Hartkopp
2012-04-11 18:58       ` Wolfgang Grandegger
2012-04-12  6:16         ` Oliver Hartkopp
2012-04-11 19:02     ` Oliver Hartkopp
2012-04-11 19:36       ` Fabio Baltieri
2012-04-12  6:05         ` Oliver Hartkopp
2012-04-12  6:32         ` Alexander Stein
2012-04-12 15:52           ` Oliver Hartkopp
2012-04-12 18:30             ` Fabio Baltieri
2012-04-13 19:00               ` Oliver Hartkopp
2012-04-12  7:37         ` Wolfgang Grandegger
2012-04-12 11:07           ` Martin Gysel
2012-04-12 16:02             ` Oliver Hartkopp
2012-04-12 16:13               ` Wolfgang Grandegger
2012-04-12 17:28                 ` Fabio Baltieri
2012-04-12 18:47                   ` Wolfgang Grandegger
2012-04-12 17:46           ` Fabio Baltieri
2012-04-12 18:53             ` Wolfgang Grandegger
2012-04-11  6:29 ` Alexander Stein
2012-04-11 18:03   ` Fabio Baltieri
2012-04-11 14:45 ` Wolfgang Grandegger
2012-04-11 16:24   ` Oliver Hartkopp
2012-04-11 19:11   ` Fabio Baltieri

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F852161.90706@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=fabio.baltieri@gmail.com \
    --cc=linux-can@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox