problem about usleep() on p1010rdb-pb

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

problem about usleep() on p1010rdb-pb

647 Views
tcguchengjie
Contributor II

Hello,I write a simple program to print time every 1ms.

#include <errno.h>

#include <signal.h>

#include <stdio.h>

#include <string.h>

#include <sys/resource.h>

#include <sys/time.h>

int main(void)

{

pid_t pid = getpid();

setpriority(PRIO_PROCESS, pid, -20);

while (1)

{

usleep(1000);

struct timeval t;

gettimeofday(&t, NULL);

printf("%u.%06u\n", t.tv_sec, t.tv_usec);

}

return 0;

}

while I get the following result.

......

1402463778.370107

1402463778.371202

1402463778.372297

1402463778.373393

1402463778.374487

1402463778.375582

1402463778.376677

1402463778.377772

1402463778.378893

1402463778.380010

1402463778.381105

1402463778.382199

1402463778.383293

1402463778.384388      ***********

1402463778.718214      ***********lost

1402463778.719311

1402463778.720407

1402463778.721502

1402463778.722597

1402463778.723691

1402463778.724786

1402463778.725896

1402463778.726992

......

about 300ms lost every 1s.Why?

Then I use setitimer() and pause()

struct itimerval tv; 

tv.it_interval.tv_sec = 0;

tv.it_interval.tv_usec = 1000;

tv.it_value.tv_sec = 0;

tv.it_value.tv_usec = 1000;

I get the following result.

1402465124.8487241402465124.851723

1402465124.852722

1402465124.854723

1402465124.855724

1402465124.856722

1402465124.858724

1402465124.860722

1402465124.862724

1402465124.863722

1402465124.865724

1402465124.866724

1402465124.869723

1402465124.870721     ******

1402465124.872723     ******lost

1402465124.873724

1402465124.874722

1402465124.8767231402465124.879724   ******output overlap

1402465124.880723

1402465124.881721

1402465124.883724

1402465124.884741

1402465124.885722

1402465124.888721

1402465124.890723

1402465124.891724

1402465124.892722

1402465124.8947241402465124.897723

lost and  output overlap.Why?

Thanks in advance for any help.

0 Kudos
3 Replies

565 Views
Pavel
NXP Employee
NXP Employee

Look at the following pages about testing of this patch and priority changing for your task.

https://lwn.net/Articles/146861/

https://events.linuxfoundation.org/sites/events/files/slides/toyooka_LCJ2014_v10.pdf

http://people.redhat.com/williams/latency-howto/rt-latency-howto.txt

https://rt.wiki.kernel.org/index.php/RT_PREEMPT_HOWTO


Have a great day,
Pavel Chubakov

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

565 Views
Pavel
NXP Employee
NXP Employee

Linux is not real-time operating system.

See the following pages:

https://en.wikipedia.org/wiki/Real-time_operating_system

http://www.ni.com/white-paper/3938/en/

See the following pages about differences between Linux and real-time operating system:

http://www.nxp.com/files/soft_dev_tools/doc/white_paper/CWLNXRTOSWP.pdf

http://www.embedded.com/design/operating-systems/4371651/Comparing-the-real-time-scheduling-policies...


Have a great day,
Pavel Chubakov

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

565 Views
tcguchengjie
Contributor II

well,I use the preempt_rt patch to make the os real-time.But it doesn't work.

0 Kudos