【转载】Linux 进程调度时间测量
2024-09-27 22:21:43
测试Context Switch time(进程上下文切换时间)
--------------------------------------------------
创建两个进程(实时进程)并在它们之间传送一个令牌,如此往返传送一定的次数。其中一个进程在读取令牌时就会引起阻塞。另一个进程发送令牌后等待其返回时也处于阻塞状态。发送令牌带来的开销与上下文切换带来的开销相比,可以忽略不计。 (利用管道传递令牌)
测试程序(1) 使用gettimeofday()获取当前时间
--------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <sched.h>
#include <sys/types.h>
#include <unistd.h> //pipe() int main()
{
int x, i, fd[2], p[2];
char send = 's';
char receive;
pipe(fd);
pipe(p);
struct timeval tv;
struct sched_param param;
param.sched_priority = 0; while ((x = fork()) == -1);
if (x==0) {
sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
gettimeofday(&tv, NULL);
printf("Before Context Switch Time %u us\n", tv.tv_usec);
for (i = 0; i < 10000; i++) {
read(fd[0], &receive, 1);
write(p[1], &send, 1);
}
exit(0);
}
else {
sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
for (i = 0; i < 10000; i++) {
write(fd[1], &send, 1);
read(p[0], &receive, 1);
}
gettimeofday(&tv, NULL);
printf("After Context SWitch Time %u us\n", tv.tv_usec);
}
return 0;
}
最新文章
- PyAutoGUI 简介
- 真机测试无缘无故finish了。程序也没有启动
- Node.js&#160;的初步理解
- 将递归函数非递归化的一般方法(cont)
- SQL Server TVPs 批量插入数据
- 低延时的P2P HLS直播技术实践
- LeetCode 78 - 子集
- [UE4]Grabbable接口
- C语言编程漫谈——main函数
- SpringBoot Junit Maven JaCoCo
- JQUERY方法给TABLE动态增加行
- mongodb int字段的一个小坑
- POJ:2386 Lake Counting(dfs)
- Mysql 日期类型 date、datetime、timestamp.
- Spring3.x错误---- Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
- UBUNTU 下 APACHE2 Too many open files: Error retrieving pid file /var/run/apache2.pid
- VS2010中生成遇到的 web.config 问题
- 在windows中使用Navicat连接Linux虚拟机中的mysql数据库
- azkaban平台的使用
- php 当不确定用户输入的是浮点 还是整数 还是字符串时