Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
efc12b8e
提交
efc12b8e
8月 27, 2007
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace yield system call with sleep.
上级
e1872bb1
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
52 行增加
和
26 行删除
+52
-26
defs.h
defs.h
+2
-0
syscall.c
syscall.c
+2
-2
syscall.h
syscall.h
+1
-1
sysproc.c
sysproc.c
+15
-2
trap.c
trap.c
+26
-16
trapasm.S
trapasm.S
+1
-1
user.h
user.h
+1
-0
usys.S
usys.S
+1
-1
zombie.c
zombie.c
+3
-3
没有找到文件。
defs.h
浏览文件 @
efc12b8e
...
...
@@ -139,7 +139,9 @@ void syscall(void);
// trap.c
void
idtinit
(
void
);
extern
int
ticks
;
void
tvinit
(
void
);
extern
struct
spinlock
tickslock
;
// number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
...
...
syscall.c
浏览文件 @
efc12b8e
...
...
@@ -102,10 +102,10 @@ extern int sys_open(void);
extern
int
sys_pipe
(
void
);
extern
int
sys_read
(
void
);
extern
int
sys_sbrk
(
void
);
extern
int
sys_sleep
(
void
);
extern
int
sys_unlink
(
void
);
extern
int
sys_wait
(
void
);
extern
int
sys_write
(
void
);
extern
int
sys_yield
(
void
);
static
int
(
*
syscalls
[])(
void
)
=
{
[
SYS_chdir
]
sys_chdir
,
...
...
@@ -124,10 +124,10 @@ static int (*syscalls[])(void) = {
[
SYS_pipe
]
sys_pipe
,
[
SYS_read
]
sys_read
,
[
SYS_sbrk
]
sys_sbrk
,
[
SYS_sleep
]
sys_sleep
,
[
SYS_unlink
]
sys_unlink
,
[
SYS_wait
]
sys_wait
,
[
SYS_write
]
sys_write
,
[
SYS_yield
]
sys_yield
,
};
void
...
...
syscall.h
浏览文件 @
efc12b8e
...
...
@@ -18,4 +18,4 @@
#define SYS_dup 17
#define SYS_getpid 18
#define SYS_sbrk 19
#define SYS_
yield
20
#define SYS_
sleep
20
sysproc.c
浏览文件 @
efc12b8e
...
...
@@ -70,8 +70,21 @@ sys_sbrk(void)
}
int
sys_
yield
(
void
)
sys_
sleep
(
void
)
{
yield
();
int
n
,
ticks0
;
if
(
argint
(
0
,
&
n
)
<
0
)
return
-
1
;
acquire
(
&
tickslock
);
ticks0
=
ticks
;
while
(
ticks
-
ticks0
<
n
){
if
(
cp
->
killed
){
release
(
&
tickslock
);
return
-
1
;
}
sleep
(
&
ticks
,
&
tickslock
);
}
release
(
&
tickslock
);
return
0
;
}
trap.c
浏览文件 @
efc12b8e
...
...
@@ -6,10 +6,13 @@
#include "x86.h"
#include "traps.h"
#include "syscall.h"
#include "spinlock.h"
// Interrupt descriptor table (shared by all CPUs).
struct
gatedesc
idt
[
256
];
extern
uint
vectors
[];
// in vectors.S: array of 256 entry pointers
struct
spinlock
tickslock
;
int
ticks
;
void
tvinit
(
void
)
...
...
@@ -19,6 +22,8 @@ tvinit(void)
for
(
i
=
0
;
i
<
256
;
i
++
)
SETGATE
(
idt
[
i
],
0
,
SEG_KCODE
<<
3
,
vectors
[
i
],
0
);
SETGATE
(
idt
[
T_SYSCALL
],
0
,
SEG_KCODE
<<
3
,
vectors
[
T_SYSCALL
],
DPL_USER
);
initlock
(
&
tickslock
,
"time"
);
}
void
...
...
@@ -47,21 +52,14 @@ trap(struct trapframe *tf)
// PAGEBREAK: 10
switch
(
tf
->
trapno
){
case
IRQ_OFFSET
+
IRQ_TIMER
:
lapic_timerintr
();
cpus
[
cpu
()].
nlock
--
;
if
(
cp
){
// Force process exit if it has been killed and is in user space.
// (If it is still executing in the kernel, let it keep running
// until it gets to the regular system call return.)
if
((
tf
->
cs
&
3
)
==
DPL_USER
&&
cp
->
killed
)
proc_exit
();
// Force process to give up CPU and let others run.
// If locks were held with interrupts on, would need to check nlock.
if
(
cp
->
state
==
RUNNING
)
yield
();
if
(
cpu
()
==
0
){
acquire
(
&
tickslock
);
ticks
++
;
wakeup
(
&
ticks
);
release
(
&
tickslock
);
}
return
;
lapic_eoi
();
break
;
case
IRQ_OFFSET
+
IRQ_IDE
:
ide_intr
();
...
...
@@ -75,6 +73,7 @@ trap(struct trapframe *tf)
case
IRQ_OFFSET
+
IRQ_SPURIOUS
:
cprintf
(
"spurious interrupt from cpu %d eip %x
\n
"
,
cpu
(),
tf
->
eip
);
lapic_eoi
();
break
;
default:
...
...
@@ -84,12 +83,23 @@ trap(struct trapframe *tf)
cp
->
pid
,
cp
->
name
,
tf
->
trapno
,
tf
->
err
,
cpu
(),
tf
->
eip
);
proc_exit
();
}
// Otherwise it's our mistake.
cprintf
(
"unexpected trap %d from cpu %d eip %x
\n
"
,
tf
->
trapno
,
cpu
(),
tf
->
eip
);
panic
(
"trap"
);
}
cpus
[
cpu
()].
nlock
--
;
if
(
tf
->
trapno
==
IRQ_OFFSET
+
IRQ_TIMER
&&
cp
!=
0
){
// Force process exit if it has been killed and is in user space.
// (If it is still executing in the kernel, let it keep running
// until it gets to the regular system call return.)
if
((
tf
->
cs
&
3
)
==
DPL_USER
&&
cp
->
killed
)
proc_exit
();
// Force process to give up CPU and let others run.
// If locks were held with interrupts on, would need to check nlock.
if
(
cp
->
state
==
RUNNING
)
yield
();
}
}
trapasm.S
浏览文件 @
efc12b8e
...
...
@@ -3,7 +3,7 @@
.globl trapret1
.globl alltraps
.set SEG_KDATA_SEL
0x10 # selector for SEG_KDATA
.set SEG_KDATA_SEL
,
0x10 # selector for SEG_KDATA
# vectors.S sends all traps here.
alltraps:
...
...
user.h
浏览文件 @
efc12b8e
...
...
@@ -18,6 +18,7 @@ int chdir(char*);
int
dup
(
int
);
int
getpid
();
char
*
sbrk
(
int
);
int
sleep
(
int
);
// ulib.c
int
stat
(
char
*
,
struct
stat
*
);
...
...
usys.S
浏览文件 @
efc12b8e
...
...
@@ -27,4 +27,4 @@ STUB(chdir)
STUB(dup)
STUB(getpid)
STUB(sbrk)
STUB(
yield
)
STUB(
sleep
)
zombie.c
浏览文件 @
efc12b8e
// Create a zombie process.
// Create a zombie process that
// must be reparented at exit.
#include "types.h"
#include "stat.h"
...
...
@@ -10,7 +11,6 @@ main(void)
int
i
;
if
(
fork
()
>
0
)
for
(
i
=
0
;
i
<
10
;
i
++
)
yield
();
sleep
(
5
);
// Let child exit before parent.
exit
();
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论