00001 #include "conv-taskQ.h" 00002 #if CMK_SMP && CMK_TASKQUEUE 00003 extern "C" void StealTask() { 00004 #if CMK_TRACE_ENABLED 00005 double _start = CmiWallTimer(); 00006 #endif 00007 int random_rank = CrnRand() % (CmiMyNodeSize()-1); 00008 if (random_rank >= CmiMyRank()) 00009 ++random_rank; 00010 #if CMK_TRACE_ENABLED 00011 char s[10]; 00012 sprintf( s, "%d", random_rank ); 00013 traceUserSuppliedBracketedNote(s, TASKQ_QUEUE_STEAL_EVENTID, _start, CmiWallTimer()); 00014 #endif 00015 void* msg = TaskQueueSteal((TaskQueue)CpvAccessOther(CsdTaskQueue, random_rank)); 00016 if (msg != NULL) { 00017 TaskQueuePush((TaskQueue)CpvAccess(CsdTaskQueue), msg); 00018 } 00019 #if CMK_TRACE_ENABLED 00020 traceUserSuppliedBracketedNote(s, TASKQ_STEAL_EVENTID, _start, CmiWallTimer()); 00021 #endif 00022 } 00023 00024 static void TaskStealBeginIdle(void *dummy) { 00025 if (CmiMyNodeSize() > 1 && CpvAccess(isHelperOn)) 00026 StealTask(); 00027 } 00028 00029 extern "C" void CmiTaskQueueInit() { 00030 if(CmiMyNodeSize() > 1) { 00031 CcdCallOnConditionKeep(CcdPROCESSOR_BEGIN_IDLE, 00032 (CcdVoidFn) TaskStealBeginIdle, NULL); 00033 00034 CcdCallOnConditionKeep(CcdPROCESSOR_STILL_IDLE, 00035 (CcdVoidFn) TaskStealBeginIdle, NULL); 00036 } 00037 #if CMK_TRACE_ENABLED 00038 traceRegisterUserEvent("taskq create work", TASKQ_CREATE_EVENTID); 00039 traceRegisterUserEvent("taskq work", TASKQ_WORK_EVENTID); 00040 traceRegisterUserEvent("taskq steal", TASKQ_STEAL_EVENTID); 00041 traceRegisterUserEvent("taskq from queue steal", TASKQ_QUEUE_STEAL_EVENTID); 00042 #endif 00043 } 00044 #endif