ibp_capset_t *create_allocs(int nallocs, int asize) { int i, err; ibp_attributes_t attr; ibp_depot_t *depot; oplist_t *iolist; ibp_op_t *op; ibp_capset_t *caps = (ibp_capset_t *)malloc(sizeof(ibp_capset_t)*nallocs); set_ibp_attributes(&attr, time(NULL) + a_duration, IBP_HARD, IBP_BYTEARRAY); iolist = new_ibp_oplist(NULL); for (i=0; i<nallocs; i++) { depot = &(depot_list[i % n_depots]); op = new_ibp_alloc_op(&(caps[i]), asize, depot, &attr, ibp_timeout, NULL, NULL); add_ibp_oplist(iolist, op); } io_start(iolist); err = io_waitall(iolist); if (err != IBP_OK) { printf("create_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); abort(); } free_oplist(iolist); return(caps); }
void alias_remove_allocs(ibp_capset_t *caps_list, ibp_capset_t *mcaps_list, int nallocs, int mallocs) { int i, j, err; oplist_t *iolist; ibp_op_t *op; iolist = new_ibp_oplist(NULL); for (i=0; i<nallocs; i++) { j = i % mallocs; op = new_ibp_alias_remove_op(get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP), get_ibp_cap(&(mcaps_list[j]), IBP_MANAGECAP), ibp_timeout, NULL, NULL); add_ibp_oplist(iolist, op); } io_start(iolist); err = io_waitall(iolist); if (err != IBP_OK) { printf("alias_remove_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); } free_oplist(iolist); //** Lastly free all the caps and the array for (i=0; i<nallocs; i++) { destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_READCAP)); destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_WRITECAP)); destroy_ibp_cap(get_ibp_cap(&(caps_list[i]), IBP_MANAGECAP)); } free(caps_list); return; }
ibp_capset_t *create_alias_allocs(int nallocs, ibp_capset_t *base_caps, int n_base) { int i, err; oplist_t *iolist; ibp_op_t *op; ibp_capset_t *bcap; ibp_capset_t *caps = (ibp_capset_t *)malloc(sizeof(ibp_capset_t)*nallocs); iolist = new_ibp_oplist(NULL); for (i=0; i<nallocs; i++) { bcap = &(base_caps[i % n_base]); op = new_ibp_alias_alloc_op(&(caps[i]), get_ibp_cap(bcap, IBP_MANAGECAP), 0, 0, 0, ibp_timeout, NULL, NULL); add_ibp_oplist(iolist, op); } io_start(iolist); err = io_waitall(iolist); if (err != IBP_OK) { printf("create_alias_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); } free_oplist(iolist); return(caps); }
double small_random_allocs(ibp_capset_t *caps, int n, int asize, double readfrac, int small_count, int min_size, int max_size) { int i, io_size, offset, slot, err; oplist_t *iolist; ibp_op_t *op; double rnd, lmin, lmax; double nbytes; iolist = new_ibp_oplist(NULL); lmin = log(min_size); lmax = log(max_size); if (asize < max_size) { max_size = asize; log_printf(0, "small_random_allocs: Adjusting max_size=%d\n", max_size); } char *buffer = (char *)malloc(max_size); memset(buffer, 0, max_size); nbytes = 0; for (i=0; i<small_count; i++) { rnd = rand()/(RAND_MAX+1.0); slot = n * rnd; rnd = rand()/(RAND_MAX+1.0); rnd = lmin + (lmax - lmin) * rnd; io_size = exp(rnd); if (io_size == 0) io_size = 1; nbytes = nbytes + io_size; rnd = rand()/(RAND_MAX+1.0); offset = (asize - io_size) * rnd; // log_printf(15, "small_random_allocs: slot=%d offset=%d size=%d\n", slot, offset, io_size); rnd = rand()/(RAND_MAX+1.0); if (rnd < readfrac) { op = new_ibp_read_op(get_ibp_cap(&(caps[slot]), IBP_READCAP), offset, io_size, buffer, ibp_timeout, NULL, cc); } else { op = new_ibp_write_op(get_ibp_cap(&(caps[slot]), IBP_WRITECAP), offset, io_size, buffer, ibp_timeout, NULL, cc); } add_ibp_oplist(iolist, op); } io_start(iolist); err = io_waitall(iolist); if (err != IBP_OK) { printf("small_random_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); } free_oplist(iolist); free(buffer); return(nbytes); }
void random_allocs(ibp_capset_t *caps, int n, int asize, int block_size, double rfrac) { int i, slot, err; int j, nblocks, rem, len; oplist_t *iolist; ibp_op_t *op; double rnd; char *buffer = (char *)malloc(asize); memset(buffer, 'R', asize); iolist = new_ibp_oplist(NULL); nblocks = asize / block_size; rem = asize % block_size; if (rem > 0) nblocks++; for (j=0; j<nblocks; j++) { for (i=0; i<n; i++) { rnd = rand()/(RAND_MAX+1.0); slot = n * rnd; rnd = rand()/(RAND_MAX + 1.0); if ((j==(nblocks-1)) && (rem > 0)) { len = rem; } else { len = block_size; } // op = new_ibp_read_op(get_ibp_cap(&(caps[i]), IBP_READCAP), j*block_size, len, buffer, ibp_timeout, NULL, cc); if (rnd < rfrac) { op = new_ibp_read_op(get_ibp_cap(&(caps[i]), IBP_READCAP), j*block_size, len, buffer, ibp_timeout, NULL, cc); } else { op = new_ibp_write_op(get_ibp_cap(&(caps[i]), IBP_WRITECAP), j*block_size, len, buffer, ibp_timeout, NULL, cc); } add_ibp_oplist(iolist, op); } } io_start(iolist); err = io_waitall(iolist); if (err != IBP_OK) { printf("random_allocs: At least 1 error occured! * ibp_errno=%d * nfailed=%d\n", err, oplist_nfailed(iolist)); } free_oplist(iolist); free(buffer); }
int main(void) { // INITIALIZING struct queue cmd_queue; q_init (&cmd_queue); uint8_t *mem = calloc (__MEMORY_SIZE, sizeof(uint8_t)); char *input = malloc (sizeof(char)*__INPUT_SIZE); char *cmd = malloc (sizeof(char)*__CMD_SIZE); char *filename = malloc (sizeof(char)*__FILENAME_SIZE); if (mem == NULL || input == NULL || filename == NULL || cmd == NULL) { puts("MEMORY INSUFFICIENT"); goto memory_clear; } if (!init_oplist (__OPCODE_FILENAME)) { puts("OPCODE LIST INITIALIZATION FAILED."); goto memory_clear; } // COMMAND PROCESSING while (true) { int i; struct q_elem *qe; uint8_t value; uint32_t start, end; DIR *dirp = NULL; struct dirent *dir = NULL; char check[2]; bool is_valid_cmd = false; char *tok = NULL; printf("%s", __SHELL_FORM); if (!get_chars(input, __INPUT_SIZE)) goto memory_clear; // Processing input string snprintf((char *) __CMD_FORMAT, __CMD_FORMAT_SIZE, "%%%ds", __CMD_SIZE - 1); if (sscanf(input, (const char *) __CMD_FORMAT, cmd)!=1) cmd[0] = '\0'; // Switching with commands switch(get_cmd_index(cmd)) { case CMD_HELP: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } puts(__HELP_FORM); is_valid_cmd = true; break; case CMD_DIR: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } // open directory and read through all elem. i = 1; dirp = opendir("."); dir = readdir(dirp); for(; dir!=NULL; dir = readdir(dirp)) { struct stat st; if(stat((const char*) dir->d_name, &st)!=0) { puts("FILE NOT FOUND"); goto memory_clear; } // FIX: ignore . and .. if(_SAME_STR(dir->d_name, ".") || _SAME_STR(dir->d_name, "..")) continue; printf("%20s", dir->d_name); if(S_ISDIR(st.st_mode)) // is Directory? putchar('/'); else if( (st.st_mode & S_IXUSR) // is exe? || (st.st_mode & S_IXGRP) || (st.st_mode & S_IXOTH) ) putchar('*'); putchar('\t'); // print newline after 3 elements if((i++)%3==0) putchar('\n'); } if((i-1)%3!=0) putchar('\n'); is_valid_cmd = true; break; case CMD_QUIT: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } is_valid_cmd = true; goto memory_clear; case CMD_HISTORY: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } qe = q_begin (&cmd_queue); i = 1; // print every formatted history for (; qe!=q_end(&cmd_queue); qe=q_next(qe)) printf("%-4d %s\n", i++, q_entry(qe, struct cmd_elem, elem)->cmd); printf("%-4d %s\n", i, input); is_valid_cmd = true; break; case CMD_DUMP: switch(sscanf(input, "%s %x , %x", cmd, &start, &end)) { case 1: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } start = get_location (0, false); end = start + 0x10 * 10 - 1; // if end is too large, point to end and go 0 if ( end >= __MEMORY_SIZE ) end = __MEMORY_SIZE - 1; hexdump (mem, start, end); if ( end == __MEMORY_SIZE - 1) get_location (0, true); else get_location (end + 1, true); is_valid_cmd = true; break; case 2: if(sscanf(input, "%*s %*x %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } if (start >= __MEMORY_SIZE) { puts("OUT OF MEMORY BOUNDS."); break; } end = start + 0x10 * 10 - 1; // if end is too large, point to end and go 0 if ( end >= __MEMORY_SIZE ) end = __MEMORY_SIZE - 1; hexdump (mem, start, end); if ( end == __MEMORY_SIZE - 1) get_location (0, true); else get_location (end + 1, true); is_valid_cmd = true; break; case 3: if(sscanf(input, "%*s %*x , %*x %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } if (!(start<=end && end<__MEMORY_SIZE)) { puts("OUT OF MEMORY BOUNDS."); break; } hexdump (mem, start, end); // if end is too large, point to end and go 0 if ( end == __MEMORY_SIZE - 1) get_location (0, true); else get_location (end + 1, true); is_valid_cmd = true; break; default: puts("WRONG INSTRUCTION"); break; } break; case CMD_EDIT: switch(sscanf(input, "%s %x , %hhx", cmd, &start, &value)) { case 3: if(sscanf(input, "%*s %*x , %*x %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } hexfill (mem, __MEMORY_SIZE, start, start, value); is_valid_cmd = true; break; default: puts("WRONG INSTRUCTION"); break; } break; case CMD_FILL: switch(sscanf(input, "%s %x , %x , %hhx", cmd, &start, &end, &value)) { case 4: if(sscanf(input, "%*s %*x , %*x , %*x %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } hexfill (mem, __MEMORY_SIZE, start, end, value); is_valid_cmd = true; break; default: puts("WRONG INSTRUCTION"); break; } break; case CMD_RESET: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } // equivalent to fill 0, __MEMORY_SIZE-1 hexfill (mem, __MEMORY_SIZE, 0, __MEMORY_SIZE - 1, 0); is_valid_cmd = true; break; case CMD_OPCODE: switch(sscanf(input, "%*s %s", cmd)) { case 1: if(sscanf(input, "%*s %*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } i = find_oplist (cmd); if (i != -1) printf("opcode is %02X\n", i); else { printf("%s: NO SUCH OPCODE\n", cmd); is_valid_cmd = false; } break; default: puts("WRONG INSTRUCTION"); break; } break; case CMD_OPCODELIST: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } print_oplist (); is_valid_cmd = true; break; case CMD_ASSEMBLE: // Processing input string snprintf((char *) __CMD_FORMAT, __CMD_FORMAT_SIZE, "%%%ds %%%ds %%1s", __CMD_SIZE - 1, __FILENAME_SIZE - 1); if (sscanf(input, (const char *) __CMD_FORMAT, cmd, filename, check)!=2) { puts("WRONG INSTRUCTION"); break; } if (!is_file((const char*)filename)) { puts("FILE NOT FOUND"); break; } is_valid_cmd = assemble_file (filename); break; case CMD_TYPE: // Processing input string snprintf((char *) __CMD_FORMAT, __CMD_FORMAT_SIZE, "%%%ds %%%ds %%1s", __CMD_SIZE - 1, __FILENAME_SIZE - 1); if (sscanf(input, (const char *) __CMD_FORMAT, cmd, filename, check)!=2) { puts("WRONG INSTRUCTION"); break; } if (!is_file((const char*)filename)) { puts("FILE NOT FOUND"); break; } else { print_file((const char*)filename); is_valid_cmd = true; } break; case CMD_SYMBOL: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } print_symbol_table (); is_valid_cmd = true; break; case CMD_PROGADDR: if(sscanf(input, "%*s %*x %1s", check) == 1 || sscanf(input, "%*s %x", &i) != 1) { puts("WRONG INSTRUCTION"); break; } if (i < 0 || i >= __MEMORY_SIZE - 1) { puts("INVALID PROGRAM ADDRESS"); break; } set_progaddr ((uint32_t) i); is_valid_cmd = true; break; case CMD_LOADER: init_loader (); tok = strtok (input, " "); while ( (tok = strtok (NULL, " ")) != NULL) { if (!is_file (tok)) { printf ("[%s]: INVALID FILE\n", tok); free_loader (); break; } if (!add_obj_loader (tok)) { printf ("[%s]: LOADER FAILED\n", tok); free_loader (); break; } } // if normally added if (tok == NULL) { // address __MEMORY_SIZE is reserved for boot if (get_proglen()+get_progaddr()>=__MEMORY_SIZE-1) { puts ("PROGRAM IS TOO BIG: LOADER FAILED"); free_loader (); break; } if (!run_loader (mem)) { puts ("LOADER FAILED"); free_loader (); break; } print_load_map (); } free_loader (); is_valid_cmd = true; break; case CMD_RUN: if(sscanf(input, "%*s %1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } if (!init_run ()) { puts ("RUN FAILED"); free_run (); break; } run (mem); free_run (); is_valid_cmd = true; break; case CMD_BP: if(sscanf(input, "%*s %1s", check) != 1) { print_bp (); is_valid_cmd = true; break; } if(sscanf(input, "%*s %6s %1s", cmd, check) == 2 || sscanf(input, "%*s %6s", cmd) != 1) { puts("WRONG INSTRUCTION"); break; } if (_SAME_STR(cmd, "clear")) { puts ("\t[ok] clear all breakpoints"); free_bp (); is_valid_cmd = true; break; } if(sscanf(input, "%*s %*x %1s", check) == 1 || sscanf(input, "%*s %x", &start) != 1) { puts("WRONG INSTRUCTION"); break; } if (start >= __MEMORY_SIZE - 1) { puts ("INVALID BREAKPOINT ADDRESS"); break; } if (add_bp (start)) printf ("\t[ok] create breakpoint %x\n", start); is_valid_cmd = true; break; default: if(sscanf(input, "%1s", check) == 1) { puts("WRONG INSTRUCTION"); break; } } if (is_valid_cmd) { // Saving commands struct cmd_elem *e = malloc(sizeof(struct cmd_elem)); if (e == NULL) { puts("MEMORY INSUFFICIENT."); goto memory_clear; } e->cmd = malloc(sizeof(char)*(strlen(input)+1)); if (e->cmd == NULL) { puts("MEMORY INSUFFICIENT."); goto memory_clear; } strcpy(e->cmd, input); q_insert (&cmd_queue, &(e->elem)); } } memory_clear: if (mem != NULL) free (mem); if (input != NULL) free (input); if (cmd != NULL) free (cmd); while (!q_empty(&cmd_queue)) { struct q_elem *e = q_delete(&cmd_queue); struct cmd_elem *ce = q_entry(e, struct cmd_elem, elem); if (ce->cmd != NULL) free(ce->cmd); free(ce); } free_oplist (); free_loader (); free_bp (); free_run (); return 0; }
void simple_test() { int size = 1024*1024; int block = 5000; char buffer[size+1]; char buffer_cmp[size+1]; char block_buf[block+1]; ibp_attributes_t attr; ibp_depot_t *depot; ibp_capset_t caps; ibp_cap_t *cap; int err, i, offset, bcount, remainder; ibp_op_t *op; oplist_t *iol; //** Make the allocation *** depot = &(depot_list[0]); //** Create the list for handling the commands iol = new_ibp_oplist(NULL); oplist_start_execution(iol); //** and start executing the commands //** Create the allocation used for test set_ibp_attributes(&attr, time(NULL) + a_duration, IBP_HARD, IBP_BYTEARRAY); op = new_ibp_alloc_op(&caps, size, depot, &attr, ibp_timeout, NULL, NULL); add_ibp_oplist(iol, op); err = oplist_waitall(iol); if (err != IBP_OK) { printf("simple_test: ibp_allocate error! * ibp_errno=%d\n", err); abort(); } printf("simple_test: rcap=%s\n", get_ibp_cap(&caps, IBP_READCAP)); printf("simple_test: wcap=%s\n", get_ibp_cap(&caps, IBP_WRITECAP)); printf("simple_test: mcap=%s\n", get_ibp_cap(&caps, IBP_MANAGECAP)); //** Init the buffers buffer[size] = '\0'; memset(buffer, '*', size); buffer_cmp[size] = '\0'; memset(buffer_cmp, '_', size); block_buf[block] = '\0'; memset(block_buf, '0', block); //------------------------------- //** Do the initial upload op = new_ibp_write_op(get_ibp_cap(&caps, IBP_WRITECAP), 0, size, buffer_cmp, ibp_timeout, NULL, NULL); add_ibp_oplist(iol, op); err = oplist_waitall(iol); if (err != IBP_OK) { printf("simple_test: Initial ibp_write error! * ibp_errno=%d\n", err); abort(); } bcount = size / (2*block); remainder = size - bcount * (2*block); //** Now do the striping ** offset = 0; // Now store the data in chunks cap = get_ibp_cap(&caps, IBP_WRITECAP); for (i=0; i<bcount; i++) { op = new_ibp_write_op(cap, offset, block, block_buf, ibp_timeout, NULL, NULL); add_ibp_oplist(iol, op); memset(&(buffer_cmp[offset]), '0', block); offset = offset + 2*block; } if (remainder>0) { if (remainder > block) remainder = block; op = new_ibp_write_op(cap, offset, remainder, block_buf, ibp_timeout, NULL, NULL); add_ibp_oplist(iol, op); memset(&(buffer_cmp[offset]), '0', remainder); } //** Now wait for them to complete err = oplist_waitall(iol); if (err != IBP_OK) { printf("simple_test: Error in stripe write! * ibp_errno=%d\n", err); abort(); } //------------------------------- bcount = size / block; remainder = size - bcount * block; //** Generate the Read list offset = 0; // Now store the data in chunks cap = get_ibp_cap(&caps, IBP_READCAP); for (i=0; i<bcount; i++) { op = new_ibp_read_op(cap, offset, block, &(buffer[offset]), ibp_timeout, NULL, NULL); add_ibp_oplist(iol, op); offset = offset + block; } if (remainder>0) { op = new_ibp_read_op(cap, offset, remainder, &(buffer[offset]), ibp_timeout, NULL, NULL); add_ibp_oplist(iol, op); } //** Now wait for them to complete err = oplist_waitall(iol); if (err != IBP_OK) { printf("simple_test: Error in stripe read! * ibp_errno=%d\n", err); abort(); } //------------------------------- //** Do the comparison ** i = strcmp(buffer, buffer_cmp); if (i == 0) { printf("simple_test: Success!\n"); } else { printf("simple_test: Failed! strcmp = %d\n", i); } // printf("simple_test: buffer_cmp=%s\n", buffer_cmp); // printf("simple_test: buffer=%s\n", buffer); //------------------------------- //** Remove the allocation ** op = new_ibp_remove_op(get_ibp_cap(&caps, IBP_MANAGECAP), ibp_timeout, NULL, NULL); add_ibp_oplist(iol, op); err = oplist_waitall(iol); if (err != IBP_OK) { printf("simple_test: Error removing the allocation! ibp_errno=%d\n", err); abort(); } free_oplist(iol); }