int main(int argc, char **argv) { int i, nloop, contpipe[2], datapipe[2]; pid_t childpid; if (argc != 4) err_quit("usage: bw_pipe <#loops> <#mbytes> <#bytes/write>"); nloop = atoi(argv[1]); totalnbytes = atoi(argv[2]) * 1024 * 1024; xfersize = atoi(argv[3]); buf = Valloc(xfersize); Touch(buf, xfersize); Pipe(contpipe); Pipe(datapipe); if ( (childpid = Fork()) == 0) { writer(contpipe[0], datapipe[1]); /* child */ exit(0); } /* 4parent */ Start_time(); for (i = 0; i < nloop; i++) reader(contpipe[1], datapipe[0], totalnbytes); printf("bandwidth: %.3f MB/sec\n", totalnbytes / Stop_time() * nloop); kill(childpid, SIGTERM); exit(0); }
int main(int argc, char **argv) { int i, nloop, contpipe[2], msqid; pid_t childpid; if (argc != 4) err_quit("usage: bw_svmsg <#loops> <#mbytes> <#bytes/write>"); nloop = atoi(argv[1]); totalnbytes = atoi(argv[2]) * 1024 * 1024; xfersize = atoi(argv[3]); buf = Valloc(xfersize); Touch(buf, xfersize); buf->mtype = 1; Pipe(contpipe); msqid = Msgget(IPC_PRIVATE, IPC_CREAT | SVMSG_MODE); if ( (childpid = Fork()) == 0) { writer(contpipe[0], msqid); /* child */ exit(0); } Start_time(); for (i = 0; i < nloop; i++) reader(contpipe[1], msqid, totalnbytes); printf("bandwidth: %.3f MB/sec\n", totalnbytes / Stop_time() * nloop); kill(childpid, SIGTERM); Msgctl(msqid, IPC_RMID, NULL); exit(0); }
int init_super(const char *dev_name) { int fd; if ((vbfs_superblock_disk = Valloc(VBFS_SUPER_SIZE)) == NULL) goto err; memset(vbfs_superblock_disk, 0, VBFS_SUPER_SIZE); fd = open(dev_name, O_RDWR | O_DIRECT | O_LARGEFILE); if (fd < 0) { fprintf(stderr, "open %s error, %s\n", dev_name, strerror(errno)); goto err; } init_vbfs_ctx(fd); if (read_from_disk(fd, vbfs_superblock_disk, VBFS_SUPER_OFFSET, VBFS_SUPER_SIZE)) goto err; if (load_super()) goto err; vbfs_ctx.super.s_mount_time = time(NULL); vbfs_ctx.super.s_state = MOUNT_DIRTY; vbfs_ctx.super.super_vbfs_dirty = SUPER_DIRTY; vbfs_ctx.super.inode_offset = vbfs_ctx.super.extend_bitmap_offset + vbfs_ctx.super.extend_bitmap_count; vbfs_ctx.super.inode_extends = ((__u64)vbfs_ctx.super.s_inode_count * INODE_SIZE) / vbfs_ctx.super.s_extend_size; /* bad extend init */ if (init_bad_extend()) goto err; /* calculate free extend */ /* */ return 0; err: return -1; }
void *mp_valloc(unsigned int size) { return Valloc(size); }