Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
da450a4f
提交
da450a4f
4月 27, 2012
创建
作者:
Austin Clements
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support static construction of lockstat-enabled locks
This works by lazily allocating a lock's klockstat structure when the lock is first acquired.
上级
b6308520
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
10 行删除
+31
-10
spinlock.h
include/spinlock.h
+8
-5
spinlock.cc
kernel/spinlock.cc
+23
-5
没有找到文件。
include/spinlock.h
浏览文件 @
da450a4f
#pragma once
#include "lockstat.h"
#if LOCKSTAT
extern
klockstat
klockstat_lazy
;
#endif
// Mutual exclusion lock.
struct
spinlock
{
u32
locked
;
// Is the lock held?
...
...
@@ -29,16 +33,15 @@ struct spinlock {
#endif
{
}
// Create a spinlock without lockstat tracking. This is constexpr,
// so it can be used for global spinlocks without incurring a static
// constructor.
constexpr
spinlock
(
const
char
*
name
)
// Create a spinlock. This is constexpr, so it can be used for
// global spinlocks without incurring a static constructor.
constexpr
spinlock
(
const
char
*
name
,
bool
lockstat
=
false
)
:
locked
(
0
)
#if SPINLOCK_DEBUG
,
name
(
name
),
cpu
(
nullptr
),
pcs
{}
#endif
#if LOCKSTAT
,
stat
(
nullptr
)
,
stat
(
lockstat
?
nullptr
:
&
klockstat_lazy
)
#endif
{
}
};
...
...
kernel/spinlock.cc
浏览文件 @
da450a4f
...
...
@@ -13,8 +13,14 @@
#include "major.h"
#if LOCKSTAT
// The klockstat structure pointed to by spinlocks that want lockstat,
// but have never been acquired.
struct
klockstat
klockstat_lazy
(
"<lazy>"
);
static
int
lockstat_enable
;
void
lockstat_init
(
struct
spinlock
*
lk
,
bool
lazy
);
static
inline
struct
cpulockstat
*
mylockstat
(
struct
spinlock
*
lk
)
{
...
...
@@ -49,8 +55,11 @@ locking(struct spinlock *lk)
#endif
#if LOCKSTAT
if
(
lockstat_enable
&&
lk
->
stat
!=
nullptr
)
if
(
lockstat_enable
&&
lk
->
stat
!=
nullptr
)
{
if
(
lk
->
stat
==
&
klockstat_lazy
)
lockstat_init
(
lk
,
true
);
mylockstat
(
lk
)
->
locking_ts
=
rdtsc
();
}
#endif
mtlock
(
lk
);
...
...
@@ -128,12 +137,21 @@ klockstat::klockstat(const char *name) :
};
void
lockstat_init
(
struct
spinlock
*
lk
)
lockstat_init
(
struct
spinlock
*
lk
,
bool
lazy
)
{
lk
->
stat
=
new
klockstat
(
lk
->
name
);
if
(
lk
->
stat
==
0
)
klockstat
*
ls
=
new
klockstat
(
lk
->
name
);
if
(
!
ls
)
return
;
if
(
lazy
)
{
if
(
!
__sync_bool_compare_and_swap
(
&
lk
->
stat
,
&
klockstat_lazy
,
ls
))
{
delete
ls
;
return
;
}
}
else
{
lk
->
stat
=
ls
;
}
acquire
(
&
lockstat_lock
);
LIST_INSERT_HEAD
(
&
lockstat_list
,
lk
->
stat
,
link
);
release
(
&
lockstat_lock
);
...
...
@@ -256,7 +274,7 @@ initlock(struct spinlock *lk, const char *name, int lockstat)
#if LOCKSTAT
lk
->
stat
=
(
struct
klockstat
*
)
nullptr
;
if
(
lockstat
)
lockstat_init
(
lk
);
lockstat_init
(
lk
,
false
);
#endif
lk
->
locked
=
0
;
}
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论