/* * Output time array into a CSV file. It takes in a number of arrays with information received when experiments were executed. * type: 1 - filtered, 2 - unfiltered. */ void write_to_csv(unsigned long long *time, unsigned long long *timeMin, int type, int testArg, int testId, int experimentsRun, unsigned long long interrupts[][TIMES_RUN_SUB_EXPERIMENT], unsigned long long pageFaultsMinor[][TIMES_RUN_SUB_EXPERIMENT], unsigned long long pageFaultsMajor[][TIMES_RUN_SUB_EXPERIMENT], unsigned long long contextSwitches[][TIMES_RUN_SUB_EXPERIMENT]) { FILE *fp; // Pointer to a file char fileName[100]; // Address of the file (name) /* * Open the filestream. */ if (type == 1) { // Create file name for a new csv file snprintf(fileName, 100, "%s-%d-%d.csv", CSV_FILE_CLEAN, testArg, testId); fp = fopen(fileName, "wb+"); // Open the file } else { // Create file name for a new csv file snprintf(fileName, 100, "%s-%d-%d.csv", CSV_FILE_DIRTY, testArg, testId); fp = fopen(fileName, "wb+"); // Open the file } // If the file does not exist, create it if (fp == NULL) { printf("Error creating file.\n"); } /* * Write data into the file */ // Write headers fprintf(fp, "N,Time,TimMin"); // Header int j = 0; for (j = 0; j < TIMES_RUN_SUB_EXPERIMENT; ++j) { // For each sub-experiment. fprintf(fp, ",%d.INT,%d.PFMIN,%d.PFMAJ", j + 1, j + 1, j + 1); } // Write timing information int i = 0; long n = 1; for (i = 0; i < experimentsRun; ++i) { // For each processed experiment. fprintf(fp, "\n%lu,%llu,%llu", n * sizeof(long), time[i], timeMin[i]); int j = 0; for (j = 0; j < TIMES_RUN_SUB_EXPERIMENT; ++j) { // For each sub-experiment. fprintf(fp, ",%llu,%llu,%llu", interrupts[i][j], pageFaultsMinor[i][j], pageFaultsMajor[i][j]); } n = calculate_n(n); // Calculate the next amount of data exchanged. } // Close filestream if (fp) { fclose(fp); } #ifdef DEBUG printf("Finished writing to file %d.\n", type); #endif }
/******************************************************************************* Set Saturation */ Error_t TapeSetSaturation(Tape* tape, float saturation) { if (tape) { float n = calculate_n(saturation, tape->speed); tape->saturation = saturation; return PolySaturatorSetN(tape->polysat, n); } else { return NULL_PTR_ERROR; } }
/******************************************************************************* Set Speed */ Error_t TapeSetSpeed(Tape* tape, TapeSpeed speed) { if (tape) { // Set speed tape->speed = speed; // Update saturation curve PolySaturatorSetN(tape->polysat, calculate_n(tape->saturation, speed)); // Clear old flutter/wow modulation waveform ClearBuffer(tape->flutter_mod, tape->flutter_mod_length); // Yes, clear the old length... // Calculate new modulation waveform length... tape->flutter_mod_length = (unsigned)(tape->sample_rate / \ (0.80 * powf(2.0, (float)speed))); // Generate flutter/wow modulation waveform float temp_buffer[tape->flutter_mod_length]; for (unsigned comp = 0; comp < N_FLUTTER_COMPONENTS; ++comp) { float phase_step = (2.0 * M_PI * comp * powf(2.0, (float)speed)) / tape->sample_rate; ClearBuffer(temp_buffer, tape->flutter_mod_length); for (unsigned i = 0; i < tape->flutter_mod_length; ++i) { temp_buffer[i] = sinf(i * phase_step) / N_FLUTTER_COMPONENTS; } VectorVectorAdd(tape->flutter_mod, tape->flutter_mod, temp_buffer, tape->flutter_mod_length); } return NOERR;; } else { return NULL_PTR_ERROR; } }