コード例 #1
0
ファイル: ld_pd_map.c プロジェクト: bahamas10/openzfs
U8
megasas_get_best_arm(PLD_LOAD_BALANCE_INFO lbInfo, U8 arm, U64 block,
    U32 count)
{
	U16 pend0, pend1;
	U64 diff0, diff1;
	U8 bestArm;

	/* get the pending cmds for the data and mirror arms */
	pend0 = lbInfo->scsi_pending_cmds[0];
	pend1 = lbInfo->scsi_pending_cmds[1];

	/* Determine the disk whose head is nearer to the req. block */
	diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[0]);
	diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[1]);
	bestArm = (diff0 <= diff1 ? 0 : 1);

	if ((bestArm == arm && pend0 > pend1 + 16) ||
	    (bestArm != arm && pend1 > pend0 + 16)) {
		bestArm ^= 1;
	}

	/* Update the last accessed block on the correct pd */
	lbInfo->last_accessed_block[bestArm] = block + count - 1;
	return (bestArm);
}
コード例 #2
0
u8 megasas_get_best_arm(struct LD_LOAD_BALANCE_INFO *lbInfo, u8 arm, u64 block,
			u32 count)
{
	u16     pend0, pend1;
	u64     diff0, diff1;
	u8      bestArm;

	/* get the pending cmds for the data and mirror arms */
	pend0 = atomic_read(&lbInfo->scsi_pending_cmds[0]);
	pend1 = atomic_read(&lbInfo->scsi_pending_cmds[1]);

	/* Determine the disk whose head is nearer to the req. block */
	diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[0]);
	diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[1]);
	bestArm = (diff0 <= diff1 ? 0 : 1);

	/*Make balance count from 16 to 4 to keep driver in sync with Firmware*/
	if ((bestArm == arm && pend0 > pend1 + 4)  ||
	    (bestArm != arm && pend1 > pend0 + 4))
		bestArm ^= 1;

	/* Update the last accessed block on the correct pd */
	lbInfo->last_accessed_block[bestArm] = block + count - 1;

	return bestArm;
}
コード例 #3
0
ファイル: diff_c.c プロジェクト: francofrizzo/orga2-tp2
void diff_c (
    unsigned char *src,
    unsigned char *src_2,
    unsigned char *dst,
    int m, // columnas
    int n, // filas
    int src_row_size,
    int src_2_row_size,
    int dst_row_size
) {
    unsigned char (*src_matrix)[src_row_size] = (unsigned char (*)[src_row_size]) src;
    unsigned char (*src_2_matrix)[src_2_row_size] = (unsigned char (*)[src_2_row_size]) src_2;
    unsigned char (*dst_matrix)[dst_row_size] = (unsigned char (*)[dst_row_size]) dst;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 4 * m; j = j + 4) {
            unsigned char b_diff = ABS_DIFF(src_matrix[i][j], src_2_matrix[i][j]);
            unsigned char g_diff = ABS_DIFF(src_matrix[i][j+1], src_2_matrix[i][j+1]);
            unsigned char r_diff = ABS_DIFF(src_matrix[i][j+2], src_2_matrix[i][j+2]);

            unsigned char diff = MAX_3(b_diff, g_diff, r_diff);

            dst_matrix[i][j] = diff;
            dst_matrix[i][j+1] = diff;
            dst_matrix[i][j+2] = diff;
            dst_matrix[i][j+3] = 255;
        }
    }
}
コード例 #4
0
ファイル: mst.c プロジェクト: 3dots/ece454h1f
static int
min_dist_from_mst(int node_outside,
		  int inet,
		  boolean * in_mst,
		  int *node_inside)
{
    int ipin, blk1, blk2, dist, closest_node_in_mst, shortest_dist;

/* given a node outside the mst this routine finds its shortest distance to the current partial 
 * mst, as well as the corresponding node inside mst */

    closest_node_in_mst = -1;
    shortest_dist = -1;
    /* search over all blocks inside mst */
    for(ipin = 0; ipin < (net[inet].num_sinks + 1); ipin++)
	{
	    if(in_mst[ipin])
		{
		    blk1 = net[inet].node_block[node_outside];
		    blk2 = net[inet].node_block[ipin];

		    dist =
			ABS_DIFF(block[blk1].x,
				 block[blk2].x) + ABS_DIFF(block[blk1].y,
							   block[blk2].y);

		    if(closest_node_in_mst == -1)
			{
			    closest_node_in_mst = ipin;
			    shortest_dist = dist;
			}
		    else
			{
			    if(shortest_dist > dist)
				{
				    closest_node_in_mst = ipin;
				    shortest_dist = dist;
				}
			}
		}
	}

    *node_inside = closest_node_in_mst;

    return shortest_dist;
}
コード例 #5
0
/* Calculate speed of allocation and waste memory of specific space respectively, 
  * then decide whether to execute a space tuning according to the infomation.*/
static void gc_decide_space_tune(GC* gc)
{
  Blocked_Space* mspace = (Blocked_Space*)gc_get_mos((GC_Gen*)gc);
  Blocked_Space* fspace = (Blocked_Space*)gc_get_nos((GC_Gen*)gc);  
  Space* lspace = (Space*)gc_get_los((GC_Gen*)gc);  
  Space_Tuner* tuner = gc->tuner;

  tuner->speed_los = lspace->accumu_alloced_size;
  tuner->speed_los = (tuner->speed_los + tuner->last_speed_los) >> 1;
  /*The possible survivors from the newly allocated NOS should be counted into the speed of MOS*/
  tuner->speed_mos = mspace->accumu_alloced_size +   (uint64)((float)fspace->last_alloced_size * fspace->survive_ratio);;
  tuner->speed_mos = (tuner->speed_mos + tuner->last_speed_mos) >> 1;
  tuner->speed_nos = fspace->accumu_alloced_size;
  tuner->speed_nos = (tuner->speed_nos + tuner->last_speed_nos) >> 1;
  
  /*Statistic wasted memory*/
  uint64 curr_used_los = lspace->last_surviving_size + lspace->last_alloced_size;
  uint64 curr_wast_los = 0;
  if(gc->cause != GC_CAUSE_LOS_IS_FULL) curr_wast_los =  lspace->committed_heap_size - curr_used_los;
  tuner->wast_los += (POINTER_SIZE_INT)curr_wast_los;
  
  uint64 curr_used_mos = 
                                mspace->period_surviving_size + mspace->accumu_alloced_size + (uint64)(fspace->last_alloced_size * fspace->survive_ratio);
  float expected_mos_ratio = mspace_get_expected_threshold_ratio((Mspace*)mspace);
  uint64 expected_mos = (uint64)((mspace->committed_heap_size + fspace->committed_heap_size) * expected_mos_ratio);
  uint64 curr_wast_mos = 0;
  if(expected_mos > curr_used_mos) curr_wast_mos = expected_mos - curr_used_mos;
  tuner->wast_mos += curr_wast_mos;

  tuner->current_dw = ABS_DIFF(tuner->wast_mos, tuner->wast_los);

  /*For_statistic ds in heuristic*/
  tuner->current_ds = (unsigned int)((float)fspace->committed_heap_size * fspace->survive_ratio);
  /*Fixme: Threshold should be computed by heuristic. tslow, total recycled heap size shold be statistic.*/
  tuner->threshold_waste = tuner->current_ds;
  if(tuner->threshold_waste > 8 * MB) tuner->threshold_waste = 8 * MB;
  tuner->min_tuning_size = tuner->current_ds;
  if(tuner->min_tuning_size > 4 * MB) tuner->min_tuning_size = 4 * MB;  

  if(tuner->speed_los == 0) tuner->speed_los = 16;
  if(tuner->speed_mos == 0) tuner->speed_mos = 16;

  /*Needn't tune if dw does not reach threshold.*/  
  if(tuner->current_dw > tuner->threshold_waste)  tuner->need_tune = 1;
  /*If LOS is full, we should tune at lease "tuner->least_tuning_size" size*/
  if(gc->cause == GC_CAUSE_LOS_IS_FULL) tuner->force_tune = 1;

  return;
}
コード例 #6
0
ファイル: place_stats.c プロジェクト: eddiehung/dox-vtr
void
print_relative_pos_distr(void)
{

	/* Prints out the probability distribution of the relative locations of *
	 * input pins on a net -- i.e. simulates 2-point net distance probability *
	 * distribution.                                                        */
#ifdef PRINT_REL_POS_DISTR
	FILE *out_bin_file;
	relapos_rec_t rp_rec;
#endif /* PRINT_REL_POS_DISTR */

	int inet, len, rp, src_x, src_y, dst_x, dst_y, del_x, del_y, min_del,
	sink_pin, sum;
	int *total_conn;
	int **relapos;
	double **relapos_distr;

	total_conn = (int *)my_malloc((nx + ny + 1) * sizeof(int));
	relapos = (int **)my_malloc((nx + ny + 1) * sizeof(int *));
	relapos_distr = (double **)my_malloc((nx + ny + 1) * sizeof(double *));
	for (len = 0; len <= nx + ny; len++)
	{
		relapos[len] = (int *)my_calloc(len / 2 + 1, sizeof(int));
		relapos_distr[len] =
		(double *)my_calloc((len / 2 + 1), sizeof(double));
	}

	for (inet = 0; inet < num_nets; inet++)
	{
		if (clb_net[inet].is_global == FALSE)
		{

			src_x = block[clb_net[inet].node_block[0]].x;
			src_y = block[clb_net[inet].node_block[0]].y;

			for (sink_pin = 1; sink_pin <= clb_net[inet].num_sinks;
					sink_pin++)
			{
				dst_x = block[clb_net[inet].node_block[sink_pin]].x;
				dst_y = block[clb_net[inet].node_block[sink_pin]].y;

				del_x = ABS_DIFF(dst_x, src_x);
				del_y = ABS_DIFF(dst_y, src_y);

				len = del_x + del_y;

				min_del = (del_x < del_y) ? del_x : del_y;

				if (!(min_del <= (len / 2)))
				{
					vpr_printf(TIO_MESSAGE_ERROR, "Error calculating relative location min_del = %d, len = %d\n",
						min_del, len);
					exit(1);
				}
				else
				{
					relapos[len][min_del]++;
				}
			}
		}
	}

#ifdef PRINT_REL_POS_DISTR
	out_bin_file =
	fopen("/jayar/b/b5/fang/vpr_test/wirelength/relapos2.bin", "rb+");
#endif /* PRINT_REL_POS_DISTR */

	for (len = 0; len <= nx + ny; len++)
	{
		sum = 0;
		for (rp = 0; rp <= len / 2; rp++)
		{
			sum += relapos[len][rp];
		}
		if (sum != 0)
		{
#ifdef PRINT_REL_POS_DISTR
			fseek(out_bin_file, sizeof(relapos_rec_t) * len,
					SEEK_SET);
			fread(&rp_rec, sizeof(relapos_rec_t), 1, out_bin_file);
#endif /* PRINT_REL_POS_DISTR */

			for (rp = 0; rp <= len / 2; rp++)
			{

				relapos_distr[len][rp] =
				(double)relapos[len][rp] / (double)sum;

				/* updating the binary record at "len" */
#ifdef PRINT_REL_POS_DISTR
				vpr_printf(TIO_MESSAGE_ERROR, "old %d increased by %d\n", rp_rec.num_rp[rp], relapos[len][rp]);
				rp_rec.num_rp[rp] += relapos[len][rp];
				vpr_printf(TIO_MESSAGE_ERROR, "becomes %d\n", rp_rec.num_rp[rp]);
#endif /* PRINT_REL_POS_DISTR */
			}
#ifdef PRINT_REL_POS_DISTR
			/* write back the updated record at "len" */
			fseek(out_bin_file, sizeof(relapos_rec_t) * len,
					SEEK_SET);
			fwrite(&rp_rec, sizeof(relapos_rec_t), 1, out_bin_file);
#endif /* PRINT_REL_POS_DISTR */

		}
		total_conn[len] = sum;
	}

	fprintf(stdout, "Source to sink relative positions:\n");
	for (len = 1; len <= nx + ny; len++)
	{
		if (total_conn[len] != 0)
		{
			fprintf(stdout, "Of 2-pin distance %d exists %d\n\n", len,
					total_conn[len]);
			for (rp = 0; rp <= len / 2; rp++)
			{
				fprintf(stdout, "\trp%d\t%d\t\t(%.5f)\n", rp,
						relapos[len][rp], relapos_distr[len][rp]);
			}
			fprintf(stdout, "----------------\n");
		}
	}

	free((void *)total_conn);
	for (len = 0; len <= nx + ny; len++)
	{
		free((void *)relapos[len]);
		free((void *)relapos_distr[len]);
	}
	free((void *)relapos);
	free((void *)relapos_distr);

#ifdef PRINT_REL_POS_DISTR
	fclose(out_bin_file);
#endif /* PRINT_REL_POS_DISTR */
}
コード例 #7
0
static uint8_t search_861_mode(sync_info_type *p_sync_info)
{
    int i;
    uint8_t detected_video_idx = SI_VIDEO_MODE_NON_STD;
    int16_t range;

    enum
    {
        not_found = 0,
        found_not_exact = 1,
        found_exact = 2
    }
    search_result = not_found;

    for(i=0; VideoModeTable[i].Vic4x3 || VideoModeTable[i].Vic16x9; i++)
    {
        const videoMode_t *p_video_table = &VideoModeTable[i];
        bool_t interlaced = p_sync_info->Interlaced;
        uint16_t total_V_lines_measured =
            (interlaced ?
             (p_sync_info->TotalLines * 2)
             : p_sync_info->TotalLines);

        // check progressive/interlaced
        if(interlaced != p_video_table->Interlaced)
            continue;

        // check number of lines
        if(ABS_DIFF(total_V_lines_measured, p_video_table->Total.V) > LINES_TOLERANCE)
            continue;

        // check number of clocks per line (it works for all possible replications)
        if(ABS_DIFF(p_sync_info->ClocksPerLine, p_video_table->Total.H) > PIXELS_TOLERANCE)
            continue;

        // check Pixel Freq (in 10kHz units)
//		if(ABS_DIFF(p_sync_info->PixelFreq, p_video_table->PixClk) > FPIX_TOLERANCE)  // tolerance based on fixed bandwidth
        if (0 != ABS_DIFF(p_sync_info->PixelFreq, p_video_table->PixClk))  // tolerance based on dynamic bandwidth (fixed ratio)
        {
            range = p_video_table->PixClk / ABS_DIFF(p_sync_info->PixelFreq, p_video_table->PixClk);

            if( (range) < FPIX_TOLERANCE_RANGE)    // per PLL range
                continue;
        }

#if 0        // enable it for mode search tuning
        DEBUG_PRINT(MSG_STAT,
                    "Index in table: %d, interlaced: %d, range: %d",
                    (int) i, (int) interlaced, (int)range);

        DEBUG_PRINT(MSG_STAT,
                    "Pixel Freq detected: %d, Pixel Freq in video table: %d",
                    (int) p_sync_info->PixelFreq, (int) p_video_table->PixClk);

        DEBUG_PRINT(MSG_STAT,
                    "clock per lines detected: %d, lines detected: %d",
                    (int) p_sync_info->ClocksPerLine, (int) total_V_lines_measured);

        DEBUG_PRINT(MSG_STAT,
                    "clock per lines in video table: %d, lines in video table: %d\n",
                    (int) p_video_table->Total.H, (int) p_video_table->Total.V);
#endif

        // if all previous tests passed, then we found at least one mode even polarity is mismatched
        if(search_result == not_found)
        {
            search_result = found_not_exact;
            detected_video_idx = i;
        }

        // check exact number of lines
        if(ABS_DIFF(total_V_lines_measured, p_video_table->Total.V) > 1)
            continue;

        // check polarities
        if(
            (p_sync_info->HPol == p_video_table->HPol) &&
            (p_sync_info->VPol == p_video_table->VPol)
        )
        {
            // if all previous checks passed
            search_result = found_exact;
            detected_video_idx = i;
            break;
        }
    }

    switch(search_result)
    {
    case not_found:
        break;
    case found_exact:
        break;
    case found_not_exact:
        DEBUG_PRINT(MSG_STAT, ("RX: Warning: not exact video mode found\n"));
        break;
    }

    return detected_video_idx;
}