Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
e3b99cc0
提交
e3b99cc0
2月 09, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename wq to cilk
上级
53b19d0a
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
107 行增加
和
102 行删除
+107
-102
Makefile
Makefile
+1
-1
cilk.c
cilk.c
+70
-70
console.c
console.c
+2
-2
cpu.h
cpu.h
+2
-2
exec.c
exec.c
+5
-5
kernel.h
kernel.h
+19
-12
main.c
main.c
+3
-3
param.h
param.h
+2
-4
proc.c
proc.c
+1
-1
proc.h
proc.h
+2
-2
没有找到文件。
Makefile
浏览文件 @
e3b99cc0
...
...
@@ -29,6 +29,7 @@ LDFLAGS += -m elf_x86_64
OBJS
=
\
bio.o
\
cga.o
\
cilk.o
\
condvar.o
\
console.o
\
crange.o
\
...
...
@@ -68,7 +69,6 @@ OBJS = \
vm.o
\
trap.o
\
trapasm.o
\
wq.o
\
incbin.o
OBJS
:=
$
(
addprefix
$(O)
/,
$(OBJS)
)
...
...
wq
.c
→
cilk
.c
浏览文件 @
e3b99cc0
...
...
@@ -12,20 +12,20 @@
// }
// void foo(uptr a0, uptr a1) {
// char *arg = (char*) a0;
//
wq
_push(goo, a0, 0);
//
cilk
_push(goo, a0, 0);
// arg[0] = 'f';
// cprintf("foo\n");
// }
// void example(void) {
// char arg[2];
//
wq
_start();
//
wq
_push(foo, (uptr)arg, 0);
//
cilk
_start();
//
cilk
_push(foo, (uptr)arg, 0);
// cprintf("example\n");
//
wq
_end();
//
cilk
_end();
// cprintf("%c %c\n", arg[0], arg[1]);
// }
#if
WQ
ENABLE
#if
CILK
ENABLE
#include "types.h"
#include "kernel.h"
#include "amd64.h"
...
...
@@ -38,10 +38,10 @@
#include "mtrace.h"
#include "qlock.h"
#define NSLOTS (1 <<
WQ
SHIFT)
#define NSLOTS (1 <<
CILK
SHIFT)
struct
w
queue
{
struct
wq
thread
*
thread
[
NSLOTS
];
struct
cilk
queue
{
struct
cilk
thread
*
thread
[
NSLOTS
];
volatile
int
head
__mpalign__
;
qlock_t
lock
;
...
...
@@ -49,15 +49,15 @@ struct wqueue {
__padout__
;
}
__mpalign__
;
struct
wq
thread
{
struct
cilk
thread
{
u64
rip
;
u64
arg0
;
u64
arg1
;
struct
wqframe
*
frame
;
// parent wq
frame
struct
cilkframe
*
frame
;
// parent cilk
frame
__padout__
;
}
__mpalign__
;
struct
wq
stat
{
struct
cilk
stat
{
u64
push
;
u64
full
;
u64
pop
;
...
...
@@ -65,47 +65,47 @@ struct wqstat {
__padout__
;
}
__mpalign__
;
struct
w
queue
queue
[
NCPU
]
__mpalign__
;
struct
wq
stat
stat
[
NCPU
]
__mpalign__
;
struct
cilk
queue
queue
[
NCPU
]
__mpalign__
;
struct
cilk
stat
stat
[
NCPU
]
__mpalign__
;
static
struct
w
queue
*
wq
_cur
(
void
)
static
struct
cilk
queue
*
cilk
_cur
(
void
)
{
return
&
queue
[
mycpu
()
->
id
];
}
static
struct
wq
frame
*
wq
_frame
(
void
)
static
struct
cilk
frame
*
cilk
_frame
(
void
)
{
return
mycpu
()
->
wq
frame
;
return
mycpu
()
->
cilk
frame
;
}
static
struct
wq
stat
*
wq
_stat
(
void
)
static
struct
cilk
stat
*
cilk
_stat
(
void
)
{
return
&
stat
[
mycpu
()
->
id
];
}
static
int
__
wq_push
(
struct
wqueue
*
q
,
struct
wq
thread
*
t
)
__
cilk_push
(
struct
cilkqueue
*
q
,
struct
cilk
thread
*
t
)
{
int
i
;
i
=
q
->
head
;
if
((
i
-
q
->
tail
)
==
NSLOTS
)
{
wq
_stat
()
->
full
++
;
cilk
_stat
()
->
full
++
;
return
-
1
;
}
i
=
i
&
(
NSLOTS
-
1
);
q
->
thread
[
i
]
=
t
;
q
->
head
++
;
wq
_stat
()
->
push
++
;
cilk
_stat
()
->
push
++
;
return
0
;
}
static
struct
wq
thread
*
__
wq_pop
(
struct
w
queue
*
q
)
static
struct
cilk
thread
*
__
cilk_pop
(
struct
cilk
queue
*
q
)
{
struct
qnode
qn
;
int
i
;
...
...
@@ -120,12 +120,12 @@ __wq_pop(struct wqueue *q)
q
->
head
--
;
ql_unlock
(
&
q
->
lock
,
&
qn
);
wq
_stat
()
->
pop
++
;
cilk
_stat
()
->
pop
++
;
return
q
->
thread
[
i
];
}
static
struct
wq
thread
*
__
wq_steal
(
struct
w
queue
*
q
)
static
struct
cilk
thread
*
__
cilk_steal
(
struct
cilk
queue
*
q
)
{
struct
qnode
qn
;
int
i
;
...
...
@@ -140,19 +140,19 @@ __wq_steal(struct wqueue *q)
q
->
tail
++
;
ql_unlock
(
&
q
->
lock
,
&
qn
);
wq
_stat
()
->
steal
++
;
cilk
_stat
()
->
steal
++
;
return
q
->
thread
[
i
];
}
static
void
__
wq_run
(
struct
wq
thread
*
th
)
__
cilk_run
(
struct
cilk
thread
*
th
)
{
void
(
*
fn
)(
uptr
arg0
,
uptr
arg1
)
=
(
void
*
)
th
->
rip
;
struct
wqframe
*
old
=
mycpu
()
->
wq
frame
;
struct
cilkframe
*
old
=
mycpu
()
->
cilk
frame
;
mycpu
()
->
wq
frame
=
th
->
frame
;
mycpu
()
->
cilk
frame
=
th
->
frame
;
fn
(
th
->
arg0
,
th
->
arg1
);
mycpu
()
->
wq
frame
=
old
;
mycpu
()
->
cilk
frame
=
old
;
subfetch
(
&
th
->
frame
->
ref
,
1
);
kfree
(
th
);
}
...
...
@@ -161,12 +161,12 @@ __wq_run(struct wqthread *th)
// 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
)
cilk
_push
(
void
*
rip
,
u64
arg0
,
u64
arg1
)
{
void
(
*
fn
)(
uptr
,
uptr
)
=
rip
;
struct
wq
thread
*
th
;
struct
cilk
thread
*
th
;
th
=
(
struct
wq
thread
*
)
kalloc
();
th
=
(
struct
cilk
thread
*
)
kalloc
();
if
(
th
==
NULL
)
{
fn
(
arg0
,
arg1
);
return
;
...
...
@@ -174,27 +174,27 @@ wq_push(void *rip, u64 arg0, u64 arg1)
th
->
rip
=
(
uptr
)
rip
;
th
->
arg0
=
arg0
;
th
->
arg1
=
arg1
;
th
->
frame
=
wq
_frame
();
th
->
frame
=
cilk
_frame
();
if
(
__
wq_push
(
wq
_cur
(),
th
))
{
if
(
__
cilk_push
(
cilk
_cur
(),
th
))
{
kfree
(
th
);
fn
(
arg0
,
arg1
);
}
else
fetchadd
(
&
wq
_frame
()
->
ref
,
1
);
fetchadd
(
&
cilk
_frame
()
->
ref
,
1
);
}
// Try to execute one
wq
thread.
// Try to execute one
cilk
thread.
// Check local queue then steal from other queues.
int
wq
_trywork
(
void
)
cilk
_trywork
(
void
)
{
struct
wq
thread
*
th
;
struct
cilk
thread
*
th
;
int
i
;
pushcli
();
th
=
__
wq_pop
(
wq
_cur
());
th
=
__
cilk_pop
(
cilk
_cur
());
if
(
th
!=
NULL
)
{
__
wq
_run
(
th
);
__
cilk
_run
(
th
);
popcli
();
return
1
;
}
...
...
@@ -204,9 +204,9 @@ wq_trywork(void)
if
(
i
==
mycpu
()
->
id
)
continue
;
th
=
__
wq
_steal
(
&
queue
[
i
]);
th
=
__
cilk
_steal
(
&
queue
[
i
]);
if
(
th
!=
NULL
)
{
__
wq
_run
(
th
);
__
cilk
_run
(
th
);
popcli
();
return
1
;
}
...
...
@@ -219,41 +219,41 @@ wq_trywork(void)
// Start a new work queue frame.
// We don't allow nested work queue frames.
void
wq
_start
(
void
)
cilk
_start
(
void
)
{
pushcli
();
if
(
myproc
()
->
wq
frame
.
ref
!=
0
)
panic
(
"
wq
_start"
);
mycpu
()
->
wqframe
=
&
myproc
()
->
wq
frame
;
if
(
myproc
()
->
cilk
frame
.
ref
!=
0
)
panic
(
"
cilk
_start"
);
mycpu
()
->
cilkframe
=
&
myproc
()
->
cilk
frame
;
}
// End of the current work queue frame.
// The core works while the reference count of the current
// work queue frame is not 0.
void
wq
_end
(
void
)
cilk
_end
(
void
)
{
while
(
wq
_frame
()
->
ref
!=
0
)
{
struct
wq
thread
*
th
;
while
(
cilk
_frame
()
->
ref
!=
0
)
{
struct
cilk
thread
*
th
;
int
i
;
while
((
th
=
__
wq_pop
(
wq
_cur
()))
!=
NULL
)
__
wq
_run
(
th
);
while
((
th
=
__
cilk_pop
(
cilk
_cur
()))
!=
NULL
)
__
cilk
_run
(
th
);
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
{
th
=
__
wq
_steal
(
&
queue
[
i
]);
th
=
__
cilk
_steal
(
&
queue
[
i
]);
if
(
th
!=
NULL
)
{
__
wq
_run
(
th
);
__
cilk
_run
(
th
);
break
;
}
}
}
mycpu
()
->
wq
frame
=
NULL
;
mycpu
()
->
cilk
frame
=
NULL
;
popcli
();
}
void
wq
_dump
(
void
)
cilk
_dump
(
void
)
{
int
i
;
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
...
...
@@ -268,7 +268,7 @@ __test_stub(uptr a0, uptr a1)
}
void
test
wq
(
void
)
test
cilk
(
void
)
{
enum
{
iters
=
1000
};
static
volatile
int
running
=
1
;
...
...
@@ -279,33 +279,33 @@ testwq(void)
if
(
mycpu
()
->
id
==
0
)
{
microdelay
(
1
);
s
=
rdtsc
();
wq
_start
();
cilk
_start
();
for
(
i
=
0
;
i
<
iters
;
i
++
)
wq
_push
(
__test_stub
,
i
,
i
);
wq
_end
();
cilk
_push
(
__test_stub
,
i
,
i
);
cilk
_end
();
e
=
rdtsc
();
cprintf
(
"test
wq
: %lu
\n
"
,
(
e
-
s
)
/
iters
);
wq
_dump
();
cprintf
(
"test
cilk
: %lu
\n
"
,
(
e
-
s
)
/
iters
);
cilk
_dump
();
running
=
0
;
}
else
{
while
(
running
)
wq
_trywork
();
cilk
_trywork
();
}
popcli
();
}
void
init
wqframe
(
struct
wqframe
*
wq
)
init
cilkframe
(
struct
cilkframe
*
cilk
)
{
memset
(
wq
,
0
,
sizeof
(
*
wq
));
memset
(
cilk
,
0
,
sizeof
(
*
cilk
));
}
void
init
wq
(
void
)
init
cilk
(
void
)
{
int
i
;
for
(
i
=
0
;
i
<
NCPU
;
i
++
)
ql_init
(
&
queue
[
i
].
lock
,
"queue lock"
);
}
#endif //
WQ
ENABLE
#endif //
CILK
ENABLE
console.c
浏览文件 @
e3b99cc0
...
...
@@ -248,8 +248,8 @@ consoleintr(int (*getc)(void))
consputc
(
BACKSPACE
);
}
break
;
case
C
(
'
W'
):
// Work queue
stats
wq
_dump
();
case
C
(
'
C'
):
// cilk
stats
cilk
_dump
();
break
;
case
C
(
'L'
):
// Prof stats
profdump
();
...
...
cpu.h
浏览文件 @
e3b99cc0
#include "mmu.h"
struct
wq
frame
;
struct
cilk
frame
;
// Per-CPU state
struct
cpu
{
...
...
@@ -10,7 +10,7 @@ struct cpu {
struct
segdesc
gdt
[
NSEGS
];
// x86 global descriptor table
struct
taskstate
ts
;
// Used by x86 to find stack for interrupt
struct
context
*
scheduler
;
// swtch() here to enter scheduler
struct
wqframe
*
wq
frame
;
struct
cilkframe
*
cilk
frame
;
// Cpu-local storage variables; see below
struct
cpu
*
cpu
;
...
...
exec.c
浏览文件 @
e3b99cc0
...
...
@@ -190,7 +190,7 @@ exec(char *path, char **argv)
args
.
path
=
path
;
args
.
argv
=
argv
;
wq
_start
();
cilk
_start
();
for
(
i
=
0
,
off
=
elf
.
phoff
;
i
<
elf
.
phnum
;
i
++
,
off
+=
sizeof
(
ph
)){
Elf64_Word
type
;
if
(
readi
(
ip
,
(
char
*
)
&
type
,
...
...
@@ -199,7 +199,7 @@ exec(char *path, char **argv)
goto
bad
;
if
(
type
!=
ELF_PROG_LOAD
)
continue
;
wq
_push
(
dosegment
,
(
uptr
)
&
args
,
(
uptr
)
off
);
cilk
_push
(
dosegment
,
(
uptr
)
&
args
,
(
uptr
)
off
);
}
if
(
odp
)
{
...
...
@@ -210,14 +210,14 @@ exec(char *path, char **argv)
ip
=
0
;
}
wq
_push
(
doheap
,
(
uptr
)
&
args
,
(
uptr
)
0
);
cilk
_push
(
doheap
,
(
uptr
)
&
args
,
(
uptr
)
0
);
// dostack reads from the user address space. The wq
// stuff doesn't switch to the user address space.
//
wq
_push(dostack, (uptr)&args, (uptr)0);
//
cilk
_push(dostack, (uptr)&args, (uptr)0);
dostack
((
uptr
)
&
args
,
(
uptr
)
0
);
wq
_end
();
cilk
_end
();
// Commit to the user image.
oldvmap
=
myproc
()
->
vmap
;
...
...
kernel.h
浏览文件 @
e3b99cc0
...
...
@@ -11,9 +11,9 @@ static inline uptr v2p(void *a) { return (uptr) a - KBASE; }
static
inline
void
*
p2v
(
uptr
a
)
{
return
(
void
*
)
a
+
KBASE
;
}
struct
trapframe
;
struct
cilkframe
;
struct
spinlock
;
struct
condvar
;
struct
wqframe
;
struct
context
;
struct
vmnode
;
struct
inode
;
...
...
@@ -325,20 +325,27 @@ struct vmap * vmap_copy(struct vmap *, int);
// wq.c
#if WQENABLE
void
wq_push
(
void
*
rip
,
u64
arg0
,
u64
arg1
);
void
wq_start
(
void
);
void
wq_end
(
void
);
void
wq_dump
(
void
);
int
wq_trywork
(
void
);
void
initwqframe
(
struct
wqframe
*
wq
);
#else
#define wq_push(rip, arg0, arg1) do { \
#define wq_trywork() 0
#endif
// cilk.c
#if CILKENABLE
void
cilk_push
(
void
*
rip
,
u64
arg0
,
u64
arg1
);
void
cilk_start
(
void
);
void
cilk_end
(
void
);
void
cilk_dump
(
void
);
int
cilk_trywork
(
void
);
void
initcilkframe
(
struct
cilkframe
*
wq
);
#else
#define cilk_push(rip, arg0, arg1) do { \
void (*fn)(uptr, uptr) = rip; \
fn(arg0, arg1); \
} while(0)
#define
wq
_start() do { } while(0)
#define
wq
_end() do { } while(0)
#define
wq
_dump() do { } while(0)
#define
wq
_trywork() 0
#define init
wq
frame(x) do { } while (0)
#define
cilk
_start() do { } while(0)
#define
cilk
_end() do { } while(0)
#define
cilk
_dump() do { } while(0)
#define
cilk
_trywork() 0
#define init
cilk
frame(x) do { } while (0)
#endif
main.c
浏览文件 @
e3b99cc0
...
...
@@ -23,7 +23,7 @@ extern void initinode(void);
extern
void
initdisk
(
void
);
extern
void
inituser
(
void
);
extern
void
inithz
(
void
);
extern
void
init
wq
(
void
);
extern
void
init
cilk
(
void
);
extern
void
initsamp
(
void
);
extern
void
initpci
(
void
);
extern
void
initnet
(
void
);
...
...
@@ -103,8 +103,8 @@ cmain(u64 mbmagic, u64 mbaddr)
initbio
();
// buffer cache
initinode
();
// inode cache
initdisk
();
// disk
#if
WQ
ENABLE
init
wq
();
// work queues
#if
CILK
ENABLE
init
cilk
();
#endif
initsamp
();
initlockstat
();
...
...
param.h
浏览文件 @
e3b99cc0
...
...
@@ -13,27 +13,25 @@
#define CACHELINE 64 // cache line size
#define CPUKSTACKS (NPROC + NCPU)
#define QUANTUM 10 // scheduling time quantum and tick length (in msec)
#define
WQSHIFT
4 // 2^WORKSHIFT work queue slots
#define
CILKSHIFT
4 // 2^WORKSHIFT work queue slots
#define VICTIMAGE 1000000 // cycles a proc executes before an eligible victim
#define VERBOSE 0 // print kernel diagnostics
#define SPINLOCK_DEBUG 1 // Debug spin locks
#define LOCKSTAT 0
#define VERIFYFREE LOCKSTAT
#define ALLOC_MEMSET 1
#define WQENABLE 0
#if defined(HW_josmp)
#define NCPU 16 // maximum number of CPUs
#define MTRACE 0
#define WQENABLE 0 // Enable work queue
#define PERFSIZE (1<<30ull)
#elif defined(HW_qemu)
#define NCPU 4 // maximum number of CPUs
#define MTRACE 0
#define WQENABLE 0 // Enable work queue
#define PERFSIZE (16<<20ull)
#elif defined(HW_ud0)
#define NCPU 4 // maximum number of CPUs
#define MTRACE 0
#define WQENABLE 0 // Enable work queue
#define PERFSIZE (512<<20ull)
#else
#error "Unknown HW"
...
...
proc.c
浏览文件 @
e3b99cc0
...
...
@@ -206,7 +206,7 @@ allocproc(void)
snprintf
(
p
->
lockname
,
sizeof
(
p
->
lockname
),
"cv:proc:%d"
,
p
->
pid
);
initlock
(
&
p
->
lock
,
p
->
lockname
+
3
,
LOCKSTAT_PROC
);
initcondvar
(
&
p
->
cv
,
p
->
lockname
);
init
wqframe
(
&
p
->
wq
frame
);
init
cilkframe
(
&
p
->
cilk
frame
);
if
(
ns_insert
(
nspid
,
KI
(
p
->
pid
),
(
void
*
)
p
)
<
0
)
panic
(
"allocproc: ns_insert"
);
...
...
proc.h
浏览文件 @
e3b99cc0
...
...
@@ -13,7 +13,7 @@ struct context {
}
__attribute__
((
packed
));
// Work queue frame
struct
wq
frame
{
struct
cilk
frame
{
volatile
u64
ref
;
};
...
...
@@ -63,7 +63,7 @@ struct proc {
struct
mtrace_stacks
mtrace_stacks
;
#endif
struct
runq
*
runq
;
struct
wqframe
wq
frame
;
struct
cilkframe
cilk
frame
;
STAILQ_ENTRY
(
proc
)
runqlink
;
struct
condvar
*
oncv
;
// Where it is sleeping, for kill()
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论