Esempio n. 1
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;              /* Loop index. */
	double *mask;       /* Mask.       */
	uint64_t end;       /* End time.   */
	uint64_t start;     /* Start time. */
	unsigned char *img; /* Image.      */
	
	readargs(argc, argv);
	
	timer_init();
	srandnum(seed);
	
	/* Benchmark initialization. */
	if (verbose)
		printf("initializing...\n");
	start = timer_get();
	img = smalloc(p->imgsize*p->imgsize*sizeof(char));
	for (i = 0; i < p->imgsize*p->imgsize; i++)
		img[i] = randnum() & 0xff;
	mask = smalloc(p->masksize*p->masksize*sizeof(double));
	generate_mask(mask);
	end = timer_get();
	if (verbose)
		printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);
		
	/* Apply filter. */
	if (verbose)
		printf("applying filter...\n");
	start = timer_get();
	gauss_filter(img, p->imgsize, mask, p->masksize);
	end = timer_get();
	
	total = timer_diff(start, end);

	/* Print timing statistics. */
	printf("timing statistics:\n");
	printf("  master:        %f\n", master*MICROSEC);
	for (i = 0; i < nclusters; i++)
		printf("  slave %d:      %f\n", i, slave[i]*MICROSEC);
	printf("  communication: %f\n", communication*MICROSEC);
	printf("  total time:    %f\n", total*MICROSEC);
	
	/* House keeping. */
	free(mask);
	free(img);
	
	return (0);
}
Esempio n. 2
0
int main(int argc, char **argv)
{
	timer_init();

    ((void) argc);
    
    total = 0;
    
    rank = atoi(argv[0]);
    
    open_noc_connectors();
	
    getwork();

	start = timer_get();
    friendly_numbers();
	end = timer_get();

    syncNumbers();

	total = timer_diff(start, end);
	data_send(outfd, &total, sizeof(uint64_t));

    /* Close channels. */
    mppa_close(infd);
    mppa_close(outfd);

    mppa_exit(0);
    return (0);
}
Esempio n. 3
0
/*
 * Compute the target congestion window for the next RTT according to 
 * cubic equation when an ack is received.
 *
 * W(t) = C(t-K)^3 + W(last_max)
 */
static uint32_t
tcp_cubic_update(struct tcpcb *tp, u_int32_t rtt)
{
	float K, var;
	u_int32_t elapsed_time, win;

	win = min(tp->snd_cwnd, tp->snd_wnd);
	if (tp->t_ccstate->cub_last_max == 0)
		tp->t_ccstate->cub_last_max = tp->snd_ssthresh;

	if (tp->t_ccstate->cub_epoch_start == 0) {
		/*
		 * This is the beginning of a new epoch, initialize some of
		 * the variables that we need to use for computing the 
		 * congestion window later.
		 */
		tp->t_ccstate->cub_epoch_start = tcp_now;
		if (tp->t_ccstate->cub_epoch_start == 0)
			tp->t_ccstate->cub_epoch_start = 1;
		if (win < tp->t_ccstate->cub_last_max) {

			VERIFY(current_task() == kernel_task);

			/*
			 * Compute cubic epoch period, this is the time
			 * period that the window will take to increase to
			 * last_max again after backoff due to loss.
			 */
			K = (tp->t_ccstate->cub_last_max - win)
			    / tp->t_maxseg / tcp_cubic_coeff;
			K = cbrtf(K);
			tp->t_ccstate->cub_epoch_period = K * TCP_RETRANSHZ;
			/* Origin point */
			tp->t_ccstate->cub_origin_point = 
				tp->t_ccstate->cub_last_max;
		} else {
			tp->t_ccstate->cub_epoch_period = 0;
			tp->t_ccstate->cub_origin_point = win;
		}
		tp->t_ccstate->cub_target_win = 0;
	}
	
	VERIFY(tp->t_ccstate->cub_origin_point > 0);	
	/*
	 * Compute the target window for the next RTT using smoothed RTT
	 * as an estimate for next RTT.
	 */
	elapsed_time = timer_diff(tcp_now, 0, 
		tp->t_ccstate->cub_epoch_start, 0);

	if (tcp_cubic_use_minrtt)
		elapsed_time += max(tcp_cubic_use_minrtt, rtt);
	else
		elapsed_time += rtt;
	var = (elapsed_time  - tp->t_ccstate->cub_epoch_period) / TCP_RETRANSHZ;
	var = var * var * var * (tcp_cubic_coeff * tp->t_maxseg);

	tp->t_ccstate->cub_target_win = tp->t_ccstate->cub_origin_point + var;
	return (tp->t_ccstate->cub_target_win);
}
Esempio n. 4
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;          /* Loop index.         */
	int *a;         /* Array to be sorted. */
	uint64_t end;   /* End time.           */
	uint64_t start; /* Start time.         */
	
	readargs(argc, argv);
	
	timer_init();
	srandnum(seed);
	
	/* Benchmark initialization. */
	if (verbose)
		printf("initializing...\n");
	start = timer_get();
	a = smalloc(p->n*sizeof(int));
	for (i = 0; i < p->n; i++)
		a[i] = randnum() & 0xfffff;
	end = timer_get();
	if (verbose)
		printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);
	
	/* Cluster data. */
	if (verbose)
		printf("sorting...\n");
	start = timer_get();
	bucketsort(a, p->n);
	end = timer_get();

	total = timer_diff(start, end);

	/* Print timing statistics. */
	printf("timing statistics:\n");
	printf("  master:        %f\n", master*MICROSEC);
	for (i = 0; i < nclusters; i++)
		printf("  slave %d:      %f\n", i, slave[i]*MICROSEC);
	printf("  communication: %f\n", communication*MICROSEC);
	printf("  total time:    %f\n", total*MICROSEC);
	
	/* House keeping. */
	free(a);
	
	return (0);
}
Esempio n. 5
0
int timer_get_shortest(egg_timeval_t *howlong)
{
	egg_timer_t *timer = timer_repeat_head;

	/* No timers? Boo. */
	if (!timer) return(1);

	timer_diff(&now, &timer->trigger_time, howlong);
	return(0);
}
Esempio n. 6
0
/*
 * Asserts if another iteration is needed.
 */
static int again(void)
{
	int i;
	
	start = timer_get();
	
	/* Checks if another iteration is needed. */	
	for (i = 0; i < nprocs*NUM_THREADS; i++)
	{
		if (has_changed[i] && too_far[i])
		{
			end = timer_get();
			total += timer_diff(start, end);
			return (1);
		}
	}
	
	end = timer_get();
	total += timer_diff(start, end);
			
	return (0);
}
Esempio n. 7
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;          /* Loop index.      */
	int *map;       /* Map of clusters. */
	uint64_t end;   /* End time.        */
	uint64_t start; /* Start time.      */
	vector_t *data; /* Data points.     */
	
	readargs(argc, argv);
	printf("CAPBench - KM kernel\n");
	printf("  # of threads: %d \n", nthreads);
	
	timer_init();
	srandnum(seed);
	omp_set_num_threads(nthreads);
	
	/* Benchmark initialization. */
	start = timer_get();
	data = smalloc(p->npoints*sizeof(vector_t));
	for (i = 0; i < p->npoints; i++)
	{
		data[i] = vector_create(p->dimension);
		vector_random(data[i]);
	}
	end = timer_get();
	
	/* Cluster data. */
	printf("Entering in KM ROI - Clustering data...\n");
	start = timer_get();
	m5_reset_stats(0,0);
	map = kmeans(data, p->npoints, p->ncentroids, p->mindistance);
	end = timer_get();
	m5_dump_stats(0,0);
		
	printf("KM total time:    %f\n", timer_diff(start, end)*MICROSEC);
	
	/* House keeping. */
	free(map);
	for (i = 0; i < p->npoints; i++)
		vector_destroy(data[i]);
	free(data);
	
	return (0);
}
Esempio n. 8
0
static void test_basic(void)
{
  char buf[64];
  struct timespec ts = { .tv_sec = 0, .tv_nsec = 500000000 };
  timer *t = timer_new();

  info("Starting");
  timer_start(t);
  nanosleep(&ts, NULL);
  timer_stop(t);
  info("Diff: %s", timer_diff(t, buf, 64));
}


int main(int argc, char **argv)
{
  run_test("basic", &test_basic);

  return 0;
}
Esempio n. 9
0
/*
 * Populates clusters.
 */
static void populate(void)
{
	int i, j;        /* Loop indexes.       */
	float tmp;      /* Auxiliary variable. */
	float distance; /* Smallest distance.  */

	start = timer_get();
	memset(&too_far[rank*NUM_THREADS], 0, NUM_THREADS*sizeof(int)); 
	
	/* Iterate over data points. */
	#pragma omp parallel for schedule(static) default(shared) private(i, j, tmp, distance)
	for (i = 0; i < lnpoints; i++)
	{
		distance = vector_distance(CENTROID(map[i]), POINT(i));
		
		/* Look for closest cluster. */
		for (j = 0; j < ncentroids; j++)
		{
			/* Point is in this cluster. */
			if (j == map[i])
				continue;
				
			tmp = vector_distance(CENTROID(j), POINT(i));
			
			/* Found. */
			if (tmp < distance)
			{
				map[i] = j;
				distance = tmp;
			}
		}
		
		/* Cluster is too far away. */
		if (distance > mindistance)
			too_far[rank*NUM_THREADS + omp_get_thread_num()] = 1;
	}
	end = timer_get();
	total += timer_diff(start, end);
	
}
Esempio n. 10
0
/*
 * Computes clusters' centroids.
 */
static void compute_centroids(void)
{
	int i, j;       /* Loop indexes.        */
	int population; /* Centroid population. */

	start = timer_get();
	
	memcpy(lcentroids, CENTROID(rank*(ncentroids/nprocs)), lncentroids[rank]*dimension*sizeof(float));
	memset(&has_changed[rank*NUM_THREADS], 0, NUM_THREADS*sizeof(int));
	memset(centroids, 0, (ncentroids + DELTA*nprocs)*dimension*sizeof(float));
	memset(ppopulation, 0, (ncentroids + nprocs*DELTA)*sizeof(int));

	/* Compute partial centroids. */
	#pragma omp parallel for schedule(static) default(shared) private(i, j)
	for (i = 0; i < lnpoints; i++)
	{
		j = map[i]%NUM_THREADS;
		
		omp_set_lock(&lock[j]);
		
		vector_add(CENTROID(map[i]), POINT(i));
			
		ppopulation[map[i]]++;
		
		omp_unset_lock(&lock[j]);
	}
	
	end = timer_get();
	total += timer_diff(start, end);
	
	sync_pcentroids();

	sync_ppopulation();
	
	start = timer_get();

	/* Compute centroids. */
	#pragma omp parallel for schedule(static) default(shared) private(i, j, population)
	for (j = 0; j < lncentroids[rank]; j++)
	{
		population = 0;
		
		for (i = 0; i < nprocs; i++)
		{
			if (*POPULATION(i, j) == 0)
				continue;
			
			population += *POPULATION(i, j);
			
			if (i == rank)
				continue;
			
			vector_add(PCENTROID(rank, j), PCENTROID(i, j));
		}
		
		if (population > 1)
			vector_mult(PCENTROID(rank, j), 1.0/population);
		
		/* Cluster mean has changed. */
		if (!vector_equal(PCENTROID(rank, j), LCENTROID(j)))
		{
			has_changed[rank*NUM_THREADS + omp_get_thread_num()] = 1;
			vector_assign(LCENTROID(j), PCENTROID(rank, j));
		}
	}
	
	end = timer_get();
	total += timer_diff(start, end);
		
	sync_centroids();
		
	sync_status();
}
Esempio n. 11
0
/*
 * When a new ack with SACK is received, check if it indicates packet
 * reordering. If there is packet reordering, the socket is marked and
 * the late time offset by which the packet was reordered with
 * respect to its closest neighboring packets is computed.
 */
static void
tcp_sack_detect_reordering(struct tcpcb *tp, struct sackhole *s,
    tcp_seq sacked_seq, tcp_seq snd_fack)
{
	int32_t rext = 0, reordered = 0;

	/*
	 * If the SACK hole is past snd_fack, this is from new SACK
	 * information, so we can ignore it.
	 */
	if (SEQ_GT(s->end, snd_fack))
		return;
	/*
	 * If there has been a retransmit timeout, then the timestamp on 
	 * the SACK segment will be newer. This might lead to a
	 * false-positive. Avoid re-ordering detection in this case.
	 */
	if (tp->t_rxtshift > 0)
		return;

	/*
	 * Detect reordering from SACK information by checking
	 * if recently sacked data was never retransmitted from this hole.
	 */
	if (SEQ_LT(s->rxmit, sacked_seq)) {
		reordered = 1;
		tcpstat.tcps_avoid_rxmt++;
	}

	if (reordered) {
		if (tcp_detect_reordering == 1 &&
		    !(tp->t_flagsext & TF_PKTS_REORDERED)) {
			tp->t_flagsext |= TF_PKTS_REORDERED;
			tcpstat.tcps_detect_reordering++;
		}

		tcpstat.tcps_reordered_pkts++;
		tp->t_reordered_pkts++;

		/*
		 * If reordering is seen on a connection wth ECN enabled,
		 * increment the heuristic
		 */
		if (TCP_ECN_ENABLED(tp)) {
			INP_INC_IFNET_STAT(tp->t_inpcb, ecn_fallback_reorder);
			tcpstat.tcps_ecn_fallback_reorder++;
			tcp_heuristic_ecn_aggressive(tp);
		}

		VERIFY(SEQ_GEQ(snd_fack, s->rxmit));

		if (s->rxmit_start > 0) {
			rext = timer_diff(tcp_now, 0, s->rxmit_start, 0);
			if (rext < 0)
				return;

			/*
			 * We take the maximum reorder window to schedule
			 * DELAYFR timer as that will take care of jitter
			 * on the network path.
			 *
			 * Computing average and standard deviation seems
			 * to cause unnecessary retransmissions when there
			 * is high jitter.
			 *
			 * We set a maximum of SRTT/2 and a minimum of
			 * 10 ms on the reorder window.
			 */
			tp->t_reorderwin = max(tp->t_reorderwin, rext);
			tp->t_reorderwin = min(tp->t_reorderwin,
			    (tp->t_srtt >> (TCP_RTT_SHIFT - 1)));
			tp->t_reorderwin = max(tp->t_reorderwin, 10);
		}
	}
Esempio n. 12
0
/*
 * RT kernel.
 */
int main(int argc, char **argv)
{
    /* Number of spheres. */
#define NR_SPHERES 6

    int i;                        /* Loop index. */
    image_t img;                  /* Image.      */
    sphere_t spheres[NR_SPHERES]; /* Spheres.    */
    uint64_t end;                 /* End time.   */
    uint64_t start;               /* Start time. */

#ifdef _XEON_PHI_
    double power;
#endif

    readargs(argc, argv);

    timer_init();
    omp_set_num_threads(nthreads);

    /* Benchmark initialization. */
    if (verbose)
        printf("initializing...\n");
    start = timer_get();
    /* Ground sphere. */
    spheres[0] = sphere_create(
                     VECTOR(0, -10004, -20), /* Center         */
                     10000,                  /* Radius         */
                     VECTOR(0.2, 0.2, 0.2),  /* Surface Color  */
                     0,                      /* Reflection     */
                     0,                      /* Transparency   */
                     VECTOR(0, 0, 0));       /* Emission Color */

    /* Red sphere. */
    spheres[1] = sphere_create(
                     VECTOR(0, 0, -20),        /* Center         */
                     4,                        /* Radius         */
                     VECTOR(1.00, 0.32, 0.36), /* Surface Color  */
                     1,                        /* Reflection     */
                     0.5,                      /* Transparency   */
                     VECTOR(0, 0, 0));         /* Emission Color */

    /* Yellow sphere. */
    spheres[2] = sphere_create(
                     VECTOR(5, -1, -15),
                     2,
                     VECTOR(0.90, 0.76, 0.46),
                     1,
                     0.0,
                     VECTOR(0, 0, 0));

    /* Blue sphere. */
    spheres[3] = sphere_create(
                     VECTOR(5, 0, -25),
                     3,
                     VECTOR(0.65, 0.77, 0.97),
                     1,
                     0.0,
                     VECTOR(0, 0, 0));

    /* Gray sphere. */
    spheres[4] = sphere_create(
                     VECTOR(-5.5, 0, -15),
                     3,
                     VECTOR(0.90, 0.90, 0.90),
                     1,
                     0.0,
                     VECTOR(0, 0, 0));

    /* Light source. */
    spheres[5] = sphere_create(
                     VECTOR(0, 30, -30),
                     3,
                     VECTOR(0, 0, 0),
                     0,
                     0,
                     VECTOR(3, 3, 3));
    end = timer_get();
    if (verbose)
        printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);

#ifdef _XEON_PHI_
    power_init();
#endif

    /* Ray tracing. */
    if (verbose)
        printf("rendering scene...\n");
    start = timer_get();
    img = render(spheres, NR_SPHERES, p->height, p->width, p->depth);
    end = timer_get();

#ifdef _XEON_PHI_
    power = power_end();
#endif

    if (verbose)
        image_export("out.ppm", img, IMAGE_PPM);

    printf("timing statistics:\n");
    printf("  total time:    %f\n", timer_diff(start, end)*MICROSEC);

#ifdef _XEON_PHI_
    printf("  average power: %f\n", power*0.000001);
#endif

    /* Hous keeping. */
    for (i = 0; i < NR_SPHERES; i++)
        sphere_destroy(spheres[i]);
    image_destroy(img);

    return (EXIT_SUCCESS);
}
Esempio n. 13
0
int main(int argc, char **argv)
{
	Timer *render_timer;
	Sdl *sdl;
	FILE *out;
	Colour *buffer;
	Pixel *pixels;
	int num_pixels;

	SDL_Event event = {0};

	if (argc < 2)
		return 1;

	sdl = sdl_load(argv[1]);
	if (sdl == NULL)
		return 1;

	if (!init_SDL())
		return 1;

	num_pixels = config->width * config->height;
	buffer = calloc(num_pixels, sizeof(Colour));
	pixels = calloc(num_pixels, sizeof(Pixel));
	for (int j = 0; j < config->height; j++)
	for (int i = 0; i < config->width; i++)
	{
		pixels[j*config->width + i].x = i;
		pixels[j*config->width + i].y = j;
	}
	srand(time(NULL));
	shuffle_pixels(pixels, config->width, config->height);
	srand(0x20071208);

	/* START */
	render_timer = timer_start("Rendering");

	for (int i = 0; i < num_pixels; i++)
	{
		Camera *cam = scene->camera;
		Colour c;
		Ray r;
		int x = pixels[i].x, y = pixels[i].y;

		/* The last parameter is the near plane, which is irrelevant for
		 * the moment. */
		r = camera_ray(cam, x, y, 1);

		c = ray_colour(r, 0);

		buffer[config->width*y + x] = c;
		put_pixel(display_surface, x, y, c);
		if (i % config->width == 0)
		{
			SDL_Flip(display_surface);
			while (SDL_PollEvent(&event))
				if (event.type == SDL_QUIT)
					return 0;
		}
	}

	/* STOP */
	timer_stop(render_timer);
	timer_diff_print(render_timer);
	printf("%.2f kilopixels per second\n",
			num_pixels/1000./(timer_diff(render_timer)));

	out = fopen("ray.ppm", "w");
	ppm_write(buffer, config->width, config->height, out);
	free(buffer);
	fclose(out);

	SDL_Flip(display_surface);
	while(1)
	{
		while (SDL_WaitEvent(&event))
			if (event.type == SDL_QUIT)
				return 0;
			else if (event.type == SDL_VIDEOEXPOSE)
				SDL_Flip(display_surface);
	}

	return 0;
}
Esempio n. 14
0
/*
 * Bucket-sort algorithm.
 */
extern void bucketsort(int *array, int n)
{
	int max;                  /* Maximum number.      */
	int i, j;                 /* Loop indexes.        */
	int range;                /* Bucket range.        */
	struct minibucket *minib; /* Working mini-bucket. */
	struct message *msg;      /* Working message.     */
	struct bucket **todo;     /* Todo buckets.        */
	struct bucket **done;     /* Done buckets.        */
	uint64_t start, end;      /* Timers.              */
	
	/* Setup slaves. */
	open_noc_connectors();
	spawn_slaves();
	sync_slaves();
	
	todo = smalloc(NUM_BUCKETS*sizeof(struct bucket *));
	done = smalloc(NUM_BUCKETS*sizeof(struct bucket *));
	for (i = 0; i < NUM_BUCKETS; i++)
	{
		done[i] = bucket_create();
		todo[i] = bucket_create();
	}

	/* Find max number in the array. */
	start = timer_get();
	max = INT_MIN;
	for (i = 0; i < n; i++)
	{
		/* Found. */
		if (array[i] > max)
			max = array[i];
	}

	/* Distribute numbers. */
	range = max/NUM_BUCKETS;
	for (i = 0; i < n; i++)
	{
		j = array[i]/range;
		if (j >= NUM_BUCKETS)
			j = NUM_BUCKETS - 1;
		
		bucket_insert(&todo[j], array[i]);
	}
	end = timer_get();
	master += timer_diff(start, end);

	/* Sort buckets. */
	j = 0;
	for (i = 0; i < NUM_BUCKETS; i++)
	{	
		while (bucket_size(todo[i]) > 0)
		{
			minib = bucket_pop(todo[i]);
			
			/* Send message. */
			msg = message_create(SORTWORK, i, minib->size);
			message_send(outfd[j], msg);
			message_destroy(msg);
			
			/* Send data. */
			communication += 
				data_send(outfd[j], minib->elements, minib->size*sizeof(int));
			minibucket_destroy(minib);
			
			j++;
			
			/* 
			 * Slave processes are busy.
			 * So let's wait for results.
			 */
			if (j == nclusters)
			{	
				/* Receive results. */
				for (/* NOOP */ ; j > 0; j--)
				{					
					/* Receive message. */
					msg = message_receive(infd[nclusters - j]);
					
					/* Receive mini-bucket. */
					minib = minibucket_create();
					minib->size = msg->u.sortresult.size;
					communication += data_receive(infd[nclusters -j], minib->elements, 
													minib->size*sizeof(int));
					
					bucket_push(done[msg->u.sortresult.id], minib);
					
					message_destroy(msg);
				}
			}
		}
	}

	/* Receive results. */
	for (/* NOOP */ ; j > 0; j--)
	{						
		/* Receive message. */
		msg = message_receive(infd[j - 1]);
					
		/* Receive bucket. */
		minib = minibucket_create();
		minib->size = msg->u.sortresult.size;
		communication += 
			data_receive(infd[j - 1], minib->elements, minib->size*sizeof(int));
					
		bucket_push(done[msg->u.sortresult.id], minib);
					
		message_destroy(msg);
	}

	start = timer_get();
	rebuild_array(done, array);
	end = timer_get();
	master += timer_diff(start, end);
	
	/* House keeping. */
	for (i = 0; i < NUM_BUCKETS; i++)
	{
		bucket_destroy(todo[i]);
		bucket_destroy(done[i]);
	}
	free(done);
	free(todo);
	join_slaves();
	close_noc_connectors();
}
Esempio n. 15
0
/*
 * Runs benchmark.
 */
int main(int argc, char **argv)
{
	int i;              /* Loop index.            */
	int *mask;       	/* Mask.                  */
	uint64_t end;       /* End time.              */
	uint64_t start;     /* Start time.            */
	char *img; 			/* Image.                 */
	int numcorners=0;	/* Total corners detected */
	
#ifdef _XEON_PHI_
	double power;
#endif	
	
	readargs(argc, argv);
	
	timer_init();
	srandnum(seed);
	omp_set_num_threads(nthreads);
	
	/* Benchmark initialization. */
	if (verbose)
		printf("initializing...\n");
	start = timer_get();
	img = smalloc(p->imgsize*p->imgsize*sizeof(char));
	for (i = 0; i < p->imgsize*p->imgsize; i++){
		char val = randnum() & 0xff;
		img[i] = (val>0) ? val : val*(-1);
	}	
	mask = smalloc(p->maskrows*p->maskcolumns*sizeof(int));
	generate_mask(mask);
	end = timer_get();
	if (verbose)
		printf("  time spent: %f\n", timer_diff(start, end)*MICROSEC);
	
#ifdef _XEON_PHI_
	power_init();
#endif		
		
	/* Detect corners. */
	if (verbose)
		printf("detecting corners...\n");
	start = timer_get();
	numcorners = fast(img, p->imgsize, mask);
	end = timer_get();
	
#ifdef _XEON_PHI_
	power = power_end();
#endif

	printf("timing statistics:\n");
	printf("  total time:       %f\n", timer_diff(start, end)*MICROSEC);

#ifdef _XEON_PHI_
	printf("  average power: %f\n", power*0.000001);
#endif

	printf("  corners detected: %d\n", numcorners);
	
	/* House keeping. */
	free(mask);
	free(img);
	
	return (0);
}
Esempio n. 16
0
//-----------------------------------------------------------------
// usb_control_send: Perform a transfer via IN
//-----------------------------------------------------------------
int usb_control_send(unsigned char *buf, int size)
{
	t_time tS;
	int send;
	int remain;
	int count = 0;
    int err = 0;

    log_printf(USBLOG_SETUP_IN, "USB: usb_control_send %d\n", size);

    // Loop until partial packet sent
    do
	{
		remain = size - count;
		send = MIN(remain, EP0_MAX_PACKET_SIZE);

        log_printf(USBLOG_SETUP_IN_DBG, " Remain %d, Send %d\n", remain, send);

		usbhw_load_tx_buffer(ENDPOINT_CONTROL, buf, (unsigned char) send);

		buf += send;
		count += send;

        log_printf(USBLOG_SETUP_IN_DBG, " Sent %d, Remain %d\n", send, (size - count));

		tS = timer_now();
		while ( !usbhw_has_tx_space( ENDPOINT_CONTROL ) )
		{
            if (timer_diff(timer_now(), tS) > USB_CTRL_TX_TIMEOUT)
			{
                log_printf(USBLOG_ERR, "USB: Timeout sending IN data\n");
                err = 1;
				break;
			}            
		}
	}
    while (send >= EP0_MAX_PACKET_SIZE);

    if (!err)
    {
        log_printf(USBLOG_SETUP_IN, "USB: Sent total %d\n", count);

	    // Wait for ACK from host
	    tS = timer_now();
	    do
        {
            if (timer_diff(timer_now(), tS) > USB_CTRL_TX_TIMEOUT)
		    {
			    log_printf(USBLOG_ERR, "USB: ACK not received\n");
                err = 1;
			    break;
		    }
	    } 
        while (!usbhw_is_rx_ready(ENDPOINT_CONTROL));

        usbhw_clear_rx_ready(ENDPOINT_CONTROL);

        if (!err)
        {
            log_printf(USBLOG_SETUP_IN, "USB: ACK received\n");
        }
    }

    return !err;
}