Beispiel #1
0
int __init hello_init(void)
{
	RTIME sampling;

	rt_printk(KERN_INFO "TESTE - *************************** INICIO *******************************\n");

	rt_task_init(&Task_1, signalIchi, 0, 3000, 0, 0, NULL);
	rt_task_init(&Task_2,   signalNi, 0, 3000, 0, 0, NULL);
	rt_task_init(&Task_3,  signalSan, 0, 3000, 0, 0, NULL);

	sampling = start_rt_timer(nano2count(TICK));

	rt_sem_init(&rMutex, 1);

	rt_task_make_periodic(&Task_1, rt_get_time() + sampling * 16, sampling * 16);
	rt_task_make_periodic(&Task_2, rt_get_time() + sampling * 18, sampling * 18);
	rt_task_make_periodic(&Task_3, rt_get_time() + sampling * 30, sampling * 30);

	rt_change_prio(&Task_1, 2);
	rt_change_prio(&Task_2, 1);
	rt_change_prio(&Task_3, 3);

	rt_printk(KERN_INFO "Init module function\n");
	return 0;
}
Beispiel #2
0
void *signalSan(void *arg)
{
	RT_TASK *Task_3;

	unsigned long Task_3_name = nam2num("TSK_3") + i++;
	time_t aclock;
	time_t clockNow;
	int timeEx, begin_3;
	int count = 0;
	struct tm *newtime;

	Task_3 = rt_task_init(Task_3_name, 0, 0, 0);

//	if(!(Task_3 = rt_task_init_schmod(Task_3_name,3,0,0,SCHED_FIFO,1))) {
//		printf("CANNOT INIT HANDLER TASK > Task 3 <\n");
//		exit(1);
//	}
	rt_allow_nonroot_hrt();

        rt_make_hard_real_time();

	rt_task_make_periodic(Task_3, rt_get_time(), sampling * 30);
	rt_change_prio(Task_3, 3);

	begin_3 = begin;
	while (count < 20) {
		rt_sem_wait(rMutex);
		time(&aclock); // Pega tempo em segundos.
		newtime = localtime(&aclock);


		printf(" Signal 3 =======> %s", asctime(newtime));

		sleep(1);

		time(&aclock); // Pega tempo em segundos.
		newtime = localtime(&aclock);

		printf(" Signal 3 after Sleep =======> %s", asctime(newtime));


		timeEx = 3600 * newtime->tm_hour + 60 * newtime->tm_min + newtime->tm_sec;
		if( (timeEx - begin_3) > 15 )
			printf(" Time Failure of the Signal 3\n");
		else printf(" Time Correct of the Signal 3\n");
		begin_3 = timeEx + (15 - (timeEx-begin)%15);

		rt_sem_signal(rMutex);

		rt_task_wait_period();
		count++;
	}

	rt_make_soft_real_time();
	rt_task_delete(Task_3);

	return 0;


}
        INTERNAL_QUAL int rtos_task_set_priority(RTOS_TASK * mytask, int priority)
        {
            int rv;

            if (mytask->rtaitask == 0)
                return -1;

            // returns the *old* priority.
            rv = rt_change_prio( mytask->rtaitask, priority);
            if (rv == mytask->priority) {
                mytask->priority = priority;
                return 0;
            }
            return -1;
        }
Beispiel #4
0
void *signalIchi(void *arg)
{
	RT_TASK *Task_1;

	unsigned long Task_1_name = nam2num("TSK_1") + i++;
	time_t aclock;
	time_t clockNow;
	int timeEx;
	int begin_1;
	int count = 0;

	struct tm *newtime, *timeNow;

	Task_1 = rt_task_init(Task_1_name, 0, 0, 0);

//	if(!(Task_1 = rt_task_init_schmod(Task_1_name,2,0,0,SCHED_FIFO,1))) {
//		printf("CANNOT INIT HANDLER TASK > Task 1 <\n");
//		exit(1);
//	}

    /**
     *  Allows a non root user to use the Linux POSIX soft real time process management and memory
     *  lock functions, and allows it to do any input-output operation from user space.
     *
     *  Only the process itself can use this functions, it is not possible to impose the related
     *  transition from another process.
     */
	rt_allow_nonroot_hrt();

        rt_make_hard_real_time();

	rt_task_make_periodic(Task_1, rt_get_time(), sampling * 16);
	rt_change_prio(Task_1, 2);

	begin_1 = begin;
	while (count < 20) {
		time(&aclock); // Pega tempo em segundos.
		newtime = localtime(&aclock);

		rt_sem_wait(rMutex);

		printf(" Signal 1 =======> %s", asctime(newtime));

		sleep(1);

		time(&aclock); // Pega tempo em segundos.
		newtime = localtime(&aclock);

		printf(" Signal 1 after Sleep =======> %s", asctime(newtime));

		timeEx = 3600 * newtime->tm_hour + 60 * newtime->tm_min + newtime->tm_sec;
		if( (timeEx - begin_1) > 8 )
			printf(" Time Failure of the Signal 1\n");
		else printf(" Time Correct of the Signal 1\n");
		begin_1 = timeEx + (8 - (timeEx-begin)%8);
		rt_sem_signal(rMutex);

		rt_task_wait_period();
		count++;
	}

	rt_make_soft_real_time();
	rt_task_delete(Task_1);

	return 0;

}
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;
}