00001
00011 #include "charm++.h"
00012 #include "queueing.h"
00013 #include "conv-trace.h"
00014
00015
00016
00017 int CqsFindRemoveSpecificPrioq(_prioq q, void *&msgPtr, const int *entryMethod, const int numEntryMethods );
00018 int CqsFindRemoveSpecificDeq(_deq q, void *&msgPtr, const int *entryMethod, const int numEntryMethods );
00019
00020
00022 void CqsIncreasePriorityForEntryMethod(Queue q, const int entrymethod){
00023 #if !CMK_USE_STL_MSGQ
00024 void *removedMsgPtr;
00025 int numRemoved;
00026
00027 int entryMethods[1];
00028 entryMethods[0] = entrymethod;
00029
00030 numRemoved = CqsFindRemoveSpecificPrioq(&(q->negprioq), removedMsgPtr, entryMethods, 1 );
00031 if(numRemoved == 0)
00032 numRemoved = CqsFindRemoveSpecificDeq(&(q->zeroprio), removedMsgPtr, entryMethods, 1 );
00033 if(numRemoved == 0)
00034 numRemoved = CqsFindRemoveSpecificPrioq(&(q->posprioq), removedMsgPtr, entryMethods, 1 );
00035
00036 if(numRemoved > 0){
00037 CkAssert(numRemoved==1);
00038 int prio = -1000000;
00039 CqsEnqueueGeneral(q, removedMsgPtr, CQS_QUEUEING_IFIFO, 0, (unsigned int*)&prio);
00040
00041 #if CMK_TRACE_ENABLED
00042 char traceStr[64];
00043 sprintf(traceStr, "Replacing %p in message queue with NULL", removedMsgPtr);
00044 traceUserSuppliedNote(traceStr);
00045 #endif
00046 }
00047 #endif
00048 }
00049
00050 #ifdef ADAPT_SCHED_MEM
00051
00052 void CqsIncreasePriorityForMemCriticalEntries(Queue q){
00053 #if !CMK_USE_STL_MSGQ
00054 void *removedMsgPtr;
00055 int numRemoved;
00056
00057 numRemoved = CqsFindRemoveSpecificPrioq(&(q->negprioq), removedMsgPtr, memCriticalEntries, numMemCriticalEntries);
00058 if(numRemoved == 0)
00059 numRemoved = CqsFindRemoveSpecificDeq(&(q->zeroprio), removedMsgPtr, memCriticalEntries, numMemCriticalEntries);
00060 if(numRemoved == 0)
00061 numRemoved = CqsFindRemoveSpecificPrioq(&(q->posprioq), removedMsgPtr, memCriticalEntries, numMemCriticalEntries);
00062
00063 if(numRemoved > 0){
00064 CkAssert(numRemoved==1);
00065 int prio = -1000000;
00066 CqsEnqueueGeneral(q, removedMsgPtr, CQS_QUEUEING_IFIFO, 0, (unsigned int*)&prio);
00067
00068 #if CMK_TRACE_ENABLED
00069 char traceStr[64];
00070 sprintf(traceStr, "Replacing %p in message queue with NULL", removedMsgPtr);
00071 traceUserSuppliedNote(traceStr);
00072 #endif
00073 }
00074 #endif
00075 }
00076 #endif
00077
00078 static bool checkAndRemoveMatching(void *&msgPtr, const int *entryMethod, const int numEntryMethods, envelope *env, void** &p) {
00079 if(env != NULL && (env->getMsgtype() == ForArrayEltMsg ||
00080 env->getMsgtype() == ForChareMsg)
00081 ){
00082 const int ep = env->getsetArrayEp();
00083 bool foundMatch = false;
00084
00085 for(int i=0;i<numEntryMethods;++i){
00086 if(ep==entryMethod[i]){
00087 foundMatch=true;
00088 break;
00089 }
00090 }
00091 if(foundMatch){
00092
00093 *p = NULL;
00094 msgPtr = env;
00095 return true;
00096 }
00097 }
00098 return false;
00099 }
00100
00111 int CqsFindRemoveSpecificDeq(_deq q, void *&msgPtr, const int *entryMethod, const int numEntryMethods ){
00112 void **iter = q->head;
00113
00114 while(iter != q->tail){
00115
00116 envelope *env = (envelope*)*iter;
00117 if (checkAndRemoveMatching(msgPtr, entryMethod, numEntryMethods, env, iter))
00118 return 1;
00119
00120
00121 iter++;
00122 if(iter == q->end)
00123 iter = q->bgn;
00124 }
00125 return 0;
00126 }
00127
00128
00129
00140 int CqsFindRemoveSpecificPrioq(_prioq q, void *&msgPtr, const int *entryMethod, const int numEntryMethods ){
00141
00142
00143 for(int i = 1; i < q->heapnext; i++){
00144
00145 _prioqelt pe = (q->heap)[i];
00146 void **head;
00147 void **tail;
00148 head = pe->data.head;
00149 tail = pe->data.tail;
00150 while(head != tail){
00151
00152 envelope *env = (envelope*)*head;
00153 if (checkAndRemoveMatching(msgPtr, entryMethod, numEntryMethods, env, head))
00154 return 1;
00155
00156
00157 head++;
00158 if(head == (pe->data).end)
00159 head = (pe->data).bgn;
00160 }
00161 }
00162 return 0;
00163 }
00164
00165
00166
00167
00168