int main(int argn, char *argv[]) { unsigned int i, ret, readers, writers, tot_count_read = 0; timer exec_time; if(argn < 7) { fprintf(stderr, "Usage: %s: n_writer n_reader end_write end_read busy_write busy_read size\n", argv[0]); exit(EXIT_FAILURE); } writers = atoi(argv[1]); readers = atoi(argv[2]); size = atoi(argv[3]); if(argn == 7){ busy_write = atoi(argv[4]); busy_read = atoi(argv[5]); duration = atoi(argv[6]); } else if (argn == 8){ busy_write = atoi(argv[4]); busy_read = atoi(argv[5]); end_write = atoi(argv[6]); end_read = atoi(argv[7]); } pthread_t p_tid[writers + readers]; reg = reg_init(writers, readers, size); //reg = reg_init(writers, readers, DIM*sizeof(unsigned long long)); if((count_read = calloc(readers, sizeof(unsigned int))) == NULL){ printf("malloc failed\n"); abort(); } for(i = 0; i < writers; i++) { if( (ret = pthread_create(&p_tid[i], NULL, run_write, NULL)) != 0) { fprintf(stderr, "%s\n", strerror(errno)); abort(); } } for(i = 0; i < readers; i++) { if( (ret = pthread_create(&p_tid[writers+i], NULL, run_read, NULL)) != 0) { fprintf(stderr, "%s\n", strerror(errno)); abort(); } } sleep(1); printf("\n\n+-----------------------------------------------------------------------------------+\n"); printf("START TEST on REGISTER(%u,%u) of size %u: +\n", writers, readers, size); printf("\t write operation: %u, %u: +\n", end_write, busy_write); printf("\t read operation: %u, %u: +\n", end_read, busy_read); printf("+-----------------------------------------------------------------------------------+\n\n\n"); timer_start(exec_time); start = true; if(duration > 0){ sleep(duration); end = true; } for(i = 0; i < writers + readers; i++){ pthread_join(p_tid[i], NULL); } printf("\n\n+-----------------------------------------------------------------------------------+\n"); printf("TEST ENDED: %.5f seconds\n", (double)timer_value_seconds(exec_time)); printf("TOTAL WRTE: %u\n", count_write); for(i = 0; i < readers; i++) tot_count_read +=count_read[i]; printf("TOTAL READ: %u\n", tot_count_read); printf("TOTAL OPER: %u\n", tot_count_read+count_write); printf("+-----------------------------------------------------------------------------------+\n\n\n"); reg_free(reg); }
void serial_simulation(void) { timer serial_event_execution; timer serial_gvt_timer; msg_t *event; unsigned int completed = 0; #ifdef EXTRA_CHECKS unsigned long long hash1, hash2; hash1 = hash2 = 0; #endif timer_start(serial_gvt_timer); statistics_post_other_data(STAT_SIM_START, 0.0); while(!serial_simulation_complete) { event = (msg_t *)calqueue_get(); if(event == NULL) { rootsim_error(true, "No events to process!\n"); } #ifdef EXTRA_CHECKS if(event->size > 0) { hash1 = XXH64(event->event_content, event->size, current_lp); } #endif current_lp = event->receiver; current_lvt = event->timestamp; timer_start(serial_event_execution); ProcessEvent_light(current_lp, current_lvt, event->type, event->event_content, event->size, serial_states[current_lp]); statistics_post_lp_data(current_lp, STAT_EVENT, 1.0); statistics_post_lp_data(current_lp, STAT_EVENT_TIME, timer_value_seconds(serial_event_execution) ); #ifdef EXTRA_CHECKS if(event->size > 0) { hash2 = XXH64(event->event_content, event->size, current_lp); } if(hash1 != hash2) { printf("hash1 = %llu, hash2= %llu\n", hash1, hash2); rootsim_error(true, "Error, LP %d has modified the payload of event %d during its processing. Aborting...\n", current_lp, event->type); } #endif current_lp = IDLE_PROCESS; // Termination detection can happen only after the state is initialized if(serial_states[event->receiver] != NULL) { // Should we terminate the simulation? if(!serial_completed_simulation[event->receiver] && OnGVT_light(event->receiver, serial_states[event->receiver])) { completed++; serial_completed_simulation[event->receiver] = true; if(completed == n_prc_tot) { serial_simulation_complete = true; } } } // Termination detection on reached LVT value if(rootsim_config.simulation_time > 0 && event->timestamp >= rootsim_config.simulation_time) { serial_simulation_complete = true; } // Simulate the execution of GVT protocol if (timer_value_milli(serial_gvt_timer) > (int)rootsim_config.gvt_time_period) { timer_restart(serial_gvt_timer); printf("TIME BARRIER: %f\n", current_lvt); statistics_post_other_data(STAT_GVT, 0.0); statistics_post_other_data(STAT_GVT_TIME, current_lvt); } rsfree(event); } simulation_shutdown(EXIT_SUCCESS); }