From: Andri Yngvason <andri.yngvason@marel.com>
To: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: linux-can@vger.kernel.org, david@protonic.nl
Subject: Re: [PATCH v2 02/12] can: rx-offload: Add support for timestamp based irq offloading
Date: Tue, 5 Jul 2016 11:58:51 +0000 [thread overview]
Message-ID: <20160705115851.GA13601@maxwell> (raw)
In-Reply-To: <4456cc74-7d85-c05e-fc86-af916ce0edb0@pengutronix.de>
On Tue, Jul 05, 2016 at 12:30:32AM +0200, Marc Kleine-Budde wrote:
> On 07/04/2016 10:59 PM, Marc Kleine-Budde wrote:
> > Actually I want to have the difference between two timestamps in order
> > to sort . The timestamps are monotonically increasing and will
> > eventually roll over. As the flexcan core only has a 16 bit timer, I
> > shift the timestamp by 16 bit (cb = reg_ts << 16), to fill the whole 32
> > bit. This way I don't have to take care about the overflow, right?
> >
Hmmm, yes, that is quite clever. If I understand correctly, this means that if
you have three timestamps on the roll-over boundary: 0xfffe0000, 0xffff0000 and
0x0001000, the sorting algorithm will sort them in this particular order because
(int)(0xfffe0000 - 0xffff0000) < 0
and
(int)(0xffff0000 - 0x00010000) < 0
Perhaps there should be a comment explaining this?
> >> main: a=0xfffffff0 b=0xfffffffc diff= 12
> >> main: a=0xfffffff0 b=0xfffffffd diff= 13
> >> main: a=0xfffffff0 b=0xfffffffe diff= 14
> >> main: a=0xfffffff0 b=0xffffffff diff= 15
> >> main: a=0xfffffff0 b=0x00000000 diff= 16
> >> main: a=0xfffffff0 b=0x00000001 diff= 17
> >> main: a=0xfffffff0 b=0x00000002 diff= 18
> >> main: a=0xfffffff0 b=0x00000003 diff= 19
> >> main: a=0xfffffff0 b=0x00000004 diff= 20
>
> It's also working when the difference is negative:
>
> > main: a=0xfffffffc b=0xfffffff0 diff=-12
> > main: a=0xfffffffd b=0xfffffff0 diff=-13
> > main: a=0xfffffffe b=0xfffffff0 diff=-14
> > main: a=0xffffffff b=0xfffffff0 diff=-15
> > main: a=0x00000000 b=0xfffffff0 diff=-16
> > main: a=0x00000001 b=0xfffffff0 diff=-17
> > main: a=0x00000002 b=0xfffffff0 diff=-18
> > main: a=0x00000003 b=0xfffffff0 diff=-19
>
> It will get "problematic" if the difference between the two u32 is
> around 2^31. But then it's hard to tell which of the mailboxes holds the
> older timestamp.
>
Yes, it's also safe to assume that if you ever get this much of a difference
between timestamps in the mailbox, something else must be wrong before that
happens.
I've run into bugs involving this kind of a comparison function where the
difference actually can be large enough to cause problems, so this was a red
flag for me, but it turns out to be OK.
Best regards,
Andri
next prev parent reply other threads:[~2016-07-05 16:33 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-04 18:32 [PATCH v2 00/12] can: rx-offload: add implmentation and switch flexcan driver to use it Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 01/12] can: rx-offload: Add support for HW fifo based irq offloading Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 02/12] can: rx-offload: Add support for timestamp " Marc Kleine-Budde
2016-07-04 18:49 ` Andri Yngvason
2016-07-04 20:59 ` Marc Kleine-Budde
2016-07-04 22:30 ` Marc Kleine-Budde
2016-07-05 11:58 ` Andri Yngvason [this message]
2016-07-05 12:40 ` Marc Kleine-Budde
2016-07-05 5:46 ` Alexander Stein
2016-07-05 6:19 ` Marc Kleine-Budde
2016-07-05 6:31 ` David Jander
2016-07-05 7:21 ` Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 03/12] can: flexcan: remove write-only member pdata of struct flexcan_priv Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 04/12] can: flexcan: make declaration of devtype_data const Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 05/12] can: flexcan: calculate default value for imask1 during runtime Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 06/12] can: flexcan: make TX mailbox selectable " Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 07/12] can: flexcan: make use of rx-offload's irq_offload_fifo Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 08/12] can: flexcan: add missing register definitions Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 09/12] can: flexcan: activate individual RX masking and initialize reg_rximr Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 10/12] can: flexcan: add quirk FLEXCAN_QUIRK_ENABLE_EACEN_RRS Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 11/12] can: flexcan: add support for timestamp based rx-offload Marc Kleine-Budde
2016-07-04 18:32 ` [PATCH v2 12/12] can: flexcan: switch imx6 and vf610 to timestamp based offloading Marc Kleine-Budde
2016-07-13 7:28 ` [PATCH v2 00/12] can: rx-offload: add implmentation and switch flexcan driver to use it Mirza Krak
2016-07-13 7:46 ` Marc Kleine-Budde
2016-09-07 6:33 ` Holger Schurig
2016-10-04 6:32 ` Holger Schurig
2016-10-04 11:57 ` Alexander Stein
2016-10-04 12:33 ` David Jander
2016-10-05 12:37 ` Alexander Stein
2016-11-30 14:22 ` Alexander Stein
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=20160705115851.GA13601@maxwell \
--to=andri.yngvason@marel.com \
--cc=david@protonic.nl \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
/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;
as well as URLs for NNTP newsgroup(s).