5 #include "bgconverse.h"
7 #include "ccs-server.h"
11 extern "C" void CcsHandleRequest(CcsImplHeader *hdr,const char *reqData);
13 extern "C" void req_fw_handler(char *msg)
15 int offset = CmiReservedHeaderSize + sizeof(CcsImplHeader);
16 CcsImplHeader *hdr = (CcsImplHeader *)(msg+CmiReservedHeaderSize);
17 int destPE = (int)ChMessageInt(hdr->pe);
18 if (CmiMyPe() == 0 && destPE == -1) {
19 /* Broadcast message to all other processors */
20 int len=CmiReservedHeaderSize+sizeof(CcsImplHeader)+ChMessageInt(hdr->len);
21 CmiSyncBroadcast(len, msg);
23 else if (destPE < -1) {
24 /* Multicast the message to your children */
25 int len=CmiReservedHeaderSize+sizeof(CcsImplHeader)+ChMessageInt(hdr->len)-destPE*sizeof(ChMessageInt_t);
27 int *pes = (int*)(msg+CmiReservedHeaderSize+sizeof(CcsImplHeader));
28 ChMessageInt_t *pes_nbo = (ChMessageInt_t *)pes;
29 offset -= destPE * sizeof(ChMessageInt_t);
30 if (ChMessageInt(pes_nbo[0]) == CmiMyPe()) {
31 for (index=0; index<-destPE; ++index) pes[index] = ChMessageInt(pes_nbo[index]);
33 for (index=0; index<-destPE; ++index) {
34 if (pes[index] == CmiMyPe()) break;
36 child = (index << 2) + 1;
38 if (child+i < -destPE) {
39 CmiSyncSend(pes[child+i], len, msg);
43 CcsHandleRequest(hdr, msg+offset);
48 extern "C" size_t write(int fd, const void *buf, size_t count);
51 extern "C" int rep_fw_handler_idx;
53 * Decide if the reply is ready to be forwarded to the waiting client,
54 * or if combination is required (for broadcast/multicast CCS requests.
56 extern "C" int CcsReply(CcsImplHeader *rep,int repLen,const void *repData) {
57 int repPE = (int)ChMessageInt(rep->pe);
59 /* Reduce the message to get the final reply */
61 int len=CmiReservedHeaderSize+sizeof(CcsImplHeader)+repLen;
62 char *msg=(char*)CmiAlloc(len);
63 char *r=msg+CmiReservedHeaderSize;
65 rep->len = ChMessageInt_new(repLen);
66 *(CcsImplHeader *)r=*rep; r+=sizeof(CcsImplHeader);
67 memcpy(r,repData,repLen);
68 CmiSetHandler(msg,rep_fw_handler_idx);
69 handlerStr=rep->handler;
70 fn=(CcsHandlerRec *)CcsGetHandler(handlerStr);
71 if (fn->mergeFn == NULL) CmiAbort("Called CCS broadcast with NULL merge function!\n");
74 CkReduce(msg, len, fn->mergeFn);
77 CmiListReduce(-repPE, (int*)(rep+1), msg, len, fn->mergeFn, fn->redID);
80 if (_conditionalDelivery == 0) CcsImpl_reply(rep, repLen, repData);
82 /* We are the child of a conditional delivery, write to the parent the reply */
83 write(conditionalPipe[1], &repLen, 4);
84 write(conditionalPipe[1], repData, repLen);
91 /**********************************************
92 "ccs_getinfo"-- takes no data
93 Return the number of parallel nodes, and
94 the number of processors per node as an array
95 of 4-byte big-endian ints.
98 void ccs_getinfo(char *msg)
100 int nNode=CmiNumNodes();
101 int len=(1+nNode)*sizeof(ChMessageInt_t);
102 ChMessageInt_t *table=(ChMessageInt_t *)malloc(len);
104 table[0]=ChMessageInt_new(nNode);
105 for (n=0;n<nNode;n++)
106 table[1+n]=ChMessageInt_new(CmiNodeSize(n));
107 CcsSendReply(len,(const char *)table);
112 ///////////////////////////////// middle-debug.C
120 CpvDeclare(void *, debugQueue);
121 CpvDeclare(int, freezeModeFlag);
124 Start the freeze-- call will not return until unfrozen
133 CpdNotify(CPD_FREEZE,pid);
134 if (CpvAccess(freezeModeFlag)) return; /*Already frozen*/
135 CpvAccess(freezeModeFlag) = 1;
136 #if ! CMK_BIGSIM_CHARM
137 CpdFreezeModeScheduler();
141 void CpdUnFreeze(void)
143 CpvAccess(freezeModeFlag) = 0;
146 int CpdIsFrozen(void) {
147 return CpvAccess(freezeModeFlag);
153 #include "blue_impl.h"
154 void BgProcessMessageFreezeMode(threadInfo *t, char *msg) {
155 // CmiPrintf("BgProcessMessageFreezeMode\n");
156 #if CMK_CCS_AVAILABLE
157 void *debugQ=CpvAccess(debugQueue);
158 CmiAssert(msg!=NULL);
159 int processImmediately = CpdIsDebugMessage(msg);
160 if (processImmediately) BgProcessMessageDefault(t, msg);
161 while (!CpvAccess(freezeModeFlag) && !CdsFifo_Empty(debugQ)) {
162 BgProcessMessageDefault(t, (char*)CdsFifo_Dequeue(debugQ));
164 if (!processImmediately) {
165 if (!CpvAccess(freezeModeFlag)) BgProcessMessageDefault(t, msg);
166 else CdsFifo_Enqueue(debugQ, msg);
169 BgProcessMessageDefault(t, msg);
174 void PrintDebugStackTrace(void *);
175 extern "C" void * MemoryToSlot(void *ptr);
176 extern "C" int Slot_StackTrace(void *s, void ***stack);
177 extern "C" int Slot_ChareOwner(void *s);
180 void CpdNotify(int type, ...) {
181 void *ptr; int integer, i;
187 va_start(list, type);
190 CmiPrintf("CPD: %d Abort %s\n",CmiMyPe(), va_arg(list, char*));
193 CmiPrintf("CPD: %d Signal %d\n",CmiMyPe(), va_arg(list, int));
199 CmiPrintf("CPD: %d Freeze %d\n",CmiMyPe(),pid);
202 CmiPrintf("CPD: %d BP %s\n",CmiMyPe(), va_arg(list, char*));
204 case CPD_CROSSCORRUPTION:
205 ptr = va_arg(list, void*);
206 integer = va_arg(list, int);
207 CmiPrintf("CPD: %d Cross %p %d ",CmiMyPe(), ptr, integer);
208 sl = MemoryToSlot(ptr);
210 int stackLen; void **stackTrace;
211 stackLen = Slot_StackTrace(sl, &stackTrace);
212 CmiPrintf("%d %d ",Slot_ChareOwner(sl),stackLen);
213 for (i=0; i<stackLen; ++i) CmiPrintf("%p ",stackTrace[i]);
217 CmiBacktraceRecord(stackPtrs,1,&levels);
218 CmiPrintf("%d ",levels);
219 for (i=0; i<levels; ++i) CmiPrintf("%p ",stackPtrs[i]);