Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
98c1ea02
提交
98c1ea02
4月 11, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More usched tweaks
上级
f6d240e6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
25 行删除
+23
-25
Makefrag.usched
user/Makefrag.usched
+3
-3
usched.cc
user/usched.cc
+20
-22
没有找到文件。
user/Makefrag.usched
浏览文件 @
98c1ea02
NCXXFLAGS = -
static -g
-MD -m64 -O3 -Wall -Werror -DHW_$(HW) \
NCXXFLAGS = -
g -static
-MD -m64 -O3 -Wall -Werror -DHW_$(HW) \
-fno-builtin -fno-strict-aliasing -fno-omit-frame-pointer \
-fms-extensions -mcx16 -mno-red-zone -std=c++0x \
-Wno-sign-compare -fno-exceptions -fno-rtti -fcheck-new \
-iquote . -iquote include \
-include param.h -include include/compiler.h
NCFLAGS = -
static -g
-MD -m64 -O3 -Wall -Werror -DHW_$(HW) \
NCFLAGS = -
g -static
-MD -m64 -O3 -Wall -Werror -DHW_$(HW) \
-fno-builtin -fno-strict-aliasing -fno-omit-frame-pointer \
-fms-extensions -mcx16 -mno-red-zone -std=c99 \
-Wno-sign-compare -fno-exceptions \
...
...
@@ -25,7 +25,7 @@ $(O)/user/%.o: user/%.cc
$(O)/%: $(O)/user/%.o
@echo " LD $@"
$(Q)mkdir -p $(@D)
$(Q)$(CXX) -o $@ $^ -lpthread
$(Q)$(CXX) -o $@ $^ -lpthread
-ljemalloc
.PRECIOUS: $(O)/user/%.o
-include $(O)/user/*.d
...
...
user/usched.cc
浏览文件 @
98c1ea02
// export LD_PRELOAD="/usr/lib/libjemalloc.so.1"
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
...
...
@@ -13,11 +15,13 @@ typedef uint64_t u64;
#include "sched.hh"
#include "queue.h"
static
int
nprocs
=
2
;
static
int
the_time
=
2
;
static
int
nprocs
=
NCPU
;
static
int
the_time
=
5
;
static
uint64_t
start
;
static
volatile
int
go
;
static
__thread
unsigned
myid_
;
percpu
<
uint64_t
>
ops
;
struct
proc
:
public
sched_link
...
...
@@ -26,8 +30,6 @@ struct proc : public sched_link
LIST_ENTRY
(
proc
)
link
;
};
//percpu<proc_list> proc_list;
struct
stuff
{
bool
flipper
;
uint32_t
seed
;
...
...
@@ -38,24 +40,17 @@ struct stuff {
}
proc
*
allocproc
()
{
if
(
LIST_EMPTY
(
&
proc_list
))
die
(
"allocproc"
);
proc
*
p
=
LIST_FIRST
(
&
proc_list
);
LIST_REMOVE
(
p
,
link
);
proc
*
p
=
(
proc
*
)
malloc
(
sizeof
(
proc
));
return
p
;
}
void
freeproc
(
proc
*
p
)
{
LIST_INSERT_HEAD
(
&
proc_list
,
p
,
link
);
free
(
p
);
}
void
fillproc
(
void
)
{
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
proc
*
p
=
new
proc
();
freeproc
(
p
);
}
}
};
percpu
<
stuff
>
stuff_
;
...
...
@@ -71,14 +66,14 @@ public:
volatile
u64
ncansteal_
__mpalign__
;
sched_stat
stats_
;
private
:
pthread_spinlock_t
lock_
;
sched_link
head_
;
};
percpu
<
schedule
>
schedule_
;
static
__thread
unsigned
myid_
;
int
mycpuid
(
void
)
{
...
...
@@ -103,7 +98,7 @@ sighandler(int x)
tot
=
0
;
for
(
int
i
=
0
;
i
<
NCPU
;
i
++
)
{
tot
+=
ops
[
i
];
printf
(
"
%lu
\n
"
,
schedule_
[
i
].
ncansteal_
);
printf
(
"
%lu %lu
\n
"
,
ops
[
i
],
schedule_
[
i
].
stats_
.
steals
);
}
printf
(
"%f
\n
"
,
(
stop
-
start
)
/
(
tot
/
NCPU
));
...
...
@@ -129,6 +124,7 @@ schedule::enq(proc* p)
head_
.
prev
=
entry
;
if
(
cansteal
((
proc
*
)
entry
,
true
))
ncansteal_
++
;
stats_
.
enqs
++
;
pthread_spin_unlock
(
&
lock_
);
}
...
...
@@ -150,6 +146,7 @@ schedule::deq(void)
entry
->
prev
->
next
=
entry
->
next
;
if
(
cansteal
((
proc
*
)
entry
,
true
))
--
ncansteal_
;
stats_
.
deqs
++
;
pthread_spin_unlock
(
&
lock_
);
return
(
proc
*
)
entry
;
}
...
...
@@ -165,10 +162,12 @@ schedule::steal(bool nonexec)
ptr
->
next
->
prev
=
ptr
->
prev
;
ptr
->
prev
->
next
=
ptr
->
next
;
--
ncansteal_
;
++
stats_
.
steals
;
pthread_spin_unlock
(
&
lock_
);
return
(
proc
*
)
ptr
;
}
pthread_spin_unlock
(
&
lock_
);
++
stats_
.
misses
;
return
nullptr
;
}
...
...
@@ -190,7 +189,7 @@ stealit(void)
for
(
int
i
=
0
;
i
<
NCPU
;
i
++
)
{
if
(
i
==
myid_
)
break
;
continue
;
p
=
schedule_
[
i
].
steal
(
true
);
if
(
p
)
{
return
p
;
...
...
@@ -214,16 +213,14 @@ schedit(void)
runit
(
p
);
(
*
ops
)
++
;
if
(
r
<
10
&&
!
stuff_
->
flipper
)
{
stuff_
->
flipper
=
!
stuff_
->
flipper
;
if
(
r
<
10
&&
(
myid_
%
2
)
==
0
)
{
stuff_
->
freeproc
(
p
);
}
else
schedule_
->
enq
(
p
);
}
if
(
r
>=
10
&&
r
<
20
&&
stuff_
->
flipper
)
{
stuff_
->
flipper
=
!
stuff_
->
flipper
;
if
(
r
>
90
&&
(
myid_
%
2
)
==
1
)
{
schedule_
->
enq
(
stuff_
->
allocproc
());
}
}
...
...
@@ -238,7 +235,7 @@ worker(void* x)
if
(
myid_
==
0
)
{
for
(
int
i
=
0
;
i
<
nprocs
;
i
++
)
schedule_
->
enq
(
new
proc
());
schedule_
->
enq
(
stuff_
->
alloc
proc
());
if
(
signal
(
SIGALRM
,
sighandler
)
==
SIG_ERR
)
edie
(
"signal failed
\n
"
);
...
...
@@ -270,6 +267,7 @@ main(int ac, char** av)
edie
(
"pthread_create"
);
}
sleep
(
1
);
worker
((
void
*
)
0
);
return
0
;
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论