Linux kernel 中断之proc接口之interrupts

用于对中断观察的主要有两个文件,一个是proc/irq,另一个是proc/interrupts。
需要配置CONFIG_GENERIC_IRQ_SHOW
在proc目录下实现interrupts文件,用于获取中断发生次数统计:
fs/proc/interrupts.c

static const struct seq_operations int_seq_ops = {  .start = int_seq_start,  .next  = int_seq_next,  .stop  = int_seq_stop,  .show  = show_interrupts };

static int interrupts_open(struct inode *inode, struct file *filp) {  return seq_open(filp, &int_seq_ops); }

static const struct file_operations proc_interrupts_operations = {  .open  = interrupts_open,  .read  = seq_read,  .llseek  = seq_lseek,  .release = seq_release, };

static int __init proc_interrupts_init(void) {  proc_create("interrupts", 0, NULL, &proc_interrupts_operations);  return 0; } fs_initcall(proc_interrupts_init);

#ifdef CONFIG_GENERIC_IRQ_SHOW

int __weak arch_show_interrupts(struct seq_file *p, int prec) {  return 0; }

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');  }

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

 raw_spin_lock_irqsave(&desc->lock, flags);  for_each_online_cpu(j)   any_count |= kstat_irqs_cpu(i, j);  action = desc->action;  if ((!action || irq_desc_is_chained(desc)) && !any_count)   goto out;

 seq_printf(p, "%*d: ", prec, i);  for_each_online_cpu(j)   seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));

 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); #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);

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

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

/proc # cat interrupts cat interrupts            CPU0       CPU1   29:       0          0          GIC  arch_timer  30:    1923       1077          GIC  arch_timer  34:       0          0          GIC  fa608000.ap_dmas  38:       0          0          GIC  MIPI irq  43:       0          0          GIC  fa100000.gpu  44:       0          0          GIC  fa100000.gpu  45:       1          0          GIC  fa100000.gpu  49:     279          0          GIC  dwc3  51:    2856          0          GIC  malidp-de  52:       0          0          GIC  malidp-se  53:     392          0          GIC  isp_irq  

 
 
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值