Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
25489a0c
提交
25489a0c
3月 04, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
c++ify kernel/wq.cc
上级
afb40915
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
50 行增加
和
191 行删除
+50
-191
kernel.hh
include/kernel.hh
+1
-3
wq.hh
include/wq.hh
+11
-2
async.cc
kernel/async.cc
+5
-5
script.cc
kernel/script.cc
+2
-2
wq.cc
kernel/wq.cc
+30
-178
wq.cc
user/wq.cc
+1
-1
没有找到文件。
include/kernel.hh
浏览文件 @
25489a0c
...
@@ -252,10 +252,8 @@ int pagefault(struct vmap *, uptr, u32);
...
@@ -252,10 +252,8 @@ int pagefault(struct vmap *, uptr, u32);
// wq.c
// wq.c
int
wq_trywork
(
void
);
int
wq_trywork
(
void
);
int
wq_push
(
struct
work
*
w
);
int
wq_push
(
work
*
w
);
void
wq_dump
(
void
);
void
wq_dump
(
void
);
struct
work
*
allocwork
(
void
);
void
freework
(
struct
work
*
w
);
// cilk.c
// cilk.c
void
initcilkframe
(
struct
cilkframe
*
);
void
initcilkframe
(
struct
cilkframe
*
);
...
...
include/wq.hh
浏览文件 @
25489a0c
struct
work
{
struct
work
{
virtual
void
run
()
=
0
;
};
struct
cwork
:
public
work
{
virtual
void
run
();
static
void
*
operator
new
(
unsigned
long
);
static
void
*
operator
new
(
unsigned
long
,
cwork
*
);
static
void
operator
delete
(
void
*
p
);
void
*
rip
;
void
*
rip
;
void
*
arg0
;
void
*
arg0
;
void
*
arg1
;
void
*
arg1
;
void
*
arg2
;
void
*
arg2
;
void
*
arg3
;
void
*
arg3
;
void
*
arg4
;
void
*
arg4
;
char
data
[];
};
};
struct
run_work
{
struct
run_work
{
...
@@ -15,7 +24,7 @@ struct run_work {
...
@@ -15,7 +24,7 @@ struct run_work {
void
initwq
(
void
);
void
initwq
(
void
);
struct
work
*
allocwork
(
void
);
struct
work
*
allocwork
(
void
);
void
freework
(
struct
work
*
w
);
void
freework
(
struct
work
*
w
);
int
wq_push
(
struct
work
*
w
);
int
wq_push
(
work
*
w
);
template
<
typename
IT
,
typename
BODY
>
template
<
typename
IT
,
typename
BODY
>
struct
for_work
:
public
run_work
{
struct
for_work
:
public
run_work
{
...
...
kernel/async.cc
浏览文件 @
25489a0c
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
static_assert
(
sizeof
(
struct
ipcctl
)
<
PGSIZE
,
"struct ipcctl too large"
);
static_assert
(
sizeof
(
struct
ipcctl
)
<
PGSIZE
,
"struct ipcctl too large"
);
static
void
static
void
pread_work
(
struct
work
*
w
,
void
*
a0
,
void
*
a1
,
void
*
a2
,
pread_work
(
void
*
a0
,
void
*
a1
,
void
*
a2
,
void
*
a3
,
void
*
a4
)
void
*
a3
,
void
*
a4
)
{
{
struct
inode
*
ip
=
(
inode
*
)
a0
;
struct
inode
*
ip
=
(
inode
*
)
a0
;
...
@@ -34,11 +34,11 @@ pread_work(struct work *w, void *a0, void *a1, void *a2,
...
@@ -34,11 +34,11 @@ pread_work(struct work *w, void *a0, void *a1, void *a2,
iput
(
ip
);
iput
(
ip
);
}
}
static
struct
work
*
static
c
work
*
pread_allocwork
(
struct
inode
*
ip
,
size_t
count
,
off_t
off
,
pread_allocwork
(
struct
inode
*
ip
,
size_t
count
,
off_t
off
,
struct
ipcmsg
*
msg
,
void
*
ubuf
)
struct
ipcmsg
*
msg
,
void
*
ubuf
)
{
{
struct
work
*
w
=
allo
cwork
();
cwork
*
w
=
new
cwork
();
if
(
w
==
nullptr
)
if
(
w
==
nullptr
)
return
0
;
return
0
;
...
@@ -57,7 +57,7 @@ sys_async(int fd, size_t count, off_t off,
...
@@ -57,7 +57,7 @@ sys_async(int fd, size_t count, off_t off,
msgid_t
msgid
,
pageid_t
pageid
)
msgid_t
msgid
,
pageid_t
pageid
)
{
{
struct
file
*
f
;
struct
file
*
f
;
struct
work
*
w
;
c
work
*
w
;
char
*
kshared
=
myproc
()
->
vmap
->
kshared
;
char
*
kshared
=
myproc
()
->
vmap
->
kshared
;
struct
ipcctl
*
ipcctl
=
(
struct
ipcctl
*
)
kshared
;
struct
ipcctl
*
ipcctl
=
(
struct
ipcctl
*
)
kshared
;
...
@@ -85,7 +85,7 @@ sys_async(int fd, size_t count, off_t off,
...
@@ -85,7 +85,7 @@ sys_async(int fd, size_t count, off_t off,
}
}
if
(
wq_push
(
w
)
<
0
)
{
if
(
wq_push
(
w
)
<
0
)
{
iput
(
f
->
ip
);
iput
(
f
->
ip
);
freework
(
w
)
;
delete
w
;
return
-
1
;
return
-
1
;
}
}
msg
->
off
=
off
;
msg
->
off
=
off
;
...
...
kernel/script.cc
浏览文件 @
25489a0c
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include "file.hh"
#include "file.hh"
void
void
script_mmap_work
(
struct
work
*
w
,
void
*
a0
,
void
*
a1
,
void
*
a2
,
void
*
a3
)
script_mmap_work
(
void
*
a0
,
void
*
a1
,
void
*
a2
,
void
*
a3
)
{
{
void
*
addr
=
(
void
*
)
a0
;
void
*
addr
=
(
void
*
)
a0
;
u64
len
=
(
u64
)
a1
;
u64
len
=
(
u64
)
a1
;
...
@@ -40,7 +40,7 @@ sys_script(void *addr, u64 len, u64 chunk)
...
@@ -40,7 +40,7 @@ sys_script(void *addr, u64 len, u64 chunk)
if
(
x
>
chunk
)
if
(
x
>
chunk
)
x
=
chunk
;
x
=
chunk
;
struct
work
*
w
=
allo
cwork
();
cwork
*
w
=
new
cwork
();
if
(
w
==
0
)
if
(
w
==
0
)
panic
(
"sys_script allocwork"
);
panic
(
"sys_script allocwork"
);
w
->
rip
=
(
void
*
)
script_mmap_work
;
w
->
rip
=
(
void
*
)
script_mmap_work
;
...
...
kernel/wq.cc
浏览文件 @
25489a0c
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#define NSLOTS (1 << WQSHIFT)
#define NSLOTS (1 << WQSHIFT)
struct
wqueue
{
struct
wqueue
{
struct
work
*
w
[
NSLOTS
];
work
*
w
[
NSLOTS
];
volatile
int
head
__mpalign__
;
volatile
int
head
__mpalign__
;
volatile
int
tail
;
volatile
int
tail
;
...
@@ -46,20 +46,8 @@ wq_stat(void)
...
@@ -46,20 +46,8 @@ wq_stat(void)
return
&
stat
[
mycpu
()
->
id
];
return
&
stat
[
mycpu
()
->
id
];
}
}
struct
work
*
allocwork
(
void
)
{
return
(
struct
work
*
)
kalloc
();
}
void
freework
(
struct
work
*
w
)
{
kfree
(
w
);
}
int
int
wq_push
(
struct
work
*
w
)
wq_push
(
work
*
w
)
{
{
int
i
;
int
i
;
...
@@ -78,51 +66,11 @@ wq_push(struct work *w)
...
@@ -78,51 +66,11 @@ wq_push(struct work *w)
return
0
;
return
0
;
}
}
int
static
inline
work
*
wq_push1
(
void
(
*
fn
)(
struct
work
*
w
,
void
*
a0
),
void
*
a0
)
{
struct
work
*
w
=
allocwork
();
if
(
w
==
nullptr
)
return
-
1
;
w
->
rip
=
(
void
*
)
fn
;
w
->
arg0
=
a0
;
if
(
wq_push
(
w
)
<
0
)
{
freework
(
w
);
return
-
1
;
}
return
0
;
}
int
wq_push2
(
void
(
*
fn
)(
struct
work
*
,
void
*
,
void
*
),
void
*
a0
,
void
*
a1
)
{
struct
work
*
w
=
allocwork
();
if
(
w
==
nullptr
)
return
-
1
;
w
->
rip
=
(
void
*
)
fn
;
w
->
arg0
=
a0
;
w
->
arg1
=
a1
;
if
(
wq_push
(
w
)
<
0
)
{
freework
(
w
);
return
-
1
;
}
return
0
;
}
static
void
__wq_run
(
struct
work
*
w
)
{
void
(
*
fn
)(
struct
work
*
,
void
*
,
void
*
,
void
*
,
void
*
,
void
*
)
=
(
void
(
*
)(
work
*
,
void
*
,
void
*
,
void
*
,
void
*
,
void
*
))
w
->
rip
;
fn
(
w
,
w
->
arg0
,
w
->
arg1
,
w
->
arg2
,
w
->
arg3
,
w
->
arg4
);
freework
(
w
);
}
static
inline
struct
work
*
__wq_pop
(
int
c
)
__wq_pop
(
int
c
)
{
{
struct
wqueue
*
wq
=
&
queue
[
c
];
struct
wqueue
*
wq
=
&
queue
[
c
];
struct
work
*
w
;
work
*
w
;
int
i
;
int
i
;
i
=
wq
->
head
;
i
=
wq
->
head
;
...
@@ -144,11 +92,11 @@ __wq_pop(int c)
...
@@ -144,11 +92,11 @@ __wq_pop(int c)
return
w
;
return
w
;
}
}
static
inline
struct
work
*
static
inline
work
*
__wq_steal
(
int
c
)
__wq_steal
(
int
c
)
{
{
struct
wqueue
*
wq
=
&
queue
[
c
];
struct
wqueue
*
wq
=
&
queue
[
c
];
struct
work
*
w
;
work
*
w
;
int
i
;
int
i
;
if
(
tryacquire
(
&
wq
->
lock
)
==
0
)
if
(
tryacquire
(
&
wq
->
lock
)
==
0
)
...
@@ -170,7 +118,7 @@ __wq_steal(int c)
...
@@ -170,7 +118,7 @@ __wq_steal(int c)
int
int
wq_trywork
(
void
)
wq_trywork
(
void
)
{
{
struct
work
*
w
;
work
*
w
;
u64
i
,
k
;
u64
i
,
k
;
// A "random" victim CPU
// A "random" victim CPU
...
@@ -178,7 +126,7 @@ wq_trywork(void)
...
@@ -178,7 +126,7 @@ wq_trywork(void)
w
=
__wq_pop
(
mycpu
()
->
id
);
w
=
__wq_pop
(
mycpu
()
->
id
);
if
(
w
!=
nullptr
)
{
if
(
w
!=
nullptr
)
{
__wq_run
(
w
);
w
->
run
(
);
return
1
;
return
1
;
}
}
...
@@ -190,7 +138,7 @@ wq_trywork(void)
...
@@ -190,7 +138,7 @@ wq_trywork(void)
w
=
__wq_steal
(
j
);
w
=
__wq_steal
(
j
);
if
(
w
!=
nullptr
)
{
if
(
w
!=
nullptr
)
{
__wq_run
(
w
);
w
->
run
(
);
return
1
;
return
1
;
}
}
}
}
...
@@ -207,137 +155,41 @@ wq_dump(void)
...
@@ -207,137 +155,41 @@ wq_dump(void)
stat
[
i
].
push
,
stat
[
i
].
full
,
stat
[
i
].
pop
,
stat
[
i
].
steal
);
stat
[
i
].
push
,
stat
[
i
].
full
,
stat
[
i
].
pop
,
stat
[
i
].
steal
);
}
}
static
void
void
__test_stub
(
struct
work
*
w
,
void
*
a0
,
void
*
a1
)
initwq
(
void
)
{
{
//long i = (long)a0
;
int
i
;
//cprintf("%u: %lu\n", cpunum(), i);
volatile
atomic
<
int
>
*
running
=
(
volatile
atomic
<
int
>*
)
a1
;
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
(
*
running
)
--
;
initlock
(
&
queue
[
i
].
lock
,
"wq lock"
,
LOCKSTAT_WQ
)
;
}
}
void
void
testwq
(
void
)
cwork
::
run
(
void
)
{
{
enum
{
iters
=
10
};
void
(
*
fn
)(
void
*
,
void
*
,
void
*
,
void
*
,
void
*
)
=
static
volatile
atomic
<
int
>
running
(
iters
);
(
void
(
*
)(
void
*
,
void
*
,
void
*
,
void
*
,
void
*
))
rip
;
u64
e
,
s
;
fn
(
arg0
,
arg1
,
arg2
,
arg3
,
arg4
);
long
i
;
delete
this
;
pushcli
();
if
(
mycpu
()
->
id
==
0
)
{
microdelay
(
1
);
s
=
rdtsc
();
for
(
i
=
0
;
i
<
iters
;
i
++
)
{
if
(
wq_push2
(
__test_stub
,
(
void
*
)
i
,
(
void
*
)
&
running
)
<
0
)
panic
(
"testwq: oops"
);
}
while
(
running
)
nop_pause
();
e
=
rdtsc
();
cprintf
(
"testwq: %lu
\n
"
,
(
e
-
s
)
/
iters
);
wq_dump
();
}
else
{
while
(
running
)
wq_trywork
();
}
popcli
();
}
}
static
struct
work
*
*
void
*
do_allocwork
(
struct
work
**
w
,
int
iter
s
)
cwork
::
operator
new
(
unsigned
long
nbyte
s
)
{
{
int
i
;
assert
(
nbytes
==
sizeof
(
cwork
));
return
kmalloc
(
sizeof
(
cwork
));
for
(
i
=
0
;
i
<
iters
;
i
++
)
w
[
i
]
=
allocwork
();
return
w
;
}
}
static
struct
work
*
*
void
*
do_freework
(
struct
work
**
w
,
int
iters
)
cwork
::
operator
new
(
unsigned
long
nbytes
,
cwork
*
buf
)
{
{
int
i
;
assert
(
nbytes
==
sizeof
(
cwork
));
return
buf
;
for
(
i
=
0
;
i
<
iters
;
i
++
)
freework
(
w
[
i
]);
return
w
;
}
}
void
void
benchwq
(
void
)
cwork
::
operator
delete
(
void
*
p
)
{
{
enum
{
alloc_iters
=
100
};
kmfree
(
p
,
sizeof
(
cwork
));
static
volatile
atomic
<
int
>
running
(
alloc_iters
);
static
struct
work
*
w
[
alloc_iters
];
u64
e2
,
e
,
s
;
long
i
;
pushcli
();
if
(
mycpu
()
->
id
==
0
)
{
microdelay
(
1
);
// Warm up
do_allocwork
(
w
,
alloc_iters
);
do_freework
(
w
,
alloc_iters
);
s
=
rdtsc
();
do_allocwork
(
w
,
alloc_iters
);
e
=
rdtsc
();
cprintf
(
"allocwork: %lu
\n
"
,
(
e
-
s
)
/
alloc_iters
);
s
=
rdtsc
();
do_freework
(
w
,
alloc_iters
);
e
=
rdtsc
();
cprintf
(
"freework: %lu
\n
"
,
(
e
-
s
)
/
alloc_iters
);
do_allocwork
(
w
,
alloc_iters
);
for
(
i
=
0
;
i
<
alloc_iters
;
i
++
)
{
w
[
i
]
->
rip
=
(
void
*
)
__test_stub
;
w
[
i
]
->
arg1
=
(
void
*
)
&
running
;
}
s
=
rdtsc
();
for
(
i
=
0
;
i
<
alloc_iters
;
i
++
)
{
if
(
wq_push
(
w
[
i
])
<
0
)
panic
(
"testwq: oops"
);
}
e
=
rdtsc
();
while
(
running
)
nop_pause
();
e2
=
rdtsc
();
cprintf
(
"wq_push: %lu
\n
"
,
(
e
-
s
)
/
alloc_iters
);
cprintf
(
"wq finished: %lu
\n
"
,
(
e2
-
s
)
/
alloc_iters
);
do_allocwork
(
w
,
alloc_iters
);
for
(
i
=
0
;
i
<
alloc_iters
;
i
++
)
{
w
[
i
]
->
rip
=
(
void
*
)
__test_stub
;
w
[
i
]
->
arg1
=
(
void
*
)
&
running
;
}
s
=
rdtsc
();
for
(
i
=
0
;
i
<
alloc_iters
;
i
++
)
{
running
=
1
;
if
(
wq_push
(
w
[
i
])
<
0
)
panic
(
"testwq: oops"
);
while
(
running
)
nop_pause
();
}
e
=
rdtsc
();
cprintf
(
"wq_push one: %lu
\n
"
,
(
e
-
s
)
/
alloc_iters
);
wq_dump
();
}
popcli
();
}
}
void
initwq
(
void
)
{
int
i
;
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
initlock
(
&
queue
[
i
].
lock
,
"wq lock"
,
LOCKSTAT_WQ
);
}
user/wq.cc
浏览文件 @
25489a0c
...
@@ -97,7 +97,7 @@ wq_push(struct work *w)
...
@@ -97,7 +97,7 @@ wq_push(struct work *w)
}
}
static
void
static
void
__wq_run
(
struct
work
*
w
)
__wq_run
(
work
*
w
)
{
{
void
(
*
fn
)(
struct
work
*
,
void
*
,
void
*
,
void
*
,
void
*
,
void
*
)
=
void
(
*
fn
)(
struct
work
*
,
void
*
,
void
*
,
void
*
,
void
*
,
void
*
)
=
(
void
(
*
)(
work
*
,
void
*
,
void
*
,
void
*
,
void
*
,
void
*
))
w
->
rip
;
(
void
(
*
)(
work
*
,
void
*
,
void
*
,
void
*
,
void
*
,
void
*
))
w
->
rip
;
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论