提交 f844189d 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

time, in terms of hw cycles

上级 289a4b72
......@@ -88,6 +88,8 @@ UPROGS= \
_sh \
_thrtest \
_halt \
_time \
_sleep \
_usertests
UPROGS := $(addprefix $(O)/, $(UPROGS))
......
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "amd64.h"
int
main(void)
main(int ac, char *av[])
{
int i;
for (i = 0; i < 10000000; i++) {
sleep(1);
if (ac != 2) {
printf(1, "Usage: %s ticks\n", av[0]);
exit();
}
sleep(atoi(av[1]));
exit();
}
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "amd64.h"
int
main(int ac, char *av[])
{
u64 t0 = rdtsc();
int pid = fork(0);
if (pid < 0) {
printf(1, "time: fork failed\n");
exit();
}
if (pid == 0) {
exec(av[1], av+1);
printf(1, "time: exec failed\n");
exit();
}
wait();
u64 t1 = rdtsc();
printf(1, "%lu cycles\n", t1-t0);
exit();
}
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论