static void print_and_free_lcores(lcore_t *lc) { if (lc) { print_and_free_lcores(lc->next); printf("%u/%u/%u\t%u\n", lc->u.s.socket_id, lc->u.s.core_id, lc->u.s.thread_id, lc->u.s.id); free(lc); } }
int wr_coremap(const char *arg, lc_info_t *get_lcores, int max_cnt, const char *proc_cpuinfo) { FILE *f; char *line = NULL; size_t line_sz = 0; unsigned print_map = 0; unsigned balanced = 1; unsigned mode = 0; lcore_t *lcores = NULL; if (proc_cpuinfo == NULL) proc_cpuinfo = PROC_CPUINFO; if ( (f = fopen(proc_cpuinfo, "r")) == NULL) { fprintf(stderr, "Cannot open %s on this system\n", proc_cpuinfo); return -1; } while (getline(&line, &line_sz, f) >= 0) lcores = get_matching_action(line) (line, lcores); if (f) fclose(f); if (line) free(line); zero_base(lcores, get_socket_id, set_socket_id); zero_base(lcores, get_core_id, set_core_id); if (strcmp(arg, "info") != 0) { print_map = 1; if (strcmp(arg, "paired_balanced") == 0) { mode = 0; balanced = 1; } else if (strcmp(arg, "unpaired_balanced") == 0) { mode = 1; balanced = 1; } else if (strcmp(arg, "paired_unbalanced") == 0) { mode = 0; balanced = 0; } else if (strcmp(arg, "unpaired_unbalanced") == 0) { mode = 1; balanced = 0; } else if (strcmp(arg, "array") == 0) { int num_cores = count_cores(lcores); if ( (get_lcores != NULL) || (max_cnt > 0) ) get_and_free_lcores(lcores, &get_lcores[0], max_cnt); return num_cores; } } if (print_map) { print_core_map(lcores, mode, balanced); return 0; } printf("CPU : %s", model_name); printf("%u socket%s, %u core%s per socket and %u thread%s per core\n", cnt(lcores, get_socket_id), cnt(lcores, get_socket_id) > 1 ? "s" : "", cnt(lcores, get_core_id), cnt(lcores, get_core_id) > 1 ? "s" : "", cnt(lcores, get_thread_id), cnt(lcores, get_thread_id) > 1 ? "s" : ""); print_and_free_lcores(lcores); return 0; }