Considerando o código a seguir, responda:(0,25 pontos)
#include <p18f4550.h>
// CONFIGURATION
#pragma config FOSC=HS
//TASKS PROTOTYPES
void vTASKO(void);
void vTASK1(void);
void vTASK2(void);
void main( void ){
//Configurações da serial
TXSTAbits.BRGH=1;
xTaskCreate(vTASK0,(const charconst)“T0”, configMINIMAL_STACK_SIZE, NULL,(tskIDLE_PRIORITY+1), NULL);
xTaskCreate(vTASK1,(const charconst)“T1”, configMINIMAL_STACK_SIZE, NULL,(tskIDLE_PRIORITY+1), NULL);
xTaskCreate(vTASK2,(const char*const)“T2”, configMINIMAL_STACK_SIZE, NULL,(tskIDLE_PRIORITY+2), NULL);
vTaskStartScheduler();
}
void vTASK0(void){
while(1){
while (TXSTAbits.TRMT0) {}
TXREG=‘0’;
while (TXSTAbits.TRMT0) {}
TXREG=0x0D;
while (TXSTAbits.TRMT0) {}
TXREG=0x0A;
}}
void vTASK1(void){
while(1){
while (TXSTAbits.TRMT0) {}
TXREG=‘1’;
while (TXSTAbits.TRMT0) {}
TXREG=0x0D;
while (TXSTAbits.TRMT0) {}
TXREG=0x0A;
}}
void vTASK2(void){
while(1){
while (TXSTAbits.TRMT0) {}
TXREG=‘2’;
while (TXSTAbits.TRMT0) {}
TXREG=0x0D;
while (TXSTAbits.TRMT==0) {}
TXREG=0x0A;
vTaskDelay(10/portTICK_RATE_MS);
}}
Ocorre Starvation com uma ou mais tasks? Se sim, explique detalhadamente.
#include <p18f4550.h>
// CONFIGURATION
#pragma config FOSC=HS
//TASKS PROTOTYPES
void vTASKO(void);
void vTASK1(void);
void vTASK2(void);
void main( void ){
//Configurações da serial
TXSTAbits.BRGH=1;
xTaskCreate(vTASK0,(const charconst)“T0”, configMINIMAL_STACK_SIZE, NULL,(tskIDLE_PRIORITY+1), NULL);
xTaskCreate(vTASK1,(const charconst)“T1”, configMINIMAL_STACK_SIZE, NULL,(tskIDLE_PRIORITY+1), NULL);
xTaskCreate(vTASK2,(const char*const)“T2”, configMINIMAL_STACK_SIZE, NULL,(tskIDLE_PRIORITY+2), NULL);
vTaskStartScheduler();
}
void vTASK0(void){
while(1){
while (TXSTAbits.TRMT0) {}
TXREG=‘0’;
while (TXSTAbits.TRMT0) {}
TXREG=0x0D;
while (TXSTAbits.TRMT0) {}
TXREG=0x0A;
}}
void vTASK1(void){
while(1){
while (TXSTAbits.TRMT0) {}
TXREG=‘1’;
while (TXSTAbits.TRMT0) {}
TXREG=0x0D;
while (TXSTAbits.TRMT0) {}
TXREG=0x0A;
}}
void vTASK2(void){
while(1){
while (TXSTAbits.TRMT0) {}
TXREG=‘2’;
while (TXSTAbits.TRMT0) {}
TXREG=0x0D;
while (TXSTAbits.TRMT==0) {}
TXREG=0x0A;
vTaskDelay(10/portTICK_RATE_MS);
}}
Ocorre Starvation com uma ou mais tasks? Se sim, explique detalhadamente.
Passo 1
O enunciado nos dá três tarefas FreeRTOS em um PIC
F
:
vTASK
e vTASK
têm prioridade
vTASK
tem prioridade
Todas as tasks fazem busy-wait no bit
\(tskIDLE_PRIORITY +1\)
.\(tskIDLE_PRIORITY +2\)
e faz um vTaskDelay(\(10\)/\(portTICK_RATE_MS\))
a cada iteração.Todas as tasks fazem busy-wait no bit
TXSTAbits.TRMT
antes de escrever em TXREG
. Queremos ver se alguma task fica permanentemente sem rodar (starvation).Passo 2
Definição de starvation em escalonamento preemptivo: uma tarefa de prioridade menor nunca chega a executar porque tarefas de prioridade igual ou superior monopolizam a CPU sem jamais liberar voluntariamente.
Passo 3
Analisando vTASK
(prioridade mais alta):
-- Ela é preemptiva sobre vTASK /vTASK
sempre que sair de
-- Após imprimir +C
F, faz /
), ficando bloqueada \sim
ms.
Logo, vTASK não impede que as de menor prioridade rodem durante seus
ms de bloqueio. Não há starvation de vTASK
nem vTASK
por vTASK
.
-- Ela é preemptiva sobre vTASK
vTaskDelay
.-- Após imprimir
vTaskDelay
(
Logo, vTASK
Passo 4
Analisando vTASK
e vTASK
(mesma prioridade):
– Nenhuma chama
– Com time slicing habilitado ( e vTASK
se alternam, sem starvation nenhuma.
– Se time slicing estiver desabilitado ( ) roda infinitamente, e vTASK
fica permanentemente pronta mas sem CPU
starvation de vTASK
.
– Nenhuma chama
vTaskDelay
, vTaskYIELD
ou qualquer API de bloqueio FreeRTOS; apenas busy-wait em TXSTAbits.TRMT
, que não é blocking do RTOS, e imediatamente volta a rodar.– Com time slicing habilitado (
\(configUSE_TIME_SLICING =1\)
, default do FreeRTOS), o kernel faz context switch entre tasks de mesma prioridade a cada tick, e vTASK
– Se time slicing estiver desabilitado (
\(configUSE_TIME_SLICING =0\)
), tarefas de mesma prioridade só cedem CPU se bloquearem voluntariamente. Como nenhuma o faz, a primeira criada (vTASK
Passo 5
Conclusão:
vTASK
não é starvation nem é starved, pois faz
vTASK
e vTASK
compartilham CPU via time slicing se este estiver habilitado (sem starvation).
Se o projeto desabilitar time slicing, vTASK
monopoliza e vTASK
sofre starvation.
vTaskDelay
.Resposta
Sim. vTASK
só fica starved se o projeto tiver
, pois vTASK
e vTASK
têm mesma prioridade e nenhuma faz bloqueio do kernel, então a primeira criada monopoliza a CPU e impede vTASK
de executar. Se o time slicing estiver habilitado (config
), não há starvation.