Presentation is loading. Please wait.

Presentation is loading. Please wait.

TI BIOS TSK – Task Authoring 15 November 2018 Dr. Veton Këpuska.

Similar presentations


Presentation on theme: "TI BIOS TSK – Task Authoring 15 November 2018 Dr. Veton Këpuska."— Presentation transcript:

1 TI BIOS TSK – Task Authoring 15 November 2018 Dr. Veton Këpuska

2 1 2 3 4 5 6 Objectives Describe the fundamental concepts of tasks
Demonstrate the use of semaphores in tasks 2 Author TSK code using simple data block pointers 3 Create a TSK with the CCS GUI 4 Describe the TSK object 5 Modify SWI based code to employ TSK 6 15 November 2018 Dr. Veton Këpuska 2

3 1 2 3 4 5 6 Outline TSK vs. SWI TSK Scheduling Semaphores (SEM)
Task Object 4 Review 5 Lab 6 15 November 2018 Dr. Veton Këpuska 3

4 1 2 3 4 5 6 Tasks vs. SWI TSK vs. SWI TSK Scheduling Semaphores (SEM)
Task Object 4 Review 5 Lab 6 15 November 2018 Dr. Veton Këpuska 3

5 TSK vs. SWI 15 November 2018 Dr. Veton Këpuska

6 Scheduler States: TSK vs. SWI
Created Created Inactive post Ready 1 2 Posted when highest priority Ready 1 2 Blocked preempted completed when highest priority preempted pend Running 1 2 Running 1 2 Terminated 15 November 2018 Dr. Veton Këpuska

7 Tasks Are: Ready to Run when Created Preemptive
by BIOS startup if specified in GCONF by TSK_create() in dynamic systems (mod 11) Preemptive Blocked when Pending on an unavailable resource Returned to Ready state when resource is posted May be Terminated when no longer needed 15 November 2018 Dr. Veton Këpuska

8 SWI vs. TSK SWI Feature TSK  Preemptable - Block, Suspend
Delete prior to completion by other threads User Name, Error Number, Environment Pointer Can interface with SIO Faster context switch speed Slower Context preserved across accesses to thread NO* Can call SEM_pend() System Stack Individual ASM, C API callable by C * SEM_pend with timeout of 0 is allowed 15 November 2018 Dr. Veton Këpuska

9 1 2 3 4 5 6 TSK Scheduling TSK vs. SWI TSK Scheduling Semaphores (SEM)
Task Object 4 Review 5 Lab 6 15 November 2018 Dr. Veton Këpuska 3

10 Task Scheduling 15 November 2018 Dr. Veton Këpuska

11 DSP/BIOS Scheduler HWI SWI Priority TSK IDL 15 TSK priority levels
Hardware Interrupts HWI priorities set by hardware Fixed number, preemption optional Hard R/T Foreground SWI Software Interrupts 14 SWI priority levels Any number possible, all preemptive Priority TSK Tasks 15 TSK priority levels Any number possible, all preemptive Background IDL Background Continuous loop Non-realtime in nature Soft R/T 15 November 2018 Dr. Veton Këpuska

12 DSP/BIOS Scheduler All TSKs are preempted by all SWIs and HWIs
All SWIs are preempted by all HWIs Preemption amongst HWI is determined by user In absence of HWI, SWI, and TSK, IDL functions run in a loop 15 November 2018 Dr. Veton Këpuska

13 Thread Preemption Example
Digital Systems: Hardware Organization and Design 11/15/2018 Thread Preemption Example post swi1 post swi2 post sem2 return return return post swi2 return HWI post sem1 post sem2 return SWI 2 return return SWI 1 pend sem2 pend sem2 pend sem2 interrupt TSK 2 pend sem1 pend sem1 TSK 1 The main point of this slide is that BIOS (scheduler) manages priorities for you. Each thread (SWI, TSK) runs unaware of the others around it. As INTs post SEMs and SWIs, higher priority threads become ready, and BIOS will run each in order of priority, dropping down to lower levels as higher ones are satisfied or block waiting for additional resources. All this is automatic to the user - just write each thread, assign it a priority, and BIOS does the rest. A few points to note: SWIs run to completion - like a function call - a one shot, if you like. TSKs, instead, usually linger much longer - their execute phase is a while loop. They block when they run out of resources, and lower threads (or idle) can run until the requested resource arrives. In Bridge, TSKs are dynamically created and can be deleted, but normally are ready, running, or blocked. An interesting point: if RMS is a TSK of low priority (1), how come it’s running when TSK1 and TSK2 are ready? Recall that RMS implements the create phase of each TSK, and until the gateway puts the TSK in run mode, its priority is (minus) -1, thus TSK1 and TSK2 have no priority until elevated with DSPNode_run(). interrupt interrupt IDL interrupt Events over time 15 November 2018 Dr. Veton Këpuska Architecture of a Respresentative 32 Bit Processor

14 1 2 3 4 5 6 TSK Scheduling TSK vs. SWI TSK Scheduling Semaphores (SEM)
Task Object 4 Review 5 Lab 6 15 November 2018 Dr. Veton Këpuska 3

15 Semaphores (SEM) 15 November 2018 Dr. Veton Këpuska

16 Task Code Topology: SEM Posting
Void taskFunction(…) { /* Prolog */ while (‘condition’) { SEM_pend(); /* Process */ } /* Epilog */ Initialization (runs once only) Processing loop - option: termination condition Wait for resources to be available Perform desired DSP work... Shutdown (runs once - at most) 15 November 2018 Dr. Veton Këpuska

17 Task Code Topology: SEM Posting
TSK can encompass three phases of activity SEM can be used to signal resource availability to TSK SEM_pend() blocks TSK until next buffer is available 15 November 2018 Dr. Veton Këpuska

18 Semaphore Pending: SEM_pend()
Digital Systems: Hardware Organization and Design 11/15/2018 Semaphore Pending: SEM_pend() SEM_pend(&sem,timeout) Pend Count > 0 yes false true Decrement count timeout = 0 no Semaphore Structure: Non-negative 16-bit counter Pending queue (FIFO) timeout expires Block task Return FALSE SEM posted Return TRUE #define SYS_FOREVER (Uns) -1 // wait forever #define SYS_POLL (Uns) // don’t wait 15 November 2018 Dr. Veton Këpuska Architecture of a Respresentative 32 Bit Processor

19 Semaphore Post: SEM_post()
SEM_post(&sem) Post Task pending on sem? Ready first waiting task Increment count False True Semaphore Structure: Non-negative count Pending queue (FIFO) Task switch will occur if higher priority task is made ready Return 15 November 2018 Dr. Veton Këpuska

20 Creation of SEM Object Creating a new SEM Obj right click on SEM mgr
select “Insert SEM” type object name right click on new SEM select “Properties” indicate desired User Comment (FYI) Initial SEM count var mySem = SEM.create("mySem"); mySem.comment = "my SEM"; mySem.count = 0; 15 November 2018 Dr. Veton Këpuska

21 Digital Systems: Hardware Organization and Design
11/15/2018 SEM API Summary SEM API Description SEM_pend Wait for the semaphore SEM_post Signal the semaphore SEM_pendBinary Wait for binary semaphore to = 1 SEM_postBinary Write a 1 to the specified semaphore SEM_count Get the current semaphore count SEM_reset Reset SEM count to the argument-specified value SEM_new Puts specified count value in specified SEM SEM_ipost SEM_post in ISR – obsolete – use SEM_post SEM_create Create a semaphore SEM_delete Delete a semaphore Mod 11 15 November 2018 Dr. Veton Këpuska Architecture of a Respresentative 32 Bit Processor

22 1 2 3 4 5 6 TSK Scheduling TSK vs. SWI TSK Scheduling Semaphores (SEM)
Task Object 4 Review 5 Lab 6 15 November 2018 Dr. Veton Këpuska 3

23 Task Object 15 November 2018 Dr. Veton Këpuska

24 Static Creation of TSK Creating a new TSK right click on TSK mgr
select “Insert TSK” type TSK name right click on new TSK select “Properties” indicate desired priority stack properties function arguments etc 15 November 2018 Dr. Veton Këpuska

25 Task Object Concepts... Task object: TSK_setenv(TSK_self(),&myEnv);
Pointer to task function Priority: changable Pointer to task’s stack Stores local variables Nested function calls Makes blocking possible Interrupts run on the system stack Pointer to text name of TSK Environment: pointer to user defined structure: myTsk fxn * environ priority 6 stack name lpf1 struct myEnv TSK stack C fxn, eg: bk FIR inst2 fxn * environ priority 6 stack name lpf2 struct myEnv TSK stack TSK_setenv(TSK_self(),&myEnv); hMyEnv = TSK_getenv(&myTsk); 15 November 2018 Dr. Veton Këpuska

26 TSK Object typedef struct TSK_Stat {
TSK_Attrs attrs; // task attributes TSK_Mode mode; // running, blocked... Ptr sp; // stack ptr size_t used; // stack max } TSK_Stat; typedef struct TSK_Obj { // from TSK.h KNL_Obj kobj; // kernel object Ptr stack; // used w TSK_delete() size_t stacksize; // ditto Int stackseg; // stack alloc’n RAM String name; // printable name Ptr environ; // environment pointer Int errno; // TSK_seterr()/_geterr() Bool exitflag; // FALSE for server tasks } TSK_Obj, *TSK_Handle; typedef struct TSK_Attrs { Int priority; // task priority Ptr stack; // stack supplied size_t stacksize; // size of stack Int stackseg; // stack alloc’n seg Ptr environ; // environment pointer String name; // printable name Bool exitflag; // server tasks = false Bool initstackflag; // FALSE: no stack init } TSK_Attrs; struct KNL_Obj { // from KNL.h QUE_Elem ready; // ready/sem queue QUE_Elem alarm; // alarm queue elem QUE_Elem setpri; // set priority queue QUE_Handle queue; // task's ready queue Int priority; // task priority Uns mask; // 1 << priority Ptr sp; // current stack ptr Uns timeout; // timeout value Int mode; // blocked, ready, STS_Obj *sts; // for TSK_deltatime() Bool signalled; // woken by sem or t-out }; typedef struct TSK_Config { Int STACKSEG; Int PRIORITY; size_t STACKSIZE; Fxn CREATEFXN; Fxn DELETEFXN; Fxn EXITFXN; Fxn SWITCHFXN; Fxn READYFXN; } TSK_Config; 15 November 2018 Dr. Veton Këpuska

27 1 2 3 4 5 6 TSK Scheduling TSK vs. SWI TSK Scheduling Semaphores (SEM)
Task Object 4 Review 5 Lab 6 15 November 2018 Dr. Veton Këpuska 3

28 Review 15 November 2018 Dr. Veton Këpuska

29 TSK API Summary TSK API Description TSK_exit
Terminate execution of the current task TSK_getenv Get task environment TSK_setenv Set task environment TSK_getname Get task name TSK_create Create a task ready for execution TSK_delete Delete a task Mod 11 Most TSK API are used outside the TSK so other parts of the system can interact with or control the TSK Most TSK API are to allow: TSK scheduler management (Mod 7) TSK monitor & debug (Mod 8) Dynamic creation & deletion of TSK (Mod 11) TSK author usually has no need for any TSK API within the TSK code itself 15 November 2018 Dr. Veton Këpuska

30 TSK API Summary TSK API Description Mod 8 Mod 7 TSK_settime
Set task statistics initial time TSK_deltatime Record time elapsed since TSK made ready TSK_getsts Get task STS object TSK_seterr Set task error number TSK_geterr Get task error number TSK_stat Retrieve the status of a task TSK_checkstacks Check for stack overflow Mod 8 TSK_disable Disable DSP/BIOS task scheduler TSK_enable Enable DSP/BIOS task scheduler TSK_getpri Get task priority TSK_setpri Set a tasks execution priority TSK_tick Advance system alarm clock TSK_itick Advance system alarm clock (ISR) TSK_sleep Delay execution of the current task TSK_time Return current value of system clock TSK_yield Yield processor to equal priority task Mod 7 15 November 2018 Dr. Veton Këpuska 21

31 1 2 3 4 5 6 TSK Scheduling TSK vs. SWI TSK Scheduling Semaphores (SEM)
Task Object 4 Review 5 Lab 6 15 November 2018 Dr. Veton Këpuska 3

32 Lab 15 November 2018 Dr. Veton Këpuska

33 Lab 5: Task Thread - TSK BIOS\Labs\HW BIOS\Labs\Work Audio In (48 KHz)
isrAudio pInBuf[bkCnt]=MCBSP_read MCBSP_write(pOutBuf[bkCnt]) if(bkCnt=2*BUF) { QUE_put(&from DevQbufs) SEM_post(&mySem) bkCnt=0; } HWI12 ADC AIC33 McBSP DRR mcbsp.c DAC AIC33 McBSP DXR Audio Out (48 KHz) BIOS\Labs\Algos tskProcBuf procBuf while() SEM_pend(&mySem) for (i =0, i<HIST; i ++) pIn[i]=pPriorIn[2*BUF-HIST]; if( sw0 == 1 ) FIR(in[pIn-HIST],out[pOut]) else {pOut[i]=pIn[i]} FIR.c FIR Code coeffs.c Coefficients 15 November 2018 Dr. Veton Këpuska

34 Lab 5: Task Thread - TSK Begin with the SWI-based buffered system
Modify SWI to run as TSK; add SEM_pend and while loop TCF: remove SWI obj, add TSK and SEM objs Modify HWI to post SEM instead of SWI Build, load, test, verify performance 15 November 2018 Dr. Veton Këpuska

35 Lab 5 : Summary In the procBuf (TSK) function
In the TCF file: replace the processing SWI with a TSK create a SEM In audio.c: In the isrAudio (HWI) function: Post a SEM instead of the SWI In the procBuf (TSK) function Add a while loop and SEM_pend to the remaining code in procBuf() Build, download, run, and verify the correct operation of the new solution Optionally, copy the solution files to C:\BIOS\mySols\05 15 November 2018 Dr. Veton Këpuska

36 Lab 5: Procedure Overview
Below are the steps required to adapt the SWI-based processing thread to a TSK-based version. If necessary, start CCS and open the solution from lab 4. Build the project and verify it performs properly In myWork.tcf : Replace the SWI that called procBuf with a TSK named tskProcBuf Create a SEM named semBufRdy In isr.c Replace the SWI_post() with a SEM_post() of semBufRdy 15 November 2018 Dr. Veton Këpuska

37 Lab 5: Procedure Overview
In proc.c Add a while(1) loop around all the iterative code in procBuf. Add a SEM_pend on the newly created semaphore as the first line of the while loop Having completed the adaptation steps you can now: Build, load, run, and verify the correct operation of the new solution (optional) Relocate the initialization of the messages and toDevQ to the prolog of the TSK. While not required, this makes the TSK a more complete (and instantiable) component Using windows explorer, copy all files from C:\BIOS\Labs\Work to C:\BIOS\mySols\05 15 November 2018 Dr. Veton Këpuska

38 Lab Details Observations:
HWI – based lab 3 Observations: Moving from SWI to TSK showed results within 0.1% of being the same So… the ‘extra overhead’ of TSK vs. SWI doesn’t really amount to much at all, and could easily be countered by a small increase in buffer size, which will have much greater effect than thread type Filter Debug Release Off 18% 4.7% On 61% 6.5% SWI – based lab 4 Filter Debug Release Off 3.8% 2.3% On 45% 3.7% TSK – based lab 5 Filter Debug Release Off 3.8% 2.5% On 45% 15 November 2018 Dr. Veton Këpuska

39 TI BIOS TSK END 15 November 2018 Dr. Veton Këpuska


Download ppt "TI BIOS TSK – Task Authoring 15 November 2018 Dr. Veton Këpuska."

Similar presentations


Ads by Google