Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17769
  • 博文数量: 4
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 30
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-09 21:20
文章分类
文章存档

2014年(4)

我的朋友

分类: 嵌入式

2014-04-23 22:22:56

    linux 系统调用times函数,参数返回进程的各种事件,函数返回值就返回实际运行的时间!
    在编程时,如果对times参数不使用的情况下,建议times传递NULL参数,可以提高系统性能!内核代码如下:

void do_sys_times(struct tms *tms)
{
 cputime_t tgutime, tgstime, cutime, cstime;

 spin_lock_irq(¤t->sighand->siglock);
 thread_group_times(current, &tgutime, &tgstime);
 cutime = current->signal->cutime;
 cstime = current->signal->cstime;
 spin_unlock_irq(¤t->sighand->siglock);
 tms->tms_utime = cputime_to_clock_t(tgutime);
 tms->tms_stime = cputime_to_clock_t(tgstime);
 tms->tms_cutime = cputime_to_clock_t(cutime);
 tms->tms_cstime = cputime_to_clock_t(cstime);
}

SYSCALL_DEFINE1(times, struct tms __user *, tbuf)
{
 if (tbuf) {
  struct tms tmp;

  do_sys_times(&tmp);
  if (copy_to_user(tbuf, &tmp, sizeof(struct tms)))
   return -EFAULT;
 }
 force_successful_syscall_return();
 return (long) jiffies_64_to_clock_t(get_jiffies_64());
}

当参数为NULL时,此时if语句就不会进去,系统就不会对该进程的所有线程进行扫描,从而提高性能!如果不传NULL,也可以直接
将if语句屏蔽。

阅读(2931) | 评论(0) | 转发(0) |
0

上一篇:嵌入式开发工具集合及资料(转载)

下一篇:没有了

给主人留下些什么吧!~~