Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
0dd42537
提交
0dd42537
7月 17, 2006
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ide_lock for sleep
上级
b5f17007
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
41 行增加
和
8 行删除
+41
-8
defs.h
defs.h
+3
-4
ide.c
ide.c
+7
-1
proc.c
proc.c
+12
-0
spinlock.c
spinlock.c
+13
-1
spinlock.h
spinlock.h
+2
-1
syscall.c
syscall.c
+4
-1
没有找到文件。
defs.h
浏览文件 @
0dd42537
...
@@ -61,10 +61,9 @@ int cpu(void);
...
@@ -61,10 +61,9 @@ int cpu(void);
// spinlock.c
// spinlock.c
struct
spinlock
;
struct
spinlock
;
void
acquire
(
struct
spinlock
*
lock
);
void
acquire
(
struct
spinlock
*
);
void
release
(
struct
spinlock
*
lock
);
void
release
(
struct
spinlock
*
);
void
acquire1
(
struct
spinlock
*
lock
,
struct
proc
*
);
int
holding
(
struct
spinlock
*
);
void
release1
(
struct
spinlock
*
lock
,
struct
proc
*
);
// main.c
// main.c
void
load_icode
(
struct
proc
*
p
,
uint8_t
*
binary
,
uint
size
);
void
load_icode
(
struct
proc
*
p
,
uint8_t
*
binary
,
uint
size
);
...
...
ide.c
浏览文件 @
0dd42537
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "proc.h"
#include "proc.h"
#include "defs.h"
#include "defs.h"
#include "x86.h"
#include "x86.h"
#include "spinlock.h"
#define IDE_BSY 0x80
#define IDE_BSY 0x80
#define IDE_DRDY 0x40
#define IDE_DRDY 0x40
...
@@ -23,6 +24,7 @@ struct ide_request {
...
@@ -23,6 +24,7 @@ struct ide_request {
};
};
struct
ide_request
request
[
NREQUEST
];
struct
ide_request
request
[
NREQUEST
];
int
head
,
tail
;
int
head
,
tail
;
struct
spinlock
ide_lock
;
static
int
diskno
=
0
;
static
int
diskno
=
0
;
int
disk_channel
;
int
disk_channel
;
...
@@ -107,12 +109,14 @@ void *
...
@@ -107,12 +109,14 @@ void *
ide_start_read
(
uint32_t
secno
,
void
*
dst
,
uint
nsecs
)
ide_start_read
(
uint32_t
secno
,
void
*
dst
,
uint
nsecs
)
{
{
struct
ide_request
*
r
;
struct
ide_request
*
r
;
if
(
!
holding
(
&
ide_lock
))
panic
(
"ide_start_read: not holding ide_lock"
);
if
(
nsecs
>
256
)
if
(
nsecs
>
256
)
panic
(
"ide_start_read: nsecs too large"
);
panic
(
"ide_start_read: nsecs too large"
);
while
((
head
+
1
)
%
NREQUEST
==
tail
)
while
((
head
+
1
)
%
NREQUEST
==
tail
)
sleep
(
&
disk_channel
,
0
);
sleep
(
&
disk_channel
,
&
ide_lock
);
r
=
&
request
[
head
];
r
=
&
request
[
head
];
r
->
secno
=
secno
;
r
->
secno
=
secno
;
...
@@ -132,6 +136,8 @@ ide_finish_read(void *c)
...
@@ -132,6 +136,8 @@ ide_finish_read(void *c)
int
r
=
0
;
int
r
=
0
;
struct
ide_request
*
req
=
(
struct
ide_request
*
)
c
;
struct
ide_request
*
req
=
(
struct
ide_request
*
)
c
;
if
(
!
holding
(
&
ide_lock
))
panic
(
"ide_start_read: not holding ide_lock"
);
for
(;
req
->
nsecs
>
0
;
req
->
nsecs
--
,
req
->
dst
+=
512
)
{
for
(;
req
->
nsecs
>
0
;
req
->
nsecs
--
,
req
->
dst
+=
512
)
{
if
((
r
=
ide_wait_ready
(
1
))
<
0
)
if
((
r
=
ide_wait_ready
(
1
))
<
0
)
break
;
break
;
...
...
proc.c
浏览文件 @
0dd42537
...
@@ -176,6 +176,15 @@ scheduler(void)
...
@@ -176,6 +176,15 @@ scheduler(void)
if
(
p
->
state
==
RUNNING
)
if
(
p
->
state
==
RUNNING
)
panic
(
"swtch to scheduler with state=RUNNING"
);
panic
(
"swtch to scheduler with state=RUNNING"
);
if
(
!
holding
(
&
proc_table_lock
)){
cprintf
(
"back to scheduler without proc_table_lock (pid=%d state=%d)"
,
p
->
pid
,
p
->
state
);
panic
(
"scheduler lock"
);
}
if
(
cpus
[
cpu
()].
nlock
!=
1
){
cprintf
(
"holding %d locks in scheduler (pid=%d state=%d)
\n
"
,
cpus
[
cpu
()].
nlock
,
p
->
pid
,
p
->
state
);
panic
(
"scheduler lock"
);
}
// XXX if not holding proc_table_lock panic.
// XXX if not holding proc_table_lock panic.
}
}
release
(
&
proc_table_lock
);
release
(
&
proc_table_lock
);
...
@@ -236,6 +245,9 @@ sleep(void *chan, struct spinlock *lk)
...
@@ -236,6 +245,9 @@ sleep(void *chan, struct spinlock *lk)
if
(
p
==
0
)
if
(
p
==
0
)
panic
(
"sleep"
);
panic
(
"sleep"
);
if
(
lk
==
0
)
panic
(
"sleep without lk"
);
// Must acquire proc_table_lock in order to
// Must acquire proc_table_lock in order to
// change p->state and then call sched.
// change p->state and then call sched.
// Once we hold proc_table_lock, we can be
// Once we hold proc_table_lock, we can be
...
...
spinlock.c
浏览文件 @
0dd42537
...
@@ -21,20 +21,32 @@ getcallerpc(void *v)
...
@@ -21,20 +21,32 @@ getcallerpc(void *v)
void
void
acquire
(
struct
spinlock
*
lock
)
acquire
(
struct
spinlock
*
lock
)
{
{
if
(
holding
(
lock
))
panic
(
"acquire"
);
if
(
cpus
[
cpu
()].
nlock
++
==
0
)
if
(
cpus
[
cpu
()].
nlock
++
==
0
)
cli
();
cli
();
while
(
cmpxchg
(
0
,
1
,
&
lock
->
locked
)
==
1
)
while
(
cmpxchg
(
0
,
1
,
&
lock
->
locked
)
==
1
)
;
;
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
lock
->
locker_pc
=
getcallerpc
(
&
lock
);
lock
->
pc
=
getcallerpc
(
&
lock
);
lock
->
cpu
=
cpu
();
}
}
void
void
release
(
struct
spinlock
*
lock
)
release
(
struct
spinlock
*
lock
)
{
{
if
(
!
holding
(
lock
))
panic
(
"release"
);
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
cpuid
(
0
,
0
,
0
,
0
,
0
);
// memory barrier
lock
->
locked
=
0
;
lock
->
locked
=
0
;
if
(
--
cpus
[
cpu
()].
nlock
==
0
)
if
(
--
cpus
[
cpu
()].
nlock
==
0
)
sti
();
sti
();
}
}
int
holding
(
struct
spinlock
*
lock
)
{
return
lock
->
locked
&&
lock
->
cpu
==
cpu
();
}
spinlock.h
浏览文件 @
0dd42537
struct
spinlock
{
struct
spinlock
{
uint
locked
;
uint
locked
;
uint
locker_pc
;
uint32_t
pc
;
int
cpu
;
};
};
syscall.c
浏览文件 @
0dd42537
...
@@ -228,17 +228,20 @@ sys_block(void)
...
@@ -228,17 +228,20 @@ sys_block(void)
char
buf
[
512
];
char
buf
[
512
];
int
i
,
j
;
int
i
,
j
;
void
*
c
;
void
*
c
;
extern
struct
spinlock
ide_lock
;
cprintf
(
"%d: call sys_block
\n
"
,
cpu
());
cprintf
(
"%d: call sys_block
\n
"
,
cpu
());
for
(
i
=
0
;
i
<
100
;
i
++
)
{
for
(
i
=
0
;
i
<
100
;
i
++
)
{
acquire
(
&
ide_lock
);
if
((
c
=
ide_start_read
(
i
,
buf
,
1
))
==
0
)
{
if
((
c
=
ide_start_read
(
i
,
buf
,
1
))
==
0
)
{
panic
(
"couldn't start read
\n
"
);
panic
(
"couldn't start read
\n
"
);
}
}
cprintf
(
"call sleep
\n
"
);
cprintf
(
"call sleep
\n
"
);
sleep
(
c
,
0
);
sleep
(
c
,
&
ide_lock
);
if
(
ide_finish_read
(
c
))
{
if
(
ide_finish_read
(
c
))
{
panic
(
"couldn't do read
\n
"
);
panic
(
"couldn't do read
\n
"
);
}
}
release
(
&
ide_lock
);
cprintf
(
"sector %d: "
,
i
);
cprintf
(
"sector %d: "
,
i
);
for
(
j
=
0
;
j
<
2
;
j
++
)
for
(
j
=
0
;
j
<
2
;
j
++
)
cprintf
(
"%x "
,
buf
[
j
]
&
0xff
);
cprintf
(
"%x "
,
buf
[
j
]
&
0xff
);
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论