




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 遵义医科大学《产品交互设计》2023-2024学年第二学期期末试卷
- 唐山工业职业技术学院《中医四诊技能》2023-2024学年第二学期期末试卷
- 河北东方学院《幼儿园教育环境创设》2023-2024学年第二学期期末试卷
- 做账实操-代理记账公司的利润计算
- 入党积极分子民主表
- 辽宁工程技术大学《男装制版与工艺》2023-2024学年第二学期期末试卷
- 吉林航空职业技术学院《专题设计》2023-2024学年第二学期期末试卷
- 焦作大学《新闻评论与体育》2023-2024学年第二学期期末试卷
- 广东酒店管理职业技术学院《抽样设计与推断》2023-2024学年第二学期期末试卷
- 湖北大学知行学院《结构化学A》2023-2024学年第二学期期末试卷
- LY/T 3400-2024荒漠与荒漠化防治术语
- 2024-2025学年第二学期英语教研组工作计划
- 2025年往年教师职称考试试题
- 2025年春季学期学校全面工作安排表
- 幼儿园开学前的厨房人员培训
- 《幼儿教育政策与法规》教案-单元6 幼儿园的工作人员
- 虚拟制片技术在VRAR应用中的角色建模与渲染-洞察分析
- 光伏施工安全培训课件
- 消防员证考试题库2000题中级
- 部编人教版小学4四年级《道德与法治》下册全册教案
- 《 大学生军事理论教程》全套教学课件
评论
0/150
提交评论