Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
ef3ccaee
提交
ef3ccaee
10月 27, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the PIT to time the CPU clock, use rdtsc to implement microdelay.
上级
5b532e09
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
54 行增加
和
13 行删除
+54
-13
Makefile
Makefile
+1
-1
amd64.h
amd64.h
+0
-6
hz.c
hz.c
+45
-0
kernel.h
kernel.h
+3
-0
main.c
main.c
+5
-6
没有找到文件。
Makefile
浏览文件 @
ef3ccaee
...
...
@@ -23,7 +23,6 @@ ASFLAGS = -m64 -gdwarf-2
LDFLAGS
+=
-m
elf_x86_64
OBJS
=
\
asm.o
\
bio.o
\
cga.o
\
condvar.o
\
...
...
@@ -33,6 +32,7 @@ OBJS = \
fs.o
\
ioapic.o
\
lapic.o
\
hz.o
\
kalloc.o
\
kbd.o
\
main.o
\
...
...
amd64.h
浏览文件 @
ef3ccaee
...
...
@@ -25,12 +25,6 @@ stosb(void *addr, int data, int cnt)
"memory"
,
"cc"
);
}
static
inline
void
microdelay
(
u32
delay
)
{
}
static
inline
u32
xchg32
(
volatile
u32
*
addr
,
u32
newval
)
{
...
...
hz.c
0 → 100644
浏览文件 @
ef3ccaee
// Intel 8253/8254/82C54 Programmable Interval Timer (PIT).
// http://en.wikipedia.org/wiki/Intel_8253
#include "types.h"
#include "amd64.h"
#define IO_TIMER1 0x040 // 8253 Timer #1
#define TIMER_FREQ 1193182
#define TIMER_CNTR (IO_TIMER1 + 0) // timer counter port
#define TIMER_MODE (IO_TIMER1 + 3) // timer mode port
#define TIMER_SEL0 0x00 // select counter 0
#define TIMER_TCOUNT 0x00 // mode 0, terminal count
#define TIMER_16BIT 0x30 // r/w counter 16 bits, LSB first
#define TIMER_STAT 0xe0 // read status mode
#define TIMER_STAT0 (TIMER_STAT | 0x2) // status mode counter 0
u64
cpuhz
;
void
microdelay
(
u64
delay
)
{
u64
tscdelay
=
(
cpuhz
*
delay
)
/
1000000
;
u64
s
=
rdtsc
();
while
(
rdtsc
()
-
s
<
tscdelay
)
nop_pause
();
}
void
inithz
(
void
)
{
// Setup PIT for terminal count starting from 2^16 - 1
u64
ticks
=
0x000000000000FFFFull
;
outb
(
TIMER_MODE
,
TIMER_SEL0
|
TIMER_TCOUNT
|
TIMER_16BIT
);
outb
(
IO_TIMER1
,
ticks
%
256
);
outb
(
IO_TIMER1
,
ticks
/
256
);
// Wait until OUT bit of status byte is set
u64
s
=
rdtsc
();
do
{
outb
(
TIMER_MODE
,
TIMER_STAT0
);
}
while
(
!
(
inb
(
TIMER_CNTR
)
&
0x80
));
u64
e
=
rdtsc
();
cpuhz
=
((
e
-
s
)
*
10000000
)
/
((
ticks
*
10000000
)
/
TIMER_FREQ
);
}
kernel.h
浏览文件 @
ef3ccaee
...
...
@@ -81,6 +81,9 @@ int dirlink(struct inode*, char*, u32);
void
dir_init
(
struct
inode
*
dp
);
void
dir_flush
(
struct
inode
*
dp
);
// hz.c
void
microdelay
(
u64
);
// ide.c
void
ideinit
(
void
);
void
ideintr
(
void
);
...
...
main.c
浏览文件 @
ef3ccaee
...
...
@@ -22,12 +22,10 @@ extern void initbio(void);
extern
void
initinode
(
void
);
extern
void
initdisk
(
void
);
extern
void
inituser
(
void
);
extern
void
inithz
(
void
);
static
volatile
int
bstate
;
// Common CPU setup code.
// Bootstrap CPU comes here from mainc().
// Other CPUs jump here from bootother.S.
void
mpboot
(
void
)
{
...
...
@@ -38,7 +36,6 @@ mpboot(void)
scheduler
();
// start running processes
}
// Start the non-boot processors.
static
void
bootothers
(
void
)
{
...
...
@@ -77,10 +74,12 @@ void
cmain
(
void
)
{
extern
pml4e_t
kpml4
[];
extern
u64
cpuhz
;
initpg
();
initseg
();
inittls
();
inittls
();
// thread local storage
inithz
();
// CPU Hz, microdelay
initpic
();
// interrupt controller
initioapic
();
inituart
();
...
...
@@ -97,7 +96,7 @@ cmain(void)
initinode
();
// inode cache
initdisk
();
// disk
cprintf
(
"ncpu %d
\n
"
,
ncpu
);
cprintf
(
"ncpu %d
%lu MHz
\n
"
,
ncpu
,
cpuhz
/
1000000
);
inituser
();
// first user process
bootothers
();
// start other processors
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论