static void *do_spmv_thread_main(void *arg) { spm_mt_thread_t *spm_mt_thread = (spm_mt_thread_t *) arg; SPMV_NAME(_fn_t) *spmv_mt_fn = spm_mt_thread->spmv_fn; setaffinity_oncpu(spm_mt_thread->cpu); int i; tsc_t total_tsc, thread_tsc; tsc_init(&total_tsc); tsc_init(&thread_tsc); tsc_start(&total_tsc); for (i = 0; i < loops_nr; i++) { pthread_barrier_wait(&barrier); tsc_start(&thread_tsc); spmv_mt_fn(spm_mt_thread->spm, spm_mt_thread->data, y); tsc_pause(&thread_tsc); pthread_barrier_wait(&barrier); } tsc_pause(&total_tsc); spm_mt_thread->secs = tsc_getsecs(&thread_tsc); secs = tsc_getsecs(&total_tsc); tsc_shut(&thread_tsc); tsc_shut(&total_tsc); return (void *) 0; }
int main(int argc, char **argv) { pid_t pid; int status; char **new_argv; prfcnt_t prfcnt; tsc_t timer; cpu_set_t cpu_set; int err; if ( argc < 2){ printf("Usage: %s <cmd> (args)\n", argv[0]); exit(1); } new_argv = &argv[1]; /* * CPU affinity is inherited across a fork() */ CPU_ZERO(&cpu_set); CPU_SET(0,&cpu_set); err = sched_setaffinity(getpid(), sizeof(cpu_set_t), &cpu_set); if (err){ perror("sched_setaffinity"); exit(1); } if ( (pid = fork()) < 0){ perror("fork"); exit(1); } tsc_init(&timer); prfcnt_init(&prfcnt,0,PRFCNT_FL_T0|PRFCNT_FL_T1); /* * FIXME: Is this efficient enough ? Could it be done better ? */ if (pid) { prfcnt_start(&prfcnt); tsc_start(&timer); wait(&status); tsc_pause(&timer); prfcnt_pause(&prfcnt); } else { execv(argv[1],new_argv); perror("execv"); exit(1); } tsc_report(&timer); prfcnt_report(&prfcnt); return 0; }
static void *do_spmv_thread_main_swap(void *arg) { spm_mt_thread_t *spm_mt_thread; #ifdef SPMV_PRFCNT prfcnt_t *prfcnt; #endif SPMV_NAME(_fn_t) *spmv_mt_fn; tsc_t tsc; spm_mt_thread = arg; spmv_mt_fn = spm_mt_thread->spmv_fn; #ifdef SPMV_PRFCNT prfcnt = (prfcnt_t *) spm_mt_thread->data; #endif setaffinity_oncpu(spm_mt_thread->cpu); VECTOR_NAME(_init_rand_range)(x, (ELEM_TYPE) -1000, (ELEM_TYPE) 1000); // Assert this is a square matrix and swap is ok. assert(x->size == y->size); tsc_init(&tsc); tsc_start(&tsc); #ifdef SPMV_PRFCNT prfcnt_init(prfcnt, spm_mt_thread->cpu, PRFCNT_FL_T0 | PRFCNT_FL_T1); prfcnt_start(prfcnt); #endif int i; for (i = 0; i < loops_nr; i++) { pthread_barrier_wait(&barrier); spmv_mt_fn(spm_mt_thread->spm, x, y); pthread_barrier_wait(&barrier); SWAP(x, y); } tsc_pause(&tsc); #ifdef SPMV_PRFCNT prfcnt_pause(prfcnt); #endif secs = tsc_getsecs(&tsc); tsc_shut(&tsc); return NULL; }
int main(int argc, const char *argv[]) { unsigned nthreads; size_t nints; int sum1, sum2; int *arr; nints = 0; if (argc > 1) nints = atol(argv[1]); if (nints == 0) nints = 100000; #pragma omp parallel #pragma omp master nthreads = omp_get_num_threads(); printf("Number of threads: %u\n", nthreads); printf("number of ints: %lu\n", nints); arr = arr_int_mkrand(nints, &sum1); sum2 = 0; tsc_t t; tsc_init(&t); tsc_start(&t); #pragma omp parallel for reduction(+:sum2) for (size_t i=0; i<nints; i++) { sum2 += sum_op(arr[i]); } tsc_pause(&t); tsc_report("sum_OMP", &t); if (sum1 != sum2) { fprintf(stderr, "Error in sum: %d vs %d\n", sum1, sum2); abort(); } printf("DONE\n"); return 0; }
static void *do_spmv_thread_main(void *arg) { spm_mt_thread_t *spm_mt_thread = arg; SPMV_NAME(_sym_fn_t) *spmv_mt_sym_fn = spm_mt_thread->spmv_fn; setaffinity_oncpu(spm_mt_thread->cpu); tsc_t tsc; tsc_init(&tsc); tsc_start(&tsc); // Switch Reduction Phase int i/*, j, start, end*/; /* start = 0; end = n / ncpus; */ for (i = 0; i < nloops; i++) { // Switch Reduction Phase. VECTOR_NAME(_init_from_map)(temp, 0, spm_mt_thread->map); pthread_barrier_wait(&barrier); spmv_mt_sym_fn(spm_mt_thread->spm, spm_mt_thread->data, y, y); pthread_barrier_wait(&barrier); // Switch Reduction Phase. /* for (j = 0; j < ncpus; j++) VECTOR_NAME(_add_part)(y, temp[j], y, start, end); */ VECTOR_NAME(_add_from_map)(y, temp, y, spm_mt_thread->map); pthread_barrier_wait(&barrier); } tsc_pause(&tsc); secs = tsc_getsecs(&tsc); tsc_shut(&tsc); return NULL; }
int main(int argc, char *argv[]) { bool inhibit_loadfade = false; bool error = false; bool freshstart; SetLogFilename("debug.txt"); if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { staterr("ack, sdl_init failed: %s.", SDL_GetError()); return 1; } atexit(SDL_Quit); // start up inputs first thing because settings_load may remap them input_init(); // load settings, or at least get the defaults, // so we know the initial screen resolution. settings_load(); if (Graphics::init(settings->resolution)) { staterr("Failed to initialize graphics."); return 1; } if (font_init()) { staterr("Failed to load font."); return 1; } //speed_test(); //return 1; #ifdef CONFIG_DATA_EXTRACTOR if (!settings->files_extracted) { if (extract_main()) { Graphics::close(); font_close(); return 0; } else { settings->files_extracted = true; settings_save(); } } #endif if (check_data_exists()) { return 1; } Graphics::ShowLoadingScreen(); if (sound_init()) { fatal("Failed to initialize sound."); return 1; } if (trig_init()) { fatal("Failed trig module init."); return 1; } if (tsc_init()) { fatal("Failed to initialize script engine."); return 1; } if (textbox.Init()) { fatal("Failed to initialize textboxes."); return 1; } if (Carets::init()) { fatal("Failed to initialize carets."); return 1; } if (game.init()) return 1; game.setmode(GM_NORMAL); // set null stage just to have something to do while we go to intro game.switchstage.mapno = 0; //#define REPLAY #ifdef REPLAY game.switchstage.mapno = START_REPLAY; //Replay::set_ffwd(6000); //Replay::set_stopat(3500); game.switchstage.param = 1; #else //game.switchstage.mapno = LOAD_GAME; //game.pause(GP_OPTIONS); if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot))) game.switchstage.mapno = LOAD_GAME; else game.setmode(GM_INTRO); #endif // for debug if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; } if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true; game.running = true; freshstart = true; stat("Entering main loop..."); #ifdef __SDLSHIM__ set_console_visible(false); #endif //speed_test(); //return 1; while(game.running) { // SSS/SPS persists across stage transitions until explicitly // stopped, or you die & reload. It seems a bit risky to me, // but that's the spec. if (game.switchstage.mapno >= MAPNO_SPECIALS) { StopLoopSounds(); } // enter next stage, whatever it may be if (game.switchstage.mapno == LOAD_GAME || \ game.switchstage.mapno == LOAD_GAME_FROM_MENU) { if (game.switchstage.mapno == LOAD_GAME_FROM_MENU) freshstart = true; stat("= Loading game ="); if (game_load(settings->last_save_slot)) { fatal("savefile error"); goto ingame_error; } Replay::OnGameStarting(); if (!inhibit_loadfade) fade.Start(FADE_IN, FADE_CENTER); else inhibit_loadfade = false; } else if (game.switchstage.mapno == START_REPLAY) { stat(">> beginning replay '%s'", GetReplayName(game.switchstage.param)); StopScripts(); if (Replay::begin_playback(GetReplayName(game.switchstage.param))) { fatal("error starting playback"); goto ingame_error; } } else { if (game.switchstage.mapno == NEW_GAME || \ game.switchstage.mapno == NEW_GAME_FROM_MENU) { bool show_intro = (game.switchstage.mapno == NEW_GAME_FROM_MENU); InitNewGame(show_intro); } // slide weapon bar on first intro to Start Point if (game.switchstage.mapno == STAGE_START_POINT && \ game.switchstage.eventonentry == 91) { freshstart = true; } // switch maps if (load_stage(game.switchstage.mapno)) goto ingame_error; player->x = (game.switchstage.playerx * TILE_W) << CSF; player->y = (game.switchstage.playery * TILE_H) << CSF; } // start the level if (game.initlevel()) return 1; if (freshstart) weapon_introslide(); gameloop(); game.stageboss.OnMapExit(); freshstart = false; } shutdown: ; Replay::close(); game.close(); Carets::close(); Graphics::close(); input_close(); font_close(); sound_close(); tsc_close(); textbox.Deinit(); return error; ingame_error: ; stat(""); stat(" ************************************************"); stat(" * An in-game error occurred. Game shutting down."); stat(" ************************************************"); error = true; goto shutdown; }
BOOT_CODE bool_t init_sys_state( cpu_id_t cpu_id, mem_p_regs_t mem_p_regs, ui_info_t ui_info, p_region_t boot_mem_reuse_p_reg, /* parameters below not modeled in abstract specification */ uint32_t num_drhu, paddr_t* drhu_list, acpi_rmrr_list_t *rmrr_list, seL4_X86_BootInfo_VBE *vbe ) { cap_t root_cnode_cap; vptr_t extra_bi_frame_vptr; vptr_t bi_frame_vptr; vptr_t ipcbuf_vptr; cap_t it_vspace_cap; cap_t it_ap_cap; cap_t ipcbuf_cap; pptr_t bi_frame_pptr; word_t extra_bi_size = sizeof(seL4_BootInfoHeader); region_t extra_bi_region; pptr_t extra_bi_offset = 0; create_frames_of_region_ret_t create_frames_ret; create_frames_of_region_ret_t extra_bi_ret; /* convert from physical addresses to kernel pptrs */ region_t ui_reg = paddr_to_pptr_reg(ui_info.p_reg); region_t boot_mem_reuse_reg = paddr_to_pptr_reg(boot_mem_reuse_p_reg); /* convert from physical addresses to userland vptrs */ v_region_t ui_v_reg; v_region_t it_v_reg; ui_v_reg.start = ui_info.p_reg.start - ui_info.pv_offset; ui_v_reg.end = ui_info.p_reg.end - ui_info.pv_offset; ipcbuf_vptr = ui_v_reg.end; bi_frame_vptr = ipcbuf_vptr + BIT(PAGE_BITS); extra_bi_frame_vptr = bi_frame_vptr + BIT(PAGE_BITS); if (vbe->vbeMode != -1) { extra_bi_size += sizeof(seL4_X86_BootInfo_VBE); } /* The region of the initial thread is the user image + ipcbuf and boot info */ it_v_reg.start = ui_v_reg.start; it_v_reg.end = ROUND_UP(extra_bi_frame_vptr + extra_bi_size, PAGE_BITS); init_freemem(ui_info.p_reg, mem_p_regs); /* create the root cnode */ root_cnode_cap = create_root_cnode(); /* create the IO port cap */ write_slot( SLOT_PTR(pptr_of_cap(root_cnode_cap), seL4_CapIOPort), cap_io_port_cap_new( 0, /* first port */ NUM_IO_PORTS - 1, /* last port */ VPID_INVALID ) ); /* create the cap for managing thread domains */ create_domain_cap(root_cnode_cap); /* create the IRQ CNode */ if (!create_irq_cnode()) { return false; } /* initialise the IRQ states and provide the IRQ control cap */ init_irqs(root_cnode_cap); /* create the bootinfo frame */ bi_frame_pptr = allocate_bi_frame(0, ksNumCPUs, ipcbuf_vptr); if (!bi_frame_pptr) { return false; } extra_bi_region = allocate_extra_bi_region(extra_bi_size); if (extra_bi_region.start == 0) { return false; } /* populate vbe info block */ if (vbe->vbeMode != -1) { vbe->header.id = SEL4_BOOTINFO_HEADER_X86_VBE; vbe->header.len = sizeof(seL4_X86_BootInfo_VBE); memcpy((void*)(extra_bi_region.start + extra_bi_offset), vbe, sizeof(seL4_X86_BootInfo_VBE)); extra_bi_offset += sizeof(seL4_X86_BootInfo_VBE); } /* provde a chunk for any leftover padding in the extended boot info */ seL4_BootInfoHeader padding_header; padding_header.id = SEL4_BOOTINFO_HEADER_PADDING; padding_header.len = (extra_bi_region.end - extra_bi_region.start) - extra_bi_offset; memcpy((void*)(extra_bi_region.start + extra_bi_offset), &padding_header, sizeof(seL4_BootInfoHeader)); /* Construct an initial address space with enough virtual addresses * to cover the user image + ipc buffer and bootinfo frames */ it_vspace_cap = create_it_address_space(root_cnode_cap, it_v_reg); if (cap_get_capType(it_vspace_cap) == cap_null_cap) { return false; } /* Create and map bootinfo frame cap */ create_bi_frame_cap( root_cnode_cap, it_vspace_cap, bi_frame_pptr, bi_frame_vptr ); /* create and map extra bootinfo region */ extra_bi_ret = create_frames_of_region( root_cnode_cap, it_vspace_cap, extra_bi_region, true, pptr_to_paddr((void*)(extra_bi_region.start - extra_bi_frame_vptr)) ); if (!extra_bi_ret.success) { return false; } ndks_boot.bi_frame->extraBIPages = extra_bi_ret.region; /* create the initial thread's IPC buffer */ ipcbuf_cap = create_ipcbuf_frame(root_cnode_cap, it_vspace_cap, ipcbuf_vptr); if (cap_get_capType(ipcbuf_cap) == cap_null_cap) { return false; } /* create all userland image frames */ create_frames_ret = create_frames_of_region( root_cnode_cap, it_vspace_cap, ui_reg, true, ui_info.pv_offset ); if (!create_frames_ret.success) { return false; } ndks_boot.bi_frame->userImageFrames = create_frames_ret.region; /* create the initial thread's ASID pool */ it_ap_cap = create_it_asid_pool(root_cnode_cap); if (cap_get_capType(it_ap_cap) == cap_null_cap) { return false; } write_it_asid_pool(it_ap_cap, it_vspace_cap); ndks_boot.bi_frame->archInfo = tsc_init(); /* create the idle thread */ if (!create_idle_thread()) { return false; } /* create the initial thread */ if (!create_initial_thread( root_cnode_cap, it_vspace_cap, ui_info.v_entry, bi_frame_vptr, ipcbuf_vptr, ipcbuf_cap )) { return false; } if (config_set(CONFIG_IOMMU)) { /* initialise VTD-related data structures and the IOMMUs */ if (!vtd_init(cpu_id, num_drhu, rmrr_list)) { return false; } /* write number of IOMMU PT levels into bootinfo */ ndks_boot.bi_frame->numIOPTLevels = x86KSnumIOPTLevels; /* write IOSpace master cap */ write_slot(SLOT_PTR(pptr_of_cap(root_cnode_cap), seL4_CapIOSpace), master_iospace_cap()); } else { ndks_boot.bi_frame->numIOPTLevels = -1; } /* create all of the untypeds. Both devices and kernel window memory */ if (!create_untypeds(root_cnode_cap, boot_mem_reuse_reg)) { return false; } /* WARNING: alloc_region() must not be called anymore after here! */ /* finalise the bootinfo frame */ bi_finalise(); return true; }
/** * Entry point called from boot.S for bootstrap processor. */ void arch_init(uint32_t board_id, struct atag *atag_base, lvaddr_t elf_file, lvaddr_t alloc_top) { // // Assumptions: // // - MMU and caches are enabled. No lockdowns in caches or TLB. // - Kernel has own section starting at KERNEL_OFFSET. // - Kernel section includes the highmem relocated exception vector table. // struct atag * ae = NULL; exceptions_init(); ae = atag_find(atag_base, ATAG_MEM); paging_map_memory(0, ae->u.mem.start, ae->u.mem.bytes); ae = atag_find(atag_base, ATAG_CMDLINE); if (ae != NULL) { parse_commandline(ae->u.cmdline.cmdline, cmdargs); tick_hz = CONSTRAIN(tick_hz, 10, 1000); } if (board_id == hal_get_board_id()) { errval_t errval; serial_console_init(true); // do not remove/change this printf: needed by regression harness printf("Barrelfish CPU driver starting on ARMv5 Board id 0x%08"PRIx32"\n", board_id); printf("The address of paging_map_kernel_section is %p\n", paging_map_kernel_section); errval = serial_debug_init(); if (err_is_fail(errval)) { printf("Failed to initialize debug port: %d", serial_debug_port); } debug(SUBSYS_STARTUP, "alloc_top %08"PRIxLVADDR" %08"PRIxLVADDR"\n", alloc_top, alloc_top - KERNEL_OFFSET); debug(SUBSYS_STARTUP, "elf_file %08"PRIxLVADDR"\n", elf_file); my_core_id = hal_get_cpu_id(); extern struct kcb bspkcb; memset(&bspkcb, 0, sizeof(bspkcb)); kcb_current = &bspkcb; pic_init(); pit_init(tick_hz); tsc_init(); ae = atag_find(atag_base, ATAG_MEM); // Add unused physical memory to memory map phys_mmap_t phys_mmap; // Kernel effectively consumes [0...alloc_top] // Add region above alloc_top with care to skip exception vector // page. if (alloc_top < ETABLE_ADDR) { phys_mmap_add(&phys_mmap, alloc_top - KERNEL_OFFSET, ETABLE_ADDR - KERNEL_OFFSET); } phys_mmap_add(&phys_mmap, ETABLE_ADDR - KERNEL_OFFSET + BASE_PAGE_SIZE, ae->u.mem.start + ae->u.mem.bytes); ae = atag_find(atag_base, ATAG_VIDEOLFB); if (NULL != ae) { // Remove frame buffer (if present). phys_mmap_remove(&phys_mmap, ae->u.videolfb.lfb_base, ae->u.videolfb.lfb_base + ae->u.videolfb.lfb_size); assert(!"Not supported"); } ae = atag_find(atag_base, ATAG_INITRD2); if (NULL != ae) { phys_mmap_remove(&phys_mmap, ae->u.initrd2.start, ae->u.initrd2.start + ae->u.initrd2.bytes); arm_kernel_startup(&phys_mmap, ae->u.initrd2.start, ae->u.initrd2.bytes); } else { panic("initrd not found\n"); } } else { panic("Mis-matched board id: [current %"PRIu32", kernel %"PRIu32"]", board_id, hal_get_board_id()); } }
/** * @brief Parses command line options and implements application logic * * @param argc number of arguments in the command line * @param argv table with command line argument strings * * @return Process exit code */ int main(int argc, char *argv[]) { const long long freq_nanosecs = freq_ms * 1000LL * 1000LL; int core_id, lock_data = 1, exit_val = EXIT_SUCCESS; if (argc < 3) { printf("Usage: %s <core_id> <lock|nolock>\n", argv[0]); exit(EXIT_FAILURE); } if (strcasecmp(argv[2], "nolock") != 0 && strcasecmp(argv[2], "lock") != 0) { printf("Invalid data lock setting '%s'!\n", argv[2]); printf("Usage: %s <core_id> <lock|nolock>\n", argv[0]); exit(EXIT_FAILURE); } core_id = atoi(argv[1]); lock_data = (strcasecmp(argv[2], "nolock") == 0) ? 0 : 1; /* allocate memory blocks */ main_data_ptr = init_memory(main_data_size); timer_data_ptr = init_memory(timer_data_size); if (main_data_ptr == NULL || timer_data_ptr == NULL) { exit_val = EXIT_FAILURE; goto error_exit1; } if (lock_data) { /* initialize PQoS and lock the data */ if (init_pqos() != 0) { exit_val = EXIT_FAILURE; goto error_exit1; } /* lock the timer data */ if (dlock_init(timer_data_ptr, timer_data_size, 1 /* CLOS */, core_id) != 0) { printf("Pseudo data lock error!\n"); exit_val = EXIT_FAILURE; goto error_exit1; } } tsc_init(&timer_prof, "Timer Handler"); if (init_timer(freq_nanosecs) != 0) { printf("Timer start error!\n"); exit_val = EXIT_FAILURE; goto error_exit2; } main_thread((char *)main_data_ptr, main_data_size); (void) close_timer(); tsc_print(&timer_prof); error_exit2: if (lock_data) dlock_exit(); error_exit1: if (lock_data) (void) close_pqos(); if (main_data_ptr != NULL) free(main_data_ptr); if (timer_data_ptr != NULL) free(timer_data_ptr); return exit_val; }
void pre_main(void) { #ifdef DEBUG_LOG char debug_fname[1024]; retro_create_path_string(debug_fname, sizeof(debug_fname), g_dir, "debug.txt"); SetLogFilename(debug_fname); #endif // start up inputs first thing because settings_load may remap them input_init(); // load settings, or at least get the defaults, // so we know the initial screen resolution. settings_load(); char filename[1024]; FILE *fp; NX_LOG("= Extracting Files =\n"); retro_create_path_string(filename, sizeof(filename), g_dir, "Doukutsu.exe"); fp = fopen(filename, "rb"); extract_files(fp); if (sound_init()) { fatal("Failed to initialize sound."); error = 1; return; } extract_stages(fp); fclose(fp); settings->files_extracted = true; settings_save(); if (Graphics::init(settings->resolution)) { NX_ERR("Failed to initialize graphics.\n"); error = 1; return; } if (font_init()) { NX_ERR("Failed to load font.\n"); error = 1; return; } //return; if (check_data_exists()) { error = 1; return; } //Graphics::ShowLoadingScreen(); if (trig_init()) { fatal("Failed trig module init."); error = 1; return; } if (tsc_init()) { fatal("Failed to initialize script engine."); error = 1; return; } if (textbox.Init()) { fatal("Failed to initialize textboxes."); error = 1; return; } if (Carets::init()) { fatal("Failed to initialize carets."); error = 1; return; } if (game.init()) { error = 1; return; } game.setmode(GM_NORMAL); // set null stage just to have something to do while we go to intro game.switchstage.mapno = 0; //#define REPLAY #ifdef REPLAY game.switchstage.mapno = START_REPLAY; //Replay::set_ffwd(6000); //Replay::set_stopat(3500); game.switchstage.param = 1; #else //game.switchstage.mapno = LOAD_GAME; //game.pause(GP_OPTIONS); if (settings->skip_intro && file_exists(GetProfileName(settings->last_save_slot))) game.switchstage.mapno = LOAD_GAME; else game.setmode(GM_INTRO); #endif // for debug if (game.paused) { game.switchstage.mapno = 0; game.switchstage.eventonentry = 0; } if (game.switchstage.mapno == LOAD_GAME) inhibit_loadfade = true; game.running = true; freshstart = true; NX_LOG("Entering main loop...\n"); //return; }
int main(int argc, const char *argv[]) { if (argc < 4) { fprintf(stderr, "Usage: %s <array_size> <block_size> <accesses>\n", argv[0]); exit(1); } unsigned int asize = atol(argv[1]); unsigned int bsize = atol(argv[2]); unsigned int accesses = atol(argv[3]); unsigned int seed = time(NULL); tsc_t tc; /* normal pointers */ srand(seed); printf("CoPy\n"); unsigned int *p, *p_copy; unsigned int sum_copy = 0; p = xmalloc(asize*sizeof(unsigned int)); for (unsigned int i=0; i<asize; i++) p[i] = i; tsc_init(&tc); tsc_start(&tc); p_copy = xmalloc(asize*sizeof(unsigned int)); memcpy(p_copy, p, asize*sizeof(unsigned int)); for (unsigned int j=0; j<accesses; j++) { unsigned int idx = rand() % asize; p_copy[idx] = 0; } #ifdef DO_SUMS for (unsigned int j=0; j<asize; j++) { sum_copy += p_copy[j]; } #endif tsc_pause(&tc); tsc_report(&tc); /* versioned pointers */ tsc_t t; srand(seed); printf("VerSions\n"); unsigned int sum_versions = 0; sla_t *sla = sla_init(10, .5, 16, time(NULL)); sla->def_nitems = bsize; for (unsigned int i=0; i<asize; i++) sla_append(sla, i); tsc_init(&t); tsc_start(&t); versla_t *versla = versla_init(sla); ver_t *v1 = versla_newver(versla, versla->vo.ver_base); for (unsigned int j=0; j<accesses; j++) { unsigned int idx = rand() % asize; versla_set(versla, idx, 0, v1); } #ifdef DO_SUMS for (unsigned int j=0; j<asize; j++) { unsigned int x = versla_get(versla, j, v1); sum_versions += x; } #endif tsc_pause(&t); tsc_report(&t); printf("\ntC/tV=%lf\n", (double)tsc_getticks(&tc)/(double)tsc_getticks(&t)); for (unsigned int j=0; j<asize; j++) { unsigned int x0 = p_copy[j]; unsigned int x1 = versla_get(versla, j, v1); if (x0 != x1) { fprintf(stderr, "copy:%d and versions:%d differ for j=%d\n", x0, x1, j); } } assert(sum_versions == sum_copy); return 0; }