void EscenarioFile::find_file_sections() { sesmic_position = find_line_starting_in(0, " seismic:", true); sesmicv_position = find_line_starting_in(sesmic_position, " seismicv:", true); material_types_position = find_line_starting_in(sesmic_position, "material types:", true); material_types_end = find_empty_line(material_types_position); strength_functions_start = find_line_starting_in(material_types_end, "strength functions:", true); strength_functions_end = find_empty_line(strength_functions_start); material_names_start = find_line_starting_in(strength_functions_end, "material properties:", true); }
void cache_write_miss(Cache *cache, int pc, int addr, cache_set *cur_set) { cache->cache_misses +=1; cache->memory_reads +=1; size_t empty = find_empty_line(cur_set); if (empty < cur_set->capacity) { cur_set->lines[empty].valid = 1; cur_set->lines[empty].lru_counter = pc; cur_set->lines[empty].tag = extract_tag(cache, addr); cur_set->lines[empty].dirty = 1; } else { size_t evict = find_lowest_lru_line(cur_set); if (cache->write_policy == WRITEBACK) { if (cur_set->lines[evict].dirty == 1) { cache->memory_writes+=1; } cur_set->lines[evict].lru_counter = pc; cur_set->lines[evict].tag = extract_tag(cache, addr); cur_set->lines[evict].dirty = 1; } else { cache->memory_writes+=1; cur_set->lines[evict].lru_counter = pc; cur_set->lines[evict].tag = extract_tag(cache, addr); } } }
int skip_response_header(char *buf, int maxlen) { int pos; if (strncmp(buf, "HTTP/1.1 200 OK", 15)) return -10; pos = find_empty_line(buf, maxlen, 15); if (pos < 0) return pos; if (!strncmp(buf+pos, "<?xml ", 6)) { while (pos<maxlen && buf[pos]!='>') pos++; } pos++; while (pos<maxlen && (buf[pos] == ' ' || buf[pos] == '\r' || buf[pos] == '\n')) pos++; return pos; }
void NgrepLogParser::parse(NgrepLogParser::Handler& handler) { // skip header from ngrep if(!find_empty_line()) return; if(!next()) return; // main parsing while(!_line.empty()) { if(is_context_line()) { if(!parse_context()) break; if(!next()) break; } do { if(!parse_packet()) break; if(!next()) break; if(!_line.empty()) end_of_packet(handler); }while(!_line.empty()); if(!next()) break; if(_line.empty()) { if(!next()) { break; } if(!_line.empty()) end_of_packet(handler); } } if(_input.eof()) { end_of_packet(handler); } }
/* * simulated_cache - simulate the cache based on the given parameters from command line */ cache_output_param simulated_cache(cache* sim_cache, cache_built_param params, cache_output_param output, unsigned long long int address) { int line_index; int replace_line_index = -1; // flag - represent the line in the set to be replaced int last_hits = output.hits; // number of hits in last trace used to determine whether it's hit or miss in this trace // get the params of the cache int lines_num = params.E; long long int tag_size = 64 - (params.b) - (params.s); // get the tags and set index in input address unsigned long long int input_tag = address >> (params.b + params.s); unsigned long long int input_setIndex = address << (tag_size) >> (tag_size + params.b); // find the set in the cache to be accessed cache_set target_set = sim_cache -> sets[input_setIndex]; cache_line line; /* * implement the cache policies */ for (line_index = 0; line_index < lines_num; line_index++) { line = target_set.lines[line_index]; /* * if the line is valid, go on check the line tag * otherwise, the line is empty, just fetch a new line in this line */ if (line.valid) { /* * if the line's flag is equal to the input flag, it's a hit. Add the line index into the set's accessed queue * otherwise, it's a miss. Fetch a new line to replace a possible empty line */ if (line.tag == input_tag) { output.hits++; printf("Got a hit. Hit %d.\n", output.hits); update_queue(sim_cache, input_setIndex, line_index); } } } /* * if this trace is a miss and there is a empty line, fetch a new line and put into the empty line * if this trace is a miss and there is no empty line, fetch a new line and put into the LRU line, it's a miss + evict */ if (last_hits == output.hits) { output.misses++; printf("Got a miss. Misses %d.\n", output.misses); replace_line_index = find_empty_line(sim_cache, input_setIndex, lines_num); if(replace_line_index != -1) { sim_cache -> sets[input_setIndex].lines[replace_line_index].valid = 1; sim_cache -> sets[input_setIndex].lines[replace_line_index].tag = input_tag; sim_cache -> sets[input_setIndex].used_line_queue.rear++; sim_cache -> sets[input_setIndex].used_line_queue.indexes[sim_cache -> sets[input_setIndex].used_line_queue.rear] = replace_line_index; } else { replace_line_index = find_evict_line(sim_cache, input_setIndex, lines_num); sim_cache -> sets[input_setIndex].lines[replace_line_index].tag = input_tag; output.evicts++; sim_cache -> sets[input_setIndex].used_line_queue.rear++; sim_cache -> sets[input_setIndex].used_line_queue.indexes[sim_cache -> sets[input_setIndex].used_line_queue.rear] = replace_line_index; printf("Got a evict. Evicts %d.\n", output.evicts); } } return output; }
/* Find the end of request marker */ static char * find_eor() { return find_empty_line(policy_request, policy_request + policy_request_fill); }