static void setup(void) { tst_require_root(NULL); tst_tmpdir(); TEST_PAUSE; has_file(drop_caches_fname, 1); has_file(meminfo_fname, 1); /* check if readahead is supported */ ltp_syscall(__NR_readahead, 0, 0, 0); pagesize = getpagesize(); create_testfile(); }
static void setup(void) { if (opt_fsizestr) testfile_size = SAFE_STRTOL(opt_fsizestr, 1, INT_MAX); if (access(PROC_IO_FNAME, F_OK)) tst_brk(TCONF, "Requires " PROC_IO_FNAME); has_file(DROP_CACHES_FNAME, 1); has_file(MEMINFO_FNAME, 1); /* check if readahead is supported */ tst_syscall(__NR_readahead, 0, 0, 0); pagesize = getpagesize(); setup_readahead_length(); tst_res(TINFO, "readahead length: %d", readahead_length); setup_overlay(); }
int path_to_inode(char *orig_path) { char *cur; struct inode_block *cur_inode_block = NULL; struct inode *cur_inode = NULL; char *path; path = malloc(sizeof(char)*strlen(orig_path)); strcpy(path, orig_path); pwd = 0; //start at root //printf("path = %s\n"); //if(strcmp(path, "/") == 0) //return 0; for(cur = strtok(path, "/"); cur != NULL; cur = strtok(NULL, "/")) { int prev_wd = pwd; DEBUG1 && printf("%s \n",cur); if(get_inode(&cur_inode_block, &cur_inode, pwd)) { DEBUG2 && printf("ERROR: couldn't get free inode \n "); return -1; } pwd = has_file(cur_inode, cur); DEBUG1 && printf("pwd = %d\n", pwd); if(pwd == -1) { DEBUG2 && printf("not found or not valid inode\n"); //pwd = prev_wd; pwd = -1; break; } if(pwd == -2) { DEBUG1 && printf("not a dir\n"); //pwd = prev_wd; pwd = -1; break; } } free(path); return pwd; }
int vshDetectDiscType(const char *path) { int result, ret; u32 k1; result = -1; k1 = pspSdkSetK1(0); ret = isoOpen(path); if (ret < 0) { pspSdkSetK1(k1); return result; } result = 0; if(has_file("/PSP_GAME/SYSDIR/EBOOT.BIN")) { result |= PSP_UMD_TYPE_GAME; } if(has_file("/UMD_VIDEO/PLAYLIST.UMD")) { result |= PSP_UMD_TYPE_VIDEO; } if(has_file("/UMD_AUDIO/PLAYLIST.UMD")) { result |= PSP_UMD_TYPE_AUDIO; } if(result == 0) { result = -2; } isoClose(); pspSdkSetK1(k1); return result; }
static void test_readahead(void) { unsigned long read_bytes, read_bytes_ra; long usec, usec_ra; unsigned long cached_max, cached_low, cached, cached_ra; char proc_io_fname[128]; sprintf(proc_io_fname, "/proc/%u/io", getpid()); /* find out how much can cache hold if we read whole file */ read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); cached_max = get_cached_size(); sync(); drop_caches(); cached_low = get_cached_size(); cached_max = cached_max - cached_low; tst_resm(TINFO, "read_testfile(0)"); read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); cached = cached - cached_low; sync(); drop_caches(); cached_low = get_cached_size(); tst_resm(TINFO, "read_testfile(1)"); read_testfile(1, testfile, testfile_size, &read_bytes_ra, &usec_ra, &cached_ra); cached_ra = cached_ra - cached_low; tst_resm(TINFO, "read_testfile(0) took: %ld usec", usec); tst_resm(TINFO, "read_testfile(1) took: %ld usec", usec_ra); if (has_file(proc_io_fname, 0)) { tst_resm(TINFO, "read_testfile(0) read: %ld bytes", read_bytes); tst_resm(TINFO, "read_testfile(1) read: %ld bytes", read_bytes_ra); /* actual number of read bytes depends on total RAM */ if (read_bytes_ra < read_bytes) tst_resm(TPASS, "readahead saved some I/O"); else tst_resm(TFAIL, "readahead failed to save any I/O"); } else { tst_resm(TCONF, "Your system doesn't have /proc/pid/io," " unable to determine read bytes during test"); } tst_resm(TINFO, "cache can hold at least: %ld kB", cached_max); tst_resm(TINFO, "read_testfile(0) used cache: %ld kB", cached); tst_resm(TINFO, "read_testfile(1) used cache: %ld kB", cached_ra); if (cached_max * 1024 >= testfile_size) { /* * if cache can hold ~testfile_size then cache increase * for readahead should be at least testfile_size/2 */ if (cached_ra * 1024 > testfile_size / 2) tst_resm(TPASS, "using cache as expected"); else tst_resm(TWARN, "using less cache than expected"); } else { tst_resm(TCONF, "Page cache on your system is too small " "to hold whole testfile."); } }
int create_file(char *path, int is_dir) { char *lpath = malloc(sizeof(char)*strlen(path)+1); char *last; char *ptr; int wd, free_inode_num, found, s; struct inode_block *cur_inode_block = NULL; struct inode *cur_inode = NULL; strcpy(lpath, path); if(strlen(lpath) == 1) { if(lpath[0] == '/') { return ERR_FILE_EXISTS; } else { return ERR_INVALID_PATH; } } ptr = strrchr(lpath, '/'); if(ptr == lpath+strlen(lpath)-1) { *ptr = '\0'; ptr = strrchr(lpath, '/'); } *ptr = '\0'; ptr++; last = malloc(sizeof(char)*strlen(ptr)+1); strcpy(last, ptr); wd = path_to_inode(lpath); DEBUG1 && printf("wd = %d \n", wd); if(wd < 0) { return ERR_INVALID_PATH; } //printf("wd inode = %d \n", wd); get_inode(&cur_inode_block, &cur_inode, wd); if(cur_inode_block == NULL || cur_inode == NULL) { DEBUG2 && printf("get inode failed\n"); return ERR_INTERNAL; } found = has_file(cur_inode, last); //printf("found = %d \n", found); DEBUG1 && printf("found = %d \n", found); if(found != -1) { //printf("file or dir already exists!\n"); //printf("wd = %d, last = %s \n ", wd, last); return ERR_FILE_EXISTS; } free_inode_num = get_free_inode(); //printf("free inode num = %d\n", free_inode_num); if(free_inode_num < 0) { return ERR_MAX_FILES; } get_inode( &cur_inode_block, &cur_inode , free_inode_num); if(cur_inode_block == NULL || cur_inode == NULL) { return ERR_INTERNAL; } cur_inode->is_dir = is_dir; put_inode_block(cur_inode_block, free_inode_num); //free_data_block_num = get_free_datablock(); //printf("free_data_block_num = %d\n", free_data_block_num); s = add_dir_to_inode(wd, last, free_inode_num); return s; }
static void test_readahead(unsigned int n) { unsigned long read_bytes, read_bytes_ra; long long usec, usec_ra; unsigned long cached_high, cached_low, cached, cached_ra; int ret; struct tcase *tc = &tcases[n]; tst_res(TINFO, "Test #%d: %s", n, tc->tname); if (tc->use_overlay && !ovl_mounted) { tst_res(TCONF, "overlayfs is not configured in this kernel."); return; } create_testfile(tc->use_overlay); /* find out how much can cache hold if we read whole file */ read_testfile(tc, 0, testfile, testfile_size, &read_bytes, &usec, &cached); cached_high = get_cached_size(); sync(); drop_caches(); cached_low = get_cached_size(); cached_max = MAX(cached_max, cached_high - cached_low); tst_res(TINFO, "read_testfile(0)"); read_testfile(tc, 0, testfile, testfile_size, &read_bytes, &usec, &cached); if (cached > cached_low) cached = cached - cached_low; else cached = 0; sync(); drop_caches(); cached_low = get_cached_size(); tst_res(TINFO, "read_testfile(1)"); ret = read_testfile(tc, 1, testfile, testfile_size, &read_bytes_ra, &usec_ra, &cached_ra); if (ret == EINVAL) { if (tc->use_fadvise && (!tc->use_overlay || !fadvise_supported)) { fadvise_supported = 0; tst_res(TCONF, "CONFIG_ADVISE_SYSCALLS not configured " "in kernel?"); return; } if (!tc->use_overlay || !readahead_supported) { readahead_supported = 0; tst_res(TCONF, "readahead not supported on %s", tst_device->fs_type); return; } } if (ret) { tst_res(TFAIL | TTERRNO, "%s failed on %s", tc->use_fadvise ? "fadvise" : "readahead", tc->use_overlay ? "overlayfs" : tst_device->fs_type); return; } if (cached_ra > cached_low) cached_ra = cached_ra - cached_low; else cached_ra = 0; tst_res(TINFO, "read_testfile(0) took: %lli usec", usec); tst_res(TINFO, "read_testfile(1) took: %lli usec", usec_ra); if (has_file(PROC_IO_FNAME, 0)) { tst_res(TINFO, "read_testfile(0) read: %ld bytes", read_bytes); tst_res(TINFO, "read_testfile(1) read: %ld bytes", read_bytes_ra); /* actual number of read bytes depends on total RAM */ if (read_bytes_ra < read_bytes) tst_res(TPASS, "readahead saved some I/O"); else tst_res(TFAIL, "readahead failed to save any I/O"); } else { tst_res(TCONF, "Your system doesn't have /proc/self/io," " unable to determine read bytes during test"); } tst_res(TINFO, "cache can hold at least: %ld kB", cached_max); tst_res(TINFO, "read_testfile(0) used cache: %ld kB", cached); tst_res(TINFO, "read_testfile(1) used cache: %ld kB", cached_ra); if (cached_max * 1024 >= testfile_size) { /* * if cache can hold ~testfile_size then cache increase * for readahead should be at least testfile_size/2 */ if (cached_ra * 1024 > testfile_size / 2) tst_res(TPASS, "using cache as expected"); else if (!cached_ra) tst_res(TFAIL, "readahead failed to use any cache"); else tst_res(TWARN, "using less cache than expected"); } else { tst_res(TCONF, "Page cache on your system is too small " "to hold whole testfile."); } }