14 int device_irq_number(const char *ifname
)
17 char buff
[128], sysname
[128];
20 if (!strncmp("lo", ifname
, strlen("lo")))
23 slprintf(sysname
, sizeof(sysname
),
24 "/sys/class/net/%s/device/irq",
27 fp
= fopen(sysname
, "r");
31 memset(buff
, 0, sizeof(buff
));
33 if (fgets(buff
, sizeof(buff
), fp
) != NULL
) {
34 buff
[sizeof(buff
) - 1] = 0;
42 static char nic_irq_affinity_list
[128];
43 static bool nic_irq_stored
= false;
44 static int nic_irq
= -1;
46 static void device_save_irq_affinity_list(void)
51 bug_on(nic_irq_stored
);
53 slprintf(file
, sizeof(file
),
54 "/proc/irq/%d/smp_affinity_list", nic_irq
);
56 fd
= open(file
, O_RDONLY
);
60 memset(nic_irq_affinity_list
, 0, sizeof(nic_irq_affinity_list
));
62 ret
= read(fd
, nic_irq_affinity_list
,
63 sizeof(nic_irq_affinity_list
));
65 panic("Cannot store NIC IRQ affinity!\n");
69 nic_irq_stored
= true;
72 void device_restore_irq_affinity_list(void)
80 bug_on(nic_irq
== -1);
82 slprintf(file
, sizeof(file
),
83 "/proc/irq/%d/smp_affinity_list", nic_irq
);
85 fd
= open(file
, O_WRONLY
);
89 ret
= write(fd
, nic_irq_affinity_list
,
90 sizeof(nic_irq_affinity_list
));
92 panic("Cannot restore NIC IRQ affinity!\n");
97 int device_set_irq_affinity_list(int irq
, unsigned long from
, unsigned long to
)
100 char file
[128], list
[64];
102 if (unlikely(irq
== 0))
104 if (!nic_irq_stored
) {
106 device_save_irq_affinity_list();
109 slprintf(file
, sizeof(file
), "/proc/irq/%d/smp_affinity_list", irq
);
110 slprintf(list
, sizeof(list
), "%lu-%lu\n", from
, to
);
112 fd
= open(file
, O_WRONLY
);
116 ret
= write(fd
, list
, strlen(list
));
122 int device_set_irq_affinity(int irq
, unsigned long cpu
)
124 return device_set_irq_affinity_list(irq
, cpu
, cpu
);