Ejemplo n.º 1
0
/* ______________________________________________________________________ */
int
main( )
{
	int privity_err;
	uintptr_t ctrl_handle_portC;
	uintptr_t ctrl_handle_portB;
	uintptr_t ctrl_handle_portCTL;

    struct timespec my_timer_value;
    my_timer_value.tv_nsec = 100000000;


	/* Give this thread root permissions to access the hardware */
	privity_err = ThreadCtl( _NTO_TCTL_IO, NULL );
	if ( privity_err == -1 )
	{
		fprintf( stderr, "can't get root permissions\n" );
		return -1;
	}

	/* Get a handle to the DIO port's Control register */
	//ctrl_handle_portA = mmap_device_io( PORT_LENGTH, DIO_BASE_ADDR + 0x08 );
	ctrl_handle_portB = mmap_device_io( PORT_LENGTH, DIO_BASE_ADDR + DIO_PORTB_ADDR);
	ctrl_handle_portCTL = mmap_device_io( PORT_LENGTH, DIO_BASE_ADDR + DIO_CTL_ADDR);

	/* Initialise the DIO port */
	out8( ctrl_handle_portCTL, 0x00 );
	//out8( ctrl_handle_portA, ENABLE_IN );
	//out8( ctrl_handle_portB, ENABLE_OUT );


	for (;;)
	{
		//out8( ctrl_handle_portB, HIGH );
		out8( ctrl_handle_portB, HIGH );
		nanospin( &my_timer_value );
		//out8( ctrl_handle_portB, LOW );
		out8( ctrl_handle_portB, LOW );
		nanospin( &my_timer_value );
	}

	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[]) {
	int privity_err;
	uintptr_t ctrl_handle;
	uintptr_t data_handle;
	int count;

	struct timespec my_timer_value;
    my_timer_value.tv_nsec = 500000;

	/* Give this thread root permissions to access the hardware */
	privity_err = ThreadCtl( _NTO_TCTL_IO, NULL );
	if ( privity_err == -1 )
	{
		fprintf( stderr, "can't get root permissions\n" );
		return -1;
	}

	/* Get a handle to the parallel port's Control register */
	ctrl_handle = mmap_device_io( PORT_LENGTH, CTRL_ADDRESS );
	/* Initialise the parallel port */
	out8( ctrl_handle, INIT_BIT );

	/* Get a handle to the parallel port's Data register */
	data_handle = mmap_device_io( PORT_LENGTH, DATA_ADDRESS );

	while(1)
	{
		/* Output a byte of lows to the data lines */
		out8( data_handle, HIGH );
		nanospin( &my_timer_value );

		/* Output a byte of highs to the data lines */
		out8( data_handle, LOW );
		nanospin( &my_timer_value );
	}

	return 0;
}
Ejemplo n.º 3
0
/**
 * The start routine that is executed when the client calls start().
 */
void* Task::startRoutine()
{
	int result;
	uint64_t preStartCycleTime = 0;
	uint64_t preEndCycleTime = 0;
	uint64_t startCycleTime = 0;
	uint64_t endCycleTime = 0;
	uint64_t postEndCycleTime = 0;

	// Set up some flags used to control task execution
	bool firstRun = true;
	computeComplete = 1;
	testRunning = true;
	preempted = false;
	firstTimerRun = true;

	// Reset the current compute time for this test
	currentComputeTime = 0;

	// Wait until we are released (a test begins)
	sem_wait(&sem);

	// Create the timer and kick it off
	timer_create(CLOCK_REALTIME, &event, &timerID);
	timer_settime(timerID, 0, &timerSpec, NULL);
	sem_post(&proxySem);

	// Intermittent wait that is used to make sure every task's timer is started
	sem_wait(&sem);

	// Jump into the test loop where the task will iteratively execute
	// compute cycles when it is scheduled
	while (testRunning)
	{
		// Block on execution semaphore (only after the first cycle)
		if (!firstRun)
		{
			sem_wait(&sem);
			preempted = false;
		}
		else
		{
			firstRun = false;
		}

		// Log pre-compute cycles
		preEndCycleTime = 0;
		preStartCycleTime = ClockCycles();

		// Log the schedule event
		TraceEvent(_NTO_TRACE_INSERTSUSEREVENT, EVENT_SCHEDULE, EVENT_SCHEDULE, uid);
		scheduleList.push_back(uid);

		// Begin/resume the compute cycle.
		while (currentComputeTime < (computeTime * NS_PER_MS))
		{
			if (!preempted)
			{
				// Record start compute time jitter
				if (preEndCycleTime == 0)
				{
					preEndCycleTime = ClockCycles();
				}

				// Burn and churn.
				startCycleTime = ClockCycles();
				result = nanospin(&burnTime);
				endCycleTime = ClockCycles();

				// Preemption means that nanospin took longer than expected, so handle that case.
				if (!preempted)
				{
					realComputeTime += (endCycleTime - startCycleTime);
				}
				else
				{
					realComputeTime += TIME_QUANTUM; // unavoidable
				}

				// Check the nanospin return, just to be safe.
				if (result == 0)
				{
					// We're okay - bump up the compute time.
					currentComputeTime += TIME_QUANTUM;
					totalComputationTime += TIME_QUANTUM;
				}
				else
				{
					cout << "Error: Task " << uid << " nanospin() returned: " << result << endl;
				}
			}
			else
			{
				break; // Drop back to the execution semaphore.
			}
		}

		// Check for deadline being hit
		if (currentComputeTime >= (computeTime * NS_PER_MS))
		{
			// Update the new deadline and reset the compute time
			currentComputeTime = 0;
			computeComplete--;
			totalComputationCycles++;
		}

		// Log post compute time cycles
		postEndCycleTime = ClockCycles();
		computeTransitionTime += ((postEndCycleTime - endCycleTime) +
				(preEndCycleTime - preStartCycleTime));

		// Give up the CPU for other tasks to execute
		sched_yield();
	}

	// Suicide
	kill();

	// Delete the timer for the period - no longer needed
	timer_delete(timerID);
}
Ejemplo n.º 4
0
Archivo: pg3.c Proyecto: 2mac/iputils
static void pg_inject(void)
{
	u32 saddr;
	struct net_device *odev;
	struct sk_buff *skb;
	struct timeval start, stop;
	u32 total, idle;
	int pc, lcount;

	odev = pg_setup_inject(&saddr);
	if (!odev)
		return;

	skb = fill_packet(odev, saddr);
	if (skb == NULL)
		goto out_reldev;

	forced_stop = 0;
	idle_acc_hi = 0;
	idle_acc_lo = 0;
	pc = 0;
	lcount = pg_count;
	do_gettimeofday(&start);

	for(;;) {
		spin_lock_bh(&odev->xmit_lock);
		atomic_inc(&skb->users);
		if (!netif_queue_stopped(odev)) {
			if (odev->hard_start_xmit(skb, odev)) {
				kfree_skb(skb);
				if (net_ratelimit())
					printk(KERN_INFO "Hard xmit error\n");
			}
			pc++;
		} else {
			kfree_skb(skb);
		}
		spin_unlock_bh(&odev->xmit_lock);

		if (pg_ipg)
			nanospin(pg_ipg);
		if (forced_stop)
			goto out_intr;
		if (signal_pending(current))
			goto out_intr;

		if (--lcount == 0) {
			if (atomic_read(&skb->users) != 1) {
				u32 idle_start, idle;

				idle_start = get_cycles();
				while (atomic_read(&skb->users) != 1) {
					if (signal_pending(current))
						goto out_intr;
					schedule();
				}
				idle = get_cycles() - idle_start;
				idle_acc_lo += idle;
				if (idle_acc_lo < idle)
					idle_acc_hi++;
			}
			break;
		}

		if (netif_queue_stopped(odev) || current->need_resched) {
			u32 idle_start, idle;

			idle_start = get_cycles();
			do {
				if (signal_pending(current))
					goto out_intr;
				if (!netif_running(odev))
					goto out_intr;
				if (current->need_resched)
					schedule();
				else
					do_softirq();
			} while (netif_queue_stopped(odev));
			idle = get_cycles() - idle_start;
			idle_acc_lo += idle;
			if (idle_acc_lo < idle)
				idle_acc_hi++;
		}
	}

	do_gettimeofday(&stop);

	total = (stop.tv_sec - start.tv_sec)*1000000 +
		stop.tv_usec - start.tv_usec;

	idle = (((idle_acc_hi<<20)/pg_cpu_speed)<<12)+idle_acc_lo/pg_cpu_speed;

	if (1) {
		char *p = pg_result;

		p += sprintf(p, "OK: %u(c%u+d%u) usec, %u (%dbyte,%dfrags) %upps %uMB/sec",
			     total, total-idle, idle,
			     pc, skb->len, skb_shinfo(skb)->nr_frags,
			     ((pc*1000)/(total/1000)),
			     (((pc*1000)/(total/1000))*pkt_size)/1024/1024
			     );
	}

out_relskb:
	kfree_skb(skb);
out_reldev:
	dev_put(odev);
	return;

out_intr:
	sprintf(pg_result, "Interrupted");
	goto out_relskb;
}