Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
44d80c8c
提交
44d80c8c
4月 18, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Start of x2apic code
上级
abd2d17c
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
161 行增加
和
77 行删除
+161
-77
apic.hh
include/apic.hh
+35
-0
kernel.hh
include/kernel.hh
+0
-7
mmu.h
include/mmu.h
+2
-2
Makefrag
kernel/Makefrag
+2
-1
hwvm.cc
kernel/hwvm.cc
+1
-2
main.cc
kernel/main.cc
+1
-1
sampler.cc
kernel/sampler.cc
+1
-0
trap.cc
kernel/trap.cc
+1
-0
x2apic.cc
kernel/x2apic.cc
+47
-0
xapic.cc
kernel/xapic.cc
+65
-64
param.h
param.h
+6
-0
没有找到文件。
include/apic.hh
0 → 100644
浏览文件 @
44d80c8c
#if defined(HW_ben)
#define lapicstartap x2apicstartap
#define lapiceoi x2apiceoi
#define lapic_tlbflush x2apic_tlbflush
#define lapic_sampconf x2apic_sampconf
#define lapicpc x2apicpc
#define lapicid x2apicid
#define initlapic initx2apic
#else
#define lapicstartap xapicstartap
#define lapiceoi xapiceoi
#define lapic_tlbflush xapic_tlbflush
#define lapic_sampconf xapic_sampconf
#define lapicpc xapicpc
#define lapicid xapicid
#define initlapic initxapic
#endif
// xapic.cc
void
xapicstartap
(
hwid_t
,
u32
addr
);
void
xapiceoi
(
void
);
void
xapic_tlbflush
(
hwid_t
);
void
xapic_sampconf
(
hwid_t
);
void
xapicpc
(
char
mask
);
hwid_t
xapicid
(
void
);
void
initxapic
(
void
);
// x2apic.cc
void
x2apicstartap
(
hwid_t
,
u32
addr
);
void
x2apiceoi
(
void
);
void
x2apic_tlbflush
(
hwid_t
);
void
x2apic_sampconf
(
hwid_t
);
void
x2apicpc
(
char
mask
);
hwid_t
x2apicid
(
void
);
void
initx2apic
(
void
);
include/kernel.hh
浏览文件 @
44d80c8c
...
...
@@ -141,13 +141,6 @@ void kmemprint(void);
// kbd.c
void
kbdintr
(
void
);
// lapic.c
void
lapicstartap
(
hwid_t
,
u32
addr
);
void
lapiceoi
(
void
);
void
lapic_tlbflush
(
hwid_t
);
void
lapic_sampconf
(
hwid_t
);
void
lapicpc
(
char
mask
);
// main.c
void
halt
(
void
)
__attribute__
((
noreturn
));
...
...
include/mmu.h
浏览文件 @
44d80c8c
...
...
@@ -121,10 +121,10 @@ struct taskstate
}
__attribute__
((
packed
,
aligned
(
16
)));
typedef
struct
hwid
{
u
8
num
;
u
32
num
;
}
hwid_t
;
#define HWID(xnum) (struct hwid){ num: (u
8
)(xnum) }
#define HWID(xnum) (struct hwid){ num: (u
32
)(xnum) }
#endif
#define INT_P (1<<7)
/* interrupt descriptor present */
...
...
kernel/Makefrag
浏览文件 @
44d80c8c
...
...
@@ -16,7 +16,6 @@ OBJS = \
futex.o \
idle.o \
ioapic.o \
lapic.o \
hwvm.o \
hz.o \
kalloc.o \
...
...
@@ -52,6 +51,8 @@ OBJS = \
wqkern.o \
wqlib.o \
script.o \
xapic.o \
x2apic.o \
zalloc.o \
incbin.o \
sysvectors.o \
...
...
kernel/hwvm.cc
浏览文件 @
44d80c8c
...
...
@@ -11,6 +11,7 @@
#include "proc.hh"
#include "vm.hh"
#include "wq.hh"
#include "apic.hh"
using
namespace
std
;
...
...
@@ -213,8 +214,6 @@ freevm(pgmap *pml4)
void
inittls
(
void
)
{
extern
hwid_t
lapicid
(
void
);
struct
cpu
*
c
;
cpuid_t
id
=
-
1
;
...
...
kernel/main.cc
浏览文件 @
44d80c8c
...
...
@@ -8,6 +8,7 @@
#include "hwvm.hh"
#include "condvar.h"
#include "proc.hh"
#include "apic.hh"
void
initpic
(
void
);
void
initioapic
(
void
);
...
...
@@ -16,7 +17,6 @@ void initcga(void);
void
initconsole
(
void
);
void
initpg
(
void
);
void
initmp
(
void
);
void
initlapic
(
void
);
void
inittls
(
void
);
void
initnmi
(
void
);
void
inittrap
(
void
);
...
...
kernel/sampler.cc
浏览文件 @
44d80c8c
...
...
@@ -11,6 +11,7 @@
#include "cpu.hh"
#include "sampler.h"
#include "major.h"
#include "apic.hh"
#define LOGHEADER_SZ (sizeof(struct logheader) + \
sizeof(((struct logheader*)0)->cpu[0])*NCPU)
...
...
kernel/trap.cc
浏览文件 @
44d80c8c
...
...
@@ -11,6 +11,7 @@
#include "kmtrace.hh"
#include "bits.hh"
#include "kalloc.hh"
#include "apic.hh"
extern
"C"
void
__uaccess_end
(
void
);
...
...
kernel/x2apic.cc
0 → 100644
浏览文件 @
44d80c8c
#include "types.h"
#include "amd64.h"
#include "bits.hh"
#include "kernel.hh"
void
x2apicstartap
(
hwid_t
id
,
u32
addr
)
{
panic
(
"x2apicstartap"
);
}
void
x2apiceoi
(
void
)
{
panic
(
"x2apiceoi"
);
}
void
x2apic_tlbflush
(
hwid_t
id
)
{
panic
(
"x2apic_tlbflush"
);
}
void
x2apic_sampconf
(
hwid_t
id
)
{
panic
(
"x2apic_sampconf"
);
}
void
x2apicpc
(
char
mask
)
{
panic
(
"x2apicpc"
);
}
hwid_t
x2apicid
(
void
)
{
panic
(
"x2apicid"
);
return
HWID
(
0
);
}
void
initx2apic
(
void
)
{
panic
(
"initx2apic"
);
}
kernel/
l
apic.cc
→
kernel/
x
apic.cc
浏览文件 @
44d80c8c
...
...
@@ -7,6 +7,7 @@
#include "traps.h"
#include "bits.hh"
#include "cpu.hh"
#include "apic.hh"
// Local APIC registers, divided by 4 for use as uint[] indices.
#define ID (0x0020/4) // ID
...
...
@@ -43,31 +44,31 @@
#define IO_RTC 0x70
static
volatile
u32
*
l
apic
=
(
u32
*
)(
KBASE
+
0xfee00000
);
static
u64
l
apichz
;
static
volatile
u32
*
x
apic
=
(
u32
*
)(
KBASE
+
0xfee00000
);
static
u64
x
apichz
;
static
void
l
apicw
(
int
index
,
int
value
)
x
apicw
(
int
index
,
int
value
)
{
l
apic
[
index
]
=
value
;
l
apic
[
ID
];
// wait for write to finish, by reading
x
apic
[
index
]
=
value
;
x
apic
[
ID
];
// wait for write to finish, by reading
}
static
u32
l
apicr
(
u32
off
)
x
apicr
(
u32
off
)
{
return
l
apic
[
off
];
return
x
apic
[
off
];
}
static
int
l
apicwait
()
x
apicwait
()
{
int
i
=
100000
;
while
((
l
apicr
(
ICRLO
)
&
BUSY
)
!=
0
)
{
while
((
x
apicr
(
ICRLO
)
&
BUSY
)
!=
0
)
{
nop_pause
();
i
--
;
if
(
i
==
0
)
{
cprintf
(
"
l
apicwait: wedged?
\n
"
);
cprintf
(
"
x
apicwait: wedged?
\n
"
);
return
-
1
;
}
}
...
...
@@ -75,7 +76,7 @@ lapicwait()
}
void
init
l
apic
(
void
)
init
x
apic
(
void
)
{
u64
count
;
u64
apicbar
;
...
...
@@ -93,69 +94,69 @@ initlapic(void)
// Sanity-check..
u32
ebx
;
cpuid
(
CPUID_FEATURES
,
0
,
&
ebx
,
0
,
0
);
assert
(
l
apic
[
ID
]
>>
24
==
FEATURE_EBX_APIC
(
ebx
));
assert
(
x
apic
[
ID
]
>>
24
==
FEATURE_EBX_APIC
(
ebx
));
}
// Enable local APIC; set spurious interrupt vector.
l
apicw
(
SVR
,
ENABLE
|
(
T_IRQ0
+
IRQ_SPURIOUS
));
x
apicw
(
SVR
,
ENABLE
|
(
T_IRQ0
+
IRQ_SPURIOUS
));
if
(
l
apichz
==
0
)
{
if
(
x
apichz
==
0
)
{
// Measure the TICR frequency
l
apicw
(
TDCR
,
X1
);
l
apicw
(
TICR
,
0xffffffff
);
u64
ccr0
=
l
apicr
(
TCCR
);
x
apicw
(
TDCR
,
X1
);
x
apicw
(
TICR
,
0xffffffff
);
u64
ccr0
=
x
apicr
(
TCCR
);
microdelay
(
10
*
1000
);
// 1/100th of a second
u64
ccr1
=
l
apicr
(
TCCR
);
l
apichz
=
100
*
(
ccr0
-
ccr1
);
u64
ccr1
=
x
apicr
(
TCCR
);
x
apichz
=
100
*
(
ccr0
-
ccr1
);
}
count
=
(
QUANTUM
*
l
apichz
)
/
1000
;
count
=
(
QUANTUM
*
x
apichz
)
/
1000
;
if
(
count
>
0xffffffff
)
panic
(
"init
l
apic: QUANTUM too large"
);
panic
(
"init
x
apic: QUANTUM too large"
);
// The timer repeatedly counts down at bus frequency
// from
l
apic[TICR] and then issues an interrupt.
l
apicw
(
TDCR
,
X1
);
l
apicw
(
TIMER
,
PERIODIC
|
(
T_IRQ0
+
IRQ_TIMER
));
l
apicw
(
TICR
,
count
);
// from
x
apic[TICR] and then issues an interrupt.
x
apicw
(
TDCR
,
X1
);
x
apicw
(
TIMER
,
PERIODIC
|
(
T_IRQ0
+
IRQ_TIMER
));
x
apicw
(
TICR
,
count
);
// Disable logical interrupt lines.
l
apicw
(
LINT0
,
MASKED
);
l
apicw
(
LINT1
,
MASKED
);
x
apicw
(
LINT0
,
MASKED
);
x
apicw
(
LINT1
,
MASKED
);
// Disable performance counter overflow interrupts
// on machines that provide that interrupt entry.
if
(((
l
apic
[
VER
]
>>
16
)
&
0xFF
)
>=
4
)
l
apicpc
(
0
);
if
(((
x
apic
[
VER
]
>>
16
)
&
0xFF
)
>=
4
)
x
apicpc
(
0
);
// Map error interrupt to IRQ_ERROR.
l
apicw
(
ERROR
,
T_IRQ0
+
IRQ_ERROR
);
x
apicw
(
ERROR
,
T_IRQ0
+
IRQ_ERROR
);
// Clear error status register (requires back-to-back writes).
l
apicw
(
ESR
,
0
);
l
apicw
(
ESR
,
0
);
x
apicw
(
ESR
,
0
);
x
apicw
(
ESR
,
0
);
// Ack any outstanding interrupts.
l
apicw
(
EOI
,
0
);
x
apicw
(
EOI
,
0
);
// Send an Init Level De-Assert to synchronise arbitration ID's.
l
apicw
(
ICRHI
,
0
);
l
apicw
(
ICRLO
,
BCAST
|
INIT
|
LEVEL
);
while
(
l
apic
[
ICRLO
]
&
DELIVS
)
x
apicw
(
ICRHI
,
0
);
x
apicw
(
ICRLO
,
BCAST
|
INIT
|
LEVEL
);
while
(
x
apic
[
ICRLO
]
&
DELIVS
)
;
// Enable interrupts on the APIC (but not on the processor).
l
apicw
(
TPR
,
0
);
x
apicw
(
TPR
,
0
);
}
void
l
apicpc
(
char
mask
)
x
apicpc
(
char
mask
)
{
l
apicw
(
PCINT
,
mask
?
MASKED
:
MT_NMI
);
x
apicw
(
PCINT
,
mask
?
MASKED
:
MT_NMI
);
}
hwid_t
l
apicid
(
void
)
x
apicid
(
void
)
{
if
(
readrflags
()
&
FL_IF
)
{
cli
();
...
...
@@ -171,47 +172,47 @@ lapicid(void)
#if 0
// It should be safe to read from the APIC's MMIO anytime,
// but it's not. The BIOS might have enabled the x2APIC,
// in which case the value of
l
apic[ID]>>24 is undefined.
if (
l
apic == nullptr)
panic("
l
apicid");
return HWID(
l
apic[ID]>>24);
// in which case the value of
x
apic[ID]>>24 is undefined.
if (
x
apic == nullptr)
panic("
x
apicid");
return HWID(
x
apic[ID]>>24);
#endif
}
// Acknowledge interrupt.
void
l
apiceoi
(
void
)
x
apiceoi
(
void
)
{
if
(
l
apic
)
l
apicw
(
EOI
,
0
);
if
(
x
apic
)
x
apicw
(
EOI
,
0
);
}
// Send IPI
void
l
apic_ipi
(
hwid_t
hwid
,
int
ino
)
x
apic_ipi
(
hwid_t
hwid
,
int
ino
)
{
l
apicw
(
ICRHI
,
hwid
.
num
<<
24
);
l
apicw
(
ICRLO
,
FIXED
|
DEASSERT
|
ino
);
if
(
l
apicwait
()
<
0
)
panic
(
"
lapic_ipi: l
apicwait failure"
);
x
apicw
(
ICRHI
,
hwid
.
num
<<
24
);
x
apicw
(
ICRLO
,
FIXED
|
DEASSERT
|
ino
);
if
(
x
apicwait
()
<
0
)
panic
(
"
xapic_ipi: x
apicwait failure"
);
}
void
l
apic_tlbflush
(
hwid_t
hwid
)
x
apic_tlbflush
(
hwid_t
hwid
)
{
l
apic_ipi
(
hwid
,
T_TLBFLUSH
);
x
apic_ipi
(
hwid
,
T_TLBFLUSH
);
}
void
l
apic_sampconf
(
hwid_t
hwid
)
x
apic_sampconf
(
hwid_t
hwid
)
{
l
apic_ipi
(
hwid
,
T_SAMPCONF
);
x
apic_ipi
(
hwid
,
T_SAMPCONF
);
}
// Start additional processor running bootstrap code at addr.
// See Appendix B of MultiProcessor Specification.
void
l
apicstartap
(
hwid
hwid
,
u32
addr
)
x
apicstartap
(
hwid
hwid
,
u32
addr
)
{
int
i
;
volatile
u16
*
wrv
;
...
...
@@ -227,12 +228,12 @@ lapicstartap(hwid hwid, u32 addr)
// "Universal startup algorithm."
// Send INIT (level-triggered) interrupt to reset other CPU.
l
apicw
(
ICRHI
,
hwid
.
num
<<
24
);
l
apicw
(
ICRLO
,
hwid
.
num
|
INIT
|
LEVEL
|
ASSERT
);
l
apicwait
();
x
apicw
(
ICRHI
,
hwid
.
num
<<
24
);
x
apicw
(
ICRLO
,
hwid
.
num
|
INIT
|
LEVEL
|
ASSERT
);
x
apicwait
();
microdelay
(
10000
);
l
apicw
(
ICRLO
,
hwid
.
num
|
INIT
|
LEVEL
);
l
apicwait
();
x
apicw
(
ICRLO
,
hwid
.
num
|
INIT
|
LEVEL
);
x
apicwait
();
microdelay
(
10000
);
// should be 10ms, but too slow in Bochs!
// Send startup IPI (twice!) to enter bootstrap code.
...
...
@@ -241,8 +242,8 @@ lapicstartap(hwid hwid, u32 addr)
// should be ignored, but it is part of the official Intel algorithm.
// Bochs complains about the second one. Too bad for Bochs.
for
(
i
=
0
;
i
<
2
;
i
++
){
l
apicw
(
ICRHI
,
hwid
.
num
<<
24
);
l
apicw
(
ICRLO
,
STARTUP
|
(
addr
>>
12
));
x
apicw
(
ICRHI
,
hwid
.
num
<<
24
);
x
apicw
(
ICRLO
,
STARTUP
|
(
addr
>>
12
));
microdelay
(
200
);
}
}
param.h
浏览文件 @
44d80c8c
...
...
@@ -39,9 +39,15 @@
#define MTRACE 0
#define PERFSIZE (512<<20ull)
#elif defined(HW_tom)
#define DEBUG 0
#define NCPU 48 // maximum number of CPUs
#define MTRACE 0
#define PERFSIZE (1<<20ull)
#elif defined(HW_ben)
#define DEBUG 0
#define NCPU 80 // maximum number of CPUs
#define MTRACE 0
#define PERFSIZE (1<<20ull)
#elif defined(HW_user)
#define NCPU 256
#define MTRACE 0
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论