TI中文支持网
TI专业的中文技术问题搜集分享网站

c6678 notify()例程 从核与主核之间通信卡停问题

您好:

        我使用的是C6678的开发板,仿真器XDS100v,目前只在软件仿真。

        任务是:想要完成多核图像处理,使用主核对图像进行分块,从核对每个数据块进行处理,再使用主核对各个处理结果进行整合。

        问题是:使用notify()的例程,在从核程序中加入自己编写的子函数,在对数据块完成处理以后,程序卡停,不能激活主核进行结果整合。(尝试加入只有打印信息的子函数,可以完成主从核之间通信,没有问题。)

       卡了很久很久了,找不到原因,希望能尽快解答,万分感谢!

        DEBUG结果如图:(请问会停在这里的原因是什么?)

没有从核2的sent 打印信息,也没有主核0的最后接收打印信息

 使用test子函数,可以看到完整的打印信息:

代码如下:

#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>

///////
#include <stdio.h>
//#include "ti/omp/omp.h"

#include <c6x.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <ti/csl/csl_chip.h>
#include <ti/csl/src/intc/csl_intc.h>
#include <ti/csl/csl_cpintcAux.h>

#include "ipc_interrupt.h"
#include "math.h"
#include "image.h"


///////


#define INTERRUPT_LINE  0

/* Notify event number that the app uses */
#define EVENTID10

/* Number of times to run the loop */
#define NUMLOOPS1

UInt32 times = 0;
UInt16 recvnumes = 0;

#define masterProc 0
#define sloverProc1 1
#define sloverProc2 2

#define sloverNum 2

int readimagedata(const double *fp);
void R1_inversion(double z[512][169]);
void Rn_inversion(double z[512][169]);
void R_RXD(double z[512][169],double z1[512]);
void logo_matrix();
void logo_h();
void restore();

void test(double z[512][169]);


static double h[4096][169];
static double g[4096][169];
double m=0.000000001;
double rr=0;
double f[4096],R1[169][169],R2[169],R22[169],Rm[169][169],r1_matrix[169][169],D1[169];
double z1[512][169],z2[512][169],z3[512][169],z4[512][169],z5[512][169],z6[512][169],z7[512][169],z8[512][169];
double z11[512],z22[512],z33[512],z44[512],z55[512],z66[512],z77[512],z88[512];
int m1[512],m2[512],m3[512],m4[512],m5[512],m6[512],m7[512],m8[512];
int k[64][64];



/*
 *  ======== 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. */

	if(procId!=masterProc) // 主核注册函数
	{
		recvnumes++;  // 接收从核的数目	if(recvnumes==sloverNum) // 当收到全部从核回复的信息	{		recvnumes=0;		Semaphore_post(semHandle);	}
	}
	else{
		times = 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() == masterProc) {while (i <= NUMLOOPS) {	/* 这里可以添加主核需要执行的任务代码*/		readimagedata(image);		logo_matrix();		logo_h();		//R1_inversion(z1);		//Rn_inversion(z1);		//R_RXD(z1,z11);	printf("this is multicore,biubiubiu~~~");/* Send an event to the next processor */status = Notify_sendEvent(sloverProc1, INTERRUPT_LINE, EVENTID, i,TRUE);status = Notify_sendEvent(sloverProc2, INTERRUPT_LINE, EVENTID, i,TRUE);/* Continue until remote side is up */if (status < 0) {continue;}System_printf("MasterCore Sent Event to SloverCores in %d\n", i);/* Wait to be released by the cbFxn posting the semaphore */Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待所有从核完成其工作返回System_printf("MasterCore Received Event from All SloverCores in %d\n",i);/* restore();FILE *fp1;int j=0;if((fp1=fopen("E:\\ccs_workspace\\RX_multicore\\RX_result.txt","w"))==NULL){	printf("cannot write file!\n");}printf("result ready!");for(i=0;i<64;i++){	for(j=0;j<64;j++)	{fprintf(fp1,"%lf ",g[i][j]);if(j==63)fprintf(fp1,"\n");	}}fclose(fp1);
*/printf("result complete!");/* increment for next iteration */i++;}}else {while (times < NUMLOOPS) {/* wait forever on a semaphore, semaphore is posted in callback */Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 等待主核通知开始执行任务System_printf("SloverCore%d Received Event from MasterCore in %d\n", MultiProc_self(),times);/* 这里可以添加从核执行的任务*///uint32_t coreID = CSL_chipReadReg (CSL_CHIP_DNUM);if (1==DNUM){	printf("this is core 1!");	//test(z2);R1_inversion(z2);//Rn_inversion(z2);//R_RXD(z2,z22);}else if (2==DNUM){printf("this is core 2!");// test(z3);R1_inversion(z3);//printf("core2 end!");// Rn_inversion(z3);//R_RXD(z3,z33);}/* Send an event to the next processor */status = Notify_sendEvent(masterProc, INTERRUPT_LINE, EVENTID, times,TRUE);if (status < 0) {System_abort("sendEvent to MasterCore failed\n");}System_printf("SloverCore%d sent Event from MasterCore in %d\n", MultiProc_self(),times);}}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;status = Ipc_start();printf("Ipc_start ok!");if (status < 0) {System_abort("Ipc_start failed\n");}if(MultiProc_self()==masterProc){	while(Ipc_attach(sloverProc1)){		Task_sleep(1);	}// 完成从核1的连接	while(Ipc_attach(sloverProc2)){Task_sleep(1);	}// 完成从核2的连接status = Notify_registerEvent(sloverProc1, INTERRUPT_LINE, EVENTID,(Notify_FnNotifyCbck)cbFxn, NULL);if (status < 0) {System_abort("Notify_registerEvent for sloverCore1 failed\n");}// 完成从核1的事件注册status = Notify_registerEvent(sloverProc2, INTERRUPT_LINE, EVENTID,(Notify_FnNotifyCbck)cbFxn, NULL);if (status < 0) {System_abort("Notify_registerEvent for sloverCore2 failed \n");}// 完成从核2的事件注册}else{	while(Ipc_attach(masterProc)){Task_sleep(1);	}// 完成主核0的连接status = Notify_registerEvent(masterProc, INTERRUPT_LINE, EVENTID,(Notify_FnNotifyCbck)cbFxn, NULL);if (status < 0) {System_abort("Notify_registerEvent for masterCore0 failed\n");}// 完成主核0的事件注册}BIOS_start();return (0);
}

/*
 */
/*
 *  @(#) ti.sdo.ipc.examples.multicore.evm667x; 1, 0, 0, 0,1; 5-22-2012 16:36:06; /db/vtree/library/trees/ipc/ipc-h32/src/ xlibrary*/



int readimagedata(const double *fp)
{int i,j;printf("readimagedata ok!\n");for (i=0; i<4096; i++){for (j=0; j<169; j++){	h[i][j]=*fp;	fp+=1;//fscanf(fp, "%lf", &h[i][j]);
				//printf("%e\t",h[i][j]);}}printf("readimagedata complete!\n");return 0;
}


void  logo_matrix()
{
	printf("logo_matrix ok!");
	int i=0,j=0;
	for(i=0;i<64;)
	{
		for(j=0;j<64;)
		{
			k[j][i]=1;
			j=j+2;
		}
		i=i+4;
	}
	for(i=1;i<64;)
	{
		for(j=0;j<64;)
		{
			k[j][i]=2;
			j=j+2;
		}
		i=i+4;
	}
	for(i=2;i<64;)
	{
		for(j=0;j<64;)
		{
			k[j][i]=3;
			j=j+2;
		}
		i=i+4;
	}
	for(i=3;i<64;)
	{
		for(j=0;j<64;)
		{
			k[j][i]=4;
			j=j+2;
		}
		i=i+4;
	}
	for(i=0;i<64;)
	{
		for(j=1;j<64;)
		{
			k[j][i]=5;
			j=j+2;
		}
		i=i+4;
	}
	for(i=1;i<64;)
	{
		for(j=1;j<64;)
		{
			k[j][i]=6;
			j=j+2;
		}
		i=i+4;
	}
	for(i=2;i<64;)
	{
		for(j=1;j<64;)
		{
			k[j][i]=7;
			j=j+2;
		}
		i=i+4;
	}
	for(i=3;i<64;)
	{
		for(j=1;j<64;)
		{
			k[j][i]=8;
			j=j+2;
		}
		i=i+4;
	}

	printf("logo_matrix complete!");
	return;
}

void logo_h()
{
	printf("logo_h ok!");
	int i=0,j=0,count=0,a=0,b=0,c=0,d=0,e=0,f=0,g=0,x=0;

	for(i=0;i<512;i++){
		m1[i]=0;
		m2[i]=0;
		m3[i]=0;
		m4[i]=0;
		m5[i]=0;
		m6[i]=0;
		m7[i]=0;
		m8[i]=0;}
	for(i=0;i<64;i++)
	{
		for(j=0;j<64;j++)
		{
			if(k[j][i]==1)
			{
				m1[a]=count;
				a++;
			}
			else if(k[j][i]==2)
			{
				m2[b]=count;
				b++;
			}
			else if(k[j][i]==3)
			{
				m3[c]=count;
				c++;
			}
			else if(k[j][i]==4)
			{
				m4[d]=count;
				d++;
			}
			else if(k[j][i]==5)
			{
				m5[e]=count;
				e++;
			}
			else if(k[j][i]==6)
			{
				m6[f]=count;
				f++;
			}
			else if(k[j][i]==7)
			{
				m7[g]=count;
				g++;
			}
			else if(k[j][i]==8)
			{
				m8[x]=count;
				x++;
			}
			count++;
		}
		//count++;
	}int n=0;
	for(n=0;n<169;n++)
	{
		for(i=0;i<512;i++)
		{
			z1[i][n]=h[m1[i]][n];
			z2[i][n]=h[m2[i]][n];
			z3[i][n]=h[m3[i]][n];
			z4[i][n]=h[m4[i]][n];
			z5[i][n]=h[m5[i]][n];
			z6[i][n]=h[m6[i]][n];
			z7[i][n]=h[m7[i]][n];
			z8[i][n]=h[m8[i]][n];
		}
	}printf("logo-h complete!");return;
}


void test(double z[512][169])
{printf("test ok!\n");printf("test complete!\n");
}

void R1_inversion(double z[512][169]) {printf("R1_inversion ok!\n"); int i=0,j=0; rr=0; //float r1_matrix[169][169]; for(i=0;i<169;i++) { for(j=0;j<169;j++) { R1[i][j]=0; r1_matrix[i][j]=0; } } for(i=0;i<169;i++){rr=z[0][i]*z[0][i]+rr;}rr=rr/m+1;printf("rr=%e\n",rr);for(i=0;i<169;i++){ for(j=0;j<169;j++) { r1_matrix[i][j]=z[0][i]*z[0][j]/m/m/rr; if(i==j) R1[i][j]=1/m-r1_matrix[i][j]; else R1[i][j]=-r1_matrix[i][j]; }}printf("R1_inversion complete!\n"); }

Shine:

请问在仿真模式下有这个问题吗?还是就软仿真有这个问题?

user5179571:

回复 Shine:

您好,我尝试了一下用板子仿真,结果还是传不过去,而且主核打印一堆信息。

我在想,是不是因为我的子函数里面设置的全局变量的问题,在并行计算的时候,会产生错误??

希望能尽快解答,万分感谢~~

Shine:

回复 user5179571:

子函数的全局变量放在哪里?如果放在DDR中,有没有做cache一致性维护?

赞(0)
未经允许不得转载:TI中文支持网 » c6678 notify()例程 从核与主核之间通信卡停问题
分享到: 更多 (0)