public inbox for linux-can@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: Mohamed HAMZAOUI <requinham@gmail.com>
Cc: Alexander Stein <alexander.stein@systec-electronic.com>,
	Kurt Van Dijck <kurt.van.dijck@eia.be>,
	Pavel Pisa <pisa@cmp.felk.cvut.cz>,
	Wolfgang Grandegger <wg@grandegger.com>,
	Linux-CAN <linux-can@vger.kernel.org>
Subject: Re: [SocketCan] Problem of accuracy
Date: Mon, 09 Jul 2012 19:08:37 +0200	[thread overview]
Message-ID: <4FFB1015.2000507@hartkopp.net> (raw)
In-Reply-To: <CABMxt4iBB4aP6STAbYcgCYyvOx-JAPnP48P1k=EMGsjQPmWN-Q@mail.gmail.com>

On 09.07.2012 17:39, Mohamed HAMZAOUI wrote:

>> I compared itimer with clock_nanosleep on an ARM board and noticed the signal
>> overhead of itimer is much bigger, resulting in a higher CPU usage, than
>> clock_nanosleep upon hrtimer.
>> So I ended up using clock_nanosleep adding a constant to the last timeout.
> 
> but my problem is that when i specify 1 ms of period i have 1.3ms and
> the problem is how to eliminate the 0.3ms. If i substitute 0.3 ms from
> all payload, what's the assurance that it does not change with CPU
> load  change ?
> 


Hello Mohamed,

have you ever tried your test with a virtual CAN interface?

http://lxr.linux.no/#linux+v3.4.4/Documentation/networking/can.txt#L606

#> modprobe vcan
#> ip link add dev vcan0 type vcan
#> ifconfig vcan0 up
#> cangen vcan0

gives on my second terminal somthing like this:

#> candump -td any
 (000.000000)  vcan0  595  [3] ED 26 C7
 (000.200149)  vcan0  105  [1] CF
 (000.200149)  vcan0  346  [8] F7 4F 39 1D AD F5 76 30
 (000.200184)  vcan0  1BC  [8] DC E8 0E 19 26 9C 7E 33
 (000.200142)  vcan0  685  [4] 52 9B 56 50
 (000.200147)  vcan0  446  [2] 5F FF
 (000.200149)  vcan0  208  [8] F5 42 36 0C 5E CD AD 4A
 (000.200141)  vcan0   8D  [2] 0F 22
 (000.200143)  vcan0  4D5  [8] 2E 87 7E 11 DA ED 43 61
 (000.200143)  vcan0  38E  [8] 67 AD 44 27 D4 1E B0 0B
(..)

cangen generates a frame every 200ms (see cangen -?) and 'candump -td any'
prints the delta timestamps. As cangen arms the timer after the frame has been
sent, the cycle is ~145 us away from the default of 200ms.


When using the in-kernel hrtimers by utilizing the broadcast manager (can_bcm)
with the tst-bcm-cycle test tool
(see http://svn.berlios.de/wsvn/socketcan/trunk/test/tst-bcm-cycle.c)

it looks like this:

#> candump -td any
 (000.000000)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.004206)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.500061)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.500068)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.500059)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.500057)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.500072)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.500062)  vcan2   42  [8] EF BE AD DE EF BE AD DE
 (000.500070)  vcan2   42  [8] EF BE AD DE EF BE AD DE
(..)

so with the bcm you have a delay of ~60us.

Here also the timer is armed after the frame is send with bcm_tx_op() see:
http://lxr.linux.no/#linux+v3.4.4/net/can/bcm.c#L356

Additionally the tasklet is invoked by the hrtimer in bcm_tx_timeout_handler()
some lines below.

But both of these offsets is are far away from your measurements.

Can you confirm these values with the virtual CAN interface on your system?
FYI my values have been picked on a core i7 M 640 @ 2.80GHz notebook ...

Regards,
Oliver

  reply	other threads:[~2012-07-09 17:08 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CABMxt4ijuTMYFYXx0n4AYBO6-=SRD0U3F4BTA2=rWE80Z4-yOA@mail.gmail.com>
2012-07-05  8:38 ` Problem of accuracy Oliver Hartkopp
2012-07-07 10:02   ` [SocketCan] " Mohamed HAMZAOUI
2012-07-07 10:32     ` Wolfgang Grandegger
2012-07-08 19:43       ` Mohamed HAMZAOUI
2012-07-08 20:13         ` Wolfgang Grandegger
2012-07-08 20:30           ` Mohamed HAMZAOUI
2012-07-09  7:18             ` Wolfgang Grandegger
2012-07-09  8:14               ` Mohamed HAMZAOUI
2012-07-09  8:20                 ` Wolfgang Grandegger
2012-07-09  9:19                   ` Mohamed HAMZAOUI
2012-07-09  9:22                     ` Wolfgang Grandegger
     [not found]                       ` <CABMxt4jnztXqAmLFcBnqp3001QXds1nX3xA2y_ka=xCNr0cjjA@mail.gmail.com>
     [not found]                         ` <4FFAB09F.6090800@grandegger.com>
     [not found]                           ` <CABMxt4jLRKz8xKNbH3Qa=P0k1aEjMsqmo2vArGDo2O1Wf0=wGQ@mail.gmail.com>
2012-07-09 11:26                             ` Fwd: " Mohamed HAMZAOUI
2012-07-09 11:40                             ` Wolfgang Grandegger
2012-07-09 11:57                               ` Mohamed HAMZAOUI
2012-07-09 12:15                                 ` Wolfgang Grandegger
2012-07-09 13:19                                 ` Pavel Pisa
2012-07-09 14:29                                   ` Mohamed HAMZAOUI
2012-07-09 14:35                                   ` Mohamed HAMZAOUI
2012-07-09 14:40                                   ` Kurt Van Dijck
2012-07-09 14:57                                     ` Alexander Stein
2012-07-09 15:39                                       ` Mohamed HAMZAOUI
2012-07-09 17:08                                         ` Oliver Hartkopp [this message]
2012-07-09 20:50                                         ` Wolfgang Grandegger
2012-07-10 22:11                                           ` Mohamed HAMZAOUI
2012-07-11 12:35                                             ` Mohamed HAMZAOUI
2012-07-11 22:22                                               ` Wolfgang Grandegger
2012-07-11 22:19                                             ` Wolfgang Grandegger
2012-07-09  6:55           ` Kurt Van Dijck
     [not found] ` <1341488146.2416.9.camel@slaptop>
2012-07-05 13:57   ` [Socketcan-users] back to back can frames Kurt Van Dijck

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=4FFB1015.2000507@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=alexander.stein@systec-electronic.com \
    --cc=kurt.van.dijck@eia.be \
    --cc=linux-can@vger.kernel.org \
    --cc=pisa@cmp.felk.cvut.cz \
    --cc=requinham@gmail.com \
    --cc=wg@grandegger.com \
    /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