【问题标题】:(Linux Kernel) Adding new functions in available_filter_functions(linux内核)在available_filter_functions中添加新函数
【发布时间】:2021-05-20 05:20:05
【问题描述】:

硬件 - 树莓派 4 B 型 8GB 操作系统 - Raspberry pi OS Buster(10)(2020-05-27-raspios-buster-full-armhf.img)(linux kerenl 4.19.y)

我在proc.c中添加了rpi_get_interrupt_info()并修改了show_interrupts()

rpi_get_interrupt_info()和show_interrupts()的完整代码

void rpi_get_interrupt_info(struct irqaction *action_p)
{
    unsigned int irq_num = action_p->irq;
    void *irq_handler = NULL;
    
    if (action_p->handler) {
        irq_handler = (void*)action_p->handler;
    }

    if (irq_handler) {
        trace_printk("[%s] %d: %s, irq_handler: %pS \n",
                        current->comm, irq_num, action_p->name, irq_handler);
    }
}
    
int show_interrupts(struct seq_file *p, void *v)
{
    static int prec;

    unsigned long flags, any_count = 0;
    int i = *(loff_t *) v, j;
    struct irqaction *action;
    struct irq_desc *desc;

    if (i > ACTUAL_NR_IRQS)
        return 0;

    if (i == ACTUAL_NR_IRQS)
        return arch_show_interrupts(p, prec);

    /* print header and calculate the width of the first column */
    if (i == 0) {
        for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
            j *= 10;

        seq_printf(p, "%*s", prec + 8, "");
        for_each_online_cpu(j)
            seq_printf(p, "CPU%-8d", j);
        seq_putc(p, '\n');
    }

    rcu_read_lock();
    desc = irq_to_desc(i);
    if (!desc)
        goto outsparse;

    if (desc->kstat_irqs)
        for_each_online_cpu(j)
            any_count |= *per_cpu_ptr(desc->kstat_irqs, j);

    if ((!desc->action || irq_desc_is_chained(desc)) && !any_count)
        goto outsparse;

    seq_printf(p, "%*d: ", prec, i);
    for_each_online_cpu(j)
        seq_printf(p, "%10u ", desc->kstat_irqs ?
                    *per_cpu_ptr(desc->kstat_irqs, j) : 0);

    raw_spin_lock_irqsave(&desc->lock, flags);
    if (desc->irq_data.chip) {
        if (desc->irq_data.chip->irq_print_chip)
            desc->irq_data.chip->irq_print_chip(&desc->irq_data, p);
        else if (desc->irq_data.chip->name)
            seq_printf(p, " %8s", desc->irq_data.chip->name);
        else
            seq_printf(p, " %8s", "-");
    } else {
        seq_printf(p, " %8s", "None");
    }
    if (desc->irq_data.domain)
        seq_printf(p, " %*d", prec, (int) desc->irq_data.hwirq);
    else
        seq_printf(p, " %*s", prec, "");
#ifdef CONFIG_GENERIC_IRQ_SHOW_LEVEL
    seq_printf(p, " %-8s", irqd_is_level_type(&desc->irq_data) ? "Level" : "Edge");
#endif
    if (desc->name)
        seq_printf(p, "-%-8s", desc->name);

    action = desc->action;

    if (action)
        rpi_get_interrupt_info(action);

    if (action) {
        seq_printf(p, "  %s", action->name);
        while ((action = action->next) != NULL)
            seq_printf(p, ", %s", action->name);
    }

    seq_putc(p, '\n');
    raw_spin_unlock_irqrestore(&desc->lock, flags);
outsparse:
    rcu_read_unlock();
    return 0;
}
#endif

我更改的代码

void rpi_get_interrupt_info(struct irqaction *action_p)
{
    unsigned int irq_num = action_p->irq;
    void *irq_handler = NULL;
    
    if (action_p->handler) {
        irq_handler = (void*)action_p->handler;
    }

    if (irq_handler) {
        trace_printk("[%s] %d: %s, irq_handler: %pS \n",
                        current->comm, irq_num, action_p->name, irq_handler);
    }
}

....

if (action)
        rpi_get_interrupt_info(action);

当我尝试echo rpi_get_interrupt_info &gt; /sys/kernel/debug/tracing/set_ftrace_filter 时,它显示echo: write error: Invalid argument

所以我查看了/sys/kernel/debug/tracing/available_filter_functions,没有rpi_get_interrupt_info

我试过noinline void rpi_get_interrupt_info(struct irqaction *action_p),但没有用。

【问题讨论】:

  • trace_printk() 是无条件的。只要这段代码运行,跟踪缓冲区就会被数据填充。你到底想达到什么目的?
  • @user253751,我知道。 OP的问题仍然存在。如果他们想启用 ftracer,这是一个故事,如果是关于 trace_printk() 则是另一个故事:stackoverflow.com/questions/37592089/…
  • @0andriy rpi_get_interrupt_info() 显示进程名称、中断号、inq 名称和中断处理程序。我只想测试 ftrace,如果它运行良好。

标签: c linux gcc linux-kernel ftrace


【解决方案1】:

对不起,我在配置 bcm2711_defconfig 文件时犯了一些错误。感谢大家试图帮助我:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-08
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 2014-01-07
    • 2013-10-20
    • 2013-10-05
    相关资源
    最近更新 更多