void file_save (windata_t *vwin, int ci) { switch (ci) { case SAVE_OUTPUT: case SAVE_CONSOLE: case SAVE_SCRIPT: case SAVE_GP_CMDS: case SAVE_R_CMDS: case SAVE_DATA: case SAVE_DATA_AS: file_selector(ci, FSEL_DATA_VWIN, vwin); break; case EXPORT_CSV: case EXPORT: data_export_selection_wrapper(ci); break; case SAVE_FUNCTIONS: functions_selection_wrapper(); break; case SAVE_TEX: case SAVE_TEXT: file_selector(ci, FSEL_DATA_MISC, vwin->data); break; default: dummy_call(); } }
/* * Name read_random * Description Read all the files in a random order. * - The files to be read must be opened and placed in share_it.fd_list * We choose the files in a random order, so that the effects of * prefetching are minimized. * - Reads the number of files FILE_COUNT with random access by reading a block * of BLOCK_SIZE in each read operation. * - Random access offset is determined by share_it.index. * - Read block sizes are determined by share_it.block_size. * - Defaults are same as read_sequential. * - Measures only read. Overhead is only the overhead of measuring time * itself. * Input struct share_it * Output Boolean to indicate if all reads succeed. */ bool read_random(struct share_it* my_state) { size_t size = my_state->size; timestamp start = 0; timestamp end = 0; int bytes = 0; int i = 0; for (i = 0; i < my_state->count; i++) { size_t size = my_state->size; int fd = my_state->fd_list[i]; int j = 0; while ((size > 0)) { if (lseek(fd, my_state->offsets[j] * BLOCK_SIZE, SEEK_SET) == -1) { int err = errno; printf("Seek to start of file failed with errno %d\n", err); exit(1); } RDTSCP(start); bytes = read(fd, my_state->buf, my_state->block_size); RDTSCP(end); if (bytes <= 0 || bytes != my_state->block_size) return false; dummy_call(my_state->buf); *(my_state->total_bytes) += bytes; my_state->duration += (end - start); size -= bytes; j++; } } return true; }
/* * Name read_sequential * Description Read all the files in a sequential way. * - The files to be read must be opened and placed in share_it.fd_list * We choose the files in a random order, so that the effects of * prefetching are minimized. * - Reads the number of files FILE_COUNT sequentially by reading a block * of BLOCK_SIZE in each read operation. * - Small files are 64 bytes - 32 kB. * - Big files are 32 kb onwards. * - For small files, I have meassured with block size as 64 bytes * For big files, I have measured with block size as 32 kB * - This routine is also used to measure the time to read a full file by * share_it.block_size to same as file size. * - Measures only read. Overhead is only the overhead of measuring time * itself. * Input struct share_it * Output Boolean to indicate if all reads succeed. */ bool read_sequential(struct share_it* my_state) { size_t size = my_state->size; timestamp start = 0; timestamp end = 0; int bytes = 0; int i = 0; for (i = 0; i < my_state->count; i++) { size_t size = my_state->size; int fd = my_state->fd_list[i]; if (lseek(fd, 0, SEEK_SET) == -1) { int err = errno; printf("Seek to start of file failed with errno %d\n", err); exit(1); } while ((size > 0)) { RDTSCP(start); bytes = read(fd, my_state->buf, my_state->block_size); RDTSCP(end); if (bytes <= 0 || bytes != my_state->block_size) { int err = errno; printf("Read failed with err=%d and bytes =%d while block_size=%zu\n", errno, bytes, my_state->block_size); return false; } dummy_call(my_state->buf); *(my_state->total_bytes) += bytes; my_state->duration += (end - start); size -= bytes; } } return true; }
/* * Name open_read_close * Description This metric is only applicable for small files. * - Measures the time taken to open a small file, read all of the file and * close the file. * - Files to be opened/read/closed are chosen in random ( lessen prefetching * effects.) * - Overhead : one if-loop + overhead of measuring time. * Input struct share_it * Input filepath - to pick files from. * Output Boolean to indicate if all reads succeed. */ bool open_read_close(struct share_it* my_state, char *filepath) { timestamp start = 0; timestamp end = 0; int bytes = 0; struct drand48_data randBuffer; srand48_r(time(NULL), &randBuffer); int i = 0; long int random = 0; int idx = 0; for (i = 0; i < my_state->count; i++) { lrand48_r(&randBuffer, &random); idx = random % MAX_FILES + 1; char num[5]; sprintf(num, "%d", idx); char my_file[100] = {'\0'}; strcat(my_file, filepath); strcat(my_file, "/file"); strcat(my_file, num); RDTSCP(start); int fd = open(my_file, FLAGS); if (fd == -1) { int err = errno; printf("Could not open file descriptor for file %s. Error = %d\n", my_file, err); return false; } bytes = read(fd, my_state->buf, my_state->block_size); close(fd); RDTSCP(end); if (bytes <= 0 || bytes != my_state->block_size) return false; dummy_call(my_state->buf); *(my_state->total_bytes) += bytes; my_state->duration += (end - start); } return true; }
/* * Name write_random * Description Write all the files in a random order. * - The files to be written must be opened and placed in share_it.fd_list * We choose the files in a random order, so that the effects of * prefetching are minimized. * - Writes the number of files FILE_COUNT with random access by reading a block * of BLOCK_SIZE in each write operation. * - Random access offset is determined by share_it.index. * - Write block sizes are determined by share_it.block_size. * - Defaults are same as write_sequential. * - Measures only write. Overhead is only the overhead of measuring time * itself. * Input struct share_it * Output Boolean to indicate if all writes succeed. */ bool write_random(struct share_it* my_state) { size_t size = my_state->size; timestamp start = 0; timestamp end = 0; int bytes = 0; int rand_bytes = 0; int i = 0; for (i = 0; i < my_state->count; i++) { size_t size = my_state->size; int fd = my_state->fd_list[i]; int j = 0; while ((size > 0)) { // fill buf with random data /* rand_bytes = syscall(SYS_getrandom, my_state->buf, my_state->block_size, 0); if (rand_bytes == -1 || rand_bytes != my_state->block_size) { int err = errno; printf("Could not get random data, failed with err=%d and bytes =%d while block_size=%zu\n", errno, bytes, my_state->block_size); return false; } */ if (lseek(fd, my_state->offsets[j] * BLOCK_SIZE, SEEK_SET) == -1) { int err = errno; printf("Seek to start of file failed with errno %d\n", err); exit(1); } RDTSCP(start); bytes = write(fd, my_state->buf, my_state->block_size); RDTSCP(end); if (bytes <= 0 || bytes != my_state->block_size) return false; dummy_call(my_state->buf); *(my_state->total_bytes) += bytes; my_state->duration += (end - start); size -= bytes; j++; } } return true; }
int main (int argc, char *argv[]) { int i = 0; CRITICAL_SECTION cs; old_mutex_t ox; pthread_mutexattr_init(&ma); printf( "=============================================================================\n"); printf( "\nLock plus unlock on an unlocked mutex.\n%ld iterations\n\n", ITERATIONS); printf( "%-45s %15s %15s\n", "Test", "Total(msec)", "average(usec)"); printf( "-----------------------------------------------------------------------------\n"); /* * Time the loop overhead so we can subtract it from the actual test times. */ TESTSTART assert(1 == one); assert(1 == one); TESTSTOP durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; overHeadMilliSecs = durationMilliSecs; TESTSTART assert((dummy_call(&i), 1) == one); assert((dummy_call(&i), 1) == one); TESTSTOP durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; printf( "%-45s %15ld %15.3f\n", "Dummy call x 2", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); TESTSTART assert((interlocked_inc_with_conditionals(&i), 1) == one); assert((interlocked_dec_with_conditionals(&i), 1) == one); TESTSTOP durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; printf( "%-45s %15ld %15.3f\n", "Dummy call -> Interlocked with cond x 2", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); TESTSTART assert((InterlockedIncrement(&i), 1) == one); assert((InterlockedDecrement(&i), 1) == one); TESTSTOP durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; printf( "%-45s %15ld %15.3f\n", "InterlockedOp x 2", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); InitializeCriticalSection(&cs); TESTSTART assert((EnterCriticalSection(&cs), 1) == one); assert((LeaveCriticalSection(&cs), 1) == one); TESTSTOP DeleteCriticalSection(&cs); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; printf( "%-45s %15ld %15.3f\n", "Simple Critical Section", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); old_mutex_use = OLD_WIN32CS; assert(old_mutex_init(&ox, NULL) == 0); TESTSTART assert(old_mutex_lock(&ox) == zero); assert(old_mutex_unlock(&ox) == zero); TESTSTOP assert(old_mutex_destroy(&ox) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; printf( "%-45s %15ld %15.3f\n", "Old PT Mutex using a Critical Section (WNT)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); old_mutex_use = OLD_WIN32MUTEX; assert(old_mutex_init(&ox, NULL) == 0); TESTSTART assert(old_mutex_lock(&ox) == zero); assert(old_mutex_unlock(&ox) == zero); TESTSTOP assert(old_mutex_destroy(&ox) == 0); durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; printf( "%-45s %15ld %15.3f\n", "Old PT Mutex using a Win32 Mutex (W9x)", durationMilliSecs, (float) durationMilliSecs * 1E3 / ITERATIONS); printf( ".............................................................................\n"); /* * Now we can start the actual tests */ #ifdef PTW32_MUTEX_TYPES runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT); runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL); runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK); runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE); #else runTest("Non-blocking lock", 0); #endif printf( "=============================================================================\n"); /* * End of tests. */ pthread_mutexattr_destroy(&ma); return 0; }
//#include<stdio.h> int fork() { int a = __syscall0(SYS_FORK); //printf("DEBUG: fork(): returning value: %d %d\n",a,ret); dummy_call(a); return a; }
int execvpe(const char *file, char *argv[], char * envp[]) { //printf("EXECVPE: Passing arguments: %p %p %p\n",file,argv,envp); uint64_t a = __syscall3(SYS_EXECVPE,(uint64_t)file,(uint64_t)argv,(uint64_t)envp); dummy_call(a); return (int)a; }