重构地址

//为实际trace重构用的分析文件,将trace重写,并根据内存内部地址重构
/*****************************
* zgl_trace_analyse
* Usage:  ./zgl_trace_analyse tracefilename
******************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>

#define	TRACE_LENGTH	8
int64_t		   *buf;	//tmp buffer for fetching traces from trace_file into memory
unsigned int       rd_cnt;	//the size of data fetched from file
unsigned int	   trace_no;	//the serial number of trace

unsigned int 	   timer;	//the timestampe field of the trace, which is the duration time of current memory access
unsigned int       r_w;		//the read/write field of the trace, 1 is read, 0 is write
unsigned int       addr;	//the physical address field of the trace

unsigned int	   col;		//the col    bits of address
unsigned int	   row;		//the row    bits of address
unsigned int 	   bank;	//the bank   bits of address
unsigned int	   rank;	//the rank   bits of address
unsigned int 	   offset;	//the offset bits of address



unsigned int	   real_col;	//col[12:0]	col[12] && col[10] for autocharge and burst chop set them 0 here!
unsigned int       col_11;	//phy[31]
unsigned int       col_9;	//phy[14]              col[9]
unsigned int       col_8_3;	//phy[11:6]            col[8:3]

unsigned int       real_row;	//row[13:0]
unsigned int	   row_13_12;	//phy[30:29]           row[13:12]
unsigned int	   row_11_5;	//phy[27:21]           row[11:5]
unsigned int       row_4;       //phy[28]              row[4]
unsigned int	   row_3_0;	//phy[18:15]           row[3:0]

unsigned int       real_bank;	//bank[2:0]
unsigned int       bank_2_1;	//phy[20:19]           bank[2:1]
unsigned int       bank_0;	//phy[13]              bank[0]

unsigned int	   real_rank;	//rank[0]
unsigned int       rank_0;	//phy[12]              rank[0]
unsigned int	   offset_5_0;	//phy[5:0]             offset[5:0]

unsigned int       addr_RK_BK_R_C;

unsigned int 	   global_timer;
/****************************************************************************************
*											*
*	Decode the timestamp, read/write and physical address from			*
*	the binary traces according to the corresponding format				*
*											*
****************************************************************************************/
void trace_decode()
{
        timer  = (unsigned int)( ((*buf)>>33) & 0xfffffULL );
        global_timer += timer;
	r_w    = (unsigned int)( ((*buf)>>32) & 0x1ULL );
	addr   = (unsigned int)( (*buf) & 0xffffffffULL );
	
	return;
}

void addr_decode()
{
	col     = (unsigned int)( (*buf) & 0x80004fc0ULL);
	row     = (unsigned int)( (*buf) & 0x7fe78000ULL);
	bank    = (unsigned int)( (*buf) & 0x00182000ULL);
	rank    = (unsigned int)( (*buf) & 0x00001000ULL);
	offset  = (unsigned int)( (*buf) & 0x0000003fULL);

//	printf("--------------------------------------------------addr decode: \tcol\t%8x\trow\t%8x\tbank\t%8x\trank\t%8x\toffset\t%8x\n",col,row,bank,rank,offset);



	
	col_11  = (unsigned int)( ((*buf)>>31) & 0x1ULL);
	col_9	= (unsigned int)( ((*buf)>>14) & 0x1ULL);
	col_8_3 = (unsigned int)( ((*buf)>>6 ) & 0x3fULL);

	//real_col = (unsigned int)((col_11<<11)|(col_9<<9)|(col_8_3<<3));
	real_col = (unsigned int)((col_11<<4)|(col_9<<3)|(col_8_3));


	row_13_12 = (unsigned int)( ((*buf)>>29) & 0x3ULL);
	row_11_5  = (unsigned int)( ((*buf)>>21) & 0x7fULL);
	row_4     = (unsigned int)( ((*buf)>>28) & 0x1ULL);
	row_3_0 = (unsigned int)( ((*buf)>>15) & 0xfULL);
	real_row = (unsigned int)((row_13_12<<12)|(row_11_5<<5)|(row_4<<4)|(row_3_0));

	bank_2_1 = (unsigned int)( ((*buf)>>19) & 0x3ULL);
	bank_0   = (unsigned int)( ((*buf)>>13) & 0x1ULL);
	real_bank = (unsigned int)((bank_2_1<<1)|(bank_0));

	offset_5_0 = (unsigned int)( (*buf) & 0x3fULL);

	rank_0  = (unsigned int)( (*buf)>>12 & 0x1ULL);
	real_rank = (unsigned int)( rank_0 );
	
//	printf("--------------------------------------------------addr decode: \treal_col\t%8x %8x %8x total %8x\n",
//                             col_11,col_9,col_8_3,real_col);
//	printf("--------------------------------------------------addr decode: \treal_row\t%8x %8x %8x %8x\ttotal %8x\n",
//                             row_13_12,row_11_5,row_4,row_3_0,real_row);
//	printf("--------------------------------------------------addr decode: \treal_bank\t%8x %8x\ttotal %8x\n",
//                             bank_2_1,bank_0,real_bank);
//	printf("--------------------------------------------------addr decode: \treal_rank\t%8x\n",
//                             real_rank);
	
	printf("--------------------------------------------------addr: rank\t%8x\tbank\t%8x\trow\t%8x\tcol\t%8x\toffset%8x\n",real_rank,real_bank,real_row,real_col,offset_5_0);
	


	//RK-rank is 1 bit BK-bank is 4 bit R-row is 14 bit C-col is 8 bit
	//31=32-1 28=31-3  14=28-14 
	//means from 1 to 32 from 3 to 31
	addr_RK_BK_R_C= ((real_rank<<31) | (real_bank<<28) | (real_row<<14) | (real_col<<6)|offset_5_0);
	printf("In sequence of RK:BK:R:C the address is: \t%8x\n",addr_RK_BK_R_C);	

//	printf("--------------------------------------------------addr decode: \treal_col\t%8x %8x %8x\treal_row\t%8x %8x %8x %8x\tbank\t%8x\trank\t%8x\toffset\t%8x\n",
//				col_11,col_9,col_8_3,row_13_12,row_11_5,row_4,row_3_0,bank,rank,offset);
}
/********************************************************
*							*
*	Print the analyzed trace on the screen.		*
*							*
********************************************************/
char char_r_w()
{
	if(r_w)	return 'R';
	else	return 'W';
}

void trace_display()
{
        printf("# trace%6d:  %6x       %c      %8x\n",trace_no,timer,char_r_w(),addr);
}

/********************************************************
*							*
*			MAIN				*
*							*
********************************************************/


int main(int argc, char **argv)
{
    char filename[256];
    FILE *fp;

    FILE *outputfp;
    char outputfilename[256];
    global_timer=0;

    memset(filename, 0, 256);
    memset(outputfilename, 0, 256);

    if(argc < 2)
    {
        printf("./%s filename\n",argv[0]);
        return 0;
    }
    strcpy(filename, argv[1]);

    strcpy(outputfilename,filename);
//
    //memset(outputfilename, 0, 256);
    /
    strcat(outputfilename,".trc_nvmain");

    printf("+++++++++++++++++%s\n",outputfilename);

    if((fp = fopen(filename, "r")) == NULL)
    {
        printf("Open file %s error\n",filename);
        return 0;
    }

    if((outputfp = fopen(outputfilename, "w")) == NULL)
    {
    	printf("Open file %s error\n",outputfilename);
        return 0;
    }

    //malloc the tmp buf for trace
    buf = (int64_t*)malloc(TRACE_LENGTH);
    if(!buf) 
    {
        printf("malloc failed\n");
        return 0;
    }


    //trace analyze
    printf("# trace  no. :  interval    r/w      addr \n",trace_no,timer,char_r_w(),addr);
    printf("-----------------------------------------------\n");
        
    for(trace_no=0; trace_no<20; trace_no++)
    {
        rd_cnt = fread(buf,1, TRACE_LENGTH,fp);
    
	    trace_decode();

	    trace_display();

	    addr_decode();

	   fprintf(outputfp, "%d %c %#8x 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0\n", global_timer, char_r_w(), addr_RK_BK_R_C );
    }

    free(buf);
    fclose(fp);
    fclose(outputfp);

    return 1;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值