예제 #1
0
/**
	Initalizes the scheduler.
 
	Assumptions:
		- You may assume this will be the first scheduler function called.
		- You may assume this function will be called only once.
		- You may assume that cores is a positive, non-zero number.
		- You may assume that scheme is a valid scheduling scheme.
	@param num_cores	the number of cores that is available by the scheduler. These cores will be known as core(id=0), core(id=1), ..., core(id=cores-1).
	@param scheme	the scheduling scheme that should be used. This value will be one of the six enum values of scheme_t
*/
void scheduler_start_up(int num_cores, scheme_t scheme)
{
	jobs = (priqueue_t*)malloc(sizeof(priqueue_t));
	sch_type = scheme;
	priqueue_init(jobs,&sch_time);
	inc_time(0);

	create_core(&cores,num_cores);
}//scheduler_start_up
예제 #2
0
void messages_counter::merge( const time_counter_t& second_counter )
{
	for( time_counter_t::const_iterator it = second_counter.begin();
		 it != second_counter.end();
		 ++it )
	{
		const uint32_t message_type = it->first;
		const uint32_t message_number = it->second;

		add_count( message_type, message_number );
		inc_time( it->first );
	}
}
예제 #3
0
int Widget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: inclineChanged((*reinterpret_cast< double(*)>(_a[1])),(*reinterpret_cast< double(*)>(_a[2]))); break;
        case 1: inc_time((*reinterpret_cast< double(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
예제 #4
0
/**
	When the scheme is set to RR, called when the quantum timer has expired
	on a core.
 
	If any job should be scheduled to run on the core free'd up by
	the quantum expiration, return the job_number of the job that should be
	scheduled to run on core core_id.
	@param core_id the zero-based index of the core where the quantum has expired.
	@param time the current time of the simulator. 
	@return job_number of the job that should be scheduled on core cord_id
	@return -1 if core should remain idle
 */
int scheduler_quantum_expired(int core_id, int time)
{
	// Increment Time
	inc_time(time);

	// Process quantumn rollover
	delete_job(core_id,cores.jobs[core_id]->jid);
	
	// Schedule new job
	job_t* p = priqueue_poll(jobs);
	if ( p != NULL )
	{
		insert_job(core_id,p);
		return p->jid;
	}//if
	return -1;
}//scheduler_quantum_expired
예제 #5
0
/**
	Called when a job has completed execution.
 
	The core_id, job_number and time parameters are provided for convenience. You may be able to calculate the values with your own data structure.
	If any job should be scheduled to run on the core free'd up by the
	finished job, return the job_number of the job that should be scheduled to
	run on core core_id.
 
	@param core_id the zero-based index of the core where the job was located.
	@param job_number a globally unique identification number of the job.
	@param time the current time of the simulator.
	@return job_number of the job that should be scheduled to run on core core_id
	@return -1 if core should remain idle.
 */
int scheduler_job_finished(int core_id, int job_number, int time)
{
	// Increment Time
	inc_time(time);

	// Process job termination
	job_t* p = delete_job(core_id,job_number);
	priqueue_remove(jobs,p);
	inc_wait(cur_t - p->arr_t - p->run_t);
	inc_turn(cur_t - p->arr_t);
	free_job(p);
	
	// Schedule new job
	p = priqueue_poll(jobs);
	if ( p != NULL )
	{
		insert_job(core_id,p);
		return p->jid;
	}//if
	return -1;
}//scheduler_job_finished
예제 #6
0
/**
	Called when a new job arrives.
 
	If multiple cores are idle, the job should be assigned to the core with the
	lowest id.
	If the job arriving should be scheduled to run during the next
	time cycle, return the zero-based index of the core the job should be
	scheduled on. If another job is already running on the core specified,
	this will preempt the currently running job.
	Assumptions:
		- You may assume that every job wil have a unique arrival time.
	@param job_number a globally unique identification number of the job arriving.
	@param time the current time of the simulator.
	@param running_time the total number of time units this job will run before it will be finished.
	@param priority the priority of the job. (The lower the value, the higher the priority.)
	@return index of core job should be scheduled on
	@return -1 if no scheduling changes should be made. 
 
 */
int scheduler_new_job(int job_number, int time, int running_time, int priority)
{
	int i;
	inc_time(time);
	job_t* job = create_job(job_number, time, running_time, priority);

	if ( (i = get_core()) != -1 )
	{
		insert_job(i,job);
		return i;
	}//if
	else if ( is_prempt() )
	{
		i = preempt(job);
		if ( i == -1 )
			priqueue_offer(jobs,job);
		return i;
	}//else if
	priqueue_offer(jobs,job);
	return -1;
}//scheduler_new_job