Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483446
  • 博文数量: 118
  • 博客积分: 5003
  • 博客等级: 大校
  • 技术积分: 1213
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-07 20:29
文章存档

2011年(8)

2010年(4)

2009年(12)

2008年(85)

2007年(9)

我的朋友

分类: LINUX

2008-06-16 17:04:06

    linux的时钟精度能达到多少,任务的切换的精度能够达到多少,有人测试过吗,我今天写了一个测试程序来测试一下我们的这个系统的精度!

int main(int argc, char *argv[])
{
    int i,readlen,fd,start,end;
    char *cmd,*pra;
    char readbuf[400];
   unsigned   long   totalSpec=0; 
   struct   timeval   tvBeg,   tvEnd;  
    /*
    if(2>argc)
    {
        printf("less canshu!\n");
        return 1;
    }
    */
    pra=argv[1];
   
    /*串口设置*/   
    fd=open_port(fd,3);
    set_opt(fd,115200, 8,'N', 1);

    //printf("the g24-l is %sing",pra);

    while(1)
    {
      gettimeofday(&tvBeg,   NULL); 
        usleep(50000); 
      gettimeofday(&tvEnd,   NULL); 
        totalSpec=1000000*(tvEnd.tv_sec-tvBeg.tv_sec)+ tvEnd.tv_usec-tvBeg.tv_usec;
        printf("beg=%d\n",tvBeg.tv_usec); 
      printf("%d\n",   totalSpec);  
    }

    return 0;
}
运行的结果:
beg=887308
59781
beg=947309
59781
beg=7312
59775
beg=67304
59785
beg=127309
59780
beg=187306
59785
beg=247308
59782
beg=307309
59781
beg=367312
59778
beg=427311
59871
beg=487403
59728
beg=547351
59740
beg=607310
59784
beg=667317
59773
beg=727312
59783
beg=787314
59781
beg=847318
59777
beg=907317
59780
beg=967315
59794
beg=27328
59770
beg=87318
59780
beg=147319
59779
beg=207319
59778
beg=267318
59782

可以看出系统从工作到休眠,然后从休眠状态到唤醒消耗了时间将近10ms,这个我们能够忍受吗???我考虑系统中存在一个阻塞型的串口,一直占用这个串口设备,当没有数据被接收到的时候,程序就需要调用sleep函数来释放cpu给别的进程执行,那么我们sleep的时间准备多长了?
从这里看来,由于切换的消耗比较大,所以我们初步设想将sleep时间设置为500ms,应该不用担心因此会丢失数据,因为接收数据和发送数据都是使用中断来完成的,只要dma的缓冲区不出现溢出的情况,就能完全正常。。。。
 
阅读(1335) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~