Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
d164ddab
提交
d164ddab
2月 13, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some hacking on the sampling profiler
上级
fbecbf0c
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
181 行增加
和
16 行删除
+181
-16
Makefile
Makefile
+5
-1
perf.cc
perf.cc
+83
-0
print-perf.c
print-perf.c
+49
-0
sampler.cc
sampler.cc
+36
-15
sampler.h
sampler.h
+8
-0
spinlock.cc
spinlock.cc
+0
-0
没有找到文件。
Makefile
浏览文件 @
d164ddab
...
...
@@ -102,7 +102,8 @@ UPROGS= \
_dirbench
\
_usertests
\
_lockstat
\
_preadtest
_preadtest
\
_perf
UPROGS
:=
$
(
addprefix
$(O)
/,
$(UPROGS)
)
all
:
$(O)/kernel
...
...
@@ -155,6 +156,9 @@ $(O)/_%: $(O)/_%.unstripped
$(O)/mkfs
:
mkfs.c fs.h
gcc
-m32
-Werror
-Wall
-o
$@
mkfs.c
$(O)/print-perf
:
print-perf.c sampler.h
gcc
-m32
-Werror
-Wall
-o
$@
print-perf.c
$(O)/fs.img
:
$(O)/mkfs README $(UPROGS)
@
echo
" MKFS
$@
"
$(Q)$(O)
/mkfs
$@
README
$(UPROGS)
...
...
perf.cc
0 → 100644
浏览文件 @
d164ddab
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
#include "sampler.h"
static
u64
selector
=
0UL
<<
32
|
1
<<
24
|
1
<<
22
|
1
<<
20
|
1
<<
17
|
1
<<
16
|
0x00
<<
8
|
0x76
;
static
u64
period
=
100000
;
static
void
conf
(
int
fd
,
sampop_t
op
)
{
struct
sampconf
c
=
{
op:
op
,
selector:
selector
,
period:
period
,
};
if
(
write
(
fd
,
&
c
,
sizeof
(
c
))
!=
sizeof
(
c
))
die
(
"perf: write failed"
);
close
(
fd
);
}
static
void
save
(
void
)
{
static
char
buf
[
4096
];
int
fd
,
sfd
;
int
r
;
fd
=
open
(
"/dev/sampler"
,
O_RDONLY
);
if
(
fd
<
0
)
die
(
"perf: open failed"
);
unlink
(
"perf.data"
);
sfd
=
open
(
"perf.data"
,
O_RDWR
|
O_CREATE
);
if
(
sfd
<
0
)
die
(
"perf: open failed"
);
while
(
1
)
{
r
=
read
(
fd
,
buf
,
sizeof
(
buf
));
if
(
r
<
0
)
die
(
"perf: read failed"
);
if
(
r
==
0
)
break
;
if
(
write
(
sfd
,
buf
,
r
)
!=
r
)
die
(
"perf: truncated write"
);
}
close
(
sfd
);
close
(
fd
);
}
int
main
(
int
ac
,
const
char
*
av
[])
{
int
fd
=
open
(
"/dev/sampler"
,
O_RDWR
);
if
(
fd
<
0
)
die
(
"perf: open failed"
);
int
pid
=
fork
(
0
);
if
(
pid
<
0
)
die
(
"perf: fork failed"
);
if
(
pid
==
0
)
{
conf
(
fd
,
SAMP_ENABLE
);
exec
(
av
[
1
],
av
+
1
);
die
(
"perf: exec failed"
);
}
wait
();
conf
(
fd
,
SAMP_DISABLE
);
save
();
exit
();
}
print-perf.c
0 → 100644
浏览文件 @
d164ddab
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include "sampler.h"
int
main
(
int
ac
,
char
**
av
)
{
static
const
char
*
pathname
=
"perf.data"
;
struct
logheader
*
header
;
struct
stat
buf
;
void
*
x
;
int
fd
;
int
i
;
if
(
ac
>
1
)
pathname
=
av
[
1
];
fd
=
open
(
pathname
,
O_RDONLY
);
if
(
fd
<
0
)
{
perror
(
"open"
);
exit
(
EXIT_FAILURE
);
}
if
(
fstat
(
fd
,
&
buf
)
<
0
)
{
perror
(
"fstat"
);
exit
(
EXIT_FAILURE
);
}
x
=
mmap
(
0
,
buf
.
st_size
,
PROT_READ
,
MAP_PRIVATE
,
fd
,
0
);
if
(
x
==
MAP_FAILED
)
{
perror
(
"mmap"
);
exit
(
EXIT_FAILURE
);
}
header
=
x
;
printf
(
"ncpus %u
\n
"
,
header
->
ncpus
);
for
(
i
=
0
;
i
<
header
->
ncpus
;
i
++
)
{
printf
(
" offset %lu size %lu
\n
"
,
header
->
cpu
[
i
].
offset
,
header
->
cpu
[
i
].
size
);
}
return
0
;
}
sampler.cc
浏览文件 @
d164ddab
...
...
@@ -15,17 +15,8 @@ extern "C" {
#include "sampler.h"
}
static
const
u64
debug_sel
=
0UL
<<
32
|
1
<<
24
|
1
<<
22
|
1
<<
20
|
1
<<
17
|
1
<<
16
|
0x00
<<
8
|
0x76
;
static
const
u64
debug_cnt
=
100000
;
static
volatile
u64
selector
;
static
volatile
u64
period
;
struct
pmu
{
void
(
*
config
)(
u64
ctr
,
u64
sel
,
u64
val
);
...
...
@@ -84,20 +75,21 @@ void
sampconf
(
void
)
{
pushcli
();
pmu
.
config
(
0
,
debug_sel
,
-
debug_cnt
);
pmu
.
config
(
0
,
selector
,
-
period
);
popcli
();
}
void
sampstart
(
void
)
{
pushcli
();
for
(
struct
cpu
*
c
=
cpus
;
c
<
cpus
+
ncpu
;
c
++
)
{
if
(
c
==
cpus
+
cpunum
())
continue
;
lapic_sampconf
(
c
->
id
);
}
sampconf
();
popcli
();
}
static
int
...
...
@@ -129,7 +121,7 @@ sampintr(struct trapframe *tf)
return
0
;
if
(
samplog
(
tf
))
pmu
.
config
(
0
,
debug_sel
,
-
debug_cnt
);
pmu
.
config
(
0
,
selector
,
-
period
);
return
1
;
}
...
...
@@ -205,6 +197,35 @@ sampread(struct inode *ip, char *dst, u32 off, u32 n)
return
ret
;
}
static
int
sampwrite
(
struct
inode
*
ip
,
char
*
buf
,
u32
off
,
u32
n
)
{
struct
sampconf
*
conf
;
if
(
n
!=
sizeof
(
*
conf
))
return
-
1
;
conf
=
(
struct
sampconf
*
)
buf
;
switch
(
conf
->
op
)
{
case
SAMP_ENABLE
:
selector
=
conf
->
selector
;
period
=
conf
->
period
;
cprintf
(
"sampwrite: selector %lu period %lu
\n
"
,
selector
,
period
);
sampstart
();
break
;
case
SAMP_DISABLE
:
selector
=
0
;
period
=
0
;
for
(
int
i
=
0
;
i
<
NCPU
;
i
++
)
cprintf
(
"sampwrite: count %lu
\n
"
,
pmulog
[
i
].
count
);
sampstart
();
break
;
}
return
n
;
}
void
initsamp
(
void
)
{
...
...
@@ -234,6 +255,6 @@ initsamp(void)
pmulog
[
cpunum
()].
event
=
(
pmuevent
*
)
p
;
pmulog
[
cpunum
()].
capacity
=
PERFSIZE
/
sizeof
(
struct
pmuevent
);
devsw
[
SAMPLER
].
write
=
0
;
devsw
[
SAMPLER
].
write
=
sampwrite
;
devsw
[
SAMPLER
].
read
=
sampread
;
}
sampler.h
浏览文件 @
d164ddab
typedef
enum
{
SAMP_ENABLE
,
SAMP_DISABLE
}
sampop_t
;
struct
sampconf
{
sampop_t
op
;
u64
selector
;
u64
period
;
};
struct
pmuevent
{
u64
rip
;
};
...
...
spinlock.cc
浏览文件 @
d164ddab
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论