Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
706ea3fe
提交
706ea3fe
2月 11, 2012
创建
作者:
Nickolai Zeldovich
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'scale-amd64' of
git+ssh://pdos.csail.mit.edu/home/am0/6.828/xv6
into scale-amd64
上级
2a53d3c4
89ae1d13
隐藏空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
124 行增加
和
116 行删除
+124
-116
Makefile
Makefile
+8
-3
compiler.h
compiler.h
+8
-0
fmt.cc
fmt.cc
+2
-1
ipc.h
ipc.h
+4
-1
kernel.h
kernel.h
+1
-1
kernlet.c
kernlet.c
+10
-1
net.mk
net.mk
+6
-6
preadtest.cc
preadtest.cc
+27
-6
printf.cc
printf.cc
+5
-91
string.cc
string.cc
+1
-1
sysfile.cc
sysfile.cc
+5
-1
ulib.c
ulib.c
+0
-0
user.h
user.h
+2
-4
usertests.cc
usertests.cc
+45
-0
没有找到文件。
Makefile
浏览文件 @
706ea3fe
...
...
@@ -19,6 +19,7 @@ AS = $(TOOLPREFIX)gas
LD
=
$(TOOLPREFIX)
ld
NM
=
$(TOOLPREFIX)
nm
OBJCOPY
=
$(TOOLPREFIX)
objcopy
STRIP
=
$(TOOLPREFIX)
strip
COMFLAGS
:=
-fno-pic
-static
-fno-builtin
-fno-strict-aliasing
-O2
-Wall
\
-MD
-ggdb
-m64
-Werror
-fms-extensions
-mno-sse
\
...
...
@@ -79,7 +80,7 @@ OBJS = \
incbin.o
OBJS
:=
$
(
addprefix
$(O)
/,
$(OBJS)
)
ULIB
=
ulib.o usys.o printf.o umalloc.o uthread.o
ULIB
=
ulib.o usys.o printf.o umalloc.o uthread.o
fmt.o
ULIB
:=
$
(
addprefix
$(O)
/,
$(ULIB)
)
UPROGS
=
\
...
...
@@ -142,10 +143,14 @@ xv6memfs.img: bootblock kernelmemfs
dd
if
=
bootblock
of
=
xv6memfs.img
conv
=
notrunc
dd
if
=
kernelmemfs
of
=
xv6memfs.img
seek
=
1
conv
=
notrunc
$(O)/_%
:
$(O)/%.o $(ULIB)
$(O)/_%
.unstripped
:
$(O)/%.o $(ULIB)
@
echo
" LD
$@
"
$(Q)$(LD)
$(LDFLAGS)
-N
-e
main
-Ttext
0x100000
-o
$@
$^
$(O)/_%
:
$(O)/_%.unstripped
@
echo
" STRIP
$@
"
$(Q)$(STRIP)
-o
$@
$<
$(O)/mkfs
:
mkfs.c fs.h
gcc
-m32
-Werror
-Wall
-o
$@
mkfs.c
...
...
@@ -162,7 +167,7 @@ mscan.kern: $(O)/kernel
-include
*.d
-include
$(O)/*.d
.PRECIOUS
:
$(O)/%.o
.PRECIOUS
:
$(O)/%.o
$(O)/_%.unstripped
.PHONY
:
clean qemu gdb rsync
##
...
...
compiler.h
浏览文件 @
706ea3fe
...
...
@@ -2,3 +2,11 @@
#define __mpalign__ __attribute__((aligned(CACHELINE)))
#define __noret__ __attribute__((noreturn))
#define barrier() __asm volatile("" ::: "memory")
#ifdef __cplusplus
#define BEGIN_DECLS extern "C" {
#define END_DECLS }
#else
#define BEGIN_DECLS
#define END_DECLS
#endif
fmt.cc
浏览文件 @
706ea3fe
extern
"C"
{
#include "types.h"
#include "kernel.h"
#include <stddef.h>
#include <stdarg.h>
#include "fmt.h"
#include "lib.h"
unsigned
int
strlen
(
const
char
*
);
}
//
...
...
ipc.h
浏览文件 @
706ea3fe
struct
ipcctl
{
volatile
char
done
;
volatile
char
done
:
1
;
volatile
char
submitted
:
1
;
off_t
off
;
volatile
long
result
;
};
kernel.h
浏览文件 @
706ea3fe
...
...
@@ -294,7 +294,7 @@ void* memmove(void*, const void*, u32);
void
*
memset
(
void
*
,
int
,
u32
);
void
*
memcpy
(
void
*
,
const
void
*
,
u32
);
char
*
safestrcpy
(
char
*
,
const
char
*
,
u32
);
int
strlen
(
const
char
*
);
unsigned
int
strlen
(
const
char
*
);
int
strncmp
(
const
char
*
,
const
char
*
,
u32
);
char
*
strncpy
(
char
*
,
const
char
*
,
u32
);
int
strcmp
(
const
char
*
p
,
const
char
*
q
);
...
...
kernlet.c
浏览文件 @
706ea3fe
...
...
@@ -32,6 +32,8 @@ pread_work(struct work *w, void *a0, void *a1, void *a2, void *a3)
ipc
->
result
=
r
;
barrier
();
ipc
->
done
=
1
;
iput
(
ip
);
}
static
struct
work
*
...
...
@@ -57,18 +59,25 @@ sys_kernlet(int fd, size_t count, off_t off)
{
struct
file
*
f
;
struct
work
*
w
;
struct
ipcctl
*
ipc
=
(
struct
ipcctl
*
)
myproc
()
->
vmap
->
kshared
;
if
(
fd
<
0
||
fd
>=
NOFILE
||
(
f
=
myproc
()
->
ofile
[
fd
])
==
0
)
return
-
1
;
if
(
f
->
type
!=
FD_INODE
)
return
-
1
;
fetchadd
(
&
f
->
ip
->
ref
,
1
);
w
=
pread_allocwork
(
f
->
ip
,
myproc
()
->
vmap
->
kshared
,
count
,
off
);
if
(
w
==
NULL
)
if
(
w
==
NULL
)
{
iput
(
f
->
ip
);
return
-
1
;
}
if
(
wq_push
(
w
)
<
0
)
{
iput
(
f
->
ip
);
freework
(
w
);
return
-
1
;
}
ipc
->
off
=
off
;
ipc
->
submitted
=
1
;
return
0
;
}
net.mk
浏览文件 @
706ea3fe
...
...
@@ -16,12 +16,12 @@ UPROGS += \
CFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP
CXXFLAGS += -Ilwip/src/include -Inet -Ilwip/src/include/ipv4 -I. -DLWIP
LWIP_CFLAGS =
-fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb
\
-m64 -Werror -std=c99 -fms-extensions -mno-sse -mcmodel=large -I$(QEMUSRC)
\
-fno-omit-frame-pointer -DHW_$(HW) -include param.h -include compiler.h
\
-DXV6 -Wno-attributes -Wno-address
-Wno-char-subscripts \
-Wno-unused-but-set-variable -Wno-format
LWIP_CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
LWIP_CFLAGS =
$(COMFLAGS) -std=c99
\
-Wno-attributes
\
-Wno-address
\
-Wno-char-subscripts \
-Wno-unused-but-set-variable \
-Wno-format
LWIP_INCLUDES := \
-Ilwip/src/include \
...
...
preadtest.cc
浏览文件 @
706ea3fe
...
...
@@ -2,6 +2,7 @@
#include "stat.h"
#include "fcntl.h"
#include "user.h"
#include "lib.h"
#include "amd64.h"
#include "ipc.h"
...
...
@@ -24,6 +25,31 @@ kernlet_pread(int fd, size_t count, off_t off)
die
(
"kernlet"
);
}
static
ssize_t
xpread
(
int
fd
,
void
*
buf
,
size_t
count
,
off_t
off
)
{
if
(
ipcctl
->
submitted
)
{
while
(
ipcctl
->
done
==
0
)
nop_pause
();
if
(
ipcctl
->
result
==
-
1
)
goto
slow
;
if
(
off
<
ipcctl
->
off
)
goto
slow
;
if
(
off
>
ipcctl
->
off
+
ipcctl
->
result
)
goto
slow
;
char
*
kbuf
=
(
char
*
)
(
KSHARED
+
4096
);
off_t
kbufoff
=
off
-
ipcctl
->
off
;
size_t
kbufcount
=
MIN
(
count
,
ipcctl
->
result
-
kbufoff
);
memmove
(
buf
,
kbuf
+
kbufoff
,
kbufcount
);
return
kbufcount
;
}
slow:
return
pread
(
fd
,
buf
,
count
,
off
);
}
int
main
(
int
ac
,
char
**
av
)
{
...
...
@@ -42,14 +68,9 @@ main(int ac, char **av)
t0
=
rdtsc
();
for
(
k
=
0
;
k
<
FSIZE
;
k
+=
PSIZE
)
{
kernlet_pread
(
fd
,
PSIZE
,
k
);
while
(
ipcctl
->
done
==
0
)
nop_pause
();
die
(
"preadtest: %d
\n
"
,
(
int
)
ipcctl
->
result
);
for
(
i
=
k
;
i
<
k
+
PSIZE
;
i
+=
BSIZE
)
if
(
pread
(
fd
,
buf
,
BSIZE
,
i
)
!=
BSIZE
)
if
(
x
pread
(
fd
,
buf
,
BSIZE
,
i
)
!=
BSIZE
)
die
(
"pread failed"
);
}
t1
=
rdtsc
();
...
...
printf.cc
浏览文件 @
706ea3fe
#include "types.h"
#include "stat.h"
#include "user.h"
extern
"C"
{
#include <stdarg.h>
static
void
printint
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
s64
xx
,
int
base
,
int
sgn
)
{
const
static
char
digits
[]
=
"0123456789ABCDEF"
;
char
buf
[
21
];
int
i
,
neg
;
s64
x
;
neg
=
0
;
if
(
sgn
&&
xx
<
0
){
neg
=
1
;
x
=
-
xx
;
}
else
{
x
=
xx
;
}
i
=
0
;
do
{
buf
[
i
++
]
=
digits
[
x
%
base
];
}
while
((
x
/=
base
)
!=
0
);
if
(
neg
)
buf
[
i
++
]
=
'-'
;
while
(
--
i
>=
0
)
putch
(
putarg
,
buf
[
i
]);
}
// Only understands %d, %x, %p, %s.
void
vprintfmt
(
void
(
*
putch
)
(
void
*
,
char
),
void
*
putarg
,
const
char
*
fmt
,
va_list
ap
)
{
const
char
*
s
;
int
c
,
i
,
state
;
state
=
0
;
for
(
i
=
0
;
fmt
[
i
];
i
++
){
c
=
fmt
[
i
]
&
0xff
;
if
(
state
==
0
){
if
(
c
==
'%'
){
state
=
'%'
;
}
else
{
putch
(
putarg
,
c
);
}
}
else
if
(
state
==
'%'
){
if
(
c
==
'd'
){
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u32
),
10
,
1
);
}
else
if
(
c
==
'x'
)
{
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u32
),
16
,
0
);
}
else
if
(
c
==
'l'
)
{
state
=
'l'
;
continue
;
}
else
if
(
c
==
's'
){
s
=
(
const
char
*
)
va_arg
(
ap
,
const
char
*
);
if
(
s
==
0
)
s
=
"(null)"
;
while
(
*
s
!=
0
){
putch
(
putarg
,
*
s
);
s
++
;
}
}
else
if
(
c
==
'c'
){
putch
(
putarg
,
va_arg
(
ap
,
u32
));
}
else
if
(
c
==
'%'
){
putch
(
putarg
,
c
);
}
else
{
// Unknown % sequence. Print it to draw attention.
putch
(
putarg
,
'%'
);
putch
(
putarg
,
c
);
}
state
=
0
;
}
else
if
(
state
==
'l'
)
{
if
(
c
==
'x'
)
{
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u64
),
16
,
0
);
}
else
if
(
c
==
'u'
)
{
printint
(
putch
,
putarg
,
va_arg
(
ap
,
u64
),
10
,
0
);
}
else
{
// Unknown % sequence. Print it to draw attention.
putch
(
putarg
,
'%'
);
putch
(
putarg
,
c
);
}
state
=
0
;
}
}
#include "fmt.h"
}
// Print to the given fd.
static
void
writec
(
void
*
arg
,
char
c
)
writec
(
int
c
,
void
*
arg
)
{
int
fd
=
(
int
)
(
u64
)
arg
;
int
fd
=
(
int
)
(
u64
)
arg
;
write
(
fd
,
&
c
,
1
);
}
...
...
@@ -117,7 +31,7 @@ struct bufstate {
};
static
void
writebuf
(
void
*
arg
,
char
c
)
writebuf
(
int
c
,
void
*
arg
)
{
struct
bufstate
*
bs
=
(
bufstate
*
)
arg
;
if
(
bs
->
p
<
bs
->
e
)
{
...
...
string.cc
浏览文件 @
706ea3fe
...
...
@@ -92,7 +92,7 @@ safestrcpy(char *s, const char *t, u32 n)
return
os
;
}
int
unsigned
int
strlen
(
const
char
*
s
)
{
int
n
;
...
...
sysfile.cc
浏览文件 @
706ea3fe
...
...
@@ -79,12 +79,16 @@ ssize_t
sys_pread
(
int
fd
,
void
*
ubuf
,
size_t
count
,
off_t
offset
)
{
struct
file
*
f
;
uptr
i
=
(
uptr
)
ubuf
;
int
r
;
if
(
fd
<
0
||
fd
>=
NOFILE
||
(
f
=
myproc
()
->
ofile
[
fd
])
==
0
)
return
-
1
;
for
(
uptr
va
=
PGROUNDDOWN
(
i
);
va
<
i
+
count
;
va
=
va
+
PGSIZE
)
if
(
pagefault
(
myproc
()
->
vmap
,
va
,
0
)
<
0
)
return
-
1
;
// XXX(sbw) assuming ubuf is ok
if
(
f
->
type
==
file
::
FD_INODE
){
ilock
(
f
->
ip
,
0
);
if
(
f
->
ip
->
type
==
0
)
...
...
ulib.c
c
→
ulib.c
浏览文件 @
706ea3fe
移动文件
user.h
浏览文件 @
706ea3fe
BEGIN_DECLS
struct
stat
;
// system calls
extern
"C"
{
int
fork
(
int
);
int
exit
(
void
)
__attribute__
((
noreturn
));
int
wait
(
void
);
...
...
@@ -28,7 +28,6 @@ int unmap(void *addr, int len);
void
halt
(
void
);
ssize_t
pread
(
int
,
void
*
,
size_t
,
off_t
);
int
kernlet
(
int
,
size_t
,
off_t
);
}
// ulib.c
int
stat
(
char
*
,
struct
stat
*
);
...
...
@@ -46,11 +45,10 @@ void free(void*);
int
atoi
(
const
char
*
);
// uthread.S
extern
"C"
{
int
forkt
(
void
*
sp
,
void
*
pc
,
void
*
arg
);
}
// printf.c
void
printf
(
int
,
const
char
*
,
...);
void
snprintf
(
char
*
buf
,
unsigned
int
n
,
const
char
*
fmt
,
...);
void
die
(
const
char
*
errstr
,
...)
__attribute__
((
noreturn
));
END_DECLS
usertests.cc
浏览文件 @
706ea3fe
...
...
@@ -1544,6 +1544,50 @@ unopentest(void)
printf
(
stdout
,
"concurrent unlink/open ok
\n
"
);
}
void
preads
(
void
)
{
static
const
int
fsize
=
(
64
<<
10
);
static
const
int
bsize
=
4096
;
static
const
int
nprocs
=
4
;
static
const
int
iters
=
100
;
static
char
buf
[
bsize
];
int
fd
;
int
pid
;
printf
(
1
,
"concurrent preads
\n
"
);
fd
=
open
(
"preads.x"
,
O_CREATE
|
O_RDWR
);
if
(
fd
<
0
)
die
(
"preads: open failed"
);
for
(
int
i
=
0
;
i
<
fsize
/
bsize
;
i
++
)
if
(
write
(
fd
,
buf
,
bsize
)
!=
bsize
)
die
(
"preads: write failed"
);
close
(
fd
);
for
(
int
i
=
0
;
i
<
nprocs
;
i
++
)
{
pid
=
fork
(
0
);
if
(
pid
<
0
)
die
(
"preads: fork failed"
);
if
(
pid
==
0
)
break
;
}
for
(
int
k
=
0
;
k
<
iters
;
k
++
)
{
fd
=
open
(
"preads.x"
,
O_RDONLY
);
for
(
int
i
=
0
;
i
<
fsize
;
i
+=
bsize
)
if
(
pread
(
fd
,
buf
,
bsize
,
i
)
!=
bsize
)
die
(
"preads: pread failed"
);
close
(
fd
);
}
if
(
pid
==
0
)
exit
();
printf
(
1
,
"concurrent preads OK
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -1567,6 +1611,7 @@ main(int argc, char *argv[])
writetest
();
writetest1
();
createtest
();
preads
();
// mem();
pipe1
();
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论