README.md
更新日志
8.29 完成夏令营的最后一次提交
9.15 准备进行perf的移植,确定计划,搭建框架,把之前完成的写到框架内
Linux中perf的基本功能介绍
根据perf list所获得的基本的perf_event:
- Hardware event
- cpu cycle: cpu周期数
- instructions: 机器指令数
- cache references: 缓存命中次数
- cache misses: 缓存失效次数
- branch instructions: 分支预测成功次数
- branch misses: 分支预测失效次数
- Software event
- alignment faults: 内存对齐错误发生的次数
- context switches: 上下文切换次数
- cpu clock: cpu中的高精度计时器
- cpu migrations: cpu迁移次数
- task clock: cpu处理task所消耗的时间
- page faults: 页错误的统计
rCore-Tutorial上的perf设计方案
所有需要探测的数据
- Cpu
- cpu clock
- task clock
- cpu cycle
- cpu utilization
- contexts switches ToDo
- Task
- name
- pid / ppid
- status
- syscall runtimes
- cpu time
- Hardware(from PMU) ToDo
- branch instructions
- branch misses
- cache references
- cache misses
- instructions
数据结构
//cpu状态
struct CpuStat{
inner: RefCell<CpuStatInner>;
}
struct CpuStatInner{
cpu_clock: usize,
task_clock: usize,
cpu_cycle: usize,
context_switches: usize,
cache_references: usize,
cache_misses: usize,
branch_instructions: usize,
branch_misses: usize,
instructions: usize,
}
//task状态
pub struct TaskControlBlock {
// immutable
pub pid: PidHandle,
pub kernel_stack: KernelStack,
// mutable
inner: Mutex<TaskControlBlockInner>,
pub ppid: isize,
}
pub struct TaskControlBlockInner {
pub trap_cx_ppn: PhysPageNum,
pub base_size: usize,
pub task_cx_ptr: usize,
pub task_status: TaskStatus,
pub name: String,
pub memory_set: MemorySet,
pub parent: Option<Weak<TaskControlBlock>>,
pub children: Vec<Arc<TaskControlBlock>>,
pub exit_code: i32,
pub fd_table: Vec<Option<Arc<dyn File + Send + Sync>>>,
pub start_time: usize,
pub cpu_time: usize,
pub syscall: Arc<Mutex<SyscallCount>>,
}
//SyscallCount
pub struct SyscallCount{
pub syscall_dup: (usize, usize),
pub syscall_open: (usize, usize),
pub syscall_close: (usize, usize),
pub syscall_pipe: (usize, usize),
pub syscall_read: (usize, usize),
pub syscall_write: (usize, usize),
pub syscall_yield: (usize, usize),
pub syscall_get_time: (usize, usize),
pub syscall_getpid: (usize, usize),
pub syscall_fork: (usize, usize),
pub syscall_exec: (usize, usize),
pub syscall_waitpid: (usize, usize),
}
提供的数据接口
//cpu数据获取
impl CpuStat{
pub fn get_cpu_clock_info() -> usize;
pub fn get_cpu_cycle_info() -> usize;
pub fn get_cpu_clock_info() -> usize;
pub fn get_task_clock_info() -> usize;
pub fn get_context_switches_info() -> usize;
pub fn get_cpu_info() -> CpuStatInner;
pub fn get_cache_reference_info() -> usize;
pub fn get_cache_misses_info() -> usize;
pub fn get_instructions_info() -> usize;
pub fn get_branch_instructions_info() -> usize;
pub fn get_branch_misses_info() -> usize;
pub fn get_page_faults_info() -> usize;
pub fn get_cpu_utlization_info() -> usize; //返回百分数
}
//task数据获取
impl TaskControlBlock{
pub fn get_task_name_info(pid: usize) -> usize;
pub fn get_task_ppid_info(pid: usize) -> isize;
pub fn get_current_task_pid_info(Self) -> usize;
pub fn get_task_numbers_info() -> usize;
pub fn get_syscall_runtime_info(pid: usize) -> SyscallCount;
pub fn get_cpu_time_info(pid: usize) -> usize;
pub fn get_task_info() -> usize;
}