secondary_entry_fn secondary_cinit(void) { struct thread_info *ti = current_thread_info(); secondary_entry_fn entry; thread_info_init(ti, 0); if (!(auxinfo.flags & AUXINFO_MMU_OFF)) { ti->pgtable = mmu_idmap; mmu_mark_enabled(ti->cpu); } /* * Save secondary_data.entry locally to avoid opening a race * window between marking ourselves online and calling it. */ entry = secondary_data.entry; set_cpu_online(ti->cpu, true); sev(); /* * Return to the assembly stub, allowing entry to be called * from there with an empty stack. */ return entry; }
int main(int argc, char *argv[]) { int s, i, fd, *puzzle[ROWS]; char buff[4096]; struct thread_info *tinfo[NUMTHREADS]; pthread_attr_t attr; if (argc != 2) handle_error("Usage ./sudoku_validator <sudoke file name>"); fd = open(argv[1], O_RDONLY); if (fd == -1) handle_error_en(s, "open"); s = read(fd, buff, sizeof(buff)); if (s == -1) handle_error_en(s, "read"); s = pthread_attr_init(&attr); if (s != 0) handle_error_en(s, "pthread_attr_init"); /* allocate memory for sudoku puzzle */ for (i = 0; i < ROWS; i++) { puzzle[i] = malloc(sizeof(int) * COLUMNS); if (puzzle[i] == NULL) handle_error("puzzle memory"); } /* load puzzle into an array on points for thread use */ load_puzzle(puzzle, buff, s); //print_puzzle(puzzle); /* allocate memory and initialize thread structs */ for (i = 0; i < NUMTHREADS; i++) { tinfo[i] = malloc(sizeof(*tinfo[i])); if (tinfo == NULL) handle_error("thread_info memory"); thread_info_init(tinfo[i], i, puzzle); //thread_info_print(tinfo[i]); } /* create and put threads to work */ for (i = 0; i < NUMTHREADS; i++) { s = pthread_create(&(tinfo[i]->thread_id), &attr, &thread_start, tinfo[i]); if (s != 0) handle_error_en(s, "pthread_create"); } for (i = 0; i < NUMTHREADS; i++) { s = pthread_join(tinfo[i]->thread_id, NULL); if (s != 0) handle_error_en(s, "pthread_join"); } s = close(fd); if (s == -1) handle_error_en(s, "close"); for (i = 0; i < NUMTHREADS; i++) { if (tinfo[i]->region_valid) thread_info_print(tinfo[i]); } for (i = 0; i < NUMTHREADS; i++) free(tinfo[i]); /* free sudoku puzzle */ for (i = 0; i < ROWS; i++) free(puzzle[i]); return 0; }