Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 8 Task Utilization. Theoretical Analysis.

Similar presentations


Presentation on theme: "Lecture 8 Task Utilization. Theoretical Analysis."— Presentation transcript:

1 Lecture 8 Task Utilization

2

3 Theoretical Analysis

4

5

6

7 It means that 100,000,000 cycles are executed in 1 second.

8

9

10

11

12 Analysis of aperiodic events

13 Ineffective for high-priority, short-deadline aperiodic events. The handling of the event is delayed until the next polling cycle.

14 :

15

16

17

18

19

20

21

22

23 L(Tx) Tx = t2 – t1

24 Low Level Programming

25 Hardware Watchdog example Watchdog timer in VxWorks: -Allows C function to be connected to a specific time delay. -Is invoked as part of the system clock ISR, meaning that at the system’s clock interrupt level. All restrictions on ISRs apply to routines connected to watchdog timer. wdCreate() - create a watchdog timer wdDelete() - delete a watchdog timer wdStart() - start a watchdog timer wdCancel() - cancel a currently counting watchdog

26 In the fragment below, if maybeSlowRoutine( ) takes more than 60 ticks, logMsg() will be called with the string as a parameter, causing the message to be printed on the console. Normally, of course, more significant corrective action would be taken. WDOG_ID wid = wdCreate (); wdStart (wid, 60, logMsg, "Help, I've timed out!"); maybeSlowRoutine (); /* user-supplied routine */ wdCancel (wid);

27 Software Watchdog example void WdClass::Init() { taskSpawn( "tLX", /* task name */ WD_LO_TASK_PRIORITY, /* task priority */ NULL, /* task option word */ WD_TASK_STACK_SIZE, /* stack size (bytes) */ WdTaskFnGW, /* task entry point */ 0,0,0,0,0,0,0,0,0,0 ); /* optional params */ taskSpawn( "tHX", /* task name */ WD_LO_TASK_PRIORITY, /* task priority */ NULL, /* task option word */ WD_TASK_STACK_SIZE, /* stack size (bytes) */ WdTaskFnGW, /* task entry point */ 0,0,0,0,0,0,0,0,0,0 ); /* optional params */ }

28 STATUS WdClass::WdTaskFnGW( ) { return ( (*this)->WdTaskFn() ); } Software Watchdog example

29 STATUS WdClass::WdTaskFn() { while ( true ) { taskDelay( 2*SECOND ); // Wait between cycles // Check if task got cpu in last 'sw_wd_timeout_' seconds UINT32 now = tickGet(); UINT32 delta = (now - low_pr_task_act_time)/sysClkRateGet(); if( delta >= sw_wd_timeout_ ){ logMsg(“Help, I’ve timed out!”); taskDelay( SECOND ); } UINT32 now = tickGet(); low_pr_task_act_time = now; }

30 Software Watchdog example SysInit() { … WdClass software_watchdog; software_watchdog->Init(); … }

31 Device driver may ensure use by no more than one task at a time. Use Mutex, semaphore or message queue. Example: mutual exclusion for single device write operation. -Dev_Init() calls to sm_create() and sets initial value of semaphore to “available”. -Dev_Write() calls to sm_take() before the access to device. -Dev_Write() call to sm_give() after access to device. Mutual Exclusion for Device Access

32 Example 1: Synchronous I/O Model Calling task is blocked until I/O transaction is completed. All the other tasks or ISRs may execute. READ_OPERATION DEVICE_ISRBEGIN StartIODeviceOperation();HandleHardwareData(); semTake();semGive(); //wait for a signal//signal completion GetDeviceDataEND END

33 Example 2: Asynchronous I/O Model Calling task is not blocked while I/O is taking place. READ_OPERATION DEVICE_ISRBEGIN Rc=q_recv(D_IN, NOWAIT )TransferData; StartNextInputOperation;q_send(D_IN); Process D_IN data//send new dataEND

34 Example 3: Free Running Asynchronous Input Calling task is not blocked while I/O is taking place. But hardware can deliver inputs repeatedly without software request. READ_OPERATION DEVICE_ISRBEGIN Rc=q_recv(D_IN, NOWAIT )TransferData; Process D_IN data q_send(D_IN); //send new dataEND

35 Example 4: Handling Latest Input Only In previous examples an old data is taken. A data can be queued up and become very old. To solve we use protected shared data area. Protected shared data protects from access collisions using a Binary Semaphore. Data Area contains latest measured data only. Old data is overwritten. Input device hardware can be free running, giving interrupts whenever ready.

36 sem_take(mysm,SM_WAIT); Read data from shared data area; End access Sem_give(mysm) /*new data is available*/ sem_take(mysm,SM_NOWAIT); If semaphore OK, Write to shared data area End access; sem_give(mysm_ Else… EndIF

37 Example 5: Double Buffered Input Data One buffer being filled while the other being processed. Works OK if buffer processing completes before a new buffer is filled.

38 Example 6: Serial Input Data Spooler Characters arrive via individual interrupts. Get next message( q_receive() ) Return the buffer( pt_retbuf() ) Queue this message ( q_send() ) Request new buffer(pt_getbuf(NOWAIT))

39 Get next message( q_receive() ) Return the buffer( pt_retbuf() ) Send message ( q_send() ) Request new buffer(pt_getbuf(NOWAIT)) Direct DMA interface to new buffer Example 6: Zero Copy DMA Input Spooler Direct DMA interface to transfer data directly Return data block( de_read() ) /*Interrupt: current buffer full*/

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62


Download ppt "Lecture 8 Task Utilization. Theoretical Analysis."

Similar presentations


Ads by Google