From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Umair Ali <ali.umair@tut.fi>
Cc: "xenomai@xenomai.org" <xenomai@xenomai.org>
Subject: Re: [Xenomai] Loose determinism when reading pcap and sending as raw ethernet packets
Date: Tue, 8 Dec 2015 21:13:31 +0100 [thread overview]
Message-ID: <20151208201331.GA3667@hermes.click-hack.org> (raw)
In-Reply-To: <2396B4D2166B62479FBBE370D4A7C1F30A70DB46@mb2010-1.intra.tut.fi>
On Tue, Dec 08, 2015 at 05:25:21PM +0000, Umair Ali wrote:
> Hi there,
>
> I am reading the pcap file using the following technique:
> "
> mlockall(MCL_CURRENT|MCL_FUTURE);
> fd = open (file.pcap, O_RDONLY);
> status = fstat (fd, & s);
> size = s.st_size;
> /* Memory-map the file. */
> mapped = mmap (0, size, PROT_READ, MAP_PRIVATE, fd, 0);"
>
>
> Then i have the pcap file in mapped variable in the form of chracters (hex numbers). I read packet by packet and send them as raw packet over the network with following code:
> "struct timespec ts;
> ts.tv_sec = 0;
> ts.tv_nsec = 5000;
> j=24;
>
> while (j < size){
> i = (unsigned char) mapped[j + 8];
> sendto(sock, &mapped[j+16], i, 0,(struct sockaddr *)&peer, sizeof(peer));
> nanosleep(&ts, NULL);
> j = j+i+16;
> }
> "
>
> When i run the program and receive the packets on the receiver
> then i have observed that behaviour of sending raw packets is not
> constant. Sometimes nanosleep finish little late or quickly.
There are several problems with this program:
- for a program to run in primary mode only, pthread_setschedparam
should be called with a priority higher than 1 for the SCHED_FIFO
(or SCHED_RR) policy;
- when you call a function which returns a value, like send or
nanosleep, you should always check the return value for errors;
- if you want to send a message on average every 5us then
nanosleep(5us) is not what you should be using, you should be using
clock_nanosleep with an absolute date, or the easier but less
portable timerfd;
- what you observe is the jitter, you can measure the timer
interrupt jitter with the "latency" test, but I bet that maybe the
latency may be higher than 5us;
- if you really really need to reduce the jitter, then using kernel
timers instead of sleeping in a user-space thread is recommended,
see:
http://letsmakerobots.com/node/28812
http://letsmakerobots.com/node/32347
--
Gilles.
https://click-hack.org
next prev parent reply other threads:[~2015-12-08 20:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-08 17:25 [Xenomai] Loose determinism when reading pcap and sending as raw ethernet packets Umair Ali
2015-12-08 20:13 ` Gilles Chanteperdrix [this message]
2015-12-10 13:20 ` Umair Ali
2015-12-10 15:01 ` Gilles Chanteperdrix
2015-12-10 17:25 ` Umair Ali
2015-12-11 14:59 ` Gilles Chanteperdrix
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=20151208201331.GA3667@hermes.click-hack.org \
--to=gilles.chanteperdrix@xenomai.org \
--cc=ali.umair@tut.fi \
--cc=xenomai@xenomai.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.