Created
April 24, 2025 10:53
-
-
Save foamdino/7d233a49561b8aaa41621b9c2cd34757 to your computer and use it in GitHub Desktop.
Active irq-to-core mapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a single populated irq_info, activate the mapping from irq to cpus | |
| * | |
| * @param teb Pointer to our teb | |
| * @param irq IRQ line number to map | |
| * @param coremap Pointer to coremap to map IRQ to | |
| * | |
| * @return BL_OK on success, BL_ERR otherwise. | |
| */ | |
| __BL_STATIC int | |
| bl_pal_linux_activate_irq_mapping(bl_teb_t *teb, | |
| unsigned int irq, | |
| bl_pal_coremap_t *coremap) | |
| { | |
| char affinity_proc_file[PATH_MAX]; | |
| char coremap_buf[PATH_MAX]; | |
| FILE *file; | |
| int errsave = 0; | |
| int res; | |
| bl_assert(teb != NULL); | |
| bl_assert(coremap != NULL); | |
| bl_error_clear(teb); | |
| res = bl_string_print_ex(affinity_proc_file, | |
| sizeof(affinity_proc_file), | |
| BL_STR_F_NOTRUNCATE, | |
| NULL, | |
| "/proc/irq/%u/smp_affinity", | |
| irq); | |
| if (res != BL_OK) | |
| { | |
| bl_error_set(teb, BL_ERR_STRING_TRUNCATED); | |
| return BL_ERR; | |
| } | |
| file = fopen(affinity_proc_file, "w"); | |
| if (!file) | |
| { | |
| bl_error_set_aux(teb, | |
| BL_ERR_PAL_UNABLE_TO_OPEN_IRQ_AFFINITY, | |
| errno, | |
| "%s", | |
| affinity_proc_file); | |
| return BL_ERR; | |
| } | |
| /* Write the mask to apply to a buffer ready for dumping to correct file */ | |
| res = bl_coremap_scnprintf( | |
| coremap_buf, sizeof(coremap_buf), coremap, BL_PAL_MAX_CORES); | |
| bl_abort_ifx( | |
| !(res > 0), coremap_buf, sizeof(coremap_buf), coremap, BL_PAL_MAX_CORES); | |
| /* log applied_mask .. */ | |
| bl_debug_pal_t(teb, | |
| "activate_irq_mapping: writing [%s] to: %s", | |
| coremap_buf, | |
| affinity_proc_file); | |
| res = fprintf(file, "%s", coremap_buf); | |
| /* Cache any errno that failed in the fprintf, as this will carry the procfs error | |
| * code. */ | |
| errsave = errno; | |
| if (fclose(file) || res == -1) | |
| { | |
| bl_error_set_aux(teb, | |
| BL_ERR_PAL_UPDATE_IRQ_AFFINITY_FAILED, | |
| errsave, | |
| "mask: %s", | |
| coremap_buf); | |
| return BL_ERR; | |
| } | |
| return BL_OK; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment