1 Star 0 Fork 11

Judith/wayca-scheduler

forked from openEuler/wayca-scheduler 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
irqdump.c 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
young1c 提交于 2021-07-04 08:53 . Add missing LICENSE for Wayca scheduler
/*
* Copyright (c) 2021 HiSilicon Technologies Co., Ltd.
* Wayca scheduler is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include "wayca-scheduler.h"
#define MAX_IRQNAME_LEN 128
#define MAX_IRQNUM 2048
struct interrupt {
int name[MAX_IRQNAME_LEN];
int irqno;
} irqs[MAX_IRQNUM];
static char *trim_leadspace(const char *s)
{
while (isspace((int)*s))
s++;
return (char *)s;
}
static void remove_newline(char *s)
{
int len = strlen(s);
if (len > 0 && s[len - 1] == '\n')
s[len - 1] = '\0';
}
static int irq_dump(char *i_name)
{
FILE *fp;
char buf[4096];
bool dump_all = !i_name;
fp = fopen("/proc/interrupts", "r");
printf(" irq count %s\n", i_name ? i_name : "ALL");
while (fgets(buf, sizeof(buf), fp)) {
char *p = buf;
int irqno;
long long count;
remove_newline(p);
p = trim_leadspace(p);
/* skip IPI, NMI etc: "NMI: 20 Non-maskable interrupts" */
if (!isdigit(*p))
continue;
/* format "17: 0 9470 IR-IO-APIC 17-fasteoi ehci_hcd:usb1, ioc0" */
p = strchr(buf, ':');
if (!p)
continue;
/* "17" */
*p = '\0';
irqno = strtoul(buf, NULL, 10);
p++;
/* Sum counts for this IRQ: "0 9470" */
count = 0;
while (1) {
p = trim_leadspace(p);
if (!isdigit(*p))
break;
count += strtoull(p, &p, 10);
}
/* name "IR-IO-APIC 17-fasteoi ehci_hcd:usb1, ioc0" */
p = trim_leadspace(p);
if (dump_all || strstr(p, i_name))
printf("%8d %12lld %s\n", irqno, count, p);
}
fclose(fp);
return 0;
}
int main(int argc, char **argv)
{
int i;
if (argc == 1) /* dump all interrupts */
irq_dump(NULL);
for (i = 1; i < argc; i++)
irq_dump(argv[i]);
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/judithsq/wayca-scheduler.git
git@gitee.com:judithsq/wayca-scheduler.git
judithsq
wayca-scheduler
wayca-scheduler
master

搜索帮助