Example #1
0
File: ftl.c Project: windsoul/vssim
void FTL_INIT()
{
	int n;
	if(g_init == 0){
        	printf("[%s] start\n",__FUNCTION__);

		INIT_SSD_CONFIG();

		INIT_MAPPING_TABLE();
		INIT_INVERSE_PAGE_MAPPING();
		INIT_INVERSE_BLOCK_MAPPING();
		INIT_VALID_ARRAY();
		INIT_EMPTY_BLOCK_LIST();
		INIT_VICTIM_BLOCK_LIST();
		//INIT_PERF_CHECKER();
		
		for(n=0; n<BIN_COUNT; n++){ 
			init_bin(&bins[n]);
		}

		for(n=0; n<MAX_COMPRESSED_LPN_PER_PPN*BIN_COUNT; n++){ 
			init_bpn(&bpns[n]);
		}


		g_init = 1;

		SSD_IO_INIT();
		printf("[%s] complete\n",__FUNCTION__);
	}
}
Example #2
0
/***********************************************************************//**
 * @brief Initialise class members
 ***************************************************************************/
void GCTAEventCube::init_members(void)
{
    // Initialise members
    m_map.clear();
    m_weights.clear();
    m_bin.clear();
    m_time.clear();
    m_dirs.clear();
    m_solidangle.clear();
    m_energies.clear();
    m_ewidth.clear();
    m_ontime = 0.0;

    // Prepare event bin
    init_bin();

    // Return
    return;
}
Example #3
0
/***********************************************************************//**
 * @brief Copy class members
 *
 * @param[in] cube Event cube.
 *
 * This method copies the class members from another event cube in the actual
 * object. It also prepares the event bin member that will be returned in
 * case of an operator access to the class.
 ***************************************************************************/
void GCTAEventCube::copy_members(const GCTAEventCube& cube)
{
    // Copy members. Note that the event bin is not copied as it will
    // be initialised later. The event bin serves just as a container of
    // pointers, hence we do not want to copy over the pointers from the
    // original class.
    m_map        = cube.m_map;
    m_weights    = cube.m_weights;
    //m_bin        = cube.m_bin;
    m_time       = cube.m_time;
    m_dirs       = cube.m_dirs;
    m_solidangle = cube.m_solidangle;
    m_energies   = cube.m_energies;
    m_ewidth     = cube.m_ewidth;
    m_ontime     = cube.m_ontime;

    // Prepare event bin
    init_bin();

    // Return
    return;
}
Example #4
0
File: ftl.c Project: windsoul/vssim
/* add ratio of newly written page, one by one.
   whenever we dont have enough space to add to bin, split lpn to two parts, 
   dump page, and add overflow to the newly emptied bin*/
int _FTL_BUF(int lpn, double ratio, int is_gc)
{
	int i, bpn_idx, b_lpn, temp_bpn_idx = -1;
	int ret;
	int32_t new_ppn;
	int io_page_nb;
	int length = SECTORS_PER_PAGE; /* write 1 page at most*/
	int bin_idx = 0;
	int max_lpns = 0;
	double overflow_ratio;
	total_compression_ratio += ratio;
	total_lpn_count++;

	//if(fmod(ratio, 0.001) < 0.001)
	//	ratio = ratio - fmod(ratio, 0.001);
	LOG("lpn %d ratio %f", lpn, ratio);
	/* check if already buffered*/
	for(bpn_idx=0; bpn_idx<MAX_COMPRESSED_LPN_PER_PPN*BIN_COUNT; bpn_idx++){ 
		/* already buffered */
		if(bpns[bpn_idx].lpn == lpn){
			LOG("lpn %d already buffered in bpn %d (index %d ratio %f)", lpn, bpn_idx, bpns[bpn_idx].index, bpns[bpn_idx].ratio);
			remove_from_bin(bpn_idx);// remove from bin
			init_bpn(&bpns[bpn_idx]); 
		}
	}

	/* find empty bpn. must find one!*/
	bpn_idx = find_empty_bpn();
	assert(bpn_idx != MAX_COMPRESSED_LPN_PER_PPN*BIN_COUNT);

	//printf("found bpn_idx %d\n", bpn_idx);

	/* put in bin, and invalidate old */
	overflow_ratio = update_bin_bpn(bin_idx, bpn_idx, lpn, ratio, 0);
	LOG("overflow_ratio %f", overflow_ratio);
	//printf("add lpn %d ratio %f to bin %d. new bin count %d\n", bpns[bpn_idx].lpn, ratio, i, bins[i].count);
	LOG("lpn %d invalidate both indexes", lpn);
	UPDATE_OLD_PAGE_MAPPING(lpn, 0);
	UPDATE_OLD_PAGE_MAPPING(lpn, 1);

	/* bin not full */
	if (overflow_ratio == 0.0000)
		return 0;

dump_bin:
	/* bin too full, caused overflow. save ratio of overflow*/
	/* need to dump!*/
	if(!is_gc)
		io_alloc_overhead = ALLOC_IO_REQUEST(0, length, WRITE, &io_page_nb);

	ret = GET_NEW_PAGE(VICTIM_OVERALL, EMPTY_TABLE_ENTRY_NB, &new_ppn);
	if(ret == FAIL){
		printf("ERROR[FTL_WRITE] Get new page fail \n");
		assert(0);
		return -1;
	}
	
	ret = SSD_PAGE_WRITE(CALC_FLASH(new_ppn), CALC_BLOCK(new_ppn), CALC_PAGE(new_ppn), 0, (is_gc)?GC_WRITE:WRITE, io_page_nb);
	LOG("dumped bin to new_ppn %d", new_ppn);
#ifdef FTL_DEBUG
	if(ret == FAIL){
		printf("Error[_FTL_BIN_PACK] %d page write fail \n", new_ppn);
		assert(0);
		return -1;
	}
#endif

	/* choose bin to dump*/
	bin_idx = 0;
	max_lpns = bins[0].count;

	LOG("dump bin %d (has %d lpns)\n", bin_idx, bins[bin_idx].count);
	/* Update mappings for all moved compressed LPNs */
	for(i=0;i<MAX_COMPRESSED_LPN_PER_PPN;i++){
		temp_bpn_idx = bins[bin_idx].bpns[i];
		if(temp_bpn_idx <0){
			assert(i>0);
			break;
		}
		b_lpn = bpns[temp_bpn_idx].lpn;

		LOG("b_lpn %d update new index %d", b_lpn, bpns[temp_bpn_idx].index);
		UPDATE_NEW_PAGE_MAPPING(b_lpn, 
					new_ppn, 
					bpns[temp_bpn_idx].ratio,// updates relevant valid_array entry as well
					bpns[temp_bpn_idx].index); // index
		//printf("update mapping for lpn %d raiot %.02f new_ppn %d\n", b_lpn, bpns[temp_bpn_idx].ratio, new_ppn);
		/* dont forget to update reelvant bpn*/
		init_bpn(&bpns[temp_bpn_idx]);
	}

	/* init evicted bin, insert new bpn, and increment bin_idx */
	init_bin(&bins[bin_idx]);
	
	/* insert to bin, this time with the leftover overflow_ratio*/
	bpn_idx = find_empty_bpn();
	assert(bpn_idx < MAX_COMPRESSED_LPN_PER_PPN*BIN_COUNT);
	LOG("update overflow index 1");
	update_bin_bpn(bin_idx, bpn_idx, lpn, overflow_ratio, (overflow_ratio < ratio)?1:0 /*overflow -> index 1*/);

	/* finish writing */
	if(!is_gc)
		INCREASE_IO_REQUEST_SEQ_NB();

#ifdef GC_ON
	if(!is_gc)
		GC_CHECK(CALC_FLASH(new_ppn), CALC_BLOCK(new_ppn));
#endif

#ifdef MONITOR_ON
	char szTemp[1024];
	sprintf(szTemp, "WRITE PAGE %d ", length);
	WRITE_LOG(szTemp);
	sprintf(szTemp, "WB CORRECT %d", 1);
	WRITE_LOG(szTemp);
#endif

	return 1;
}