1/** 2 * \file 3 * \brief throughput testing program 4 */ 5 6/* 7 * Copyright (c) 2007, 2008, 2009, 2010, 2011 ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#include <stdio.h> 16#include <stdlib.h> 17#include <assert.h> 18#include <string.h> 19#include <unistd.h> 20#include <errno.h> 21 22// Specific for barrelfish 23#include <barrelfish/barrelfish.h> 24#include <vfs/vfs.h> 25#include <barrelfish/nameservice_client.h> 26#include <barrelfish/waitset.h> 27#include <netbench/netbench.h> 28 29#define MOUNT_DIR "/nfs" 30 31// reads the file over nfs 32static int cat(char *path) 33{ 34 size_t size; 35 vfs_handle_t vh; 36 errval_t err; 37 uint64_t filesize = 0; 38 39 err = vfs_open(path, &vh); 40 if (err_is_fail(err)) { 41 printf("%s: file not found\n", path); 42 return 0; 43 } 44 45 struct vfs_fileinfo info; 46 err = vfs_stat(vh, &info); 47 if(err_is_fail(err)){ 48 printf("Could not stat file %s\n", path); 49 } 50 printf("Reading %d bytes from %s.\n", (int)info.size, path); 51 void *buf = malloc(10485760); 52 assert(buf); 53 54 uint64_t start = rdtsc(); 55 56 for (; filesize != info.size;) { 57 err = vfs_read(vh, buf, 10485760, &size); 58 if (err_is_fail(err)) { 59 // XXX: Close any files that might be open 60 DEBUG_ERR(err, "error reading file"); 61 return 0; 62 } 63 debug_printf("%s: %ld:%ld\n", __func__, filesize, info.size); 64 filesize += size; 65 } 66 assert(info.size == filesize); 67 68 // record stop time 69 uint64_t stop = rdtsc(); 70 printf("Everything done\n"); 71 double speed = ((filesize/in_seconds(stop - start))/(1024 * 1024)); 72 if (speed < 50) { 73 printf("Warning: NFS throughput too low!! [%f]\n", speed); 74 } 75 printf("## Data size = %f MB, Processing time [%"PU"], speed [%f] MB/s\n", 76 filesize/(double)(1024 * 1024), in_seconds(stop - start), 77 speed); 78 79 err = vfs_close(vh); 80 if (err_is_fail(err)) { 81 DEBUG_ERR(err, "in vfs_close"); 82 } 83 free(buf); 84 return filesize; 85} 86 87int main(int argc, char**argv) 88{ 89 errval_t err; 90 vfs_init(); 91 92 if(argc < 3) { 93 printf("Usage: %s mount-URL filepath\n", argv[0]); 94 printf("Example: %s nfs://10.110.4.41/shared /nfs/pravin/601.avi\n", 95 argv[0]); 96 exit(EXIT_FAILURE); 97 } 98 99// don't have to do this, MOUNT_DIR is already there 100// err = vfs_mkdir(MOUNT_DIR); 101// if (err_is_fail(err)) { 102// DEBUG_ERR(err, "vfs_mount"); 103// } 104 105 err = vfs_mount(MOUNT_DIR, argv[1]); 106 if(err_is_fail(err)) { 107 DEBUG_ERR(err, "vfs_mount"); 108 } 109 assert(err_is_ok(err)); 110 printf("mount done\n"); 111 112 printf("reading file 1. time [%s]\n", argv[2]); 113 cat(argv[2]); 114 printf("receive 1 done.\n"); 115 116 /* 117 printf("reading file 2. time [%s]\n", argv[2]); 118 cat(argv[2]); 119 printf("receive 2 done.\n"); */ 120 printf("All done.\n"); 121 122 struct waitset *ws = get_default_waitset(); 123 while (1) { 124 err = event_dispatch(ws); 125 if (err_is_fail(err)) { 126 DEBUG_ERR(err, "in event_dispatch"); 127 break; 128 } 129 } 130 131} 132