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 void *removedMsgPtr;
00024 int numRemoved;
00025
00026 int entryMethods[1];
00027 entryMethods[0] = entrymethod;
00028
00029 numRemoved = CqsFindRemoveSpecificPrioq(&(q->negprioq), removedMsgPtr, entryMethods, 1 );
00030 if(numRemoved == 0)
00031 numRemoved = CqsFindRemoveSpecificDeq(&(q->zeroprio), removedMsgPtr, entryMethods, 1 );
00032 if(numRemoved == 0)
00033 numRemoved = CqsFindRemoveSpecificPrioq(&(q->posprioq), removedMsgPtr, entryMethods, 1 );
00034
00035 if(numRemoved > 0){
00036 CkAssert(numRemoved==1);
00037 int prio = -1000000;
00038 CqsEnqueueGeneral(q, removedMsgPtr, CQS_QUEUEING_IFIFO, 0, (unsigned int*)&prio);
00039
00040 #ifndef CMK_OPTIMIZE
00041 char traceStr[64];
00042 sprintf(traceStr, "Replacing %p in message queue with NULL", removedMsgPtr);
00043 traceUserSuppliedNote(traceStr);
00044 #endif
00045 }
00046 }
00047
00048 #ifdef ADAPT_SCHED_MEM
00049
00050 void CqsIncreasePriorityForMemCriticalEntries(Queue q){
00051 void *removedMsgPtr;
00052 int numRemoved;
00053
00054 numRemoved = CqsFindRemoveSpecificPrioq(&(q->negprioq), removedMsgPtr, memCriticalEntries, numMemCriticalEntries);
00055 if(numRemoved == 0)
00056 numRemoved = CqsFindRemoveSpecificDeq(&(q->zeroprio), removedMsgPtr, memCriticalEntries, numMemCriticalEntries);
00057 if(numRemoved == 0)
00058 numRemoved = CqsFindRemoveSpecificPrioq(&(q->posprioq), removedMsgPtr, memCriticalEntries, numMemCriticalEntries);
00059
00060 if(numRemoved > 0){
00061 CkAssert(numRemoved==1);
00062 int prio = -1000000;
00063 CqsEnqueueGeneral(q, removedMsgPtr, CQS_QUEUEING_IFIFO, 0, (unsigned int*)&prio);
00064
00065 #ifndef CMK_OPTIMIZE
00066 char traceStr[64];
00067 sprintf(traceStr, "Replacing %p in message queue with NULL", removedMsgPtr);
00068 traceUserSuppliedNote(traceStr);
00069 #endif
00070 }
00071 }
00072 #endif
00073
00084 int CqsFindRemoveSpecificDeq(_deq q, void *&msgPtr, const int *entryMethod, const int numEntryMethods ){
00085 void **iter = q->head;
00086
00087 while(iter != q->tail){
00088
00089 envelope *env = (envelope*)*iter;
00090 if(env != NULL && (env->getMsgtype() == ForArrayEltMsg || env->getMsgtype() == ForChareMsg)){
00091 const int ep = env->getsetArrayEp();
00092 bool foundMatch = false;
00093
00094 for(int i=0;i<numEntryMethods;++i){
00095 if(ep==entryMethod[i]){
00096 foundMatch=true;
00097 break;
00098 }
00099 }
00100 if(foundMatch){
00101
00102 *iter = NULL;
00103 msgPtr = env;
00104 return 1;
00105 }
00106 }
00107
00108 iter++;
00109 if(iter == q->end)
00110 iter = q->bgn;
00111 }
00112 return 0;
00113 }
00114
00115
00116
00127 int CqsFindRemoveSpecificPrioq(_prioq q, void *&msgPtr, const int *entryMethod, const int numEntryMethods ){
00128
00129
00130 for(int i = 1; i < q->heapnext; i++){
00131
00132 _prioqelt pe = (q->heap)[i];
00133 void **head;
00134 void **tail;
00135 head = pe->data.head;
00136 tail = pe->data.tail;
00137 while(head != tail){
00138
00139 envelope *env = (envelope*)*head;
00140 if(env != NULL && (env->getMsgtype() == ForArrayEltMsg || env->getMsgtype() == ForChareMsg)){
00141 const int ep = env->getsetArrayEp();
00142 bool foundMatch = false;
00143
00144 for(int i=0;i<numEntryMethods;++i){
00145 if(ep==entryMethod[i]){
00146 foundMatch=true;
00147
00148 }
00149 }
00150 if(foundMatch){
00151
00152 *head = NULL;
00153 msgPtr = env;
00154 return 1;
00155 }
00156 }
00157
00158 head++;
00159 if(head == (pe->data).end)
00160 head = (pe->data).bgn;
00161 }
00162 }
00163 return 0;
00164 }
00165
00166
00167
00168
00169