6657等多個(gè)文件網(wǎng)上雜官方bios教程itc_第1頁
6657等多個(gè)文件網(wǎng)上雜官方bios教程itc_第2頁
6657等多個(gè)文件網(wǎng)上雜官方bios教程itc_第3頁
6657等多個(gè)文件網(wǎng)上雜官方bios教程itc_第4頁
6657等多個(gè)文件網(wǎng)上雜官方bios教程itc_第5頁
已閱讀5頁,還剩44頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Workshop Outline“Core Essentials”DevicesCCSv5 Basics + MemIntro to SYS/BIOSThreads HwiThreads Swis and Tasks“Kicking It Up A Notch”Clk Fxns & RTA ToolsInter-Thread CommDynamic Memory (Heaps)“Advanced System Topics”C6000 ArchitectureC/System OptimizationsCache & Internal MemoryHow EDMA3 Works“Grab Ba

2、g” TopicsGrab Bag Topics (4) Intro to DSP/BIOS Flash Boot Drivers (SIO, PSP) Intro to C66x1Objectives Describe HOW to share resources between threads on a single-core DSP Compare different use cases (concurrent access vs. producer/consumer model) Analyze several BIOS building blocks for data sharing

3、 and signaling Identify where semaphores can be a good choice vs. where they produce problems2OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Sharing Data Between Threads - ProblemThread AThread BWhat a

4、re common ways that threads share resources?DataJust use Globals and dont worry about it !Yes, BIOS can help.but lets first look at the types of sharing that are possible.Come on, mutexs are better. They are easy and we usethem all the time. They cause no problems.Well, since were in the SYS/BIOS wo

5、rkshop, there mustbe some services this RTOS provides to help usWhat problems can occur when using globals/mutexs?4OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Resource Sharing Two Types“Producer Con

6、sumer” ModelThread AThread BBIOS “Container”MsgThread A produces a buffer or Msg and places it in a container.Thread B blocks until it is available, then consumes it when signaled (no contention)Data communication is achieved using BIOS “containers” (objects)“Concurrent Access” ModelThread AThread B

7、ResourceAny thread could access “Resource” at any time (no structured protocol or container)Pre-emption of one thread by another can cause contention or priority inversionLets look at the producer-consumer model first.Resource = Data or Peripheral6OutlineOverview of the ProblemResource Sharing - Int

8、ro“Producer-Consumer” ModelEventsUsing QueuesUsing MailboxesAdvanced Producer-Consumer“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Producer Consumer Model IntroData is UNIDIRECTIONAL one thread waits for the other to produceThread B often BLOCKS until data is producedBoth threa

9、ds use same protocol contention is often avoidedThreads e more “modular” and therefore reuse improvesHow it Works:Advantages:Examples:BIOS: Queue, Mailbox, Stream I/OMay have built-in synchronization or user can add signaling viaSemaphores and Events (discussed next)Thread AThread BBIOS“Container”Ms

10、gproduceconsume8OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” ModelEventsUsing QueuesUsing MailboxesAdvanced Producer-Consumer“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Using Events (New in SYS/BIOS)EV0EV1EV2EV3EV4EV5Semaphore_pend()only waits on o

11、ne flag a semaphore. What if you want to “unblock” based on multiple events?Use Events. Can OR or AND event IDs with bit masksEvents are “binary semaphores”. Only one Task can block on one Evt object at a time.The key “Explicit Post” and Pend APIs are:Event_post (&Evt, Event_Id_xx);Event_pend (&Evt,

12、 andMask, orMask, timeout);Hwi 5Hwi 7Hwi 9Post EV0Post EV2Post EV5mask = EV0 + EV2 + EV5;while(1) / “simplified” ver Event_pend (mask); / do workmyTaskANDORWhat about implicit posts ?10Implicit “Event Post”EV0EV1EV2EV3EV4EV5Other APIs, as shown above, can also post events implicitly the eventId is p

13、art of the params structure:SemaphoreMailboxMessageQPost EV0Post EV2Post EV5So, even a standard Semaphore_post(Sem) can post an event !Specify EventId hereNote: see “Event” example under SYS/BIOS TemplatesANDORmask = EV0 + EV2 + EV5;while(1) / “simplified” ver Event_pend (mask); / do workmyTask11Out

14、lineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” ModelEventsUsing QueuesUsing MailboxesAdvanced Producer-Consumer“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Queue ConceptsThread AThread BputgetQueueMsg1Msg2Msg3A Queue is a BIOS object that can contain any

15、thing you like“Data” is called a “Msg” and is simply a structure defined by the userMsgs are “reclaimed” on a FIFO basisKey APIs:Advantages: simple, not copy basedDisadvantage: no signaling built inQueue_put();Queue_get();How would you synchronize the writer and reader?13Synchronizing QueuesQueue_pu

16、t(&myQ, msg); TALKERmsg = Queue_get(&myQ); LISTENERSemaphore_pend(&Sem, -1); Semaphore_post(&Sem); Thread AThread BputgetQueueMsg1Msg2Msg3Use a Semaphore to synchronize writer/reader:Note: “Queue+Sem” is the basis for how “streams” are built to interface with I/O drivers e.g. Platform Support Packag

17、e (PSP) drivers from TI. (More in a later chapter) Lets see how Queues are used in a system.14Using Queues in a SystemUser Setup:Declare Queue in CFGDefine (typedef) structure of MsgFill in the Msg i.e. define “elements”Send/receive data from the queuestruct myMsg Queue_Elem elem; short *pInBuf; sho

18、rt *pOutBuf; Msg;Example RCV side of peripheral driver (Hwi):Double Buffer System main init puts TWO Msgs in toDevQputTaskgettoHwitoTSK54getHwiput23mainputput1HWI gets EMPTY Buffer from toDevQ (and fills it up with data)HWI puts FULL Buffer into toTSKQ (gets next EMPTY)TSK gets FULL buffer from toTS

19、KQ (process)TSK puts EMPTY buffer into toDevQNote: two Queues allow Msgs tocirculate between threads.toHwi = EMPTY, toTSK =FULL 15OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” ModelEventsUsing QueuesUsing MailboxesAdvanced Producer-Consumer“Concurrent Access” ModelSame Pr

20、iority ThreadsChapter Quiz (No Lab)Using MailboxesMailboxes a fixed-size BIOS Object that can contain anything you like Fixed length defined by:Number of Msgs (length of mailbox)Message Size (MAUs)Key APIs (both can block):Advantages: simple FIFO, easy to use, contains built-in semaphore for signali

21、ngDisadvantage: copy-based (both reader/writer own a copy) best if used to pass pointers or small MsgsMailbox_post (&Mbx, &Msg, timeout); / blocks if fullMailbox_pend (&Mbx, &Mail, timeout); / blocks if emptyThread AThread BpostpendMailboxMsg1Msg2Msg3Advanced producer/consumer uses.17OutlineOverview

22、 of the ProblemResource Sharing - Intro“Producer-Consumer” ModelEventsUsing QueuesUsing MailboxesAdvanced Producer-Consumer“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Advanced “Producer-Consumer” ServicesMore advanced versions of the “producer-consumer” model are builtinto SYS

23、/BIOS and other drivers/frameworks:Issue/Reclaim buffers to/from a STREAM (input and output Queues)Platform Support Package (PSP) DriversLowest layer uses BIOS MessageQ (similar to Queuesbut trans-processor)SysLink is a layer above MessageQ a driver ported to Linuxand SYS/BIOSCodec Engine (CE) is an

24、 algorithm framework built on top of SysLinkto provide users with the ultimate flexibility of launching algos on theDSP (SYS/BIOS) from the ARM (Linux)Messaging between cores (DSP DSP, ARM DSP)Codec EngineSysLink/IPCMessageQOptional chapters and another 4-day workshop address these topics in detail1

25、9OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent Access” ModelUsing GlobalsModify SchedulerUsing MUTEXsUsing Mutex GatesDeadlockSame Priority ThreadsChapter Quiz (No Lab)“Concurrent Access” Model IntroThread AThread BDataData is “up for grabs” often e, firs

26、t-serveUser must add “protection” to avoid contention between different priority threadsCommon usage many systems use MUTEXs for resource protectionHow it Works:Advantages:Examples:BIOS: Scheduler Mgmt, Gates, MUTEX (Semaphore), Task_setPriNote: watch out for “globals” accessed by multiple threads w

27、/no protectionMUTEXs can cause priority inversion or deadlock both ugly scenariosModifying scheduler behavior (e.g. disabling INTs) can cause jitter in the systemDisadvantages:Lets first look at a simple use of globals.21OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model

28、“Concurrent Access” ModelUsing GlobalsModify SchedulerUsing MUTEXsUsing Mutex GatesDeadlockSame Priority ThreadsChapter Quiz (No Lab)Whats Wrong With Using Globals ?void A (void) cnt += 1;If two threads share a global, whats the problem?void B (void) cnt += 1;Thread A (hi)Thread B (lo)What happens i

29、f Thread B gets pre-empted by A?LDADDSTB could store the wrong valueThe assembly code underneath does LD, ADD, STWhat methods can be used to solve this problem?23Critical Resource ProtectionSome sort of PROTECTION mechanism has to be used toprotect threads from conflict when sharing a resourceIn sim

30、ple terms, lets define CRITICAL SECTION as the timewhen the SHARED RESOURCE is being accessed:What other forms of “protection” exist?For example, if a Task and Hwi are sharing a resource, theGATE, or Enter/Exit commands in the Task might be:MUTEXs, between Tasks, could also be used during Enter/Exit

31、ThreadEnterExitCRITICAL SECTIONTaskEnter (Global INT = OFF)CRITICAL SECTIONExit (Global INT = ON)24OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent Access” ModelUsing GlobalsModify SchedulerUsing MUTEXsUsing Mutex GatesDeadlockSame Priority ThreadsChapter Qu

32、iz (No Lab)Modifying BIOS Scheduler Behavior“When in doubt, just turn off interrupts !”This might sound funnybut it is a common method to solve contentionproblems in systemsModifying the schedulers behavior is the ONLY solution for Hwi/Swi:Hwi_disable(); turn off global INTsHwi_restore(); restore gl

33、obal INTsSwi_disable(); turn off all SwisSwi_restore(); restore SwisTask_disable(); turn off all TasksTask_restore(); restore TasksTask_setPri(); Set Task Privoid B (void) . . . pGIE = Hwi_disable(); cnt += 1; /critical Hwi_restore(pGIE); . . .Usage (Notice Enter/Exit gates)Advantages: common, simpl

34、eDisadvantages: can cause jitter, latency26OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent Access” ModelUsing GlobalsModify SchedulerUsing MUTEXsUsing Mutex GatesDeadlockSame Priority ThreadsChapter Quiz (No Lab)Using MUTEXsThread AThread BDataMUTEX = Mutua

35、lly Exclusive (only one thread at a time)Mutex is commonly used in systems to protect a critical resourcebeing accessed by multiple threadsUsers can create a mutex using semaphores with an initial count of 1Semaphore_pend(Sem);Semaphore_post(Sem);Task HiDSemaphore_pend(Sem);Semaphore_post(Sem);Task

36、LowDSemaphore: SemInitial Count = 1Advantages: common, simpleDisadvantage: can cause priority inversionShared semaphores can cause problems.28Shared SemaphoresMUTEX = TSK Hi and TSK Lo pend on the SAME semaphorePending threads are placed in a FIFO semaphore queue:Therefore, TSK Lo runs first. This i

37、s ok, but CAN lead to priority inversionTSK HiTSK LoREADYWhat if some TSK MEDiums were living in the system?HwipostEnter (pend)INT!blockTSK LoACCESSEnter (pend)BLOCKED !TSK HiINT!Exit (post)ACCESS29Priority InversionHwiPost (sems)Enter (pend)INT!blockTSK LoEnter (pend)BLOCKED !TSK HiINT!What could y

38、ou do with TSK Los priority just before the “Enter” to avoid this priority inversion?TSK MEDRUN !TSK MED (and all other priorities between Hi and Lo) get to RUN firstThen, TSK Lo runs before TSK Hi because Lo pended on Sem firstTSK Hi is VERY FRUSTRATED30Temporarily Elevate Priority Task_setPri() TS

39、K Lo can elevate its priority just before data access and thenlower its priority just after data access using:Advantage: no semaphore/mutex required !Mutex Priority Gates can come in handy for situations like thisTask_setPri();HwiEnter - setPri(Hi)data accessTSK LoRunning (data access) !TSK HiINT!Ex

40、it - setPri(Lo)pre-emptedReady31OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent Access” ModelUsing GlobalsModify SchedulerUsing MUTEXsUsing Mutex GatesDeadlockSame Priority ThreadsChapter Quiz (No Lab)Mutex GatesMutex gates work similar to the Hwi/Swi/Task

41、gates discussed earlierUse the following code in BOTH (TSK Hi and TSK Lo)enterdataTSK LoblockTSK HiINT!leavepre-emptedenterLo inheritsHis Prirunpre-emptedleavedatadatagateKey = GateMutexPri_enter(gateMutexPri); / enter Gatecnt += 1; / protected accessGateMutexPri_leave(gateMutexPri, gateKey); / exit

42、 GateTSK Lo inherits priority of TSK Hi if TSK Hi requests resource access (enter)Advantages: simple to code, does automatic Task_setPri() of TSK LoGateMutex also available (similar to standard Mutex usage)33OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent A

43、ccess” ModelUsing GlobalsModify SchedulerUsing MUTEXsUsing Mutex GatesDeadlockSame Priority ThreadsChapter Quiz (No Lab)How DEADLOCK Can OccurSem_pend(res_1);/ use resource1 STUCK ?Sem_pend(res_2);/ use resource2Sem_post(res_1);Sem_post(res_2);Sem_pend(res_2);/ use resource1 STUCK ?Sem_pend(res_1);/

44、 use resource1Sem_post(res_2);Sem_post(res_1);Task ATask BSolutions:Use timeouts on _pendEliminate circular _pendLock one resource at a time, or ALL of themThread AThread BDataDataDeadlock occurs when two threads block each other (stalemate)Conditions for deadlock include: Use of MUTEX with multiple

45、 resources (with circular pending)Threads at different priorities35OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer” Model“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Threads At SAME PriorityNote: watch out for “Murphy” if someone changes priorities !Thr

46、ead AThread BDataPri = XPri = XCan threads at the SAME priority pre-empt each other? NO !So, it is a good idea to place threads that share a critical resourceAT THE SAME PRIORITY. Life is goodAdvantages galore:Built-in FIFO scheduling (no pre-emption or scheduler mods)No signaling required (no Semap

47、hore, no blocking)Less memory/time overhead for pre-emption (context switch)No corruption or contention easy to maintainVERY simple solves ALL types of critical resource sharing problems (e.g. priority inversion and deadlock)37OutlineOverview of the ProblemResource Sharing - Intro“Producer-Consumer”

48、 Model“Concurrent Access” ModelSame Priority ThreadsChapter Quiz (No Lab)Chapter QuizName the two basic data sharing models and examples of each:Compare and contrast mailboxes and queues:Which fxn calls are commonly used to modify scheduler behavior?What problems can occur when using MUTEXs, what is

49、 the soln?What is the mended solution for sharing data between threadswhere possible?Chapter QuizName the two basic data sharing models and examples of each:Compare and contrast mailboxes and queues:Which fxn calls are commonly used to modify scheduler behavior?What problems can occur when using MUT

50、EXs, what is the soln?What is the mended solution for sharing data between threadswhere possible?Producer-Consumer: Queues, Mailboxes, Stream I/O, Sem/EventConcurrent Access: Scheduler Mgmt, Gates, Mutexes, SAME PRI Mailbox fixed length, copy based, signaling built-in, simple useQueues anything you

51、like, not copy based, no signal, flexibleHwi_disable/restore(); Place threads that share data AT THE SAME PRIORITYPriority Inversion, Task_setPri(); GateMutexPri40ti41QUE API Summary QUE_putAdd a message to end of queue atomic write QUE_getGet message from front of queue atomic read QUE_enqueueNon-a

52、tomic QUE_put QUE_dequeueNon-atomic QUE_get QUE_headReturns ptr to head of queue (no de-queue performed) QUE_emptyReturns TRUE if queue has no messages QUE_nextReturns next element in queue QUE_prevReturns previous element in queue QUE_insertInserts element into queue in front of specified element Q

53、UE_removeRemoves specified element from queue QUE_new. QUE APIDescription QUE_createCreate a queue QUE_deleteDelete a queueMod 10Void writer(Void)MsgObjmsg;IntmyBufSIZE;.msg.addr = myBuf;msg.len = SIZE*sizeof(Int);MBX_post(&mbx, &msg, SYS_FOREVER);.Example: Passing Buffer Info Via MailboxVoid reader

54、(Void)MsgObjmail;Intsize, *buf;.MBX_pend(&mbx, &mail,SYS_FOREVER);buf = mail.addr;size = mail.len;.typedef struct MsgObj Int len; Int *addr;handle to msg obj* msg to put/gettimeoutMBX_post - add message to end of mailbox MBX_pend - get next message from mailboxblock until mail received or timeoutblock if MBX is already full43Creating Mailbox ObjectsMBX.OBJMEMSEG = prog.get(“ISRAM);var myMBX = MBX.create(myMBX); ment =

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論