Exemplo n.º 1
0
//Start tracking a CPU burst
int
sys_start_burst(void)
{
	//get current system time tick
	uint xticks = sys_uptime();

	//keep track of current tick as burst start
	proc->burstStart = xticks;

	return xticks;
}
Exemplo n.º 2
0
// lab1-2
int
sys_lottery(void)
{
    struct tstat *dist[NPROC] = {};

    getdistribution(*dist);

    cprintf("ticks: %d\n", sys_uptime());
    //for(int x;x<NPROC;x++) {
    //  cprintf("%s|%d|%d|%d\n", dist[x]->name, dist[x]->pid, dist[x]->totaltickets, dist[x]->numexecuted);
    //}

    return 0;
}
Exemplo n.º 3
0
//End tracking a CPU burst
int
sys_end_burst(void)
{
	//get current system time tick
	uint xticks = sys_uptime();

	//calculate cpu burst
	int burst = xticks - proc->burstStart;
	if (burst == 0) return 0;

	//store the burst into array
	int size = sizeof(proc->bursts) / sizeof(int);
	proc->bursts[proc->burstIdx++ % size] = burst;

	return burst;
}
Exemplo n.º 4
0
//Print all CPU burst of a process
int
sys_print_bursts(void)
{
	int idx = proc->burstIdx;
	if (idx <= 0) {
		cprintf("There is no CPU bursts yet.\r\n");
		return 0;
	}

	int size = sizeof(proc->bursts) / sizeof(int);
	int i;
	for (i = 0; i < idx; i++) {
		cprintf("%d, ", proc->bursts[i % size]);
	}

	/* Machine Problem 1.3: Modifying the Scheduler */
	int turnaround = sys_uptime() - proc->creationTime;
	cprintf("Turnaround time: %d\r\n", turnaround);

	return idx;
}