Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
e91ed64d
提交
e91ed64d
2月 06, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Track lock contends
上级
21daa928
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
20 行增加
和
13 行删除
+20
-13
lockstat.c
lockstat.c
+8
-6
lockstat.h
lockstat.h
+2
-0
spinlock.c
spinlock.c
+10
-7
没有找到文件。
lockstat.c
浏览文件 @
e91ed64d
...
@@ -24,7 +24,7 @@ stats(void)
...
@@ -24,7 +24,7 @@ stats(void)
if
(
fd
<
0
)
if
(
fd
<
0
)
die
(
"lockstat: open failed"
);
die
(
"lockstat: open failed"
);
printf
(
1
,
"## name acquires locking locked
\n
"
);
printf
(
1
,
"## name acquires
contends
locking locked
\n
"
);
while
(
1
)
{
while
(
1
)
{
r
=
read
(
fd
,
&
ls
,
sz
);
r
=
read
(
fd
,
&
ls
,
sz
);
if
(
r
<
0
)
if
(
r
<
0
)
...
@@ -34,16 +34,18 @@ stats(void)
...
@@ -34,16 +34,18 @@ stats(void)
if
(
r
!=
sz
)
if
(
r
!=
sz
)
die
(
"lockstat: unexpected read"
);
die
(
"lockstat: unexpected read"
);
u64
acquires
=
0
,
locking
=
0
,
locked
=
0
;
u64
acquires
=
0
,
contends
=
0
,
locking
=
0
,
locked
=
0
;
for
(
int
i
=
0
;
i
<
NCPU
;
i
++
)
{
for
(
int
i
=
0
;
i
<
NCPU
;
i
++
)
{
acquires
+=
ls
.
cpu
[
i
].
acquires
;
acquires
+=
ls
.
cpu
[
i
].
acquires
;
contends
+=
ls
.
cpu
[
i
].
contends
;
locking
+=
ls
.
cpu
[
i
].
locking
;
locking
+=
ls
.
cpu
[
i
].
locking
;
locked
+=
ls
.
cpu
[
i
].
locked
;
locked
+=
ls
.
cpu
[
i
].
locked
;
}
}
if
(
acquire
s
>
0
)
if
(
contend
s
>
0
)
printf
(
1
,
"%s %lu %lu %lu
\n
"
,
printf
(
1
,
"%s %lu %lu %lu
%lu
\n
"
,
ls
.
name
,
acquires
,
locking
,
locked
);
ls
.
name
,
acquires
,
contends
,
locking
,
locked
);
}
}
}
}
...
...
lockstat.h
浏览文件 @
e91ed64d
...
@@ -2,8 +2,10 @@
...
@@ -2,8 +2,10 @@
struct
cpulockstat
{
struct
cpulockstat
{
u64
acquires
;
u64
acquires
;
u64
contends
;
u64
locking
;
u64
locking
;
u64
locked
;
u64
locked
;
u64
locking_ts
;
u64
locking_ts
;
u64
locked_ts
;
u64
locked_ts
;
__padout__
;
__padout__
;
...
...
spinlock.c
浏览文件 @
e91ed64d
...
@@ -40,7 +40,7 @@ locking(struct spinlock *lk)
...
@@ -40,7 +40,7 @@ locking(struct spinlock *lk)
}
}
static
inline
void
static
inline
void
locked
(
struct
spinlock
*
lk
)
locked
(
struct
spinlock
*
lk
,
u64
retries
)
{
{
mtacquired
(
lk
);
mtacquired
(
lk
);
...
@@ -53,6 +53,8 @@ locked(struct spinlock *lk)
...
@@ -53,6 +53,8 @@ locked(struct spinlock *lk)
#if LOCKSTAT
#if LOCKSTAT
if
(
lockstat_enable
&&
lk
->
stat
!=
NULL
)
{
if
(
lockstat_enable
&&
lk
->
stat
!=
NULL
)
{
struct
cpulockstat
*
s
=
mylockstat
(
lk
);
struct
cpulockstat
*
s
=
mylockstat
(
lk
);
if
(
retries
>
0
)
s
->
contends
++
;
s
->
acquires
++
;
s
->
acquires
++
;
s
->
locked_ts
=
rdtsc
();
s
->
locked_ts
=
rdtsc
();
}
}
...
@@ -117,7 +119,7 @@ tryacquire(struct spinlock *lk)
...
@@ -117,7 +119,7 @@ tryacquire(struct spinlock *lk)
popcli
();
popcli
();
return
0
;
return
0
;
}
}
locked
(
lk
);
locked
(
lk
,
0
);
return
1
;
return
1
;
}
}
...
@@ -128,14 +130,15 @@ tryacquire(struct spinlock *lk)
...
@@ -128,14 +130,15 @@ tryacquire(struct spinlock *lk)
void
void
acquire
(
struct
spinlock
*
lk
)
acquire
(
struct
spinlock
*
lk
)
{
{
u64
retries
;
pushcli
();
pushcli
();
locking
(
lk
);
locking
(
lk
);
// The xchg is atomic.
// It also serializes, so that reads after acquire are not
retries
=
0
;
// reordered before it.
while
(
xchg32
(
&
lk
->
locked
,
1
)
!=
0
)
while
(
xchg32
(
&
lk
->
locked
,
1
)
!=
0
)
;
retries
++
;
locked
(
lk
);
locked
(
lk
,
retries
);
}
}
// Release the lock.
// Release the lock.
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论