Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
a02648fc
提交
a02648fc
10月 30, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move scheduling stuff to sched.c.
上级
d3c7235d
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
122 行增加
和
85 行删除
+122
-85
Makefile
Makefile
+1
-0
proc.c
proc.c
+4
-85
sched.c
sched.c
+112
-0
sched.h
sched.h
+5
-0
没有找到文件。
Makefile
浏览文件 @
a02648fc
...
...
@@ -46,6 +46,7 @@ OBJS = \
pipe.o
\
proc.o
\
rcu.o
\
sched.o
\
spinlock.o
\
swtch.o
\
string.o
\
...
...
proc.c
浏览文件 @
a02648fc
...
...
@@ -11,10 +11,10 @@
#include "bits.h"
#include "kmtrace.h"
#include "vm.h"
#include "sched.h"
int
__mpalign__
idle
[
NCPU
];
struct
ns
*
nspid
__mpalign__
;
struct
ns
*
nsrunq
__mpalign__
;
static
struct
proc
*
bootproc
__mpalign__
;
#if MTRACE
...
...
@@ -60,42 +60,6 @@ yield(void)
release
(
&
myproc
()
->
lock
);
}
// Mark a process RUNNABLE and add it to the runq
// of its cpu. Caller must hold p->lock so that
// some other core doesn't start running the
// process before the caller has finished setting
// the process up, and to cope with racing callers
// e.g. two wakeups on same process. and to
// allow atomic addrun(); sched();
void
addrun
(
struct
proc
*
p
)
{
#if SPINLOCK_DEBUG
if
(
!
holding
(
&
p
->
lock
))
panic
(
"addrun no p->lock"
);
#endif
if
(
p
->
on_runq
>=
0
)
panic
(
"addrun on runq already"
);
ns_insert
(
nsrunq
,
KI
(
p
->
cpuid
),
p
);
p
->
on_runq
=
p
->
cpuid
;
}
void
delrun
(
struct
proc
*
p
)
{
#if SPINLOCK_DEBUG
if
(
!
holding
(
&
p
->
lock
))
panic
(
"delrun no p->lock"
);
#endif
if
(
p
->
on_runq
<
0
)
panic
(
"delrun not on runq"
);
if
(
ns_remove
(
nsrunq
,
KI
(
p
->
on_runq
),
p
)
==
0
)
panic
(
"delrun: ns_remove"
);
p
->
on_runq
=
-
1
;
}
void
migrate
(
struct
proc
*
p
)
{
...
...
@@ -325,9 +289,7 @@ initproc(void)
if
(
nspid
==
0
)
panic
(
"pinit"
);
nsrunq
=
nsalloc
(
1
);
if
(
nsrunq
==
0
)
panic
(
"pinit runq"
);
initsched
();
for
(
c
=
0
;
c
<
NCPU
;
c
++
)
idle
[
c
]
=
1
;
...
...
@@ -341,49 +303,6 @@ initproc(void)
// - eventually that process transfers control
// via swtch back to the scheduler.
static
void
*
choose_runnable
(
void
*
pp
,
void
*
arg
)
{
struct
proc
*
p
=
pp
;
if
(
p
->
state
==
RUNNABLE
)
return
p
;
return
0
;
}
static
void
*
steal_cb
(
void
*
vk
,
void
*
v
,
void
*
arg
)
{
struct
proc
*
p
=
v
;
acquire
(
&
p
->
lock
);
if
(
p
->
state
!=
RUNNABLE
||
p
->
cpuid
==
mycpu
()
->
id
||
p
->
cpu_pin
)
{
release
(
&
p
->
lock
);
return
0
;
}
if
(
p
->
curcycles
==
0
||
p
->
curcycles
>
MINCYCTHRESH
)
{
if
(
sched_debug
)
cprintf
(
"cpu%d: steal %d (cycles=%d) from %d
\n
"
,
mycpu
()
->
id
,
p
->
pid
,
(
int
)
p
->
curcycles
,
p
->
cpuid
);
delrun
(
p
);
p
->
curcycles
=
0
;
p
->
cpuid
=
mycpu
()
->
id
;
addrun
(
p
);
release
(
&
p
->
lock
);
return
p
;
}
release
(
&
p
->
lock
);
return
0
;
}
int
steal
(
void
)
{
void
*
stole
=
ns_enumerate
(
nsrunq
,
steal_cb
,
0
);
return
stole
?
1
:
0
;
}
void
scheduler
(
void
)
{
...
...
@@ -403,7 +322,7 @@ scheduler(void)
// Enable interrupts on this processor.
sti
();
struct
proc
*
p
=
ns_enumerate_key
(
nsrunq
,
KI
(
mycpu
()
->
id
),
choose_runnable
,
0
);
struct
proc
*
p
=
schednext
(
);
if
(
p
)
{
acquire
(
&
p
->
lock
);
if
(
p
->
state
!=
RUNNABLE
)
{
...
...
@@ -595,7 +514,7 @@ void *procdump(void *vk, void *v, void *arg)
state
=
states
[
p
->
state
];
else
state
=
"???"
;
cprintf
(
"%d %s %s %d
, "
,
p
->
pid
,
state
,
p
->
name
,
p
->
cpuid
);
cprintf
(
"%d %s %s %d
%lu"
,
p
->
pid
,
state
,
p
->
name
,
p
->
cpuid
,
p
->
tsc
);
// XXX(sbw)
#if 0
...
...
sched.c
0 → 100644
浏览文件 @
a02648fc
#include "types.h"
#include "kernel.h"
#include "param.h"
#include "mmu.h"
#include "amd64.h"
#include "spinlock.h"
#include "condvar.h"
#include "queue.h"
#include "proc.h"
#include "cpu.h"
#include "bits.h"
#include "kmtrace.h"
#include "vm.h"
#include "sched.h"
enum
{
sched_debug
=
0
};
struct
ns
*
nsrunq
__mpalign__
;
// Mark a process RUNNABLE and add it to the runq
// of its cpu. Caller must hold p->lock so that
// some other core doesn't start running the
// process before the caller has finished setting
// the process up, and to cope with racing callers
// e.g. two wakeups on same process. and to
// allow atomic addrun(); sched();
void
addrun
(
struct
proc
*
p
)
{
#if SPINLOCK_DEBUG
if
(
!
holding
(
&
p
->
lock
))
panic
(
"addrun no p->lock"
);
#endif
if
(
p
->
on_runq
>=
0
)
panic
(
"addrun on runq already"
);
ns_insert
(
nsrunq
,
KI
(
p
->
cpuid
),
p
);
p
->
on_runq
=
p
->
cpuid
;
}
void
delrun
(
struct
proc
*
p
)
{
#if SPINLOCK_DEBUG
if
(
!
holding
(
&
p
->
lock
))
panic
(
"delrun no p->lock"
);
#endif
if
(
p
->
on_runq
<
0
)
panic
(
"delrun not on runq"
);
if
(
ns_remove
(
nsrunq
,
KI
(
p
->
on_runq
),
p
)
==
0
)
panic
(
"delrun: ns_remove"
);
p
->
on_runq
=
-
1
;
}
static
void
*
steal_cb
(
void
*
vk
,
void
*
v
,
void
*
arg
)
{
struct
proc
*
p
=
v
;
acquire
(
&
p
->
lock
);
if
(
p
->
state
!=
RUNNABLE
||
p
->
cpuid
==
mycpu
()
->
id
||
p
->
cpu_pin
)
{
release
(
&
p
->
lock
);
return
0
;
}
if
(
p
->
curcycles
==
0
||
p
->
curcycles
>
MINCYCTHRESH
)
{
if
(
sched_debug
)
cprintf
(
"cpu%d: steal %d (cycles=%d) from %d
\n
"
,
mycpu
()
->
id
,
p
->
pid
,
(
int
)
p
->
curcycles
,
p
->
cpuid
);
delrun
(
p
);
p
->
curcycles
=
0
;
p
->
cpuid
=
mycpu
()
->
id
;
addrun
(
p
);
release
(
&
p
->
lock
);
return
p
;
}
release
(
&
p
->
lock
);
return
0
;
}
int
steal
(
void
)
{
void
*
stole
=
ns_enumerate
(
nsrunq
,
steal_cb
,
0
);
return
stole
?
1
:
0
;
}
static
void
*
choose_runnable
(
void
*
pp
,
void
*
arg
)
{
struct
proc
*
head
=
pp
;
if
(
head
->
state
==
RUNNABLE
)
return
head
;
return
0
;
}
struct
proc
*
schednext
(
void
)
{
return
ns_enumerate_key
(
nsrunq
,
KI
(
mycpu
()
->
id
),
choose_runnable
,
0
);
}
void
initsched
(
void
)
{
nsrunq
=
nsalloc
(
1
);
if
(
nsrunq
==
0
)
panic
(
"pinit runq"
);
}
sched.h
0 → 100644
浏览文件 @
a02648fc
void
delrun
(
struct
proc
*
);
void
initsched
(
void
);
struct
proc
*
schednext
(
void
);
int
steal
(
void
);
void
addrun
(
struct
proc
*
);
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论