get_ppn_for_pre_process()介绍
前面我们介绍了SSDsim的读请求预处理函数,其功能就是将IOtrace文件中的所有IO读请求先预先处理,整体上的功能和过程就是为了模拟经过一段IO处理后整个SSD的状态。
其中,在pre_process_for_page()函数中,有一个非常重要的调用子函数get_ppn_for_pre_process(),这个函数是在程序判断当前IOtrace读请求针对当前lsn区域的操作时,根据在内存dram结构中的map_entry[lpn].state中的映射状态来考究:如果映射存在,也就说明此时该lpn对应的子页数据有效,我们可以直接从buffer中进行读取;否则如果map_entry[lpn].state状态位为0说明映射无效,该lpn对应的物理页闪存页面数据尚未成功映射至内存和拷贝至buffer中,因此我们需要重新构建新的lpn<–>ppn的映射关系。所以函数会直接调用get_ppn_for_pre_process()进行一个ppn的获取过程。
源码及注释
接下来我们便针对这个get_ppn_for_pre_process()进行一个详尽的分析。首先我们先直接看源代码和相关注释:
unsigned int get_ppn_for_pre_process(struct ssd_info *ssd,unsigned int lsn)
{
unsigned int channel=0,chip=0,die=0,plane=0;
unsigned int ppn,lpn;
unsigned int active_block;
unsigned int channel_num=0,chip_num=0,die_num=0,plane_num=0;
#ifdef DEBUG
printf("enter get_psn_for_pre_process\n");
#endif
channel_num=ssd->parameter->channel_number;
chip_num=ssd->parameter->chip_channel[0];
die_num=ssd->parameter->die_chip;
plane_num=ssd->parameter->plane_die;
lpn=lsn/ssd->parameter->subpage_page;
if (ssd->parameter->allocation_scheme==0) /*动态方式下获取ppn*/
{
if (ssd->parameter->dynamic_allocation==0) /*表示全动态方式下,也就是channel,chip,die,plane,block等都是动态分配*/
{ //全动态下,需要时才进行分配
channel=ssd->token;
ssd->token=(ssd->token+1)%ssd->parameter->channel_number; //
chip=ssd->channel_head[channel].token;
ssd->channel_head[channel].token=(chip+1)%ssd->parameter->chip_channel[0];
die=ssd->channel_head[channel].chip_head[chip].token;
ssd->channel_head[channel].chip_head[chip].token=(die+1)%ssd->parameter->die_chip;
plane=ssd->channel_head[channel].chip_head[chip].die_head[die].token;
ssd->channel_head[channel].chip_head[chip].die_head[die].token=(plane+1)%ssd->parameter->plane_die;
}
else if (ssd->parameter->dynamic_allocation==1) /*表示半动态方式,channel静态给出,package,die,plane动态分配*/
{
channel=lpn%ssd->parameter->channel_number;
chip=ssd->channel_head[channel].token;
ssd->channel_head[channel].token=(chip+1)%ssd->parameter->chip_channel[0];
die=ssd->channel_head[channel].chip_head[chip].toke