diff --git a/include/kernel.h b/include/kernel.h index daf63dc1e..a1443deb6 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -10,6 +10,8 @@ #ifndef _LINUX_H_ #define _LINUX_H_ +#include + //#include /** Check if current process has capability \p cap. @@ -61,4 +63,7 @@ int kernel_module_set_param(const char *module, const char *param, const char *v /** Get cacheline size in bytes */ int kernel_get_cacheline_size(); +/** Set SMP affinity of IRQ */ +int kernel_irq_setaffinity(unsigned irq, uintmax_t new, uintmax_t *old); + #endif /* _LINUX_H_ */ diff --git a/lib/kernel.c b/lib/kernel.c index 922e1c854..e32e91e1a 100644 --- a/lib/kernel.c +++ b/lib/kernel.c @@ -158,4 +158,24 @@ int kernel_check_cap(cap_value_t cap) return value == CAP_SET ? 0 : -1; } -#endif \ No newline at end of file +#endif + +int kernel_irq_setaffinity(unsigned irq, uintmax_t new, uintmax_t *old) +{ + char fn[64]; + FILE *f; + + snprintf(fn, sizeof(fn), "/proc/irq/%u/smp_affinity", irq); + + f = fopen(fn, "w+"); + if (!f) + return -1; /* IRQ does not exist */ + + if (old) + fscanf(f, "%jx", old); + + fprintf(f, "%jx", new); + fclose(f); + + return 0; +}