Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
943fd378
提交
943fd378
10月 01, 2007
创建
作者:
rsc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Incorporate new understanding of/with Intel SMP spec.
Dropped cmpxchg in favor of xchg, to match lecture notes. Use xchg to release lock, for future protection and to keep gcc from acting clever.
上级
9fd9f804
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
25 行增加
和
36 行删除
+25
-36
TRICKS
TRICKS
+7
-1
main.c
main.c
+2
-1
proc.h
proc.h
+1
-1
spinlock.c
spinlock.c
+10
-9
x86.h
x86.h
+5
-24
没有找到文件。
TRICKS
浏览文件 @
943fd378
...
...
@@ -102,5 +102,11 @@ after observing the earlier writes by CPU0.
So any reads in B are guaranteed to observe the
effects of writes in A.
Not sure about the second one yet.
According to the Intel manual behavior spec, the
second condition requires a serialization instruction
in release, to avoid reads in A happening after giving
up lk. No Intel SMP processor in existence actually
moves reads down after writes, but the language in
the spec allows it. There is no telling whether future
processors will need it.
main.c
浏览文件 @
943fd378
...
...
@@ -50,8 +50,9 @@ mpmain(void)
if
(
cpu
()
!=
mp_bcpu
())
lapic_init
(
cpu
());
setupsegs
(
0
);
cpus
[
cpu
()].
booted
=
1
;
xchg
(
&
cpus
[
cpu
()].
booted
,
1
)
;
cprintf
(
"cpu%d: scheduling
\n
"
);
scheduler
();
}
...
...
proc.h
浏览文件 @
943fd378
...
...
@@ -56,7 +56,7 @@ struct cpu {
struct
context
context
;
// Switch here to enter scheduler
struct
taskstate
ts
;
// Used by x86 to find stack for interrupt
struct
segdesc
gdt
[
NSEGS
];
// x86 global descriptor table
volatile
int
booted
;
// Has the CPU started?
volatile
u
int
booted
;
// Has the CPU started?
int
ncli
;
// Depth of pushcli nesting.
int
intena
;
// Were interrupts enabled before pushcli?
};
...
...
spinlock.c
浏览文件 @
943fd378
...
...
@@ -10,12 +10,6 @@
extern
int
use_console_lock
;
// Barrier to gcc's instruction reordering.
static
void
inline
gccbarrier
(
void
)
{
asm
volatile
(
""
:
:
:
"memory"
);
}
void
initlock
(
struct
spinlock
*
lock
,
char
*
name
)
{
...
...
@@ -35,7 +29,10 @@ acquire(struct spinlock *lock)
if
(
holding
(
lock
))
panic
(
"acquire"
);
while
(
cmpxchg
(
0
,
1
,
&
lock
->
locked
)
==
1
)
// The xchg is atomic.
// It also serializes, so that reads after acquire are not
// reordered before it.
while
(
xchg
(
&
lock
->
locked
,
1
)
==
1
)
;
// Record info about lock acquisition for debugging.
...
...
@@ -56,8 +53,12 @@ release(struct spinlock *lock)
lock
->
pcs
[
0
]
=
0
;
lock
->
cpu
=
0xffffffff
;
gccbarrier
();
// Keep gcc from moving lock->locked = 0 earlier.
lock
->
locked
=
0
;
// The xchg serializes, so that reads before release are
// not reordered after it. (This reordering would be allowed
// by the Intel manuals, but does not happen on current
// Intel processors. The xchg being asm volatile also keeps
// gcc from delaying the above assignments.)
xchg
(
&
lock
->
locked
,
0
);
popcli
();
}
...
...
x86.h
浏览文件 @
943fd378
...
...
@@ -96,35 +96,16 @@ write_eflags(uint eflags)
asm
volatile
(
"pushl %0; popfl"
:
:
"r"
(
eflags
));
}
// XXX: Kill this if not used.
static
inline
void
cpuid
(
uint
info
,
uint
*
eaxp
,
uint
*
ebxp
,
uint
*
ecxp
,
uint
*
edxp
)
{
uint
eax
,
ebx
,
ecx
,
edx
;
asm
volatile
(
"cpuid"
:
"=a"
(
eax
),
"=b"
(
ebx
),
"=c"
(
ecx
),
"=d"
(
edx
)
:
"a"
(
info
));
if
(
eaxp
)
*
eaxp
=
eax
;
if
(
ebxp
)
*
ebxp
=
ebx
;
if
(
ecxp
)
*
ecxp
=
ecx
;
if
(
edxp
)
*
edxp
=
edx
;
}
static
inline
uint
cmpxchg
(
uint
oldval
,
uint
newval
,
volatile
uint
*
lock_addr
)
xchg
(
volatile
uint
*
addr
,
uint
newval
)
{
uint
result
;
// The + in "+m" denotes a read-modify-write operand.
asm
volatile
(
"lock;
cmpxchgl %2, %0
"
:
"+m"
(
*
lock_
addr
),
"=a"
(
result
)
:
"r"
(
newval
),
"1"
(
old
val
)
:
"cc"
);
asm
volatile
(
"lock;
xchgl %0, %1
"
:
"+m"
(
*
addr
),
"=a"
(
result
)
:
"1"
(
new
val
)
:
"cc"
);
return
result
;
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论