mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
* feat(kprobe): Add basic kprobe support for x86_64 * feat: add ebpf support (#912) - 实现bpf()一部分命令,包括几种基本map,相关的helper函数 - 实现部分perf相关的数据结构 - 暂时为文件实现简单mmap - 实现一个使用kprobe统计syscall 调用次数的ebpf程序 对eBPF支持程度(基本): - 简单的eBPF程序(没有指定特殊的Map) - 使用内核已经实现的Map的eBPF程序 - 可以和kprobe配合使用 - 内核Map相关的接口定义已经实现,添加新的Map较为简单 不支持的功能: - 区分不同的eBPF程序类型(Network/Cgroup)并限定可调用的helper函数集 - 与内核其它跟踪机制配合(tracepoint) - 其它helper和Map todo - [ ] 修改mmap,需要讨论,因为这个和块缓存层相关 - [x] 添加文档 - [x] 修复可能的错误 - [x] 增加rbpf版本信息 * feat: add /sys/devices/system/cpu/possible file * feat: add /sys/devices/system/cpu/online
139 lines
3.3 KiB
Rust
139 lines
3.3 KiB
Rust
use core::ops::Add;
|
||
|
||
use system_error::SystemError;
|
||
|
||
use crate::arch::CurrentIrqArch;
|
||
|
||
pub mod debug;
|
||
pub mod dummychip;
|
||
pub mod ebreak;
|
||
pub mod handle;
|
||
pub mod init;
|
||
pub mod ipi;
|
||
pub mod irqchip;
|
||
pub mod irqdata;
|
||
pub mod irqdesc;
|
||
pub mod irqdomain;
|
||
pub mod manage;
|
||
pub mod msi;
|
||
mod resend;
|
||
pub mod softirq;
|
||
pub mod sysfs;
|
||
|
||
/// 中断的架构相关的trait
|
||
pub trait InterruptArch: Send + Sync {
|
||
/// 架构相关的中断初始化
|
||
unsafe fn arch_irq_init() -> Result<(), SystemError>;
|
||
/// 使能中断
|
||
unsafe fn interrupt_enable();
|
||
/// 禁止中断
|
||
unsafe fn interrupt_disable();
|
||
/// 检查中断是否被禁止
|
||
fn is_irq_enabled() -> bool;
|
||
|
||
/// 保存当前中断状态,并且禁止中断
|
||
unsafe fn save_and_disable_irq() -> IrqFlagsGuard;
|
||
unsafe fn restore_irq(flags: IrqFlags);
|
||
|
||
/// 检测系统支持的中断总数
|
||
fn probe_total_irq_num() -> u32;
|
||
|
||
fn arch_early_irq_init() -> Result<(), SystemError> {
|
||
Ok(())
|
||
}
|
||
|
||
/// ap启动时的中断初始化
|
||
fn arch_ap_early_irq_init() -> Result<(), SystemError> {
|
||
Ok(())
|
||
}
|
||
|
||
/// 响应未注册的中断
|
||
fn ack_bad_irq(irq: IrqNumber);
|
||
}
|
||
|
||
#[derive(Debug, Clone, Copy)]
|
||
pub struct IrqFlags {
|
||
flags: usize,
|
||
}
|
||
|
||
impl IrqFlags {
|
||
pub fn new(flags: usize) -> Self {
|
||
IrqFlags { flags }
|
||
}
|
||
|
||
pub fn flags(&self) -> usize {
|
||
self.flags
|
||
}
|
||
}
|
||
|
||
/// @brief 当前中断状态的保护器,当该对象被drop时,会恢复之前的中断状态
|
||
///
|
||
/// # Example
|
||
///
|
||
/// ```
|
||
/// use crate::arch::CurrentIrqArch;
|
||
///
|
||
/// // disable irq and save irq state (这是唯一的获取IrqFlagsGuard的方法)
|
||
/// let guard = unsafe{CurrentIrqArch::save_and_disable_irq()};
|
||
///
|
||
/// // do something
|
||
///
|
||
/// // 销毁guard时,会恢复之前的中断状态
|
||
/// drop(guard);
|
||
///
|
||
/// ```
|
||
#[derive(Debug)]
|
||
pub struct IrqFlagsGuard {
|
||
flags: IrqFlags,
|
||
}
|
||
|
||
impl IrqFlagsGuard {
|
||
/// @brief 创建IrqFlagsGuard对象
|
||
///
|
||
/// # Safety
|
||
///
|
||
/// 该函数不安全,因为它不会检查flags是否是一个有效的IrqFlags对象, 而当它被drop时,会恢复flags中的中断状态
|
||
///
|
||
/// 该函数只应被`CurrentIrqArch::save_and_disable_irq`调用
|
||
pub unsafe fn new(flags: IrqFlags) -> Self {
|
||
IrqFlagsGuard { flags }
|
||
}
|
||
}
|
||
impl Drop for IrqFlagsGuard {
|
||
fn drop(&mut self) {
|
||
unsafe {
|
||
CurrentIrqArch::restore_irq(self.flags);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 定义中断号结构体
|
||
// 用于表示软件逻辑视角的中断号,全局唯一
|
||
int_like!(IrqNumber, u32);
|
||
|
||
impl IrqNumber {
|
||
/// 如果一个(PCI)设备中断没有被连接,我们将设置irqnumber为IRQ_NOTCONNECTED。
|
||
/// 这导致request_irq()失败,返回-ENOTCONN,这样我们就可以区分这种情况和其他错误返回。
|
||
pub const IRQ_NOTCONNECTED: IrqNumber = IrqNumber::new(u32::MAX);
|
||
}
|
||
|
||
// 硬件中断号
|
||
// 用于表示在某个IrqDomain中的中断号
|
||
int_like!(HardwareIrqNumber, u32);
|
||
|
||
impl Add<u32> for HardwareIrqNumber {
|
||
type Output = HardwareIrqNumber;
|
||
|
||
fn add(self, rhs: u32) -> HardwareIrqNumber {
|
||
HardwareIrqNumber::new(self.0 + rhs)
|
||
}
|
||
}
|
||
|
||
impl Add<u32> for IrqNumber {
|
||
type Output = IrqNumber;
|
||
|
||
fn add(self, rhs: u32) -> IrqNumber {
|
||
IrqNumber::new(self.0 + rhs)
|
||
}
|
||
}
|