Пример #1
0
int do_waitpid(int pid, int *status, int options)
{
	struct s_task* ptask;
	int retpid;

	if (pid < -1 || pid == 0)
		return -EINVAL;

	if(pid > 0)
	{
		ptask = task_struct_find(pid);
		if(ptask)
		{
			if(current != ptask->father)
				return -ECHILD;
			if(options&WNOHANG &&
			   ptask->state != TASK_STAT_DIE)
				return 0;
			while(ptask->state != TASK_STAT_DIE)
			{
				task_set_block(current);
				task_sched();
			}
			goto recycle;
		}
	}
	if(pid == -1)
	{
	redo:
		for_each_task(ptask)
		{
			if(current != ptask->father)
				continue;
			if(ptask->state == TASK_STAT_DIE)
				goto recycle;
		}
		if(options&WNOHANG)
			return 0;
		else
		{
			task_set_block(current);
			task_sched();
			goto redo;
		}
	}
Пример #2
0
//----------------------------------------------------------------------------
// Function:
//      void task02()
//
// Description:
//		向console打印信息,之后将任务控制权交给task01。
//
// Parameters:
//      n/a
//
// Return Value:
//      n/a
//
void task02()
{ 

	putstr("Enter task02\n");	
		
	while (1)
	{
		putstr("This is task02!\n");	
		task_sched();
	}

}
Пример #3
0
int optPFRPAsync::sched(taskset *_ts)
{
	ts = _ts;

	int num_tasks = ts->num_task;
	int i;
	int endstate;
	
	g_stat->start_stat(); // start clocking	

	// a neccessary condition check: no execution time can greater than any deadline(only in sync release?)
	if(pconfig->useoffset == true)
	{
		bool found = false;
		task *t1, *t2, *t=NULL;
		int j, r=0;
		for(i=ts->num_task-1; i>0; i--)
		{
			t1 = ts->tq[i];
			for(j=0; j<i; j++)
			{
				t2 = ts->tq[j];
				if(t1->c >= t2->d)
				{
					t = t1;
					r = i;
				}
				else if(t2->c >= t1->d)
				{
					t = t2;
					r = j;
				}
				else
					continue;
				found = true;
				goto _pre_check_done;
			}
		}
_pre_check_done:
		if(found)
		{
			ts->state = TS_STATE_UNSCHED;
			ts->failedTask = t->name;
			ts->failed_task = r;
			g_stat->end_stat(ts); // stop clocking	
			return ts->state;
		}
	}

	// a simple memory check
	if(pconfig->merge == false)
	{
		INT64 cc = 0;
		for(i=0; i<num_tasks; i++)
			cc += ts->LCMs[num_tasks-2]/ts->tq[i]->p;
		if(g_mymem->num_remains < cc)
		{
			cout << "Too many nodes <needed:remains>: <" << cc << ":" << g_mymem->num_remains << ">" << endl;
			ts->state = TS_STATE_INSUFMEM;
			g_stat->end_stat(ts); // stop clocking	
			return ts->state;
		}
	}

	// sched task 0
	task *t ;
	t = ts->tq[0];
	int tc, toffset;
	tc=t->c, toffset=t->offset;
	attach_node(list_head, NULL, toffset, toffset+tc, pconfig->merge, TS_ACTION_DONE, 0);// no way to fail...
	ts->num_nodes_used[0]++;
	ts->estimateWcrt[0] = tc;
	ts->realWcrt[0] = tc;
	ts->wcrt_job[0] = 0;

	int k; // task k
	endstate = TS_STATE_UNSCHED;
	for(k=1; k<num_tasks-1; k++) // task 0 is scheduled already
	{
		// no sufficient test
		if(mode == 1)
		{
			endstate = task_sched(k); // exact test
			ts->num_nodes_used[k] = list_head->number_of_nodes;
		}
		else
		{
			endstate = process_permissibility_intervals(k); 
			if(endstate == TS_STATE_UNKNOWN)
			{
				endstate = task_sched(k); // exact test
				ts->num_nodes_used[k] = list_head->number_of_nodes;
			}
		}
		if(endstate != TS_STATE_SCHEDED)// cease scheduling
			break;
	}

	// last task
	if(k == num_tasks-1)
	{
		// no sufficient test
		if(mode == 1)
		{
			//endstate = task_sched(k); // exact test
			endstate = task_simulate(k); // exact test
			ts->num_nodes_used[k] = list_head->number_of_nodes;
		}
		else
		{
			endstate = process_permissibility_intervals(k); 
			if(endstate == TS_STATE_UNKNOWN)
			{
				//endstate = task_sched(k); // exact test
				endstate = task_simulate(k); // exact test
				ts->num_nodes_used[k] = list_head->number_of_nodes;
			}
		}
	}

	if(endstate != TS_STATE_SCHEDED)
	{
		ts->failed_task = k;
		ts->failedTask = ts->tq[k]->name;
	}

	ts->state = endstate;
	g_stat->end_stat(ts); // stop clocking
	
	return endstate;
}