void actualizarTLB(int nroPagina, int pid, int nroFrame){ pthread_mutex_lock(&tlb_semaphore); if(tlbTieneEntradasLibres()){ llenarTLB(nroPagina, pid, nroFrame); pthread_mutex_unlock(&tlb_semaphore); return; } pthread_mutex_unlock(&tlb_semaphore); //A partir de aca, es necesario hacer reemplazo de pagina int i = 0; tlb_entry* actual = list_get(TLB->entradas, i); tlb_entry* leastRecentlyUsed = actual; //victima for(i=1; i< TLB->size; i++){ actual = list_get(TLB->entradas, i); if(esFechaAnterior(actual->last_use, leastRecentlyUsed->last_use)){ leastRecentlyUsed = actual; } } log_warning(logger, "[TLB] Reemplazo: pid=%d, page=%d, frame=%d, ref=%s", leastRecentlyUsed->pid, leastRecentlyUsed->nroPagina, leastRecentlyUsed->nroFrame, leastRecentlyUsed->last_use); leastRecentlyUsed->nroFrame = nroFrame; leastRecentlyUsed->nroPagina = nroPagina; leastRecentlyUsed->pid = pid; leastRecentlyUsed->last_use = temporal_get_string_time(); log_warning(logger, "[TLB] Se agrega: pid=%d, page=%d, frame=%d, ref=%s", leastRecentlyUsed->pid, leastRecentlyUsed->nroPagina, leastRecentlyUsed->nroFrame, leastRecentlyUsed->last_use); }
static void log_write_in_level(t_log* logger, t_log_level level, const char* message_template, va_list arguments) { if (isEnableLevelInLogger(logger, level)) { char *message, *time, *buffer; unsigned int thread_id; message = malloc(LOG_MAX_LENGTH_MESSAGE + 1); vsprintf(message, message_template, arguments); time = temporal_get_string_time(); thread_id = pthread_self(); buffer = malloc(LOG_MAX_LENGTH_BUFFER + 1); sprintf(buffer, "[%s] %s %s/(%d:%d): %s\n", log_level_as_string(logger->detail), time, logger->program_name, logger->pid, thread_id, message); if (logger->file != NULL) { fprintf(logger->file, "%s", buffer); fflush(logger->file); } if (logger->is_active_console) { printf("%s", buffer); fflush(stdout); } free(time); free(message); free(buffer); } }
static void _log_write_in_level(t_log* logger, t_log_level level, const char* message_template, va_list list_arguments) { if (_isEnableLevelInLogger(logger, level)) { char *message, *time, *buffer; unsigned int thread_id; message = string_from_vformat(message_template, list_arguments); time = temporal_get_string_time(); thread_id = process_get_thread_id(); buffer = string_from_format("[%s] %s %s/(%d:%d): %s\n", log_level_as_string(level), time, logger->program_name, logger->pid, thread_id, message); if (logger->file != NULL) { txt_write_in_file(logger->file, buffer); } if (logger->is_active_console) { txt_write_in_stdout(buffer); } free(time); free(message); free(buffer); } }
//En este caso, la TLB tiene una o mas entradas libres void llenarTLB(int nroPagina, int pid, int nroFrame){ tlb_entry* entry = malloc(sizeof(tlb_entry)); entry->pid = pid; entry->nroPagina = nroPagina; entry->nroFrame = nroFrame; entry->last_use = temporal_get_string_time(); list_add(TLB->entradas, entry); log_trace(logger, "[TLB] Entrada agregada: pid=%d, page=%d, frame=%d, ref=%s", pid, nroPagina, nroFrame, entry->last_use); }
int32_t obtengoSegundos() { char* tiempo= temporal_get_string_time(); char* segundos=malloc(3); segundos[0]=tiempo[6]; segundos[1]=tiempo[7]; segundos[2]='\0'; int32_t valor=atoi(segundos); free(tiempo); free(segundos); return valor; }
int buscarEnTLB(int nroPagina, int pid){ int i; tlb_entry* actual; for(i=0; i< TLB->entradas->elements_count; i++){ actual = list_get(TLB->entradas, i); if(actual->pid == pid && actual->nroPagina == nroPagina){ actual->last_use = temporal_get_string_time(); log_trace(logger, "[TLB] Hit: pid=%d, page=%d, frame=%d, ref=%s", pid, nroPagina, actual->nroFrame, actual->last_use); return actual->nroFrame; } } log_trace(logger, "[TLB] Miss: pid=%d, page=%d", pid, nroPagina); return -1; }