Go to the documentation of this file.00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004
00005 #include "types.h"
00006 #include "debug.h"
00007 #include "traceio.h"
00008 #include "stat.h"
00009 #include "nand.h"
00010
00011 #include "ftl.h"
00012
00013
00014
00015
00016
00017
00018 void run_trace(traceio_handler h)
00019 {
00020 _t_sect start;
00021 _t_size size;
00022 int length;
00023 struct op_unit op_unit;
00024 int cnt=0;
00025 _t_size (*op_func)(_t_sect lsn, _t_size size);
00026
00027
00028 nand_stat_reset();
00029
00030 while(1) {
00031
00032 op_unit = next_op(h);
00033 if(is_last(op_unit)) break;
00034 if(!is_valid_op_unit(op_unit)) {
00035 error("Invalid op_unit");
00036 break;
00037 }
00038
00039 start = (op_unit.sector);
00040 length = (op_unit.length);
00041
00042 switch(op_unit.op) {
00043 case READ:
00044 op_func = ftl_read;
00045 io_stat.cnt_read++; io_stat.size_read+=length;
00046 break;
00047 case WRITE:
00048 op_func = ftl_write;
00049 io_stat.cnt_write++; io_stat.size_write+=length;
00050 break;
00051 }
00052
00053 while(length>0) {
00054
00055 size = op_func(start, length);
00056 start += size;
00057 length -= size;
00058 cnt++;
00059 if(cnt%10000==0) {
00060 fprintf(stderr, ".");
00061 fflush(stderr);
00062 }
00063 }
00064 }
00065
00066
00067 nand_stat_print();
00068
00069 printf("\n");
00070
00071 }
00072
00073 void sim(char *tracefile, int repeat)
00074 {
00075 int i;
00076 traceio_handler h;
00077
00078
00079 nand_open();
00080
00081 ftl_open();
00082
00083
00084
00085 i=0;
00086 if(repeat==0) repeat=1;
00087
00088 while(repeat) {
00089 fprintf(stderr,"\n%d running\n", i);
00090 printf("[%d] Simulating trace: %s\n", i, tracefile);
00091
00092 i++; repeat--;
00093
00094 h = open_traceio(tracefile, DISKMON_TRACE);
00095 if(h == NULL) {
00096 fprintf(stderr, "Error to open file:%s\n", tracefile);
00097 break;
00098 }
00099 run_trace(h);
00100 close_traceio(h);
00101 }
00102
00103
00104 ftl_close();
00105 nand_close();
00106
00107 }
00108
00109 int main(int argc, char *argv[]) {
00110 int repeat;
00111 char tracefile[256];
00112
00113 if(argc<3) {
00114 printf("Usage: %s <tracefile> <repeat>\n", argv[0]);
00115 exit(1);
00116 }
00117 #ifdef WIN32
00118 strcpy_s(tracefile, 255, argv[1]);
00119 #else
00120 strcpy(tracefile, argv[1]);
00121 #endif
00122 repeat = atoi(argv[2]);
00123
00124 sim(tracefile, repeat);
00125
00126 return 0;
00127
00128 }
00129
00130