int main(int argc, char ** argv) { // Register release_allocator() to run when program exits normally. if( atexit(release_allocator) != 0 ) err_sys("Can't register release_allocator().\n"); // PARSE INPUT ARGUMENTS unsigned int BASIC_BLOCK_SIZE; unsigned int MEMORY_LENGTH; int b_flag = 0, // Used to provide default argument values if s_flag = 0; // none are given. _Bool o_flag = 0; opterr = 0; // Disable getopt() error message. // gets the arguments from the command line and rounds them up to the nearest // power of two int c; set_output_flag(0); while( (c = getopt(argc, argv, OPTSTR)) != -1 ){ switch(c){ case 'b': b_flag = 1; BASIC_BLOCK_SIZE = convert(atoi(optarg)); break; case 's': s_flag = 1; MEMORY_LENGTH = convert(atoi(optarg)); break; case 'o': set_output_flag(1); break; }; } // Provide default arguments if needed. if ( !(b_flag) ){ BASIC_BLOCK_SIZE = 128; // Set default to 128 B printf("No argument provided; using default BASIC_BLOCK_SIZE: 128 B\n"); } if ( !(s_flag) ){ MEMORY_LENGTH = 524288; // Set default to 512 KiB printf("No argument provided; using default MEMORY_LENGTH: 512 KiB\n\n"); } printf("Basic Block Size: %d B\nMemory Size: %d B\n", BASIC_BLOCK_SIZE,MEMORY_LENGTH); //============================================================================== // initialize the allocator unsigned int allocate_flag = init_allocator(BASIC_BLOCK_SIZE, MEMORY_LENGTH); if(allocate_flag == 0){ printf("\nAllocator initialization error."); return 0; } // Otherwise, run ackerman_main() ackerman_main(); return 0; }
int main(int argc, char ** argv) { int opterr = 0; unsigned int _basic_block_size = 128; unsigned int _length = 524288; int c; while( (c = getopt(argc, argv, "b:s:") ) != -1) { switch(c) { case 'b': _basic_block_size = atoi(optarg); break; case 's': _length = atoi(optarg)*1024; break; case '?': break; default: abort(); } } init_allocator(_basic_block_size, _length); ackerman_main(); release_allocator(); }
int main(void) { FILE *f = tmpfile(); assert(f != NULL); int fd = fileno(f); ALLOC allocator; ALLOC *a = &allocator; assert(init_allocator(a, fd, O_CREAT | O_TRUNC) == 0); assert(fsize(fd) == FLT_LEN); char buf[] = "hello, world"; handle_t h, h1; assert((h = alloc_blk(a, buf, sizeof(buf))) != 0); assert(h == 1); assert(fsize(fd) % 16 == 0); size_t size = sizeof(buf); bzero(buf, sizeof(buf)); assert(read_blk(a, h, buf, &size) == buf); assert(size == sizeof(buf)); assert(strncmp(buf, "hello, world", sizeof(buf)) == 0); char buf1[] = "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohelloh"; char buf2[] = "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohelloh"; h1 = h; assert((h = alloc_blk(a, buf1, sizeof(buf1))) != 0); assert(fsize(fd) % 16 == 0); size = sizeof(buf1); bzero(buf1, sizeof(buf1)); assert(read_blk(a, h, buf1, &size) == buf1); assert(size == sizeof(buf1)); assert(strncmp(buf1, buf2, sizeof(buf1)) == 0); // Is buf's "hello, world" still there? size = sizeof(buf); bzero(buf, sizeof(buf)); assert(read_blk(a, h1, buf, &size) == buf); assert(size == sizeof(buf)); assert(strncmp(buf, "hello, world", sizeof(buf)) == 0); // replace buf1's content assert(realloc_blk(a, h, buf, sizeof(buf)) == 0); size = sizeof(buf); bzero(buf, sizeof(buf)); assert(read_blk(a, h1, buf, &size) == buf); assert(size == sizeof(buf)); assert(strncmp(buf, "hello, world", sizeof(buf)) == 0); return 0; }
int main(void) { FILE *f = tmpfile(); assert(f != NULL); int fd = fileno(f); ALLOC allocator; ALLOC *a = &allocator; assert(init_allocator(a, fd, 0) != 0); assert(init_allocator(a, fd, O_CREAT) == 0); assert(fsize(fd) == FLT_LEN); BTree bt; handle_t root = CreateBTree(&bt, a, 1, 4, cmpInt); int i; for(i = 1; i <= 100000; i++) { SetKey(&bt, &i, i); //output(&bt); //getchar(); } return 0; for(i = 1; i <= 10000; i++) { DeleteKey(&bt, &i, 100000-i+1); } return 0; }
int main(int argc, char ** argv) { int a = init_allocator(50, 1000000); /*printf("%s %d\n", "Total memory allocated" ,a ); printf("%s %d\n", "Total blocks" ,a/4 ); //print_freeList(); //check_list(); //print_freeList(); void * b = my_malloc(16000); void * d = my_malloc(16000); void * e = my_malloc(16000); void * f = my_malloc(16000); void * c = my_malloc(81000); int x = my_free(b); int y = my_free(d); int r = my_free(e); int t = my_free(f); int p = my_free(c);*/ ackerman_main(); }
int main(){ int * begin; int * go; int * go2; int * go3; init_allocator(128,19000); begin = my_malloc(300); printf("\n"); go = my_malloc(300); printf("\n"); go2 = my_malloc(300); printf("\n"); go3 = my_malloc(300); printf("memeory allocated\n"); my_free(begin); my_free(go); my_free(go2); my_free(go3); release_allocator(); return 0; }
int test(int iteration) { long i; pthread_attr_t attr; pthread_t thread[nbthreads]; hash_init(); init_allocator(); pthread_attr_init(&attr); done = 0; go = 0; ready = 0; memory_barrier(); //printf("loop %d is started\n", iteration); //printf("thread !!%d\n",thread); for(i=0; i< nbthreads; i++) { set_affinity(i); //printf("thread = %d ...", i); if(pthread_create(&thread[i], &attr, run, (void*)i)) { perror("creat"); } //printf("thread = %d created\n", i); } while(ready != nbthreads) memory_barrier(); go = 1; memory_barrier(); void* res; for(i=(nbthreads-1); i >= 0; i--) { pthread_join(thread[i], &res); if(i == nbupdaters) { done = 1;//Stop the writers! memory_barrier(); } } //printf("Done!\n", i); unsigned nbcores = get_nbcores(); unsigned mtc = nbcores < nbreaders ? nbcores : nbreaders; run_avg_rd[iteration] = get_avg(&avg_time[nbupdaters], nbreaders); run_avg_wr[iteration] = get_avg(&avg_time[0], nbupdaters); run_max_rd[iteration] = get_max(&avg_time[nbupdaters], nbreaders); run_max_wr[iteration] = get_max(&avg_time[0], nbupdaters); run_min_rd[iteration] = get_min(&avg_time[nbupdaters], nbreaders); run_min_wr[iteration] = get_min(&avg_time[0], nbupdaters); run_retry[iteration] = get_sum(&thd_retry[nbupdaters], nbreaders); run_relink[iteration] = get_sum(&thd_relink[nbupdaters], nbreaders); run_reprev[iteration] = get_sum(&thd_reprev[nbupdaters], nbreaders); run_cput[iteration] = get_cpu_work(&thd_time[nbupdaters], nbreaders, mtc)/NB_TEST; run_mallocs[iteration] = get_sum(&thd_mallocs[0], nbupdaters); run_blockeds[iteration] = get_sum(&thd_blockeds[0], nbupdaters); run_sea[iteration] = get_avg(&suc_sea[nbupdaters], nbreaders); run_del[iteration] = get_avg(&suc_del[0], nbupdaters); run_ins[iteration] = get_avg(&suc_ins[0], nbupdaters); //printf("avg = %gus\n", run_avg_rd[iteration]); //printf("first reader %gus\n", thd_time[nbupdaters]); double time = get_avg(&thd_time[nbupdaters], nbreaders); trd_ops[iteration] = get_avg(&thd_ops[nbupdaters], nbreaders)/time; twr_ops[iteration] = get_avg(&thd_ops[0], nbupdaters)/time; //hash_delete(); //delete_allocator(); }
static struct dm_cache_policy *smq_create(dm_cblock_t cache_size, sector_t origin_size, sector_t cache_block_size) { unsigned i; unsigned nr_sentinels_per_queue = 2u * NR_CACHE_LEVELS; unsigned total_sentinels = 2u * nr_sentinels_per_queue; struct smq_policy *mq = kzalloc(sizeof(*mq), GFP_KERNEL); if (!mq) return NULL; init_policy_functions(mq); mq->cache_size = cache_size; mq->cache_block_size = cache_block_size; calc_hotspot_params(origin_size, cache_block_size, from_cblock(cache_size), &mq->hotspot_block_size, &mq->nr_hotspot_blocks); mq->cache_blocks_per_hotspot_block = div64_u64(mq->hotspot_block_size, mq->cache_block_size); mq->hotspot_level_jump = 1u; if (space_init(&mq->es, total_sentinels + mq->nr_hotspot_blocks + from_cblock(cache_size))) { DMERR("couldn't initialize entry space"); goto bad_pool_init; } init_allocator(&mq->writeback_sentinel_alloc, &mq->es, 0, nr_sentinels_per_queue); for (i = 0; i < nr_sentinels_per_queue; i++) get_entry(&mq->writeback_sentinel_alloc, i)->sentinel = true; init_allocator(&mq->demote_sentinel_alloc, &mq->es, nr_sentinels_per_queue, total_sentinels); for (i = 0; i < nr_sentinels_per_queue; i++) get_entry(&mq->demote_sentinel_alloc, i)->sentinel = true; init_allocator(&mq->hotspot_alloc, &mq->es, total_sentinels, total_sentinels + mq->nr_hotspot_blocks); init_allocator(&mq->cache_alloc, &mq->es, total_sentinels + mq->nr_hotspot_blocks, total_sentinels + mq->nr_hotspot_blocks + from_cblock(cache_size)); mq->hotspot_hit_bits = alloc_bitset(mq->nr_hotspot_blocks); if (!mq->hotspot_hit_bits) { DMERR("couldn't allocate hotspot hit bitset"); goto bad_hotspot_hit_bits; } clear_bitset(mq->hotspot_hit_bits, mq->nr_hotspot_blocks); if (from_cblock(cache_size)) { mq->cache_hit_bits = alloc_bitset(from_cblock(cache_size)); if (!mq->cache_hit_bits) { DMERR("couldn't allocate cache hit bitset"); goto bad_cache_hit_bits; } clear_bitset(mq->cache_hit_bits, from_cblock(mq->cache_size)); } else mq->cache_hit_bits = NULL; mq->tick = 0; spin_lock_init(&mq->lock); q_init(&mq->hotspot, &mq->es, NR_HOTSPOT_LEVELS); mq->hotspot.nr_top_levels = 8; mq->hotspot.nr_in_top_levels = min(mq->nr_hotspot_blocks / NR_HOTSPOT_LEVELS, from_cblock(mq->cache_size) / mq->cache_blocks_per_hotspot_block); q_init(&mq->clean, &mq->es, NR_CACHE_LEVELS); q_init(&mq->dirty, &mq->es, NR_CACHE_LEVELS); stats_init(&mq->hotspot_stats, NR_HOTSPOT_LEVELS); stats_init(&mq->cache_stats, NR_CACHE_LEVELS); if (h_init(&mq->table, &mq->es, from_cblock(cache_size))) goto bad_alloc_table; if (h_init(&mq->hotspot_table, &mq->es, mq->nr_hotspot_blocks)) goto bad_alloc_hotspot_table; sentinels_init(mq); mq->write_promote_level = mq->read_promote_level = NR_HOTSPOT_LEVELS; mq->next_hotspot_period = jiffies; mq->next_cache_period = jiffies; return &mq->policy; bad_alloc_hotspot_table: h_exit(&mq->table); bad_alloc_table: free_bitset(mq->cache_hit_bits); bad_cache_hit_bits: free_bitset(mq->hotspot_hit_bits); bad_hotspot_hit_bits: space_exit(&mq->es); bad_pool_init: kfree(mq); return NULL; }
int main(int argc, char **argv) { test_init_data_t *init_data; struct env env; assert(argc >= 2); /* in order to have some shitty almost-fork-like semantics * main can get run multiple times. Look in src/helpers.c * for where this is used. Just means we check the first * arg, and if not NULL jmp to it */ void (*helper_thread)(int argc,char **argv) = (void(*)(int, char**))atol(argv[1]); if (helper_thread) { helper_thread(argc, argv); } /* parse args */ assert(argc == 3); endpoint = (seL4_CPtr) atoi(argv[2]); /* read in init data */ init_data = receive_init_data(endpoint); /* configure env */ env.cspace_root = init_data->root_cnode; env.page_directory = init_data->page_directory; env.endpoint = endpoint; env.priority = init_data->priority; env.cspace_size_bits = init_data->cspace_size_bits; env.tcb = init_data->tcb; env.domain = init_data->domain; #ifndef CONFIG_KERNEL_STABLE env.asid_pool = init_data->asid_pool; env.asid_ctrl = init_data->asid_ctrl; #endif /* CONFIG_KERNEL_STABLE */ #ifdef CONFIG_IOMMU env.io_space = init_data->io_space; #endif env.num_regions = init_data->num_elf_regions; memcpy(env.regions, init_data->elf_regions, sizeof(sel4utils_elf_region_t) * env.num_regions); /* initialse cspace, vspace and untyped memory allocation */ init_allocator(&env, init_data); /* initialise the timer */ init_timer(&env, init_data); /* find the test */ testcase_t *test = find_test(init_data->name); /* run the test */ int result = 0; if (test) { printf("Running test %s (%s)\n", test->name, test->description); result = test->function(&env); } else { result = FAILURE; ZF_LOGF("Cannot find test %s\n", init_data->name); } printf("Test %s %s\n", init_data->name, result == SUCCESS ? "passed" : "failed"); /* send our result back */ seL4_MessageInfo_t info = seL4_MessageInfo_new(seL4_NoFault, 0, 0, 1); seL4_SetMR(0, result); seL4_Send(endpoint, info); /* It is expected that we are torn down by the test driver before we are * scheduled to run again after signalling them with the above send. */ assert(!"unreachable"); return 0; }
int main(int argc, char ** argv) { unsigned long long b, M = 0; int opt; //char input[256]; while((opt = getopt(argc, argv, "b::s::")) != -1){ switch (opt){ case 'b':{ if(argv[2]) b = atoi(argv[2]); else b=32; //printf("b: %s \n",argv[2]); break; } case 's':{ if(argv[4]) M = atoi(argv[4]); else M = 128*1024*1024; //printf("M: %s \n",argv[4]); break; } default:{ fprintf(stderr, "Usage: %s [-b blocksize] [-s] memsize\n",argv[0]); exit(EXIT_FAILURE); } } } if (b == 0 || M == 0 ){ b = 32; M = 128*1024*1024; } printf("using values:\nb: %d \nM: %d \n",b,M); // init_allocator(basic block size, memory length) init_allocator(b,M); //init_allocator(32,128*1024*1024); ackerman_main(); // my_allocator DEMO /* init_allocator(32,256*32); PrintList(); cout<<endl; PrintList2(); cout<<endl; int* block1 = (int*) my_malloc(64);//allocates 128 block int* block2 = (int*) my_malloc(12);//allocates 32 block int* block3 = (int*) my_malloc(12);//allocates 32 block int* block4 = (int*) my_malloc(32);//allocates 64 block cout<<"PRINTING AFTER ALLOCATING BLOCKS"<<endl; PrintList(); cout<<endl; PrintList2(); my_free(block1); my_free(block2); my_free(block3); my_free(block4); cout<<endl<<"PRINTING AFTER FREEING BLOCKS"<<endl; PrintList(); cout<<endl; PrintList2(); */ //atexit(release_allocator()); release_allocator(); }
int main(int argc, char *argv[]) { int numThreads, time, initListSize, elementsRange; Input input = parseArgs(argc, argv, &numThreads, &time, &initListSize, &elementsRange); struct allocator allocator; int allocSize = HEAP_SIZE; #if !defined(OA) allocSize = 6000000;//15000000 #elif defined(MOA) allocSize=(numThreads>32 || (numThreads==32 && input.fractionInserts>0.2))?50000:allocSize; //for 32 threads a heap of 20000 items is too small. #endif init_allocator(&allocator, lalloc, numThreads, dirties, allocSize, HPsPerThread); #ifdef HASH_OP int logLen=0, size=(int)(initListSize/LOAD_FACTOR); while(size/=2) logLen++; assert(logLen!=0);//don't know why, but the HASH don't work well. if(logLen<9) logLen=9; assert(1<<logLen >= ARR_ENTRIES_PER_BIT); initHash(&hash, logLen); #endif for (int i = 0; i < numThreads; i++) { tg[i].input = input; tg[i].input.threadID = i; tg[i].dirty = dirties+i; tg[i].entryAllocator = lalloc+i; } // end of for loop, initializing the threads data initialize_ds(initListSize, elementsRange, tg); for (int i = 0; i < numThreads; i++) { if(pthread_create(&workerThreads[i], NULL, start_routine, &tg[i])){ printf("Error occurred when creating thread %d\n", i); exit(1); } } ////////////START TEST run = TRUE; __sync_synchronize(); sleep(time); stop=TRUE; __sync_synchronize(); ////////////END TEST for (int i=0; i< numThreads; ++i) { // join all threads pthread_join(workerThreads[i], NULL); } //TIME g_timer_stop(t); #ifndef MALLOC destroyAllocator(&allocator); #endif #if defined(OA) int numPhases = allocator.phase.phase/2-INIT_PHASE; #else int numPhases = 0; #endif num_ops = (long long)num_ops / (long double)time; const double M=1000000; printf(HG_VER "Threads=%d, Thpt=%ld, ThptM=%.1f, Phases=%d, Time=%f, InitSize=%d, Range=%d, SearchFrac=%.2f\n", numThreads, num_ops, num_ops/M, numPhases, (double)time, initListSize, elementsRange, 1-tg[0].input.fractionInserts-tg[0].input.fractionDeletes); printf("___ %ld %d %.2f\n", num_ops, numThreads, 1-tg[0].input.fractionInserts-tg[0].input.fractionDeletes); #if !defined(MOA) && !defined(OA) extern int alcctr; printf("alcctr = %d\n", alcctr); //extern int m; //printf("m =%d\n", m); #endif //TIME printf("___ %f %d %.2f\n", totalTime, numThreads, 1 - atof(argv[6]) - atof(argv[5])); return 0; }
uval test_os(uval argc, uval argv[]) { uval ret[1]; sval rc; uval r3 = argv[0]; uval r4 = argv[1]; uval ofd; const uval slot = 0x1; uval schedvals[3]; sval rot; uval nchunks = 0; uval ofd_size; uval i = 0; argc = argc; rrupts_off(); /* Setting up the IPC structures */ #ifndef RELOADER ret[0] = aipc_config(msgHandler); if (ret[0] != H_Success) { hprintf("Failed create: %ld\n", ret[0]); } #endif if (r3 == ~0UL) { /* we../src/bin/mambo-sti -n have cloned ourselves */ hputs("hello world.. this is slave\n"); rc = hcall_get_lpid(ret); assert(rc == H_Success, "hcall_get_lpid() failed\n"); hprintf("I am partition ID %ld\n", ret[0]); yield(0); } hputs("hello world.. this is controller\n"); rc = hcall_get_lpid(ret); assert(rc == H_Success, "hcall_get_lpid() failed\n"); ofd = ofd_devtree_init(r4, &ofd_size); ofd_bootargs(ofd, default_bootargs, sizeof (default_bootargs)); pgalloc_init(&pa, (uval)_end, 0, pinfo[1].mem[0].size, LOG_PGSIZE); if (ofd) { set_pages_used(&pa, (uval)ofd, ofd_size); } init_allocator(&pa); rrupts_on(); struct mem_range *mem = &pinfo[1].mem[0]; uval max_addr = mem[0].size; while (i < MAX_MEM_RANGES && mem[i].size != INVALID_MEM_RANGE) { nchunks += mem[i].size / CHUNK_SIZE; max_addr = mem[i].addr + mem[i].size; ++i; } pgalloc_init(&logical_pa, ~((uval)0), 0, max_addr, LOG_PGSIZE); set_pages_used(&logical_pa, 0, CHUNK_SIZE); uval curr = CHUNK_SIZE; i = 0; while (i < MAX_MEM_RANGES && mem[i].size != INVALID_MEM_RANGE) { if (curr < mem[i].addr) { set_pages_used(&logical_pa, curr, mem[i].addr - curr); curr = mem[i].addr; } if (curr < mem[i].addr + mem[i].size) { free_pages(&logical_pa, curr, mem[i].addr + mem[i].size - curr); curr = mem[i].addr + mem[i].size; } if (curr == mem[i].addr + mem[i].size) { ++i; } } assert(nchunks >= 1, "not enough chunks to create an LPAR\n"); hprintf("setting my sched slot to 0x%0lx\n", slot); rot = hcall_set_sched_params(schedvals, H_SELF_LPID, THIS_CPU, slot, 0); assert(rot >= 0, "set sched failed\n"); hprintf("Scheduler controller: rot: " "%ld (0x%016lx, 0x%016lx 0x%016lx)\n", rot, schedvals[0], schedvals[1], schedvals[2]); curslots = schedvals[0]; #ifdef RELOADER reload_image(image_names[0], ofd); #endif for (i = 0; i < MAX_MANAGED_PARTITIONS; ++i) { curslots &= ~partitions[i].slot; partitions[i].active = 0; partitions[i].init_mem = 0; partitions[i].init_mem_size = 0; partitions[i].lpid = -1; partitions[i].vterm = 0; partitions[i].slot = 0; partitions[i].msgrcv = 0; partitions[i].name = NULL; } ask(r3, ofd); assert(0, "controller: Should never get here\n"); return 0; }
/** * Inicialize kernel memory heap. */ void kheap_init() { _kheap = init_allocator(KHEAP_INIT_SIZE, KHEAP_VIRT_BASE); }