1 / 59

TI BIOS CLK-PRD

TI BIOS CLK-PRD. Multi-Threaded Systems. Introduction. In this chapter, the presence of multiple threads within a system will be considered.

Download Presentation

TI BIOS CLK-PRD

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TI BIOS CLK-PRD Multi-Threaded Systems Dr. Veton Këpuska

  2. Introduction • In this chapter, the presence of multiple threads within a system will be considered. • Ways to control how the scheduler operates will be considered. In addition, the ability within DSP/BIOS to pace threads by time, rather than data availability, will be considered. Dr. Veton Këpuska

  3. Objectives Dr. Veton Këpuska 2

  4. Module Topics Dr. Veton Këpuska 3

  5. Module Topics Dr. Veton Këpuska 3

  6. Multi-Threading Dr. Veton Këpuska

  7. Multi-Threading • Can BIOS keep track of time for me? • Can time instead of data availability be used to launch threads? Dr. Veton Këpuska

  8. Module Topics Dr. Veton Këpuska 3

  9. High Rate Clock Low Rate Clock CLK Object(s) System Tick Low Res Clock x f + CLK_countspms CLK_getprd CLK_gethtime CLK_getltime BIOS Clock ServicesCLK API CPU clock  4 or 8 Timer Timer ISR Timer Interrupt Counter Period Dr. Veton Këpuska

  10. BIOS Clock ServicesCLK API • CLK abstracts details of HW timer to provide low-res time / system tick • Timer period is set and CLK objects specified in BIOS configuration • CLK can drive periodic objects directly, or at different rates as PRD SWI • CLK time values are often helpful in real-time analysis (next module) Dr. Veton Këpuska

  11. Setup of CLK via Configuration Tool Setup of the CLK Module • right click on CLK mgr • select “Properties” • define Low res clockrate via usecs/int • optionally, set other parameters as desired Dr. Veton Këpuska

  12. Setup of CLK via Configuration Tool Optional: Making a new CLK object • right click on CLK mgr • select “Insert CLK” • type CLK name • right click on new CLK • select “Properties” • type function to run Dr. Veton Këpuska

  13. Setup of CLK via Configuration Tool • All CLK objects are invoked each Lo Res tick – PRD fxns can run at different intervals – next... Dr. Veton Këpuska

  14. Module Topics Dr. Veton Këpuska 3

  15. Periodic Functions: PRD • Can I have a number of functions, each invoked at a given periodic rate? • Can I invoke a function that will run once after a given time has passed? Dr. Veton Këpuska

  16. DSP/BIOS Periodic Functions • A special SWI that provides preemptive scheduling for periodic functions • While SIO indicates data available and SEM indicates posting by other thread, when time is the gating event PRD is most ideal choice • Also useful for modeling interrupts to simulate peripherals (IO devices) Dr. Veton Këpuska

  17. Periodic Events – PRD SWI Timer ISR PRD_swi System Tick CLK Object(s) PRD_obj PRD_clock ... PRD_tick ... PRD_obj ... Period # of ticks before calling fxn Function Function to execute Type Continuous or One-shot PRD_obj Dr. Veton Këpuska

  18. Periodic Events – PRD SWI • PRD_tick() is invoked by PRD_clock by default (also TSK_tick) • PRD_tick() may be called by any desired user function as well • PRD_tick() launches the PRD_swi which • Scans the list of PRD_obj’s • Determines if the specified time for the given PRD_obj has elapsed • If so, the function associated with the PRD_obj is called • All PRD_obj functions must complete within ONE system (PRD) tick • Recommended: make PRD_swi highest priority SWI • If routines are short and tick is long - no problem • Long functions can be broken up with posts of other threads Dr. Veton Këpuska

  19. Setup of PRD via Configuration Tool Creating a PRD • right click on PRD mgr • select “Insert PRD” • type PRD name • right click on new PRD • select “Properties” • indicate desired • period (ticks) • mode • function • arguments Dr. Veton Këpuska

  20. Setup of PRD via Configuration Tool • A PRD can directly launch a regular SWI by specifying: • function: _SWI_post • arg0: _mySWI allowing control of priority, and meeting requirement for all PRDs to complete before the next PRD tick Dr. Veton Këpuska

  21. TCONF Setup of PRD Module & Object PRD.OBJMEMSEG = prog.get("myMEM");where to locate PRD Objects PRD.USECLK = "true";CLK MOD will feed PRD PRD.MICROSECONDS = 1000.0;uSecs/tick – skip if using CLK varmyPrd = PRD.create(“myPrd");create a PRD Object myPrd.period = 1024;# of ticks between calls to PRD Obj * myPrd.mode = "continuous";type – continuous or “one-shot” myPrd.fxn = prog.extern(“_myFxn");function PRD Obj will run myPrd.arg0 = 0;user arguments - optional myPrd.arg1 = 0; * Underlying interrupt rate is largest binary number divisible into period value, so for lowest overhead, pick a binary number when possible Dr. Veton Këpuska

  22. One-shot Periodic Functions • Allows delayed execution of a function by n systemticks • PRD_start()invokes each iteration of the one-shot function • PRD_stop()can be used to abort a one-shot prior to timeout • Example of use: software watchdog function Low-res clock (incremented by system tick) ... 74 75 76 77 78 79 80 81 ... 0 1 2 3 4 PRD_start() funcX() Dr. Veton Këpuska

  23. PRD API Review • Tick counter can be manually incremented by the user with PRD_tick() • One-shot periodic functions are managed with PRD_start()& PRD_stop() • Inspection of tick count is possible with PRD_getticks() • Continuous periodic functions are set up via the BIOS configuration tool and are generally not managed at run-time via BIOS API Dr. Veton Këpuska

  24. Scheduler Management API Dr. Veton Këpuska 3

  25. Scheduler Control API • Scheduler Control API is designed to control: • HWI & IDL processes • SWI processes, and • TSK • Is it possible for me to alter the behavior of the BIOS scheduler when the need arises? Dr. Veton Këpuska

  26. Scheduler Management API • Generally, threads are automatically managed by BIOS according to the priorities of each thread • Sometimes, however, it is desirable to alter the normal BIOS scheduler operation, for example: • When deadlines are approaching a thread can temporarily be given higher priority or even exclusive use of the processor • When multiple threads share a resource, priorities can be modified to avoid higher priority threads interrupting critical sections of lower priority threads • To implement time slicing amongst equal priority threads (equal threads are normally “FIFO” serviced) • To allow TSKS to ‘sleep’ for a time Dr. Veton Këpuska

  27. Scheduler Management API • In these cases, API can be invoked to alter the behavior of the scheduler with respect to HWI, SWI, and TSK as required Dr. Veton Këpuska

  28. Scheduler Management API Dr. Veton Këpuska 3

  29. HWI & IDL Scheduler Control • What kind of control can I have on how hardware interrupts and the idle thread are scheduled by BIOS? • HWI_disable() Creates a period where no asynchronous events may occur • HWI_restore() does not necessarily enable interrupts, but instead asserts to state prior to HWI_disable() Dr. Veton Këpuska

  30. HWI_disable and HWI_restoreAPI • Interrupts that come in during the period where HWI_disable() is being executed will be held off until HWI is re-enabled (if a given interrupt occurs more than once in this period, the additional events will be lost) oldCSR = HWI_disable();// “critical section” ...// scheduler inhibited ...HWI_restore(oldCSR); Dr. Veton Këpuska

  31. HWI and IDL Scheduler API Dr. Veton Këpuska

  32. Interrupt Management Intrinsic • Faster than the BIOS API • They are not commonly used • Not callable by HWI or SWI Unsigned int _disable_interrupts(); Unsigned int _enable_interrupts(); Void _restore_interrupts(unsigned int); Dr. Veton Këpuska

  33. Scheduler Management API Dr. Veton Këpuska 3

  34. SWI Scheduling • What kind of control can I have on how software interrupts are scheduled by BIOS? • Similar to HWI_disable/HWI_restore • SWI_disable – All interrupts that come in during the period where SWI_disableis being executed will be held off until SWI is re-enabled. • Concludes with SWI_enable (not “SWI_restore”) • Acts on SWI scheduling only – HWI continue unchanged • Nestable - number of levels managed by BIOS Dr. Veton Këpuska

  35. Disabling & Enabling Software Interrupts SWI_disable(); // “critical section” ...// SWI scheduler inhibited ... SWI_enable(); Dr. Veton Këpuska

  36. Temporary Elevation of SWI Priority • SWI_raisepri() can be used to raise the SWI priority. • SWI_raisepri() cannot lower priority (actually disables lower priority levels) • Priority returns to the original value when the SWI exits • Original Priority (“origPrio”) should be a local variable • Priority values are bit positions, not integer numbers(eg: priority 7 would be ...0100 0000 b) • To elevate a SWI above one (or several other) SWI, use in conjunction with SWI_getpri, as per the example below: Dr. Veton Këpuska

  37. Temporary Elevation of SWI Priority origPrio = SWI_raisepri(1<<7);// critical section ... // lower prio SWIs inhibited ...SWI_restorepri(origPrio); • Example of using SWI_getpri(): For Priority level “X” select 1<<X as the argument to raisepri origPrio = SWI_raisepri(SWI_getpri(&swiX)|SWI_getpri(&swiY));// critical section ... // SWI scheduler inhibited ...SWI_restorepri(origPrio); Dr. Veton Këpuska

  38. SWI Scheduler API Dr. Veton Këpuska

  39. Scheduler Management API Dr. Veton Këpuska 3

  40. TSK Scheduling and Control • What kind of control can I have on how tasks are scheduled by BIOS? • TSK_disable and TSK_enable • Similar to SWI_disable/SWI_enable • Acts on TSK scheduling only – SWI & HWI continue unchanged • Nestable - number of levels managed by BIOS Dr. Veton Këpuska

  41. Disabling & Enabling Task Scheduling TSK_disable(); // “critical section” ...// TSK scheduler inhibited ... TSK_enable(); Dr. Veton Këpuska

  42. Modification of a Task’s Priority • TSK_setpri() can raise or lower priority • Return argument of TSK_setpri() is previous priority • New priority remains until set again or TSK is deleted and re-created • TSK priority is an integer value: 1 to 15 (unlike SWI, using binary weighted numbers) • To suspend a TSK, set its priority to negativeone (-1) • Suspended TSK not part of BIOS TSK scheduling queue • TSK can be activated at any time (by some other thread) via TSK_setpri() • Handy option for statically created TSKs that don’t need to run right away • A TSK can be suspended at any time under BIOS, by itself or another thread Dr. Veton Këpuska

  43. Modification of a Task’s Priority • Example origPrio = TSK_setpri(TSK_self(),7);// critical section ... // TSK priority increased or reduced ...TSK_setpri(TSK_self(),origPrio); Dr. Veton Këpuska

  44. TSK_yield : Time Slicing • TSK_yield() instructs the BIOS scheduler to move the current TSK to the end of the priority queue • If another TSK of equal priority is ready, it will then be the active TSK • This API can be invoked at any time by the active TSK or any SWI/HWI • If a PRD calls TSK_yield, time slicing amongst equal priority TSKs is achieved Dr. Veton Këpuska

  45. TSK_yield : Time Slicing TSK_A Running TSK_B Ready Must be Equal Priority! TSK_C TSK_D Time Dr. Veton Këpuska

  46. TSK_sleep and TSK_tick • TSK_sleep(Unssleeptime) • Blocks execution of current TSK for n TSK ticks • TSK_tick() • Similar to PRD_tick for PRD SWIs • Advances the task alarm tick by one count • Default - called from PRD_clock (system tick) • If ‘ticks’ are events and not time, TSK_tick can be called from any thread • TSK_itick() is for use inside ISRs w/o dispatcher Dr. Veton Këpuska

  47. Task Control Block Model BIOS Startup READY TSK_yield() TSK_setpri() TSK_tick() SEM_post() RUNNING BLOCKED TERMINATED TSK_sleep() TSK_exit() SEM_pend() Dr. Veton Këpuska

  48. TSK Scheduler API Dr. Veton Këpuska

  49. Module Topics Dr. Veton Këpuska 3

  50. Questions? Dr. Veton Këpuska

More Related