Exemple #1
0
/**
 * @brief Dynamic scheduler.
 * 
 * @param running Target queue of running threads.
 * @param t       Target thread
 * 
 * @returns Number scheduled tasks,
 */
int scheduler_dynamic_sched(dqueue_tt running, thread_tt t)
{
	int chunksize; /* Number of tasks scheduled. */
	int wsize;     /* Size of assigned work.     */
	int ntasks;    /* Number of tasks.           */

	ntasks = workload_ntasks(scheddata.workload);

	/* Done. */
	if (scheddata.i0 == ntasks)
		return (0);

	nchunks++;

	/* Comput chunksize. */
	chunksize = scheddata.chunksize;
	if (chunksize > (ntasks - scheddata.i0))
		chunksize = ntasks - scheddata.i0;

	/* Schedule tasks. */
	wsize = 0;
	for (int i = scheddata.i0; i < scheddata.i0 + chunksize; i++)
	{
		wsize += workload_task(scheddata.workload, i);
		thread_assign(t, workload_task(scheddata.workload, i));
	}
	
	/* Update scheduler data. */
	scheddata.i0 += chunksize;

	dqueue_insert(running, t, wsize);

	return (chunksize);
}
Exemple #2
0
/**
 * @brief Guided scheduler.
 * 
 * @param running Target queue of running threads.
 * @param t       Target thread
 * 
 * @returns Number scheduled tasks,
 */
int scheduler_guided_sched(dqueue_tt running, thread_tt t)
{
	int chunksize; /* Number of tasks scheduled. */
	int wsize;     /* Size of assigned work.     */
	int ntasks;    /* Number of tasks.           */
	int nthreads;  /* Number of hteads.          */

	ntasks = workload_ntasks(scheddata.workload);

	/* Done. */
	if (scheddata.i0 == ntasks)
		return (0);

	nchunks++;

	nthreads = array_size(scheddata.threads);

	/* Compute chunksize. */
	chunksize = (ntasks - scheddata.i0)/(2*nthreads);
	if (chunksize < scheddata.chunksize)
		chunksize = scheddata.chunksize;
	if (chunksize > ntasks - scheddata.i0)
		chunksize = ntasks - scheddata.i0;

	/* Schedule iterations. */
	wsize = 0;
	for (int i = scheddata.i0; i < (scheddata.i0 + chunksize); i++)
	{
		wsize += workload_task(scheddata.workload, i);
		thread_assign(t, workload_task(scheddata.workload, i));
	}

	/* Update schedule data. */
	scheddata.i0 += chunksize;	
	
	dqueue_insert(running, t, wsize);

	return (chunksize);
}
Exemple #3
0
/*
 *	thread_assign_default:
 *
 *	Special version of thread_assign for assigning threads to default
 *	processor set.
 */
kern_return_t
thread_assign_default(
	thread_t		thread)
{
	return (thread_assign(thread, &pset0));
}