Beispiel #1
0
void* thread(void *args)
{
    struct timespec ts1,ts2,ts3;
    int i;  


    gettime(&ts1);

#ifdef USE_SCHED_CPU
    rt_init(); 
    rt_set_period(period);
    rt_set_deadline(period);// if period = deadline, don't call "rt_set_deadline"
    rt_set_runtime(runtime);

#endif

    cuda_test_madd(1000, ".", prio);
    
    gettime(&ts2);

   // pthread_mutex_lock(&mutex);
   // printf("%ld,",timespec_to_ns_sub(&ts1,&ts2));
   // pthread_mutex_unlock(&mutex);
    return NULL;
}
Beispiel #2
0
void exec_task(task_t *task, int loop_1ms, int simtime)
{
	int k; /* do not use i! */
	int nr_jobs = simtime / task->T;
	struct timeval tv, tv_C, tv_T, tv_D, tv_timeout;
	int ret = RET_SUCCESS;

	msecs_to_timeval(task->C, tv_C);
	msecs_to_timeval(task->T, tv_T);
	msecs_to_timeval(task->D, tv_D);
	msecs_to_timeval(DEFAULT_TIMEOUT, tv_timeout);

	/* get own PID. */
	task->pid = getpid();

	/* initialization for using RESCH. */
	if (!rt_init()) {
		printf("Error: cannot begin!\n");
		ret = RET_MISS;
		goto out;
	} 

	xcpu_flag = 0;
	rt_set_priority(task->prio);
	rt_set_wcet(&tv_C); 
	rt_set_period(&tv_T);		
	rt_set_deadline(&tv_D);	
	rt_reserve_cpu(&tv_C, xcpu_handler);
	rt_run(&tv_timeout);

	/* busy loop. */
	for (k = 0; k < nr_jobs; k++) {
		while (!xcpu_flag) {
			gettimeofday(&tv, NULL);
		}
		if (!rt_wait_for_period()) {
			ret = RET_MISS;
			break;
		}
		xcpu_flag = 0;
	}

	rt_exit();
 out:
	/* call _exit() but not exit(), since exit() may remove resources
	   that are shared with the parent and other child processes. */
	_exit(ret);

	/* no return. */
}
void *init_task(void *arg)
{
	RT_TASK *Task;
	struct thread_param *config = (struct thread_param*) arg;
	int idTask = config->idTask;
	unsigned long pidTask = 0;
	unsigned int cpuFrequencyAtual = 0; // KHz

	RTIME Tinicio;
	RTIME Tperiodo = 0; // unidade -> counts
	double Tperiodo_s = 0.0;
	int prioridade = config->prioridade;

//	clock_t begin, end;
//	double time_spent;

	struct timeval  tv1, tv2;

	if(!(Task = rt_thread_init(idTask, prioridade, 0, SCHED_FIFO, CPU_ALLOWED)))
	{
		printf("[ERRO] Não foi possível criar a tarefa [%d].\n", idTask);
		exit(1);
	}

	Tinicio = start_timeline;
	Tperiodo = config->periodo;
	Tperiodo_s = count2nano(Tperiodo)/1000000000.0;

	rt_allow_nonroot_hrt();
	rt_task_make_periodic(Task, Tinicio, Tperiodo);
	rt_change_prio(Task, prioridade);
	if(config->deadline > 0)
		rt_set_deadline(Task, config->deadline);

	pidTask = rt_cfg_get_pid(Task);
	printf("[TASK %2d] [%lu] Criada com Sucesso  =============== PERIODO => %llu count => %.2f segundos \n", idTask, pidTask, Tperiodo, Tperiodo_s);

	cpuFrequencyAtual = rt_cfg_cpufreq_get(CPUID_RTAI);
	printf("[TASK %2d] [%lu] Curr Freq: %8d Khz\n", idTask, pidTask, cpuFrequencyAtual);

	//TODO: TEMPO DE COMPUTACAO - OPCAO 1
//	begin = clock();
//	rt_cfg_set_cpu_frequency(Task, (int) config->cpuFrequencyMin);
//	end = clock();
//
//	time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
//	printf("[TASK %2d] [%lu] SET_FREQUENCY(%8d Khz);\n", idTask, pidTask, config->cpuFrequencyMin);
//	cpuFrequencyAtual = rt_cfg_cpufreq_get(CPUID_RTAI);
//	printf("[TASK %2d] [%lu] Curr Freq: %8d Khz\n", idTask, pidTask, cpuFrequencyAtual);
//	printf("[TASK %2d] [%lu] TEMPO DE COMPUTACAO SET FREQUENCY - USERSPACE => %.100f segundos\n", idTask, pidTask, time_spent);

	//TODO: TEMPO DE COMPUTACAO - OPCAO 2
	gettimeofday(&tv1, NULL);
	rt_cfg_set_cpu_frequency(Task, (int) config->cpuFrequencyMin);
	gettimeofday(&tv2, NULL);

	printf("[TASK %2d] [%lu] SET_FREQUENCY(%8d Khz);\n", idTask, pidTask, config->cpuFrequencyMin);
	cpuFrequencyAtual = rt_cfg_cpufreq_get(CPUID_RTAI);
	printf("[TASK %2d] [%lu] Curr Freq: %8d Khz\n", idTask, pidTask, cpuFrequencyAtual);
	printf("[TASK %2d] [%lu] TEMPO DE COMPUTACAO SET FREQUENCY - USERSPACE => %.50f segundos\n", idTask, pidTask, (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
	         (double) (tv2.tv_sec - tv1.tv_sec));
	rt_task_delete(Task);

	return 0;
}