Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
c7d9a2ad
提交
c7d9a2ad
11月 13, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
an xv6 version of my languishing work queue implementation..
上级
3e89a345
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
279 行增加
和
0 行删除
+279
-0
Makefile
Makefile
+1
-0
kernel.h
kernel.h
+8
-0
main.c
main.c
+2
-0
param.h
param.h
+1
-0
proc.c
proc.c
+5
-0
proc.h
proc.h
+6
-0
wq.c
wq.c
+256
-0
没有找到文件。
Makefile
浏览文件 @
c7d9a2ad
...
@@ -58,6 +58,7 @@ OBJS = \
...
@@ -58,6 +58,7 @@ OBJS = \
vm.o
\
vm.o
\
trap.o
\
trap.o
\
trapasm.o
\
trapasm.o
\
wq.o
ULIB
=
ulib.o usys.o printf.o umalloc.o uthread.o
ULIB
=
ulib.o usys.o printf.o umalloc.o uthread.o
...
...
kernel.h
浏览文件 @
c7d9a2ad
...
@@ -17,10 +17,12 @@ static inline void *p2v(uptr a) { return (void *) a + KBASE; }
...
@@ -17,10 +17,12 @@ static inline void *p2v(uptr a) { return (void *) a + KBASE; }
#define cmpswap(ptr, old, new) __sync_bool_compare_and_swap(ptr, old, new)
#define cmpswap(ptr, old, new) __sync_bool_compare_and_swap(ptr, old, new)
#define subfetch(ptr, val) __sync_sub_and_fetch(ptr, val)
#define subfetch(ptr, val) __sync_sub_and_fetch(ptr, val)
#define fetchadd(ptr, val) __sync_fetch_and_add(ptr, val)
#define __offsetof offsetof
#define __offsetof offsetof
struct
spinlock
;
struct
spinlock
;
struct
condvar
;
struct
condvar
;
struct
wqframe
;
struct
context
;
struct
context
;
struct
vmnode
;
struct
vmnode
;
struct
inode
;
struct
inode
;
...
@@ -270,3 +272,9 @@ int vmn_load(struct vmnode *, struct inode*, u64, u64);
...
@@ -270,3 +272,9 @@ int vmn_load(struct vmnode *, struct inode*, u64, u64);
int
vmap_remove
(
struct
vmap
*
,
uptr
,
u64
);
int
vmap_remove
(
struct
vmap
*
,
uptr
,
u64
);
void
updatepages
(
pml4e_t
*
,
void
*
,
void
*
,
int
);
void
updatepages
(
pml4e_t
*
,
void
*
,
void
*
,
int
);
struct
vmap
*
vmap_copy
(
struct
vmap
*
,
int
);
struct
vmap
*
vmap_copy
(
struct
vmap
*
,
int
);
// wq.c
void
wq_push
(
void
*
rip
,
u64
arg0
,
u64
arg1
);
void
wq_start
(
void
);
void
wq_end
(
void
);
void
initwqframe
(
struct
wqframe
*
wq
);
main.c
浏览文件 @
c7d9a2ad
...
@@ -23,6 +23,7 @@ extern void initinode(void);
...
@@ -23,6 +23,7 @@ extern void initinode(void);
extern
void
initdisk
(
void
);
extern
void
initdisk
(
void
);
extern
void
inituser
(
void
);
extern
void
inituser
(
void
);
extern
void
inithz
(
void
);
extern
void
inithz
(
void
);
extern
void
initwq
(
void
);
static
volatile
int
bstate
;
static
volatile
int
bstate
;
...
@@ -95,6 +96,7 @@ cmain(void)
...
@@ -95,6 +96,7 @@ cmain(void)
initbio
();
// buffer cache
initbio
();
// buffer cache
initinode
();
// inode cache
initinode
();
// inode cache
initdisk
();
// disk
initdisk
();
// disk
initwq
();
// work queues
cprintf
(
"ncpu %d %lu MHz
\n
"
,
ncpu
,
cpuhz
/
1000000
);
cprintf
(
"ncpu %d %lu MHz
\n
"
,
ncpu
,
cpuhz
/
1000000
);
...
...
param.h
浏览文件 @
c7d9a2ad
...
@@ -17,3 +17,4 @@
...
@@ -17,3 +17,4 @@
#define PHYSTOP 0xE000000 // use phys mem up to here as free pool
#define PHYSTOP 0xE000000 // use phys mem up to here as free pool
#define CPUKSTACKS (NPROC + NCPU)
#define CPUKSTACKS (NPROC + NCPU)
#define QUANTUN 10 // scheduling time quantum and tick length (in msec)
#define QUANTUN 10 // scheduling time quantum and tick length (in msec)
#define WQSHIFT 4 // 2^WORKSHIFT work queue slots
proc.c
浏览文件 @
c7d9a2ad
...
@@ -196,6 +196,7 @@ allocproc(void)
...
@@ -196,6 +196,7 @@ allocproc(void)
snprintf
(
p
->
lockname
,
sizeof
(
p
->
lockname
),
"cv:proc:%d"
,
p
->
pid
);
snprintf
(
p
->
lockname
,
sizeof
(
p
->
lockname
),
"cv:proc:%d"
,
p
->
pid
);
initlock
(
&
p
->
lock
,
p
->
lockname
+
3
);
initlock
(
&
p
->
lock
,
p
->
lockname
+
3
);
initcondvar
(
&
p
->
cv
,
p
->
lockname
);
initcondvar
(
&
p
->
cv
,
p
->
lockname
);
initwqframe
(
&
p
->
wqframe
);
if
(
ns_insert
(
nspid
,
KI
(
p
->
pid
),
(
void
*
)
p
)
<
0
)
if
(
ns_insert
(
nspid
,
KI
(
p
->
pid
),
(
void
*
)
p
)
<
0
)
panic
(
"allocproc: ns_insert"
);
panic
(
"allocproc: ns_insert"
);
...
@@ -314,6 +315,10 @@ scheduler(void)
...
@@ -314,6 +315,10 @@ scheduler(void)
mycpu
()
->
proc
=
schedp
;
mycpu
()
->
proc
=
schedp
;
myproc
()
->
cpu_pin
=
1
;
myproc
()
->
cpu_pin
=
1
;
// Test the work queue
extern
void
testwq
(
void
);
testwq
();
// Enabling mtrace calls in scheduler generates many mtrace_call_entrys.
// Enabling mtrace calls in scheduler generates many mtrace_call_entrys.
// mtrace_call_set(1, cpu->id);
// mtrace_call_set(1, cpu->id);
mtstart
(
scheduler
,
schedp
);
mtstart
(
scheduler
,
schedp
);
...
...
proc.h
浏览文件 @
c7d9a2ad
...
@@ -12,6 +12,11 @@ struct context {
...
@@ -12,6 +12,11 @@ struct context {
u64
rip
;
u64
rip
;
}
__attribute__
((
packed
));
}
__attribute__
((
packed
));
// Work queue frame
struct
wqframe
{
volatile
u64
ref
;
};
// Per-process, per-stack meta data for mtrace
// Per-process, per-stack meta data for mtrace
#if MTRACE
#if MTRACE
#define MTRACE_NSTACKS 16
#define MTRACE_NSTACKS 16
...
@@ -59,6 +64,7 @@ struct proc {
...
@@ -59,6 +64,7 @@ struct proc {
struct
mtrace_stacks
mtrace_stacks
;
struct
mtrace_stacks
mtrace_stacks
;
#endif
#endif
struct
runq
*
runq
;
struct
runq
*
runq
;
struct
wqframe
wqframe
;
STAILQ_ENTRY
(
proc
)
runqlink
;
STAILQ_ENTRY
(
proc
)
runqlink
;
};
};
...
...
wq.c
0 → 100644
浏览文件 @
c7d9a2ad
#include "types.h"
#include "kernel.h"
#include "param.h"
#include "amd64.h"
#include "cpu.h"
#include "bits.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#define NSLOTS (1 << WQSHIFT)
struct
wqueue
{
struct
wqthread
*
thread
[
NSLOTS
];
volatile
int
head
__mpalign__
;
struct
spinlock
lock
;
volatile
int
tail
;
__padout__
;
}
__mpalign__
;
struct
wqthread
{
u64
rip
;
u64
arg0
;
u64
arg1
;
volatile
u64
*
ref
;
// pointer to parent wqframe.ref
__padout__
;
}
__mpalign__
;
struct
wqstat
{
u64
push
;
u64
full
;
u64
pop
;
u64
steal
;
__padout__
;
}
__mpalign__
;
struct
wqueue
queue
[
NCPU
]
__mpalign__
;
struct
wqstat
stat
[
NCPU
]
__mpalign__
;
static
struct
wqueue
*
wq_cur
(
void
)
{
return
&
queue
[
mycpu
()
->
id
];
}
static
struct
wqframe
*
wq_frame
(
void
)
{
return
&
myproc
()
->
wqframe
;
}
static
struct
wqstat
*
wq_stat
(
void
)
{
return
&
stat
[
mycpu
()
->
id
];
}
static
int
__wq_push
(
struct
wqueue
*
q
,
struct
wqthread
*
t
)
{
int
i
;
i
=
q
->
head
;
if
((
i
-
q
->
tail
)
==
NSLOTS
)
{
wq_stat
()
->
full
++
;
return
-
1
;
}
i
=
i
&
(
NSLOTS
-
1
);
q
->
thread
[
i
]
=
t
;
q
->
head
++
;
wq_stat
()
->
push
++
;
return
0
;
}
static
struct
wqthread
*
__wq_pop
(
struct
wqueue
*
q
)
{
int
i
;
acquire
(
&
q
->
lock
);
i
=
q
->
head
;
if
((
i
-
q
->
tail
)
==
0
)
{
release
(
&
q
->
lock
);
return
NULL
;
}
i
=
(
i
-
1
)
&
(
NSLOTS
-
1
);
q
->
head
--
;
release
(
&
q
->
lock
);
wq_stat
()
->
pop
++
;
return
q
->
thread
[
i
];
}
static
struct
wqthread
*
__wq_steal
(
struct
wqueue
*
q
)
{
int
i
;
acquire
(
&
q
->
lock
);
i
=
q
->
tail
;
if
((
i
-
q
->
head
)
==
0
)
{
release
(
&
q
->
lock
);
return
NULL
;
}
i
=
i
&
(
NSLOTS
-
1
);
q
->
tail
++
;
release
(
&
q
->
lock
);
wq_stat
()
->
steal
++
;
return
q
->
thread
[
i
];
}
static
void
__wq_run
(
struct
wqthread
*
th
)
{
void
(
*
fn
)(
uptr
arg0
,
uptr
arg1
)
=
(
void
*
)
th
->
rip
;
fn
(
th
->
arg0
,
th
->
arg1
);
subfetch
(
th
->
ref
,
1
);
}
// Add the (rip, arg0, arg1) work to the local work queue.
// Guarantees some core will at some point execute the work.
// The current core might execute the work immediately.
void
wq_push
(
void
*
rip
,
u64
arg0
,
u64
arg1
)
{
void
(
*
fn
)(
uptr
,
uptr
)
=
rip
;
struct
wqthread
*
th
;
th
=
(
struct
wqthread
*
)
kalloc
();
if
(
th
==
NULL
)
{
fn
(
arg0
,
arg1
);
return
;
}
th
->
rip
=
(
uptr
)
rip
;
th
->
arg0
=
arg0
;
th
->
arg1
=
arg1
;
th
->
ref
=
&
wq_frame
()
->
ref
;
if
(
__wq_push
(
wq_cur
(),
th
))
fn
(
arg0
,
arg1
);
else
fetchadd
(
&
wq_frame
()
->
ref
,
1
);
}
// Try to execute one wqthread.
// Check local queue then steal from other queues.
int
wq_trywork
(
void
)
{
struct
wqthread
*
th
;
int
i
;
th
=
__wq_pop
(
wq_cur
());
if
(
th
!=
NULL
)
{
__wq_run
(
th
);
return
1
;
}
// XXX(sbw) should be random
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
{
if
(
i
==
mycpu
()
->
id
)
continue
;
th
=
__wq_steal
(
&
queue
[
i
]);
if
(
th
!=
NULL
)
{
__wq_run
(
th
);
return
1
;
}
}
return
0
;
}
void
wq_start
(
void
)
{
pushcli
();
if
(
myproc
()
->
wqframe
.
ref
!=
0
)
panic
(
"wq_start"
);
}
void
wq_end
(
void
)
{
while
(
myproc
()
->
wqframe
.
ref
!=
0
)
{
struct
wqthread
*
th
;
int
i
;
while
((
th
=
__wq_pop
(
wq_cur
()))
!=
NULL
)
__wq_run
(
th
);
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
{
th
=
__wq_steal
(
&
queue
[
i
]);
if
(
th
!=
NULL
)
{
__wq_run
(
th
);
break
;
}
}
}
popcli
();
}
static
void
__test_stub
(
uptr
a0
,
uptr
a1
)
{
//cprintf("%lu, %lu\n", a0, a1);
}
void
testwq
(
void
)
{
enum
{
iters
=
1000
};
static
volatile
int
running
=
1
;
u64
e
,
s
;
int
i
;
pushcli
();
if
(
mycpu
()
->
id
==
0
)
{
microdelay
(
1
);
s
=
rdtsc
();
wq_start
();
for
(
i
=
0
;
i
<
iters
;
i
++
)
wq_push
(
__test_stub
,
i
,
i
);
wq_end
();
e
=
rdtsc
();
cprintf
(
"testwq: %lu
\n
"
,
(
e
-
s
)
/
iters
);
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
cprintf
(
"push %lu full %lu pop %lu steal %lu
\n
"
,
stat
[
i
].
push
,
stat
[
i
].
full
,
stat
[
i
].
pop
,
stat
[
i
].
steal
);
running
=
0
;
}
else
{
while
(
running
)
wq_trywork
();
}
popcli
();
}
void
initwqframe
(
struct
wqframe
*
wq
)
{
memset
(
wq
,
0
,
sizeof
(
*
wq
));
}
void
initwq
(
void
)
{
int
i
;
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
{
initlock
(
&
queue
[
i
].
lock
,
"queue lock"
);
}
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论