5 #include "bgconverse.h"
7 #include "ccs-server.h"
11 # include <sys/types.h>
15 # define getpid _getpid
19 void CcsHandleRequest(CcsImplHeader *hdr,const char *reqData);
21 void req_fw_handler(char *msg)
23 int offset = CmiReservedHeaderSize + sizeof(CcsImplHeader);
24 CcsImplHeader *hdr = (CcsImplHeader *)(msg+CmiReservedHeaderSize);
25 int destPE = (int)ChMessageInt(hdr->pe);
26 if (CmiMyPe() == 0 && destPE == -1) {
27 /* Broadcast message to all other processors */
28 int len=CmiReservedHeaderSize+sizeof(CcsImplHeader)+ChMessageInt(hdr->len);
29 CmiSyncBroadcast(len, msg);
31 else if (destPE < -1) {
32 /* Multicast the message to your children */
33 int len=CmiReservedHeaderSize+sizeof(CcsImplHeader)+ChMessageInt(hdr->len)-destPE*sizeof(ChMessageInt_t);
35 int *pes = (int*)(msg+CmiReservedHeaderSize+sizeof(CcsImplHeader));
36 ChMessageInt_t *pes_nbo = (ChMessageInt_t *)pes;
37 offset -= destPE * sizeof(ChMessageInt_t);
38 if (ChMessageInt(pes_nbo[0]) == CmiMyPe()) {
39 for (index=0; index<-destPE; ++index) pes[index] = ChMessageInt(pes_nbo[index]);
41 for (index=0; index<-destPE; ++index) {
42 if (pes[index] == CmiMyPe()) break;
44 child = (index << 2) + 1;
46 if (child+i < -destPE) {
47 CmiSyncSend(pes[child+i], len, msg);
51 CcsHandleRequest(hdr, msg+offset);
55 extern int rep_fw_handler_idx;
57 * Decide if the reply is ready to be forwarded to the waiting client,
58 * or if combination is required (for broadcast/multicast CCS requests.
60 int CcsReply(CcsImplHeader *rep,int repLen,const void *repData) {
61 int repPE = (int)ChMessageInt(rep->pe);
63 /* Reduce the message to get the final reply */
65 int len=CmiReservedHeaderSize+sizeof(CcsImplHeader)+repLen;
66 char *msg=(char*)CmiAlloc(len);
67 char *r=msg+CmiReservedHeaderSize;
69 rep->len = ChMessageInt_new(repLen);
70 *(CcsImplHeader *)r=*rep; r+=sizeof(CcsImplHeader);
71 memcpy(r,repData,repLen);
72 CmiSetHandler(msg,rep_fw_handler_idx);
73 handlerStr=rep->handler;
74 fn=(CcsHandlerRec *)CcsGetHandler(handlerStr);
75 if (fn->mergeFn == NULL) CmiAbort("Called CCS broadcast with NULL merge function!\n");
78 CkReduce(msg, len, fn->mergeFn);
81 CmiListReduce(-repPE, (int*)(rep+1), msg, len, fn->mergeFn, fn->redID);
84 if (_conditionalDelivery == 0) CcsImpl_reply(rep, repLen, repData);
86 /* We are the child of a conditional delivery, write to the parent the reply */
87 if (write(conditionalPipe[1], &repLen, 4) != 4) {
88 CmiAbort("CCS> writing reply length to parent failed!");
90 if (write(conditionalPipe[1], repData, repLen) != repLen) {
91 CmiAbort("CCS> writing reply data to parent failed!");
99 /**********************************************
100 "ccs_getinfo"-- takes no data
101 Return the number of parallel nodes, and
102 the number of processors per node as an array
103 of 4-byte big-endian ints.
106 void ccs_getinfo(char *msg)
108 int nNode=CmiNumNodes();
109 int len=(1+nNode)*sizeof(ChMessageInt_t);
110 ChMessageInt_t *table=(ChMessageInt_t *)malloc(len);
112 table[0]=ChMessageInt_new(nNode);
113 for (n=0;n<nNode;n++)
114 table[1+n]=ChMessageInt_new(CmiNodeSize(n));
115 CcsSendReply(len,(const char *)table);
120 ///////////////////////////////// middle-debug.C
126 CpvCExtern(void *, debugQueue);
127 CpvDeclare(void *, debugQueue);
128 CpvCExtern(int, freezeModeFlag);
129 CpvDeclare(int, freezeModeFlag);
132 Start the freeze-- call will not return until unfrozen
141 CpdNotify(CPD_FREEZE,pid);
142 if (CpvAccess(freezeModeFlag)) return; /*Already frozen*/
143 CpvAccess(freezeModeFlag) = 1;
144 #if ! CMK_BIGSIM_CHARM
145 CpdFreezeModeScheduler();
149 void CpdUnFreeze(void)
151 CpvAccess(freezeModeFlag) = 0;
154 int CpdIsFrozen(void) {
155 return CpvAccess(freezeModeFlag);
159 #include "blue_impl.h"
160 void BgProcessMessageFreezeMode(threadInfo *t, char *msg) {
161 // CmiPrintf("BgProcessMessageFreezeMode\n");
162 #if CMK_CCS_AVAILABLE
163 void *debugQ=CpvAccess(debugQueue);
164 CmiAssert(msg!=NULL);
165 int processImmediately = CpdIsDebugMessage(msg);
166 if (processImmediately) BgProcessMessageDefault(t, msg);
167 while (!CpvAccess(freezeModeFlag) && !CdsFifo_Empty(debugQ)) {
168 BgProcessMessageDefault(t, (char*)CdsFifo_Dequeue(debugQ));
170 if (!processImmediately) {
171 if (!CpvAccess(freezeModeFlag)) BgProcessMessageDefault(t, msg);
172 else CdsFifo_Enqueue(debugQ, msg);
175 BgProcessMessageDefault(t, msg);
180 void PrintDebugStackTrace(void *);
181 void * MemoryToSlot(void *ptr);
182 int Slot_StackTrace(void *s, void ***stack);
183 int Slot_ChareOwner(void *s);
186 void CpdNotify(int type, ...) {
187 void *ptr; int integer, i;
193 va_start(list, type);
196 CmiPrintf("CPD: %d Abort %s\n",CmiMyPe(), va_arg(list, char*));
199 CmiPrintf("CPD: %d Signal %d\n",CmiMyPe(), va_arg(list, int));
205 CmiPrintf("CPD: %d Freeze %d\n",CmiMyPe(),pid);
208 CmiPrintf("CPD: %d BP %s\n",CmiMyPe(), va_arg(list, char*));
210 case CPD_CROSSCORRUPTION:
211 ptr = va_arg(list, void*);
212 integer = va_arg(list, int);
213 CmiPrintf("CPD: %d Cross %p %d ",CmiMyPe(), ptr, integer);
214 sl = MemoryToSlot(ptr);
216 int stackLen; void **stackTrace;
217 stackLen = Slot_StackTrace(sl, &stackTrace);
218 CmiPrintf("%d %d ",Slot_ChareOwner(sl),stackLen);
219 for (i=0; i<stackLen; ++i) CmiPrintf("%p ",stackTrace[i]);
223 CmiBacktraceRecord(stackPtrs,1,&levels);
224 CmiPrintf("%d ",levels);
225 for (i=0; i<levels; ++i) CmiPrintf("%p ",stackPtrs[i]);