// Main setup code. static void maininit(void) { // Initialize internal interfaces. interface_init(); // Setup platform devices. platform_hardware_setup(); // call a payload if (CONFIG_RUN_PAYLOAD) { dprintf(1, "Looking for payload %s\n", CONFIG_RUN_PAYLOAD_FILE); struct romfile_s *file = NULL; file = romfile_find( CONFIG_RUN_PAYLOAD_FILE ); if (!file) printf("Could not find payload\n"); else { struct cbfs_romfile_s *cfile; cfile = container_of(file, struct cbfs_romfile_s, file); cbfs_run_payload(cfile->fhdr); } } // Start hardware initialization (if optionrom threading) if (CONFIG_THREAD_OPTIONROMS) device_hardware_setup(); // Run vga option rom vgarom_setup(); // Do hardware initialization (if running synchronously) if (!CONFIG_THREAD_OPTIONROMS) { device_hardware_setup(); wait_threads(); } // Run option roms optionrom_setup(); // show system info before the F12 menu if (CONFIG_DISPLAY_SYSTEM_INFO) dprintf(1, "\nBuild date: %s\n", __DATE__); // Allow user to modify overall boot order. interactive_bootmenu(); wait_threads(); // Prepare for boot. prepareboot(); // Write protect bios memory. make_bios_readonly(); // Invoke int 19 to start boot process. startBoot(); }
int correr_ronda() { slicer *pthis = slicer_get(); /* si no hay organismos, espero a que alguien inyecte */ if (g_list_length(slicer_list)<1) { pthread_mutex_lock(&pthis->wait_m); pthread_cond_wait(&pthis->wait_c, &pthis->wait_m); pthread_mutex_unlock(&pthis->wait_m); } pthis->cont_hilos=0; // para cada organismo... g_list_foreach(slicer_list, cel_time, NULL); #ifdef MT // si hay hilos corriendo... if (pthis->cont_hilos > 0) wait_threads(); // si hay por nacer... //g_slist_foreach(nacidos_list,born, NULL); //g_slist_free(nacidos_list); //nacidos_list=NULL; #endif return 1; }
static void benchmark(void) { int i; long sum = 0; long min_ms = LONG_MAX, max_ms = 0, avg_ms; pthread_t *tid; struct benchmark_thread_data *data; #ifdef CHUNKD_BENCHMARK stc_init(); #endif tid = xmalloc(sizeof(tid[0]) * threads); data = xmalloc(sizeof(data[0]) * threads); for (i = 0; i < threads; i++) { data[i].id = i; xpthread_create(&tid[i], NULL, benchmark_thread, &data[i]); } wait_threads(tid, threads); #define _MIN(a, b) ((a) < (b) ? (a) : (b)) #define _MAX(a, b) ((a) < (b) ? (b) : (a)) for (i = 0; i < threads; i++) { long ms = data[i].time_ms; sum += ms; min_ms = _MIN(min_ms, ms); max_ms = _MAX(max_ms, ms); } avg_ms = sum / threads; printf("%d %ld.%03ld %ld.%03ld %ld.%03ld\n", threads, avg_ms / 1000, avg_ms % 1000, min_ms / 1000, min_ms % 1000, max_ms / 1000, max_ms % 1000); if (verbose) { unsigned long long total_bytes; unsigned long long bytes_per_msec; total_bytes = value_length; total_bytes *= threads; total_bytes *= requests; bytes_per_msec = total_bytes / avg_ms; printf("Throughput: %llu KB/sec\n", bytes_per_msec * 1000UL / 1024UL); } free(data); free(tid); }
// Main setup code. static void maininit(void) { // Initialize internal interfaces. interface_init(); // Setup platform devices. platform_hardware_setup(); // Start hardware initialization (if threads allowed during optionroms) if (threads_during_optionroms()) device_hardware_setup(); // Run vga option rom vgarom_setup(); sercon_setup(); enable_vga_console(); // Do hardware initialization (if running synchronously) if (!threads_during_optionroms()) { device_hardware_setup(); wait_threads(); } // Run option roms optionrom_setup(); // Allow user to modify overall boot order. interactive_bootmenu(); wait_threads(); // Prepare for boot. prepareboot(); // Write protect bios memory. make_bios_readonly(); // Invoke int 19 to start boot process. startBoot(); }
int main () { int res; long i; pthread_barrier_init (&barrier, NULL, 2); res = pthread_create (&child_thread, NULL, child_function, NULL); pthread_barrier_wait (&barrier); wait_threads (); /* set wait-thread breakpoint here */ pthread_join (child_thread, NULL); exit (EXIT_SUCCESS); }
/* para cada organismo en la ronda ... */ static void cel_time(gpointer c, gpointer nada) { organismo *pcel = (organismo *)c; pcel->ronda_hijos=0; #ifdef MT slicer *pthis = slicer_get(); if (pthread_create(&pthis->tid[pthis->cont_hilos], NULL, vivir_thread, pcel)!=0) { assert(0); } pthis->cont_hilos++; //espero los hilos que lance si llegue a mi maximo de hilos if (pthis->cont_hilos == NHILOS) wait_threads(); #else /* Single Thread */ vivir_thread(pcel); #endif }
int main(int argc , char **argv) { #if PRINT_TIME double start, end; #endif extract_arguments(argc, argv); #if PRINT_TIME start = time_so_far(); #endif if(mr_init()) exit(EXIT_FAILURE); start_threads(); wait_threads(); if(mr_reduce()) exit(EXIT_FAILURE); #if PRINT_TIME /* Done here, to avoid counting the printing... */ end = time_so_far(); #endif if(mr_print()) exit(EXIT_FAILURE); if(mr_destroy()) exit(EXIT_FAILURE); #if PRINT_TIME printf("Done in %g msec\n", end-start); #endif exit(EXIT_SUCCESS); }
// Main setup code. static void maininit(void) { // Setup romfile items. qemu_cfg_romfile_setup(); coreboot_cbfs_setup(); // Setup ivt/bda/ebda init_ivt(); init_bda(); // Init base pc hardware. pic_setup(); timer_setup(); mathcp_setup(); // Initialize pci pci_setup(); smm_init(); // Initialize mtrr mtrr_setup(); // Setup Xen hypercalls xen_init_hypercalls(); // Initialize internal tables boot_setup(); // Start hardware initialization (if optionrom threading) if (CONFIG_THREADS && CONFIG_THREAD_OPTIONROMS) init_hw(); // Find and initialize other cpus smp_probe(); // Setup interfaces that option roms may need bios32_setup(); pmm_setup(); pnp_setup(); kbd_setup(); mouse_setup(); init_bios_tables(); // Run vga option rom vga_setup(); // Do hardware initialization (if running synchronously) if (!CONFIG_THREADS || !CONFIG_THREAD_OPTIONROMS) { init_hw(); wait_threads(); } // Run option roms optionrom_setup(); // Run BCVs and show optional boot menu boot_prep(); // Finalize data structures before boot cdemu_setup(); pmm_finalize(); malloc_finalize(); memmap_finalize(); // Setup bios checksum. BiosChecksum -= checksum((u8*)BUILD_BIOS_ADDR, BUILD_BIOS_SIZE); // Write protect bios memory. make_bios_readonly(); // Invoke int 19 to start boot process. startBoot(); }
/* PrepareToBoot */ static void handle_csm_0002(struct bregs *regs) { if (!CONFIG_BOOT) { regs->ax = 1; return; } dprintf(3, "PrepareToBoot table %04x:%04x\n", regs->es, regs->bx); struct e820entry *p = (void *)csm_compat_table.E820Pointer; int i; for (i=0; i < csm_compat_table.E820Length / sizeof(struct e820entry); i++) e820_add(p[i].start, p[i].size, p[i].type); if (csm_init_table->HiPmmMemorySizeInBytes > BUILD_MAX_HIGHTABLE) { u32 hi_pmm_end = csm_init_table->HiPmmMemory + csm_init_table->HiPmmMemorySizeInBytes; e820_add(hi_pmm_end - BUILD_MAX_HIGHTABLE, BUILD_MAX_HIGHTABLE, E820_RESERVED); } // For PCIBIOS 1ab10e if (csm_compat_table.IrqRoutingTablePointer && csm_compat_table.IrqRoutingTableLength) { PirAddr = (void *)csm_compat_table.IrqRoutingTablePointer; dprintf(3, "CSM PIRQ table at %p\n", PirAddr); } // For find_resume_vector()... and find_acpi_features() if (csm_rsdp.signature == RSDP_SIGNATURE) { RsdpAddr = &csm_rsdp; dprintf(3, "CSM ACPI RSDP at %p\n", RsdpAddr); find_acpi_features(); } // SMBIOS table needs to be copied into the f-seg // XX: OVMF doesn't seem to set SmbiosTableLength so don't check it if (csm_boot_table->SmbiosTable && !SMBiosAddr) copy_smbios((void *)csm_boot_table->SmbiosTable); // MPTABLE is just there; we don't care where. // EFI may have reinitialised the video using its *own* driver. enable_vga_console(); // EFI fills this in for us. Zero it for now... struct bios_data_area_s *bda = MAKE_FLATPTR(SEG_BDA, 0); bda->hdcount = 0; thread_setup(); mathcp_setup(); timer_setup(); clock_setup(); device_hardware_setup(); wait_threads(); interactive_bootmenu(); prepareboot(); regs->ax = 0; }
void *thread_fn_01(void *arg) { int i; unsigned char buf[write_size]; int fd = SAFE_OPEN(fname, O_RDWR); memset(buf, (intptr_t)arg, write_size); struct flock64 lck = { .l_whence = SEEK_SET, .l_start = 0, .l_len = 1, }; for (i = 0; i < writes_num; ++i) { lck.l_type = F_WRLCK; my_fcntl(fd, F_OFD_SETLKW, &lck); SAFE_LSEEK(fd, 0, SEEK_END); SAFE_WRITE(1, fd, buf, write_size); lck.l_type = F_UNLCK; my_fcntl(fd, F_OFD_SETLKW, &lck); sched_yield(); } SAFE_CLOSE(fd); return NULL; } static void test01(void) { intptr_t i; int k; pthread_t id[thread_cnt]; int res[thread_cnt]; unsigned char buf[write_size]; tst_res(TINFO, "write to a file inside threads with OFD locks"); int fd = SAFE_OPEN(fname, O_CREAT | O_TRUNC | O_RDWR, 0600); memset(res, 0, sizeof(res)); spawn_threads(id, thread_fn_01); wait_threads(id); tst_res(TINFO, "verifying file's data"); SAFE_LSEEK(fd, 0, SEEK_SET); for (i = 0; i < writes_num * thread_cnt; ++i) { SAFE_READ(1, fd, buf, write_size); if (buf[0] >= thread_cnt) { tst_res(TFAIL, "unexpected data read"); return; } ++res[buf[0]]; for (k = 1; k < write_size; ++k) { if (buf[0] != buf[k]) { tst_res(TFAIL, "unexpected data read"); return; } } } for (i = 0; i < thread_cnt; ++i) { if (res[i] != writes_num) { tst_res(TFAIL, "corrupted data found"); return; } } SAFE_CLOSE(fd); tst_res(TPASS, "OFD locks synchronized access between threads"); }