CCS+C6678LE开发记录11:多核协作(IPC)入门
为更好地发挥C6678的多核性能,需要用到多核协作。幸运的是,我们可以使用官方提供的IPC模块。
IPC=Inter-Processor Communication, 核间通信,粗略来说就是多核之间进行信息、数据交换。
作为入门篇,本文不打算深入讨论IPC,仅仅列出自带的两个简单示例:Notify和MessageQ.
"通知"(Notify)模型
"消息队列"(MessageQ)模型
以下介绍Notify示例的创建过程以及测试结果。
首先新建一个项目,取名demo_ipcNotify,项目类型从模板中选择
选择"IPC and I/O Examples"分支下的"C6678 Examples"
然后【Next】,在XDCtools version选择3.23.4.60(不带"core"后缀的那一个)
创建并编译链接无错误之后执行Debug
建议勾选下方的"Create a debug group for selected cores"
如果没有选,可以在稍后执行如下操作
分组的好处是,当有多个核心加载时,不必一一启动,只需要在组别上点击启动(分组下所有核心全部启动)
这样做虽然不是必要的,但建议这样做。
如果勾选了分组,将会是如下这个样子,测试的时候只需在"Group 1"上点击一次【Step On(继续将执行)】
以下是测试示例的输出(中间有部分省略)
[plain] view plain copy
- [C66xx_6] main: MultiProc id = 6
- main: MultiProc name = CORE6
- [C66xx_7] main: MultiProc id = 7
- main: MultiProc name = CORE7
- [C66xx_0] main: MultiProc id = 0
- [C66xx_1] main: MultiProc id = 1
- [C66xx_2] main: MultiProc id = 2
- [C66xx_3] main: MultiProc id = 3
- [C66xx_4] main: MultiProc id = 4
- [C66xx_5] main: MultiProc id = 5
- [C66xx_0] main: MultiProc name = CORE0
- [C66xx_1] main: MultiProc name = CORE1
- [C66xx_2] main: MultiProc name = CORE2
- [C66xx_3] main: MultiProc name = CORE3
- [C66xx_4] main: MultiProc name = CORE4
- [C66xx_5] main: MultiProc name = CORE5
- [C66xx_0] tsk1_func: Sent request #0 to CORE1
- [C66xx_1] tsk1_func: Received request #1 from CORE0
- tsk1_func: Sent request #1 to CORE2
- [C66xx_2] tsk1_func: Received request #1 from CORE1
- tsk1_func: Sent request #1 to CORE3
- [C66xx_3] tsk1_func: Received request #1 from CORE2
- tsk1_func: Sent request #1 to CORE4
- ///省略///
- [C66xx_3] tsk1_func: Received request #10 from CORE2
- tsk1_func: Sent request #10 to CORE4
- Test completed
- [C66xx_4] tsk1_func: Received request #10 from CORE3
- tsk1_func: Sent request #10 to CORE5
- Test completed
- [C66xx_5] tsk1_func: Received request #10 from CORE4
- tsk1_func: Sent request #10 to CORE6
- Test completed
- [C66xx_6] tsk1_func: Received request #10 from CORE5
- tsk1_func: Sent request #10 to CORE7
- Test completed
- [C66xx_7] tsk1_func: Received request #10 from CORE6
- tsk1_func: Sent request #10 to CORE0
- Test completed
- [C66xx_0] tsk1_func: Received request #10 from CORE7
- Test completed
类似的可以新建一个MessageQ示例项目
后续步骤同上,测试的输出如下(中间有部分省略)
[plain] view plain copy
- [C66xx_1] Start the main loop
- [C66xx_5] Start the main loop
- [C66xx_7] Start the main loop
- [C66xx_6] Start the main loop
- [C66xx_0] Start the main loop
- [C66xx_2] Start the main loop
- [C66xx_3] Start the main loop
- [C66xx_4] Start the main loop
- [C66xx_0] Sending a message #1 to CORE1
- [C66xx_1] Sending a message #1 to CORE2
- [C66xx_2] Sending a message #1 to CORE3
- [C66xx_3] Sending a message #1 to CORE4
- [C66xx_4] Sending a message #1 to CORE5
- [C66xx_5] Sending a message #1 to CORE6
- [C66xx_6] Sending a message #1 to CORE7
- [C66xx_7] Sending a message #1 to CORE0
- ///省略///
- [C66xx_5] Sending a message #9 to CORE6
- [C66xx_6] Sending a message #9 to CORE7
- [C66xx_7] Sending a message #9 to CORE0
- [C66xx_0] Sending a message #10 to CORE1
- [C66xx_1] Sending a message #10 to CORE2
- The test is complete
- [C66xx_2] Sending a message #10 to CORE3
- The test is complete
- [C66xx_3] Sending a message #10 to CORE4
- The test is complete
- [C66xx_4] Sending a message #10 to CORE5
- The test is complete
- [C66xx_5] Sending a message #10 to CORE6
- The test is complete
- [C66xx_6] Sending a message #10 to CORE7
- The test is complete
- [C66xx_7] Sending a message #10 to CORE0
- The test is complete
- [C66xx_0] The test is complete
最后附上示例代码(模板生成的,仅删除部分注释,其他未做改动)
示例Notify的主要代码
[cpp] view plain copy
- #include <xdc/std.h>
- /* XDC.RUNTIME module Headers */
- #include <xdc/runtime/System.h>
- /* IPC module Headers */
- #include <ti/ipc/MultiProc.h>
- #include <ti/ipc/Notify.h>
- #include <ti/ipc/Ipc.h>
- /* BIOS6 module Headers */
- #include <ti/sysbios/knl/Semaphore.h>
- #include <ti/sysbios/knl/Task.h>
- #include <ti/sysbios/BIOS.h>
- /* To get globals from .cfg Header */
- #include <xdc/cfg/global.h>
- #define INTERRUPT_LINE 0
- /* Notify event number that the app uses */
- #define EVENTID 10
- /* Number of times to run the loop */
- #define NUMLOOPS 10
- UInt32 seq = 0;
- UInt16 recvProcId;
- UInt16 srcProc, dstProc;
- /*
- * ======== cbFxn ========
- * This function was registered with Notify. It is called when any event is
- * sent to this processor.
- */
- Void cbFxn(UInt16 procId, UInt16 lineId, UInt32 eventId, UArg arg,
- UInt32 payload)
- {
- /* The payload is a sequence number. */
- recvProcId = procId;
- seq = payload;
- Semaphore_post(semHandle);
- }
- /*
- * ======== tsk0_func ========
- * Sends an event to the next processor then pends on a semaphore.
- * The semaphore is posted by the callback function.
- */
- Void tsk0_func(UArg arg0, UArg arg1)
- {
- Int i = 1;
- Int status;
- if (MultiProc_self() == 0)
- {
- while (i <= NUMLOOPS)
- {
- /* Send an event to the next processor */
- status = Notify_sendEvent(dstProc, INTERRUPT_LINE, EVENTID, i,
- TRUE);
- /* Continue until remote side is up */
- if (status < 0)
- {
- continue;
- }
- System_printf("tsk1_func: Sent request #%d to %s\n", seq,
- MultiProc_getName(dstProc));
- /* Wait to be released by the cbFxn posting the semaphore */
- Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
- System_printf("tsk1_func: Received request #%d from %s\n", seq,
- MultiProc_getName(recvProcId));
- /* increment for next iteration */
- i++;
- }
- }
- else
- {
- while (seq < NUMLOOPS)
- {
- /* wait forever on a semaphore, semaphore is posted in callback */
- Semaphore_pend(semHandle, BIOS_WAIT_FOREVER);
- System_printf("tsk1_func: Received request #%d from %s\n", seq,
- MultiProc_getName(recvProcId));
- /* Send an event to the next processor */
- status = Notify_sendEvent(dstProc, INTERRUPT_LINE, EVENTID, seq,
- TRUE);
- if (status < 0)
- {
- System_abort("sendEvent failed\n");
- }
- System_printf("tsk1_func: Sent request #%d to %s\n", seq,
- MultiProc_getName(dstProc));
- }
- }
- System_printf("Test completed\n");
- BIOS_exit(0);
- }
- /*
- * ======== main ========
- * Synchronizes all processors (in Ipc_start), calls BIOS_start, and registers
- * for an incoming event
- */
- Int main(Int argc, Char* argv[])
- {
- Int status;
- UInt numProcs = MultiProc_getNumProcessors();
- /*
- * Determine which processors Notify will communicate with based on the
- * local MultiProc id. Also, create a processor-specific Task.
- */
- srcProc = ((MultiProc_self() - 1 + numProcs) % numProcs);
- dstProc = ((MultiProc_self() + 1) % numProcs);
- System_printf("main: MultiProc id = %d\n", MultiProc_self());
- System_printf("main: MultiProc name = %s\n",
- MultiProc_getName(MultiProc_self()));
- /*
- * Ipc_start() calls Ipc_attach() to synchronize all remote processors
- * because 'Ipc.procSync' is set to 'Ipc.ProcSync_ALL' in *.cfg
- */
- status = Ipc_start();
- if (status < 0)
- {
- System_abort("Ipc_start failed\n");
- }
- /*
- * Register call back with Notify. It will be called when the processor
- * with id = srcProc sends event number EVENTID to this processor.
- */
- status = Notify_registerEvent(srcProc, INTERRUPT_LINE, EVENTID,
- (Notify_FnNotifyCbck) cbFxn, NULL);
- if (status < 0)
- {
- System_abort("Notify_registerEvent failed\n");
- }
- BIOS_start();
- return (0);
- }
示例MessageQ的主要代码
[cpp] view plain copy
- #include <xdc/std.h>
- #include <string.h>
- /* XDC.RUNTIME module Headers */
- #include <xdc/runtime/System.h>
- #include <xdc/runtime/IHeap.h>
- /* IPC module Headers */
- #include <ti/ipc/Ipc.h>
- #include <ti/ipc/MessageQ.h>
- #include <ti/ipc/HeapBufMP.h>
- #include <ti/ipc/MultiProc.h>
- /* BIOS6 module Headers */
- #include <ti/sysbios/BIOS.h>
- #include <ti/sysbios/knl/Task.h>
- /* To get globals from .cfg Header */
- #include <xdc/cfg/global.h>
- #define HEAP_NAME "myHeapBuf"
- #define HEAPID 0
- #define NUMLOOPS 10
- Char localQueueName[10];
- Char nextQueueName[10];
- UInt16 nextProcId;
- /*
- * ======== tsk0_func ========
- * Allocates a message and ping-pongs the message around the processors.
- * A local message queue is created and a remote message queue is opened.
- * Messages are sent to the remote message queue and retrieved from the
- * local MessageQ.
- */
- Void tsk0_func(UArg arg0, UArg arg1)
- {
- MessageQ_Msg msg;
- MessageQ_Handle messageQ;
- MessageQ_QueueId remoteQueueId;
- Int status;
- UInt16 msgId = 0;
- HeapBufMP_Handle heapHandle;
- HeapBufMP_Params heapBufParams;
- if (MultiProc_self() == 0)
- {
- /*
- * Create the heap that will be used to allocate messages.
- */
- HeapBufMP_Params_init(&heapBufParams);
- heapBufParams.regionId = 0;
- heapBufParams.name = HEAP_NAME;
- heapBufParams.numBlocks = 1;
- heapBufParams.blockSize = sizeof(MessageQ_MsgHeader);
- heapHandle = HeapBufMP_create(&heapBufParams);
- if (heapHandle == NULL)
- {
- System_abort("HeapBufMP_create failed\n");
- }
- }
- else
- {
- /* Open the heap created by the other processor. Loop until opened. */
- do
- {
- status = HeapBufMP_open(HEAP_NAME, &heapHandle);
- /*
- * Sleep for 1 clock tick to avoid inundating remote processor
- * with interrupts if open failed
- */
- if (status < 0)
- {
- Task_sleep(1);
- }
- } while (status < 0);
- }
- /* Register this heap with MessageQ */
- MessageQ_registerHeap((IHeap_Handle) heapHandle, HEAPID);
- /* Create the local message queue */
- messageQ = MessageQ_create(localQueueName, NULL);
- if (messageQ == NULL)
- {
- System_abort("MessageQ_create failed\n");
- }
- /* Open the remote message queue. Spin until it is ready. */
- do
- {
- status = MessageQ_open(nextQueueName, &remoteQueueId);
- /*
- * Sleep for 1 clock tick to avoid inundating remote processor
- * with interrupts if open failed
- */
- if (status < 0)
- {
- Task_sleep(1);
- }
- } while (status < 0);
- if (MultiProc_self() == 0)
- {
- /* Allocate a message to be ping-ponged around the processors */
- msg = MessageQ_alloc(HEAPID, sizeof(MessageQ_MsgHeader));
- if (msg == NULL)
- {
- System_abort("MessageQ_alloc failed\n");
- }
- /*
- * Send the message to the next processor and wait for a message
- * from the previous processor.
- */
- System_printf("Start the main loop\n");
- while (msgId < NUMLOOPS)
- {
- /* Increment...the remote side will check this */
- msgId++;
- MessageQ_setMsgId(msg, msgId);
- System_printf("Sending a message #%d to %s\n", msgId,nextQueueName);
- /* send the message to the remote processor */
- status = MessageQ_put(remoteQueueId, msg);
- if (status < 0)
- {
- System_abort("MessageQ_put had a failure/error\n");
- }
- /* Get a message */
- status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER);
- if (status < 0)
- {
- System_abort("This should not happen since timeout is forever\n");
- }
- }
- }
- else
- {
- /*
- * Wait for a message from the previous processor and
- * send it to the next processor
- */
- System_printf("Start the main loop\n");
- while (TRUE)
- {
- /* Get a message */
- status = MessageQ_get(messageQ, &msg, MessageQ_FOREVER);
- if (status < 0)
- {
- System_abort("This should not happen since timeout is forever\n");
- }
- System_printf("Sending a message #%d to %s\n",MessageQ_getMsgId(msg),
- nextQueueName);
- /* Get the message id */
- msgId = MessageQ_getMsgId(msg);
- /* send the message to the remote processor */
- status = MessageQ_put(remoteQueueId, msg);
- if (status < 0)
- {
- System_abort("MessageQ_put had a failure/error\n");
- }
- /* test done */
- if (msgId >= NUMLOOPS)
- {
- break;
- }
- }
- }
- System_printf("The test is complete\n");
- BIOS_exit(0);
- }
- /*
- * ======== main ========
- * Synchronizes all processors (in Ipc_start) and calls BIOS_start
- */
- Int main(Int argc, Char* argv[])
- {
- Int status;
- nextProcId = (MultiProc_self() + 1) % MultiProc_getNumProcessors();
- /* Generate queue names based on own proc ID and total number of procs */
- System_sprintf(localQueueName, "%s", MultiProc_getName(MultiProc_self()));
- System_sprintf(nextQueueName, "%s", MultiProc_getName(nextProcId));
- /*
- * Ipc_start() calls Ipc_attach() to synchronize all remote processors
- * because 'Ipc.procSync' is set to 'Ipc.ProcSync_ALL' in *.cfg
- */
- status = Ipc_start();
- if (status < 0)
- {
- System_abort("Ipc_start failed\n");
- }
- BIOS_start();
- return (0);
- }
本文原创,博文地址
http://blog.csdn.net/fengyhack/article/details/44034941
CCS+C6678LE开发记录11:多核协作(IPC)入门的更多相关文章
- CCS+C6678LE开发记录12:UIA组件的安装
在安装了CCS 6.0版本的IDE和最新版的MCSDK后似乎一切都很完美,但事实并非如此. 当我试图编译SDK附带的image_processing (IPC based) demo时出现如下错误: ...
- MS CRM 2011的自定义和开发(11)——插件(plugin)开发(四)
http://www.cnblogs.com/StoneGarden/archive/2012/02/08/2343294.html MS CRM 2011的自定义和开发(11)——插件(plugin ...
- MS CRM 2011的自定义和开发(11)——插件(plugin)开发(二)
http://www.cnblogs.com/StoneGarden/archive/2012/02/06/2339490.html MS CRM 2011的自定义和开发(11)——插件(plugin ...
- Windows Phone 8初学者开发—第11部分:设置SounBoard应用程序
原文 Windows Phone 8初学者开发—第11部分:设置SounBoard应用程序 原文地址: http://channel9.msdn.com/Series/Windows-Phone-8- ...
- Android艺术开发探索——第二章:IPC机制(下)
Android艺术开发探索--第二章:IPC机制(下) 我们继续来讲IPC机制,在本篇中你将会学习到 ContentProvider Socket Binder连接池 一.使用ContentProvi ...
- Python全栈开发记录_第一篇(循环练习及杂碎的知识点)
Python全栈开发记录只为记录全栈开发学习过程中一些难和重要的知识点,还有问题及课后题目,以供自己和他人共同查看.(该篇代码行数大约:300行) 知识点1:优先级:not>and 短路原则:a ...
- JFinal使用笔记3-注册和登录功能开发记录
首页 开源项目 问答 代码 博客 翻译 资讯 移动开发 招聘 城市圈 当前访客身份:游客 [ 登录 | 加入开源中国 ] 当前访客身份: 游客 [ 登录 | 加入开源中国 ] 软件 土龙 关注 ...
- CozyRSS开发记录22-界面退化
CozyRSS开发记录22-界面退化 1.问题1-HtmlTextBlock 找的这个HtmlTextBlock有很严重的bug,有时候显示不完全,有时候直接就崩了.然后看了下代码,完全是学生仔水平写 ...
- CozyRSS开发记录21-默认RSS源列表
CozyRSS开发记录21-默认RSS源列表 1.默认列表 在第一次使用CozyRSS的情况下,我们让它内置五个RSS源吧: 2.响应RSS源的更新 先不处理RSS源列表项的点击,响应下下拉菜单里的更 ...
随机推荐
- Java类的根Object
一.Object类介绍 Object全名java.lang.Object,java.lang包在使用的时候无需显示导入,编译时由编译器自动导入.Object类是类层次结构的根,Java中所有的类从根本 ...
- 笔记--js实现异步
<script type="text/javascript"> var xhr=false; function createXhr() { var xhobj = fa ...
- js从数组中取出n个不重复的数据
/** * 首先,针对这个数组做一个去重处理,避免你在后面取数据的时候,因为取到相同的元素而又要多去取一次随机数 * 将获取到的不重复的数组,再到这里样本里面去取随机数 * 每取到一次,就将这个元素从 ...
- 关于CR0寄存器
开始的时候,我认为CR0.WP如果被置位,那么内存的页面只读属性将会失效,导致可以被写入数据. 这几天正好碰到一个问题,查看了资料才发现,之前的理解不完整. 引用Intel手册中的一句话: CR0.W ...
- 博客移至 GitHub
新博客地址: github.com/FatliTalk/blog
- 【AnjularJS系列4 】 — 单个页面加载多个ng-App
第四篇,插播, 单个页面加载多个ng-App 在写范例的时候发现的问题 一个页面有多个ng-app,angular只会处理第一个ng-app 需要加载两个ng-app,需要进行手动加载: angula ...
- 洛谷T44252 线索_分治线段树_思维题
分治线段树,其实就是将标记永久化,到最后再统一下传所有标记. 至于先后顺序,可以给每个节点开一个时间戳. 一般地,分治线段树用于离线,只查询一次答案的题目. 本题中,标记要被下传 222 次. Cod ...
- Settings Django Static Files
静态文件是通过django.contrib.staticfiles来管理的. 配置Django静态文件,Djang官网静态文件配置介绍.简言之,通过以下三个步骤来配置和加载静态文件: 设置静态文件别名 ...
- [学习笔记] CS131 Computer Vision: Foundations and Applications:Lecture 3 线性代数初步
向量和矩阵 什么是矩阵/向量? Vectors and matrix are just collections of ordered numbers that represent something: ...
- Python socket通信之FTP
Python中利用socket进行server端和client端通信是网络编程的基础,是最简单的传输范例. (懂网络的请自动跳过这一部分) 首先,要想通信,必须建立连接,建立连接的过程,需要clien ...