Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
d57e7faf
提交
d57e7faf
5月 26, 2011
创建
作者:
Frans Kaashoek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
One RCU usage
Run rcu_gc periodically in a separate kernel thread?
上级
0e1ee117
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
21 行增加
和
23 行删除
+21
-23
defs.h
defs.h
+3
-2
ns.c
ns.c
+10
-4
rcu.c
rcu.c
+8
-17
没有找到文件。
defs.h
浏览文件 @
d57e7faf
...
@@ -75,8 +75,6 @@ void kfree(char*);
...
@@ -75,8 +75,6 @@ void kfree(char*);
void
*
kmalloc
(
uint
);
void
*
kmalloc
(
uint
);
void
kmfree
(
void
*
);
void
kmfree
(
void
*
);
// kbd.c
// kbd.c
void
kbdintr
(
void
);
void
kbdintr
(
void
);
...
@@ -136,6 +134,9 @@ void migrate(void);
...
@@ -136,6 +134,9 @@ void migrate(void);
void
rcuinit
(
void
);
void
rcuinit
(
void
);
void
rcu_begin_write
(
struct
spinlock
*
);
void
rcu_begin_write
(
struct
spinlock
*
);
void
rcu_end_write
(
struct
spinlock
*
);
void
rcu_end_write
(
struct
spinlock
*
);
void
rcu_begin_read
(
void
);
void
rcu_end_read
(
void
);
void
rcu_delayed
(
void
*
,
void
(
*
dofree
)(
void
*
));
// swtch.S
// swtch.S
void
swtch
(
struct
context
**
,
struct
context
*
);
void
swtch
(
struct
context
**
,
struct
context
*
);
...
...
ns.c
浏览文件 @
d57e7faf
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
// XXX maybe use open hash table, no chain, better cache locality
// XXX maybe use open hash table, no chain, better cache locality
#define NHASH 100
#define NHASH 100
static
int
rcu
=
0
;
static
int
rcu
=
1
;
#define ACQUIRE(l) (rcu) ? rcu_begin_write(l) : acquire(l)
#define ACQUIRE(l) (rcu) ? rcu_begin_write(l) : acquire(l)
#define RELEASE(l) (rcu) ? rcu_end_write(l) : release(l)
#define RELEASE(l) (rcu) ? rcu_end_write(l) : release(l)
...
@@ -109,9 +109,14 @@ ns_dolookup(struct ns *ns, int key)
...
@@ -109,9 +109,14 @@ ns_dolookup(struct ns *ns, int key)
void
*
void
*
ns_lookup
(
struct
ns
*
ns
,
int
key
)
ns_lookup
(
struct
ns
*
ns
,
int
key
)
{
{
ACQUIRE
(
&
ns
->
lock
);
if
(
rcu
)
rcu_begin_read
();
else
acquire
(
&
ns
->
lock
);
struct
elem
*
e
=
ns_dolookup
(
ns
,
key
);
struct
elem
*
e
=
ns_dolookup
(
ns
,
key
);
RELEASE
(
&
ns
->
lock
);
if
(
rcu
)
rcu_begin_read
();
else
release
(
&
ns
->
lock
);
return
(
e
==
0
)
?
0
:
e
->
val
;
return
(
e
==
0
)
?
0
:
e
->
val
;
}
}
...
@@ -123,7 +128,8 @@ ns_remove(struct ns *ns, int key)
...
@@ -123,7 +128,8 @@ ns_remove(struct ns *ns, int key)
struct
elem
*
e
=
ns_dolookup
(
ns
,
key
);
struct
elem
*
e
=
ns_dolookup
(
ns
,
key
);
if
(
e
)
{
if
(
e
)
{
TAILQ_REMOVE
(
&
(
ns
->
table
[
key
%
NHASH
].
chain
),
e
,
chain
);
TAILQ_REMOVE
(
&
(
ns
->
table
[
key
%
NHASH
].
chain
),
e
,
chain
);
kmfree
(
e
);
if
(
rcu
)
rcu_delayed
(
e
,
kmfree
);
else
kmfree
(
e
);
r
=
0
;
r
=
0
;
}
}
RELEASE
(
&
ns
->
lock
);
RELEASE
(
&
ns
->
lock
);
...
...
rcu.c
浏览文件 @
d57e7faf
...
@@ -22,9 +22,7 @@ static struct rcu *rcu_freelist;
...
@@ -22,9 +22,7 @@ static struct rcu *rcu_freelist;
static
uint
global_epoch
;
static
uint
global_epoch
;
static
uint
min_epoch
;
static
uint
min_epoch
;
static
struct
spinlock
rcu_lock
;
static
struct
spinlock
rcu_lock
;
static
int
delayed_nfree
;
static
int
delayed_nfree
;
static
int
ninuse
;
void
void
rcuinit
(
void
)
rcuinit
(
void
)
...
@@ -39,7 +37,7 @@ rcuinit(void)
...
@@ -39,7 +37,7 @@ rcuinit(void)
r
->
rcu
=
rcu_freelist
;
r
->
rcu
=
rcu_freelist
;
rcu_freelist
=
r
;
rcu_freelist
=
r
;
}
}
cprintf
(
"rcu_init: allocated %d bytes
\n
"
,
sizeof
(
struct
rcu
)
*
NRCU
);
//
cprintf("rcu_init: allocated %d bytes\n", sizeof(struct rcu) * NRCU);
}
}
struct
rcu
*
struct
rcu
*
...
@@ -70,35 +68,27 @@ rcu_gc(void)
...
@@ -70,35 +68,27 @@ rcu_gc(void)
int
n
=
0
;
int
n
=
0
;
min_epoch
=
global_epoch
;
min_epoch
=
global_epoch
;
acquire
(
&
rcu_lock
);
acquire
(
&
rcu_lock
);
ns_enumerate
(
nspid
,
rcu_min
);
ns_enumerate
(
nspid
,
rcu_min
);
for
(
r
=
rcu_delayed_head
;
r
!=
NULL
;
r
=
nr
)
{
for
(
r
=
rcu_delayed_head
;
r
!=
NULL
;
r
=
nr
)
{
if
(
r
->
epoch
>=
min_epoch
)
if
(
r
->
epoch
>=
min_epoch
)
break
;
break
;
// cprintf("free: %d\n", r->epoch);
// printf("free: %ld\n", r->epoch);
if
(
r
->
dofree
==
0
)
if
(
r
->
dofree
==
0
)
panic
(
"rcu_gc"
);
panic
(
"rcu_gc"
);
r
->
dofree
(
r
->
item
);
r
->
dofree
(
r
->
item
);
delayed_nfree
--
;
delayed_nfree
--
;
n
++
;
n
++
;
rcu_delayed_head
=
r
->
rcu
;
rcu_delayed_head
=
r
->
rcu
;
if
(
rcu_delayed_head
==
0
)
if
(
rcu_delayed_head
==
0
)
rcu_delayed_tail
=
0
;
rcu_delayed_tail
=
0
;
nr
=
r
->
rcu
;
nr
=
r
->
rcu
;
r
->
rcu
=
rcu_freelist
;
r
->
rcu
=
rcu_freelist
;
rcu_freelist
=
r
;
rcu_freelist
=
r
;
}
}
release
(
&
rcu_lock
);
release
(
&
rcu_lock
);
// printf("rcu_gc: n=%d ndelayed_free=%d nfree=%d ninuse=%d\n", n, delayed_nfree,
// cprintf("rcu_gc: n %d ndelayed_free=%d\n", n, delayed_nfree);
// tree_nfree, tree_ninuse);
}
}
// XXX Use atomic instruction to update list (instead of holding lock)
// XXX Use atomic instruction to update list (instead of holding lock)
...
@@ -113,25 +103,24 @@ rcu_delayed(void *e, void (*dofree)(void *))
...
@@ -113,25 +103,24 @@ rcu_delayed(void *e, void (*dofree)(void *))
r
->
rcu
=
0
;
r
->
rcu
=
0
;
r
->
epoch
=
global_epoch
;
r
->
epoch
=
global_epoch
;
acquire
(
&
rcu_lock
);
acquire
(
&
rcu_lock
);
//
printf("rcu_delayed: %l
d\n", global_epoch);
//
cprintf("rcu_delayed: %
d\n", global_epoch);
if
(
rcu_delayed_tail
!=
0
)
if
(
rcu_delayed_tail
!=
0
)
rcu_delayed_tail
->
rcu
=
r
;
rcu_delayed_tail
->
rcu
=
r
;
rcu_delayed_tail
=
r
;
rcu_delayed_tail
=
r
;
if
(
rcu_delayed_head
==
0
)
rcu_delayed_head
=
r
;
if
(
rcu_delayed_head
==
0
)
rcu_delayed_head
=
r
;
release
(
&
rcu_lock
);
release
(
&
rcu_lock
);
delayed_nfree
++
;
delayed_nfree
++
;
ninuse
--
;
}
}
void
void
rcu_begin_read
()
rcu_begin_read
(
void
)
{
{
proc
->
epoch
=
global_epoch
;
proc
->
epoch
=
global_epoch
;
__sync_synchronize
();
__sync_synchronize
();
}
}
void
void
rcu_end_read
()
rcu_end_read
(
void
)
{
{
proc
->
epoch
=
INF
;
proc
->
epoch
=
INF
;
}
}
...
@@ -142,6 +131,8 @@ rcu_begin_write(struct spinlock *l)
...
@@ -142,6 +131,8 @@ rcu_begin_write(struct spinlock *l)
acquire
(
l
);
acquire
(
l
);
}
}
// XXX if a process never rcu_end_write() infrequently we have a problem; run
// rcu_gc from a kernel thread periodically?
void
void
rcu_end_write
(
struct
spinlock
*
l
)
rcu_end_write
(
struct
spinlock
*
l
)
{
{
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论