static void has_finished(const char* str, double time) 
{
   DENTER(TOP_LAYER, "has_finished");

   sge_mutex_lock("has_finished", SGE_FUNC, __LINE__, &Control.mutex);
   Control.working--;
   Control.time += time;

   if (Control.working == 0) {
      Control.working = threads;
      Control.time /= threads;
      printf("%s : %fs\n", str, Control.time);
      Control.time = 0.0;
      pthread_cond_broadcast(&Control.cond_var);
      
   }
   else {
      struct timespec ts;
      ts.tv_sec = (long) (sge_get_gmt() + 180);
      ts.tv_nsec = 0; 
      pthread_cond_timedwait(&Control.cond_var,
                             &Control.mutex, &ts);
   }
   
   sge_mutex_unlock("has_finished", SGE_FUNC, __LINE__, &Control.mutex);
   
   DEXIT;
}
Ejemplo n.º 2
0
/****** qsub_terminate() *******************************************************
*  NAME
*     qsub_terminate() -- Terminates qsub
*
*  SYNOPSIS
*     void qsub_terminate(void)
*
*  FUNCTION
*     Prints out messages that qsub is ending and exits JAPI.
*
*  NOTES
*     MT-NOTES: qsub_terminate() is MT safe
*******************************************************************************/
static void qsub_terminate(void)
{
   dstring diag = DSTRING_INIT;
   int tmp_ret;
   
   fprintf(stderr, "\n%s\n", MSG_QSUB_INTERRUPTED);
   fprintf(stderr, "%s\n", MSG_QSUB_TERMINATING);

   tmp_ret = japi_exit(JAPI_EXIT_KILL_PENDING, &diag);
   
   /* No active session here means that the main thread beat us to exiting,
      in which case, we just quietly give up and go away. */
   if ((tmp_ret != DRMAA_ERRNO_SUCCESS) &&
       (tmp_ret != DRMAA_ERRNO_NO_ACTIVE_SESSION)) {
      fprintf(stderr, "\n");
      fprintf(stderr, MSG_QSUB_COULDNOTFINALIZEENV_S,
              sge_dstring_get_string(&diag));
      fprintf(stderr, "\n");
   }

   sge_dstring_free(&diag);

   sge_mutex_lock("qsub_exit_mutex", "qsub_terminate", __LINE__, &exit_mutex);
   exited = true;
   pthread_cond_signal(&exit_cv);
   sge_mutex_unlock("qsub_exit_mutex", "qsub_terminate", __LINE__, &exit_mutex);
}
/****** qmaster/sge_thread_scheduler/event_update_func() **************************
*  NAME
*     event_update_func() -- 
*
*  SYNOPSIS
*     void event_update_func(lList **alpp, lList *event_list)
*
*  FUNCTION
*
*  INPUTS
*     lList **alpp - answer list
*     lList *event_list - a report list, the event are stored in REP_list
*
*  RESULT
*     void - none
*
*  NOTES
*     MT-NOTE: is MT safe. 
*
*******************************************************************************/
void event_update_func(u_long32 ec_id, lList **alpp, lList *event_list) 
{
   DENTER(TOP_LAYER, "event_update_func");

   sge_mutex_lock("event_control_mutex", SGE_FUNC, __LINE__, &Scheduler_Control.mutex);  
   
   if (Scheduler_Control.new_events != NULL) {
      lList *events = NULL;
      lXchgList(lFirst(event_list), REP_list, &(events));
      lAddList(Scheduler_Control.new_events, &events);
   } else {
      lXchgList(lFirst(event_list), REP_list, &(Scheduler_Control.new_events));
   }   
   
   Scheduler_Control.triggered = true;

   DPRINTF(("EVENT UPDATE FUNCTION event_update_func() HAS BEEN TRIGGERED\n"));

   pthread_cond_signal(&Scheduler_Control.cond_var);

   sge_mutex_unlock("event_control_mutex", SGE_FUNC, __LINE__, &Scheduler_Control.mutex);


   DRETURN_VOID;
}
Ejemplo n.º 4
0
void log_state_set_log_context(void *theCtx)
{
   sge_mutex_lock("Log_State_Lock", "log_state_set_log_context", __LINE__, &Log_State.mutex);
   
   log_set_log_context((sge_gdi_ctx_class_t*)theCtx);

   sge_mutex_unlock("Log_State_Lock", "log_state_set_log_context", __LINE__, &Log_State.mutex);
}
Ejemplo n.º 5
0
/****** uti/log/log_state_set_log_as_admin_user() *****************************
*  NAME
*     log_state_set_log_as_admin_user() -- Enable/Disable logging as admin user 
*
*  SYNOPSIS
*     void log_state_set_log_as_admin_user(int i)
*
*  FUNCTION
*     This function enables/disables logging as admin user. This 
*     means that the function/macros switches from start user to 
*     admin user before any messages will be written. After that 
*     they will switch back to 'start' user. 
*
*  INPUTS
*     int i - 0 or 1 
*  
*  SEE ALSO
*     uti/uidgid/sge_switch2admin_user
*     uti/uidgid/sge_switch2start_user
******************************************************************************/
void log_state_set_log_as_admin_user(int i)
{
   sge_mutex_lock("Log_State_Lock", "log_state_set_log_as_admin_user", __LINE__, &Log_State.mutex);
   
   Log_State.log_as_admin_user = i;

   sge_mutex_unlock("Log_State_Lock", "log_state_set_log_as_admin_user", __LINE__, &Log_State.mutex);
}
Ejemplo n.º 6
0
/****** uti/log/log_state_set_log_verbose() *****************************************
*  NAME
*     log_state_set_log_verbose() -- Enable/disable verbose logging 
*
*  SYNOPSIS
*     void log_state_set_log_verbose(int i) 
*
*  FUNCTION
*     Enable/disable verbose logging 
*
*  INPUTS
*     int i - 0 or 1  
*
*  SEE ALSO
*     uti/log/log_state_get_log_verbose() 
******************************************************************************/
void log_state_set_log_verbose(int i)
{
   sge_mutex_lock("Log_State_Lock", "log_state_set_log_verbose", __LINE__, &Log_State.mutex);
   
   Log_State.verbose = i;
   
   sge_mutex_unlock("Log_State_Lock", "log_state_set_log_verbose", __LINE__, &Log_State.mutex);

   return;
}
Ejemplo n.º 7
0
void log_state_set_log_file(char *theFile)
{
   sge_mutex_lock("Log_State_Lock", "log_state_set_log_file", __LINE__, &Log_State.mutex);
   
   Log_State.log_file = theFile;
   
   sge_mutex_unlock("Log_State_Lock", "log_state_set_log_file", __LINE__, &Log_State.mutex);

   return;
}
Ejemplo n.º 8
0
/****** uti/tq/sge_tq_wait_for_task() ******************************************
*  NAME
*     sge_tq_wait_for_task() -- Waits for a task 
*
*  SYNOPSIS
*     bool 
*     sge_tq_wait_for_task(sge_tq_queue_t *queue, int seconds, 
*                          sge_tq_type_t type, void **data);
*
*  FUNCTION
*     This function tries to get a task of 'type'. If there is one
*     available then the data pointer will be returned in 'data'.  If there
*     is none available the this function will sleep a number of 'seconds'
*     before it checks again if there is a task available. 
*
*     The sleep time might be interrupted by another thread that adds a
*     task to the queue via sge_tq_store_notify() or by a thread that
*     called sge_tq_wakeup_waiting().
*
*     The function returns either if a task of the correct type is 
*     available of if sge_thread_has_shutdown_started() returns true to
*     indicate that the shutdown of the thread/process has been triggered.
*     In that case the function might return with NULL in *data.
*
*  INPUTS
*     sge_tq_queue_t *queue - task queue 
*     int seconds           - max number of seconds to sleep 
*     sge_tq_type_t type    - type of the task that should be returned 
*     void **data           - NULL in case of thread/process shutdown 
*                             or the data pointer of the task
*
*  RESULT
*     bool - error state
*        true  - success
*        false - error
*
*  NOTES
*     MT-NOTE: sge_tq_wait_for_task() is MT safe 
*
*  SEE ALSO
*     uti/tq/sge_tq_store_notify()
*     uti/tq/sge_tq_wakeup_waiting()
*     uti/thread_ctrl/sge_thread_has_shutdown_started()
*     uti/thread_ctrl/sge_thread_notify_all_waiting()
*******************************************************************************/
bool
sge_tq_wait_for_task(sge_tq_queue_t *queue, int seconds,
                     sge_tq_type_t type, void **data) {
   bool ret = true;
   
   DENTER(TQ_LAYER, "sge_tq_wait_for_task");
   if (queue != NULL && data != NULL) {
      sge_sl_elem_t *elem = NULL;
      sge_tq_task_t key;

      key.type = type;
      *data = NULL;

      sge_mutex_lock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));
     
      /*
       * block until either
       * - number of 'seconds' have elapsed and there is a task in the list
       * - someone notified to wakeup and shutdown of current thread/process has been triggered
       */  
      ret = sge_sl_elem_search(queue->list, &elem, &key, 
                               sge_tq_task_compare_type, SGE_SL_FORWARD);
      if (ret && elem == NULL && sge_thread_has_shutdown_started() == false) {
         queue->waiting++;
         do {
            struct timespec ts;

            sge_relative_timespec(seconds, &ts);
            pthread_cond_timedwait(&(queue->cond), sge_sl_get_mutex(queue->list), &ts);
            ret = sge_sl_elem_search(queue->list, &elem, &key, 
                                     sge_tq_task_compare_type, SGE_SL_FORWARD);
         } while (ret && elem == NULL && sge_thread_has_shutdown_started() == false);
         queue->waiting--;
      }

      /*
       * If we found a element that matches the key then remove and destroy if and return the data
       */ 
      if (ret && elem != NULL) {
         if (ret) {
            ret = sge_sl_dechain(queue->list, elem);
         }
         if (ret) {
            sge_tq_task_t *task = NULL;

            task = sge_sl_elem_data(elem);
            *data = task->data;
            ret = sge_sl_elem_destroy(&elem, (sge_sl_destroy_f)sge_tq_task_destroy);
         }
      }
 
      sge_mutex_unlock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));
   }
   DRETURN(ret);
}
Ejemplo n.º 9
0
/****** uti/log/log_state_set_log_level() *****************************************
*  NAME
*     log_state_set_log_level() -- Set log level to be used.
*
*  SYNOPSIS
*     void log_state_set_log_level(int i) 
*
*  FUNCTION
*     Set log level to be used.
*
*  INPUTS
*     u_long32 
*
*  SEE ALSO
*     uti/log/log_state_get_log_level() 
******************************************************************************/
void log_state_set_log_level(u_long32 theLevel)
{ 

   sge_mutex_lock("Log_State_Lock", "log_state_set_log_level", __LINE__, &Log_State.mutex);
   
   Log_State.log_level = theLevel;

   sge_mutex_unlock("Log_State_Lock", "log_state_set_log_level", __LINE__, &Log_State.mutex);

   return;
}
Ejemplo n.º 10
0
/****** uti/log/log_state_set_log_gui() ********************************************
*  NAME
*     log_state_set_log_gui() -- Enable/disable logging for GUIs 
*
*  SYNOPSIS
*     void log_state_set_log_gui(int i) 
*
*  FUNCTION
*     Enable/disable logging for GUIs 
*     With GUI logging enabled messages are printed to stderr/stdout.  
*
*  INPUTS
*     int i - 0 or 1 
******************************************************************************/
void log_state_set_log_gui(int i)
{

   sge_mutex_lock("Log_State_Lock", "log_state_set_log_gui", __LINE__, &Log_State.mutex);
   
   Log_State.gui_log = i;

   sge_mutex_unlock("Log_State_Lock", "log_state_set_log_gui", __LINE__, &Log_State.mutex);
   
   return;
}   
Ejemplo n.º 11
0
/****** uti/monitor/sge_monitor_free() *****************************************
*  NAME
*     sge_monitor_free() -- frees the monitoring data structure
*
*  SYNOPSIS
*     void sge_monitor_free(monitoring_t *monitor) 
*
*  FUNCTION
*     removes the line for the commlib output, and frees memory in the 
*     monitoring structure
*
*  INPUTS
*     monitoring_t *monitor - monitoring strucutre
*
*  NOTES
*     MT-NOTE: sge_monitor_free() is MT safe 
*
*******************************************************************************/
void sge_monitor_free(monitoring_t *monitor)
{
   DENTER(GDI_LAYER, "sge_monitor_free");
  
   sge_dstring_free(monitor->output_line1);
   sge_dstring_free(monitor->output_line2);
   sge_free(&(monitor->output_line1));
   sge_free(&(monitor->output_line2));
   sge_free(&(monitor->ext_data));

   if(monitor->pos != -1) {
      sge_mutex_lock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[monitor->pos].Output_Mutex));

      Output[monitor->pos].output = NULL;
      Output[monitor->pos].name = NULL;
      Output[monitor->pos].warning_timeout = NO_WARNING;
      Output[monitor->pos].error_timeout = NO_ERROR;
   
      sge_mutex_unlock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[monitor->pos].Output_Mutex));
   }
   
   monitor->ext_data_size = 0;
   monitor->ext_output = NULL;
   monitor->ext_type = NONE_EXT;
   monitor->monitor_time = 0;
   monitor->pos = -1;
   monitor->output = false;
   monitor->work_line = NULL;
   monitor->thread_name = NULL;

#if defined(LINUX) || defined(AIX43) || defined(AIX51) || defined(IRIX) || defined(SOLARIS) || defined(HP11)
   sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex);
   if (mallinfo_shlib_handle != NULL) {  
      dlclose(mallinfo_shlib_handle);
      mallinfo_shlib_handle = NULL;
   }
   sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex);
#endif
 
   DEXIT;
}
Ejemplo n.º 12
0
/****** uti/log/log_state_get_log_as_admin_user() ******************************************
*  NAME
*     log_state_get_log_as_admin_user() -- Needs sge_log() to change into admin user?
*
*  SYNOPSIS
*     trace_func_type log_state_get_log_as_admin_user(void) 
*
*  FUNCTION
*     Returns whether logging shall be done as admin user.
*
*  RESULT
*     int
*
*  SEE ALSO
*     uti/log/log_state_set_log_as_admin_user()
******************************************************************************/
int log_state_get_log_as_admin_user(void)
{
   int log_as_admin_user = 0;

   sge_mutex_lock("Log_State_Lock", "log_state_get_log_as_admin_user", __LINE__, &Log_State.mutex);
   
   log_as_admin_user = Log_State.log_as_admin_user;
   
   sge_mutex_unlock("Log_State_Lock", "log_state_get_log_as_admin_user", __LINE__, &Log_State.mutex);

   return log_as_admin_user;
}
Ejemplo n.º 13
0
/****** uti/log/log_state_get_log_gui() ******************************************
*  NAME
*     log_state_get_log_gui() -- Is GUI logging enabled?
*
*  SYNOPSIS
*     int log_state_get_log_gui(void) 
*
*  FUNCTION
*     Is GUI logging enabled? 
*     With GUI logging enabled messages are printed to stderr/stdout.  
*
*  RESULT
*     int - 0 or 1 
*
*  SEE ALSO
*     uti/log/log_state_set_log_gui()
******************************************************************************/
int log_state_get_log_gui(void)
{
   int gui_log = 0;

   sge_mutex_lock("Log_State_Lock", "log_state_get_log_gui", __LINE__, &Log_State.mutex);
   
   gui_log = Log_State.gui_log;

   sge_mutex_unlock("Log_State_Lock", "log_state_get_log_gui", __LINE__, &Log_State.mutex);

   return gui_log;
}
Ejemplo n.º 14
0
/****** uti/log/log_state_get_log_verbose() ******************************************
*  NAME
*     log_state_get_log_verbose() -- Is verbose logging enabled?
*
*  SYNOPSIS
*     int log_state_get_log_verbose(void) 
*
*  FUNCTION
*     Is verbose logging enabled? 
*     With verbose logging enabled not only ERROR/CRITICAL messages are 
*     printed to stderr but also WARNING/INFO.
*
*  RESULT
*     int - 0 or 1 
*
*  SEE ALSO
*     uti/log/log_state_set_log_verbose()
******************************************************************************/
int log_state_get_log_verbose(void)
{
   int verbose = 0;

   sge_mutex_lock("Log_State_Lock", "log_state_get_log_verbose", __LINE__, &Log_State.mutex);
   
   verbose = Log_State.verbose;
   
   sge_mutex_unlock("Log_State_Lock", "log_state_get_log_verbose", __LINE__, &Log_State.mutex);

   return verbose;
}
Ejemplo n.º 15
0
/****** uti/sge_log/log_state_get_log_file() ***********************************
*  NAME
*     log_state_get_log_file() -- get log file name
*
*  SYNOPSIS
*     const char* log_state_get_log_file(void) 
*
*  FUNCTION
*     Return name of current log file. The string returned may or may not 
*     contain a path.
*
*  INPUTS
*     void - none 
*
*  RESULT
*     const char* - log file name (with relative or absolute path)
*
*  NOTES
*     MT-NOTE: log_state_get_log_file() is not MT safe.
*     MT-NOTE:
*     MT-NOTE: It is safe, however, to call this function from within multiple
*     MT-NOTE: threads as long as no other thread does change 'Log_File'.
*
*  BUGS
*     BUGBUG-AD: This function should use something like a barrier for
*     BUGBUG-AD: synchronization.
*
*******************************************************************************/
const char *log_state_get_log_file(void)
{
   char* file = NULL;

   sge_mutex_lock("Log_State_Lock", "log_state_get_log_file", __LINE__, &Log_State.mutex);

   file = Log_State.log_file;

   sge_mutex_unlock("Log_State_Lock", "log_state_get_log_file", __LINE__, &Log_State.mutex);

   return file;
}
Ejemplo n.º 16
0
/****** uti/log/log_state_get_log_level() ******************************************
*  NAME
*     log_state_get_log_level() -- Return log level.
*
*  SYNOPSIS
*     u_long32 log_state_get_log_level(void) 
*
*  FUNCTION
*     Return log level
*
*  RESULT
*     u_long32
*
******************************************************************************/
u_long32 log_state_get_log_level(void)
{
   u_long32 level = 0;

   sge_mutex_lock("Log_State_Lock", "log_state_get_log_level", __LINE__, &Log_State.mutex);

   level = Log_State.log_level;

   sge_mutex_unlock("Log_State_Lock", "log_state_get_log_level", __LINE__, &Log_State.mutex);

   return level;
}
Ejemplo n.º 17
0
/****** uti/tq/sge_tq_get_waiting_count() **************************************
*  NAME
*     sge_tq_get_waiting_count() -- Returns number of waiting threads 
*
*  SYNOPSIS
*     u_long32 sge_tq_get_waiting_count(sge_tq_queue_t *queue) 
*
*  FUNCTION
*     This function returns the number of waiting threads. If this number
*     is bigger than 0 than this indicates that threads are waiting
*     in the function sge_tq_wait_for_task().
*
*  INPUTS
*     sge_tq_queue_t *queue - task queue 
*
*  RESULT
*     u_long32 - number of threads waiting
*
*  NOTES
*     MT-NOTE: sge_tq_get_waiting_count() is MT safe 
*
*  SEE ALSO
*     uti/tq/sge_tq_wait_for_task() 
*******************************************************************************/
u_long32
sge_tq_get_waiting_count(sge_tq_queue_t *queue) {
   u_long32 count = 0;
   
   DENTER(TQ_LAYER, "sge_tq_get_waiting_count");
   if (queue != NULL) {
      sge_mutex_lock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));
      count = queue->waiting; 
      sge_mutex_unlock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));
   }
   DRETURN(count);
}
Ejemplo n.º 18
0
/****** uti/thread_ctrl/sge_thread_has_shutdown_started() **********************
*  NAME
*     sge_thread_has_shutdown_started() -- shutdown in progress? 
*
*  SYNOPSIS
*     bool sge_thread_has_shutdown_started(void) 
*
*  FUNCTION
*     Service function which can be used to check if the executing
*     component is already shutting down. 
*
*  INPUTS
*     void - NONE
*
*  RESULT
*     bool - is in progress?
*        true  - yes
*        false - no
*
*  NOTES
*     MT-NOTE: sge_thread_has_shutdown_started() is MT safe 
*******************************************************************************/
bool
sge_thread_has_shutdown_started(void)
{
   bool res = false;

   DENTER(THREAD_LAYER, "sge_thread_has_shutdown_started");
   sge_mutex_lock(THREAD_CONTROL_MUTEX, SGE_FUNC, __LINE__, &Thread_Control.mutex);
   res = Thread_Control.shutdown_started;
   sge_mutex_unlock(THREAD_CONTROL_MUTEX, SGE_FUNC, __LINE__, &Thread_Control.mutex);
   DEXIT;
   return res;
}
Ejemplo n.º 19
0
/****** uti/monitor/sge_set_last_wait_time() ***********************************
*  NAME
*     sge_set_last_wait_time() -- updates the last wait time (health monitoring)
*
*  SYNOPSIS
*     void sge_set_last_wait_time(monitoring_t *monitor, struct timeval after) 
*
*  FUNCTION
*     Updates the last wait time, which is used for the health monitoring to 
*     determine if a thread has a problem or not.
*
*  INPUTS
*     monitoring_t *monitor    - monitoring structure
*     struct timeval wait_time - current time 
*
*  NOTES
*     MT-NOTE: sge_set_last_wait_time() is MT safe 
*
*******************************************************************************/
void sge_set_last_wait_time(monitoring_t *monitor, struct timeval wait_time) 
{
   DENTER(GDI_LAYER, "sge_set_last_wait_time");

   if (monitor->pos != -1) {
      sge_mutex_lock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[monitor->pos].Output_Mutex));

      Output[monitor->pos].last_wait_time = wait_time;

      sge_mutex_unlock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[monitor->pos].Output_Mutex));
   }
   DEXIT;
}
Ejemplo n.º 20
0
/****** uti/monitor/sge_monitor_output() ***************************************
*  NAME
*     sge_monitor_output() -- outputs the result into the message file
*
*  SYNOPSIS
*     void sge_monitor_output(monitoring_t *monitor) 
*
*  FUNCTION
*     This function computes the output line from the gathered statistics.
*     The output is only generated, when the the output flag in the
*     monitoring structure is set.
*
*     The monitoring line is printed to the message file in the profiling
*     class and it made available for the qping -f output. For the qping
*     output, it stores the the generation time, though that qping can
*     show, when the message was generated.
*
*     If an extension is set, it calls the apropriate output function for
*     it.
*
*  INPUTS
*     monitoring_t *monitor - the monitoring info
*
*  NOTES
*     MT-NOTE: sge_monitor_output() is MT safe 
*
*******************************************************************************/
void sge_monitor_output(monitoring_t *monitor) 
{
   DENTER(GDI_LAYER, "sge_monitor_output");

   if ((monitor != NULL) && (monitor->output == true)) {
      struct timeval after;
      double time;

      gettimeofday(&after, NULL); 
      time = after.tv_usec - monitor->now.tv_usec;
      time = after.tv_sec - monitor->now.tv_sec + (time/1000000);

      sge_dstring_clear(monitor->work_line);
  
      sge_dstring_sprintf_append(monitor->work_line, MSG_UTI_MONITOR_DEFLINE_SF, 
                                 monitor->thread_name, monitor->message_in_count/time); 
      
      if (monitor->ext_type != NONE_EXT) {
         sge_dstring_append(monitor->work_line, " (");
         monitor->ext_output(monitor->work_line, monitor->ext_data, time);
         sge_dstring_append(monitor->work_line, ")");
      };
      
      sge_dstring_sprintf_append(monitor->work_line, MSG_UTI_MONITOR_DEFLINE_FFFFF,  
                                 monitor->message_out_count/time,
                                 monitor->message_in_count ? (time - monitor->idle)/monitor->message_in_count: 0,
                                 monitor->idle/time*100, monitor->wait/time*100, time);           
    
      /* only log into the message file, if the user wants it */
      if (monitor->log_monitor_mes) {
         sge_log(LOG_PROF, sge_dstring_get_string(monitor->work_line),__FILE__,SGE_FUNC,__LINE__); 
      }
     
      if (monitor->pos != -1) {
         dstring *tmp = NULL;

         sge_mutex_lock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[monitor->pos].Output_Mutex));
         tmp = Output[monitor->pos].output;
         Output[monitor->pos].output = monitor->work_line;
         Output[monitor->pos].update_time = after.tv_sec;         
         sge_mutex_unlock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[monitor->pos].Output_Mutex));

         monitor->work_line = tmp;
       }

      sge_monitor_reset(monitor);
   }
   
   DRETURN_VOID;
}
Ejemplo n.º 21
0
/****** uti/thread_ctrl/sge_thread_notify_all_waiting() ************************
*  NAME
*     sge_thread_notify_all_waiting() -- notify waiting thread 
*
*  SYNOPSIS
*     void sge_thread_notify_all_waiting(void) 
*
*  FUNCTION
*     After the main thread has initialized all needed components and 
*     threads it waits for a certain condition to be signaled 
*     (sge_thread_wait_for_signal).
*     This signal will start the shutdown process of the master.
*     This function triggers this signal.
*
*  INPUTS
*     void - NONE 
*
*  RESULT
*     void - NONE
*
*  NOTES
*     MT-NOTE: sge_thread_notify_all_waiting() is MT safe 
*
*  SEE ALSO
*     uti/thread_ctrl/sge_thread_wait_for_signal()
*******************************************************************************/
void
sge_thread_notify_all_waiting(void)
{
   DENTER(THREAD_LAYER, "sge_thread_notify_all_waiting");

   sge_mutex_lock(THREAD_CONTROL_MUTEX, SGE_FUNC, __LINE__, &Thread_Control.mutex);

   Thread_Control.shutdown_started = true;
   pthread_cond_broadcast(&Thread_Control.cond_var);

   sge_mutex_unlock(THREAD_CONTROL_MUTEX, SGE_FUNC, __LINE__, &Thread_Control.mutex);

   DRETURN_VOID;
}
Ejemplo n.º 22
0
/****** uti/tq/sge_tq_wakeup_waiting() *****************************************
*  NAME
*     sge_tq_wakeup_waiting() -- wake up all waitng threads 
*
*  SYNOPSIS
*     bool sge_tq_wakeup_waiting(sge_tq_queue_t *queue) 
*
*  FUNCTION
*     This function wakes up all waiting threads that are blocking in
*     sge_tq_wait_for_task(). 
*
*  INPUTS
*     sge_tq_queue_t *queue - task queue 
*
*  RESULT
*     bool - error state
*        true  - success
*        false - error 
*
*  NOTES
*     MT-NOTE: sge_tq_wakeup_waiting() is MT safe 
*
*  SEE ALSO
*     uti/tq/sge_tq_wait_for_task() 
*******************************************************************************/
bool
sge_tq_wakeup_waiting(sge_tq_queue_t *queue) {
   bool ret = true;
   
   DENTER(TQ_LAYER, "sge_tq_wakeup_waiting");
   if (queue != NULL) {
      sge_mutex_lock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));

      /* wake up all threads waiting for a task */
      pthread_cond_broadcast(&(queue->cond));

      sge_mutex_unlock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));
   }
   DRETURN(ret);
}
Ejemplo n.º 23
0
/****** uti/thread_ctrl/sge_thread_wait_for_signal() ***************************
*  NAME
*     sge_thread_wait_for_signal() -- block current thread till shutdown 
*
*  SYNOPSIS
*     void sge_thread_wait_for_signal(void) 
*
*  FUNCTION
*     A call of this function will block the executing thread until the 
*     shutdown of the process is triggered via sge_thread_notify_all_waiting()
*
*  INPUTS
*     void - NONE
*
*  RESULT
*     void - NONE
*
*  NOTES
*     MT-NOTE: sge_thread_wait_for_signal() is not MT safe 
*
*  SEE ALSO
*     uti/thread_ctrl/sge_thread_notify_all_waiting()
*******************************************************************************/
void 
sge_thread_wait_for_signal(void)
{
   DENTER(THREAD_LAYER, "sge_thread_wait_for_signal");

   sge_mutex_lock(THREAD_CONTROL_MUTEX, SGE_FUNC, __LINE__, &Thread_Control.mutex);

   while (Thread_Control.shutdown_started == false) {
      pthread_cond_wait(&Thread_Control.cond_var, &Thread_Control.mutex);
   }

   sge_mutex_unlock(THREAD_CONTROL_MUTEX, SGE_FUNC, __LINE__, &Thread_Control.mutex);

   DEXIT;
   return;
}
Ejemplo n.º 24
0
/****** qmaster/threads/sge_scheduler_terminate() ****************************
*  NAME
*     sge_scheduler_terminate() -- terminate the scheduler 
*
*  SYNOPSIS
*     void sge_scheduler_terminate(sge_gdi_ctx_class_t *ctx) 
*
*  FUNCTION
*     Terminates the scheduler if it was started previousely. This 
*     function will return only when it is sure that the pthread canceled. 
*
*     'Master_Scheduler' is accessed by this function.
*     
*  INPUTS
*     sge_gdi_ctx_class_t *ctx - context object 
*     lList **answer_list      - answer list
*
*  RESULT
*     void - None
*
*  NOTES
*     MT-NOTE: sge_scheduler_terminate() is MT safe 
*
*  SEE ALSO
*     qmaster/threads/sge_scheduler_initialize() 
*     qmaster/threads/sge_scheduler_cleanup_thread() 
*     qmaster/threads/sge_scheduler_terminate() 
*     qmaster/threads/sge_scheduler_main() 
*******************************************************************************/
void
sge_scheduler_terminate(sge_gdi_ctx_class_t *ctx, lList **answer_list)
{
   DENTER(TOP_LAYER, "sge_scheduler_terminate");
   
   sge_mutex_lock("master scheduler struct", SGE_FUNC, __LINE__, &(Master_Scheduler.mutex));

   if (Master_Scheduler.is_running) {
      pthread_t thread_id;
      cl_thread_settings_t* thread = NULL;

      /* 
       * store thread id to use it later on 
       */
      thread = cl_thread_list_get_first_thread(Main_Control.scheduler_thread_pool);
      thread_id = *(thread->thread_pointer);

      /* 
       * send cancel signal 
       */
      pthread_cancel(thread_id);
     
      /*
       * wakeup scheduler thread which might be blocked by wait for events
       */
      pthread_cond_signal(&Scheduler_Control.cond_var);

      /*
       * cl_thread deletion and cl_thread_pool deletion will be done at 
       * schedulers cancelation point in sge_scheduler_cleanup_thread() ...
       * ... therefore we have nothing more to do.
       */
      ;

      sge_mutex_unlock("master scheduler struct", SGE_FUNC, __LINE__, &(Master_Scheduler.mutex));

      INFO((SGE_EVENT, MSG_THREAD_XTERMINATED_S, threadnames[SCHEDD_THREAD]));
      answer_list_add(answer_list, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_INFO);
   } else {
      sge_mutex_unlock("master scheduler struct", SGE_FUNC, __LINE__, &(Master_Scheduler.mutex));

      ERROR((SGE_EVENT, MSG_THREAD_XNOTRUNNING_S, threadnames[SCHEDD_THREAD]));
      answer_list_add(answer_list, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
   }

   DRETURN_VOID;
}
Ejemplo n.º 25
0
/****** qmaster/threads/sge_scheduler_cleanup_thread() ********************
*  NAME
*     sge_scheduler_cleanup_thread() -- cleanup the scheduler thread 
*
*  SYNOPSIS
*     void sge_scheduler_cleanup_thread(void) 
*
*  FUNCTION
*     Cleanup the scheduler thread. 
*
*     This function has to be executed only by the scheduler thread.
*     Ideally it should be the last function executed when the
*     pthread cancelation point is passed. 
*
*     'Master_Scheduler' is accessed by this function.
*     
*  INPUTS
*     void - None 
*
*  RESULT
*     void - none
*
*  NOTES
*     MT-NOTE: sge_scheduler_cleanup_thread() is MT safe 
*
*  SEE ALSO
*     qmaster/threads/sge_scheduler_initialize() 
*     qmaster/threads/sge_scheduler_cleanup_thread() 
*     qmaster/threads/sge_scheduler_terminate() 
*     qmaster/threads/sge_scheduler_main() 
*******************************************************************************/
void
sge_scheduler_cleanup_thread(void *ctx_ref)
{
   DENTER(TOP_LAYER, "sge_scheduler_cleanup_thread");
   
   sge_mutex_lock("master scheduler struct", SGE_FUNC, __LINE__, &(Master_Scheduler.mutex));

   if (Master_Scheduler.is_running) {
      cl_thread_settings_t* thread = NULL;

      /* 
       * The scheduler thread itself executes this function (sge_scheduler_cleanup_thread())
       * at the cancelation point as part of the cleanup. 
       * Therefore it has to unset the thread config before the
       * cl_thread is deleted. Otherwise we might run into a race condition when logging
       * is used after the call of cl_thread_list_delete_thread_without_join() 
       */
      cl_thread_unset_thread_config();

      /*
       * Delete the scheduler thread but don't wait for termination
       */
      thread = cl_thread_list_get_first_thread(Main_Control.scheduler_thread_pool);
      cl_thread_list_delete_thread_without_join(Main_Control.scheduler_thread_pool, thread);
      
      /* 
       * Trash the thread pool 
       */
      cl_thread_list_cleanup(&Main_Control.scheduler_thread_pool);

      /*
       * now a new scheduler can start
       */
      Master_Scheduler.is_running = false;

      /*
      ** free the ctx too
      */
      sge_gdi_ctx_class_destroy((sge_gdi_ctx_class_t **)ctx_ref);
   }

   sge_mutex_unlock("master scheduler struct", SGE_FUNC, __LINE__, &(Master_Scheduler.mutex));

   DRETURN_VOID;
}
Ejemplo n.º 26
0
static void sge_scheduler_wait_for_event(sge_evc_class_t *evc, lList **event_list)
{
   int wait_ret;
   bool do_ack = false;

   DENTER(TOP_LAYER, "sge_scheduler_wait_for_event");


   sge_mutex_lock("event_control_mutex", SGE_FUNC, __LINE__, &Scheduler_Control.mutex);

   if (!Scheduler_Control.triggered) {
      struct timespec ts;
      u_long32 current_time = sge_get_gmt();
      ts.tv_sec = (long) current_time + SCHEDULER_TIMEOUT_S;
      ts.tv_nsec = SCHEDULER_TIMEOUT_N;

      wait_ret = pthread_cond_timedwait(&Scheduler_Control.cond_var, &Scheduler_Control.mutex, &ts);

      /*
       * if pthread_cond_timedwait returns 0, we were triggered by event master
       * otherwise we ran into a timeout or an error
       */
      if (wait_ret != 0) {
         DPRINTF(("pthread_cond_timedwait for events failed %d\n", wait_ret));
      }
   }

   if (Scheduler_Control.triggered) {
      *event_list = Scheduler_Control.new_events;
      Scheduler_Control.new_events = NULL;
      Scheduler_Control.triggered = false;
      do_ack = true;
   }

   sge_mutex_unlock("event_control_mutex", SGE_FUNC, __LINE__, &Scheduler_Control.mutex);

   if (do_ack) {
      if (lGetElemUlong(*event_list, ET_type, sgeE_ACK_TIMEOUT) != NULL) {
         evc->ec_mark4registration(evc);
      }
      evc->ec_ack(evc);
   }

   DRETURN_VOID;
}
Ejemplo n.º 27
0
/****** uti/tq/sge_tq_store_notify() *******************************************
*  NAME
*     sge_tq_store_notify() -- Appends a new task at the end of queue 
*
*  SYNOPSIS
*     bool 
*     sge_tq_store_notify(sge_tq_queue_t *queue, 
*                         sge_tq_type_t type, void *data) 
*
*  FUNCTION
*     This function creates a new task using 'type' and 'data'. The new
*     task will then be appended to 'queue'. If there are threads waiting
*     in sge_tq_wait_for_task() then one of those waiting threads will be
*     triggered so that it will wake up. 
*
*     If there are multiple threads waiting then it might happen that
*     always the same thread wakes up to catch the task (starvation).
*
*  INPUTS
*     sge_tq_queue_t *queue - task queue 
*     sge_tq_type_t type    - task type 
*     void *data            - task data
*
*  RESULT
*     bool - error state
*        true  - success
*        false - error
*
*  NOTES
*     MT-NOTE: sge_tq_store_notify() is MT safe 
*
*  SEE ALSO
*     uti/tq/sge_tq_wait_for_task() 
*******************************************************************************/
bool
sge_tq_store_notify(sge_tq_queue_t *queue, sge_tq_type_t type, void *data) {
   bool ret = true;

   DENTER(TQ_LAYER, "sge_tq_store_notify");
   if (queue != NULL && type != SGE_TQ_UNKNOWN && data != NULL) {
      sge_tq_task_t *new_task = NULL;

      /* create a new task */
      ret &= sge_tq_task_create(&new_task, type, data); 

      /* insert the task in the list and notify one waiting thread if there is one */ 
      sge_mutex_lock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));
      if (ret) {
         ret = sge_sl_insert(queue->list, new_task, SGE_SL_BACKWARD);
      }
      if (ret && queue->waiting > 0) {
         sge_tq_wakeup_waiting(queue);
      }
      sge_mutex_unlock(TQ_MUTEX_NAME, SGE_FUNC, __LINE__, sge_sl_get_mutex(queue->list));
   }
   DRETURN(ret);
}
Ejemplo n.º 28
0
/****** uti/monitor/sge_monitor_status() ***************************************
*  NAME
*     sge_monitor_status() -- generates the status for qping / commlib
*
*  SYNOPSIS
*     u_long32 sge_monitor_status(char **info_message, u_long32 monitor_time) 
*
*  FUNCTION
*     This method creats the health monitoring output and returns the monitoring
*     info to the commlib. 
*
*  INPUTS
*     char **info_message   - info_message pointer, has to point to a NULL string
*     u_long32 monitor_time - the configured monitoring interval
*
*  RESULT
*     u_long32 - 0 : everything is okay
*                1 : warning
*                2 : error
*                3 : init problems
*
*  NOTES
*     MT-NOTE: sge_monitor_status() is MT safe 
*
*******************************************************************************/
u_long32 sge_monitor_status(char **info_message, u_long32 monitor_time)
{
   u_long32 ret = 0;
   char date[40];
   dstring ddate;
   
   DENTER(GDI_LAYER, "sge_monitor_status");

   if (info_message == NULL) {
      DEXIT;
      return 3;
   }

   sge_dstring_init(&ddate, date, sizeof(date));
   
   sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex);

   sge_dstring_clear(&Info_Line);
   
   {/* this is the qping info section, it checks if each thread is still alive */
      int i;
      int error_count = 0;
      struct timeval now;
      double time;
      char   state = 'R';
      gettimeofday(&now,NULL);
      
      for (i = 0; i < MAX_OUTPUT_LINES; i++) {
         sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex));
         if (Output[i].name != NULL) {
            time = now.tv_usec - Output[i].last_wait_time.tv_usec;
            time = now.tv_sec - Output[i].last_wait_time.tv_sec + (time /1000000);

            
            if (Output[i].warning_timeout !=  NO_WARNING) {
               if (Output[i].warning_timeout < time) {
                  if (Output[i].error_timeout < time) {
                     state = 'E';
                  }
                  else {
                     state = 'W';
                  }
                  error_count++;
               }
            } 
            sge_dstring_sprintf_append(&Info_Line, MSG_UTI_MONITOR_INFO_SCF, Output[i].name, state, time);
         }
         sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex));
      }

      if (error_count == 0) {
         sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_OK);
      }
      else if (error_count == 1) {
         ret = 1;
         sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_WARNING);
      }
      else {
         ret = 2;
         sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_ERROR);
      }
      sge_dstring_append(&Info_Line, "\n");
   }

#if defined(LINUX) || defined(AIX43) || defined(AIX51) || defined(IRIX) || defined(SOLARIS) || defined(HP11)
   if (mallinfo_func_pointer != NULL) {
      struct mallinfo mallinfo_data = mallinfo_func_pointer();

      sge_dstring_sprintf_append(&Info_Line, MSG_UTI_MONITOR_SCHEXT_UUUUUUUUUU,
                                 mallinfo_data.arena,
                                 mallinfo_data.ordblks,
                                 mallinfo_data.smblks,
                                 mallinfo_data.hblks,
                                 mallinfo_data.hblkhd,
                                 mallinfo_data.usmblks,
                                 mallinfo_data.fsmblks,
                                 mallinfo_data.uordblks,
                                 mallinfo_data.fordblks,
                                 mallinfo_data.keepcost);
      sge_dstring_append(&Info_Line, "\n");
   }
#endif
 

   if (monitor_time != 0) { /* generates the output monitoring output data */
      int i;
      sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_COLON); 
      sge_dstring_append(&Info_Line, "\n");

      for (i = 0; i < MAX_OUTPUT_LINES; i++) {
         sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex));
         if (Output[i].name != NULL) {
            append_time(Output[i].update_time, &Info_Line, false);
            sge_dstring_append(&Info_Line, " | ");
            sge_dstring_append_dstring(&Info_Line, Output[i].output);
            sge_dstring_append(&Info_Line,"\n");
         }
         sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex));
      }
   }
   else {
      sge_dstring_append(&Info_Line, MSG_UTI_MONITOR_DISABLED);
      sge_dstring_append(&Info_Line, "\n");
   }

   *info_message = strdup(sge_dstring_get_string(&Info_Line));
  
   sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex);
   DEXIT;
   return ret;
}
Ejemplo n.º 29
0
/****** uti/monitor/sge_monitor_init() *****************************************
*  NAME
*     sge_monitor_init() -- init the monitoring structure
*
*  SYNOPSIS
*     void sge_monitor_init(monitoring_t *monitor, const char *thread_name, 
*     extension_t ext, thread_warning_t warning_timeout, thread_error_t 
*     error_timeout) 
*
*  FUNCTION
*     Sets the default values and inits the structure, finds the line pos
*     for the comlib output
*
*  INPUTS
*     monitoring_t *monitor            - monitoring strucutre
*     const char *thread_name          - the thread name
*     extension_t ext                  - the extension time (-> enum)
*     thread_warning_t warning_timeout - the warning timeout (-> enum)
*     thread_error_t error_timeout     - the error timeout (-> enum)
*
*  NOTES
*     MT-NOTE: sge_monitor_init() is MT safe 
*
*******************************************************************************/
void
sge_monitor_init(monitoring_t *monitor, const char *thread_name, extension_t ext, 
                 thread_warning_t warning_timeout, thread_error_t error_timeout)
{
   DENTER(GDI_LAYER, "sge_monitor_init");

   /*
    * initialize the mallinfo function pointer if it is available
    */
#if defined(LINUX) || defined(AIX43) || defined(AIX51) || defined(IRIX) || defined(SOLARIS) || defined(HP11)
   sge_mutex_lock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex);
   if (mallinfo_initialized == false) {
      const char *function_name = "mallinfo";

      mallinfo_initialized = true;
#  ifdef RTLD_NODELETE
      mallinfo_shlib_handle = dlopen(NULL, RTLD_LAZY | RTLD_NODELETE);
#  else
      mallinfo_shlib_handle = dlopen(NULL, RTLD_LAZY );
#  endif /* RTLD_NODELETE */

      if (mallinfo_shlib_handle != NULL) {
         mallinfo_func_pointer = (struct mallinfo (*)(void)) dlsym(mallinfo_shlib_handle, function_name);
      }
   }
   sge_mutex_unlock("sge_monitor_status", SGE_FUNC, __LINE__, &global_mutex);
#endif

   monitor->thread_name = thread_name;
 
   monitor->output_line1 = (dstring*) malloc(sizeof(dstring));
   monitor->output_line2 = (dstring*) malloc(sizeof(dstring));
   
   if (monitor->output_line1 == NULL || monitor->output_line2 == NULL) {
      CRITICAL((SGE_EVENT, SFNMAX, MSG_UTI_MONITOR_MEMERROR));
      exit(1);
   } 

   memset(monitor->output_line1, 0, sizeof(dstring));
   memset(monitor->output_line2, 0, sizeof(dstring));
   
   sge_dstring_append(monitor->output_line1, thread_name);
   sge_dstring_append(monitor->output_line1, MSG_UTI_MONITOR_NODATA);
   sge_dstring_clear(monitor->output_line2);
   monitor->work_line = monitor->output_line2;
 
   switch(ext) {
      case SCH_EXT :
            monitor->ext_data = malloc(sizeof(m_sch_t));
            if (monitor->ext_data != NULL) {
               monitor->ext_type = SCH_EXT;
               monitor->ext_data_size = sizeof(m_sch_t);
               monitor->ext_output = &ext_sch_output;
            } else {
               monitor->ext_type = NONE_EXT;
               ERROR((SGE_EVENT, SFNMAX, MSG_UTI_MONITOR_MEMERROREXT));
            }
         break;

      case GDI_EXT :
            monitor->ext_data = malloc(sizeof(m_gdi_t));
            if (monitor->ext_data != NULL) {
               monitor->ext_type = GDI_EXT;
               monitor->ext_data_size = sizeof(m_gdi_t);
               monitor->ext_output = &ext_gdi_output;
            } else {
               monitor->ext_type = NONE_EXT;
               ERROR((SGE_EVENT, SFNMAX, MSG_UTI_MONITOR_MEMERROREXT));
            }
         break;

      case LIS_EXT :
            monitor->ext_data = malloc(sizeof(m_lis_t));
            if (monitor->ext_data != NULL) {
               monitor->ext_type = LIS_EXT;
               monitor->ext_data_size = sizeof(m_lis_t);
               monitor->ext_output = &ext_lis_output;
            } else {
               monitor->ext_type = NONE_EXT;
               ERROR((SGE_EVENT, SFNMAX, MSG_UTI_MONITOR_MEMERROREXT));
            }
         break;
         
      case EDT_EXT : 
            monitor->ext_data = malloc(sizeof(m_edt_t));
            if (monitor->ext_data != NULL) {
               monitor->ext_type = EDT_EXT;
               monitor->ext_data_size = sizeof(m_edt_t);
               monitor->ext_output = &ext_edt_output;
            } else {
               monitor->ext_type = NONE_EXT;
               ERROR((SGE_EVENT, SFNMAX, MSG_UTI_MONITOR_MEMERROREXT));
            }
         break;
       
      case TET_EXT : 
            monitor->ext_data = malloc(sizeof(m_tet_t));
            if (monitor->ext_data != NULL) {
               monitor->ext_type = TET_EXT;
               monitor->ext_data_size = sizeof(m_tet_t);
               monitor->ext_output = &ext_tet_output;
            } else {
               monitor->ext_type = NONE_EXT;
               ERROR((SGE_EVENT, SFNMAX, MSG_UTI_MONITOR_MEMERROREXT));
            }
         break;
         
      case NONE_EXT :
            monitor->ext_type = NONE_EXT;
         break;
         
      default : 
            monitor->ext_type = NONE_EXT;
            ERROR((SGE_EVENT, MSG_UTI_MONITOR_UNSUPPORTEDEXT_D, ext));
   };

   if (monitor->ext_type == NONE_EXT) {
      monitor->ext_data_size = 0;
      monitor->ext_data = NULL;
      monitor->ext_output = NULL;
   }
   
   sge_monitor_reset(monitor);
   
   { 
      int i;
      struct timeval time;
      monitor->pos = -1; 

      gettimeofday(&time, NULL);
      
      for (i = 0; i < MAX_OUTPUT_LINES; i++) {
         sge_mutex_lock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex));
         if (Output[i].name == NULL) {
            monitor->pos = i;
            Output[i].output = monitor->output_line1;
            Output[i].name = thread_name;
            Output[i].warning_timeout = warning_timeout;
            Output[i].error_timeout = error_timeout;
            Output[i].update_time = time.tv_sec; 
            sge_mutex_unlock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex));
            break;
         }      
         sge_mutex_unlock("sge_monitor_init", SGE_FUNC, __LINE__, &(Output[i].Output_Mutex));
      }
      
      sge_set_last_wait_time(monitor, time);
   }
  
   if (monitor->pos == -1) {
      ERROR((SGE_EVENT, MSG_UTI_MONITOR_NOLINES_S, monitor->thread_name));
   }
   
   DEXIT;
}
Ejemplo n.º 30
0
/****** category/sge_build_job_category_dstring() ******************************
*  NAME
*     sge_build_job_category_dstring() -- build the category string   
*
*  SYNOPSIS
*     void sge_build_job_category_dstring(dstring *category_str, lListElem 
*     *job, lList *acl_list) 
*
*  FUNCTION
*     The following parameter are put into the category:
*        hard_queue_list
*        master_hard_queue_list
*        hard_resource_list
*        soft_resource_list
*        checkpoint_name
*        type
*
*        owner/group: -U user_lists 
*           Omitted, if user_lists/xuser_lists were not used in
*           host_conf(5), sge_pe(5) and queue_conf(5). In sge_conf(5) 
*           user_lists/xuser_lists still can be used, as it causes
*           jobs already be rejected at submit time.
*
*        project: -P user_lists 
*           Omitted, if projects/xprojects were not used in
*           host_conf(5), sge_pe(5) and queue_conf(5). In sge_conf(5) 
*           projects/xprojects still can be used, as it cuases
*           jobs already be rejected at submit time.
*
*        pe
*
*  INPUTS
*     dstring *category_str - target string, contains the category or nothing
*     lListElem *job        - the job for the category creating
*     lList *acl_list       - global access list
*
*  NOTES
*     MT-NOTE: sge_build_job_category_dstring() is MT safe as long as the caller is
*
*******************************************************************************/
void sge_build_job_category_dstring(dstring *category_str, lListElem *job, lList *acl_list, const lList *prj_list, bool *did_project, const lList *rqs_list) 
{

   const char *owner = NULL;
   const char *group = NULL;

   DENTER(TOP_LAYER, "sge_build_job_category_dstring");

   DTRACE;

#if 0
   sge_mutex_lock("cull_order_mutex", SGE_FUNC, __LINE__, &Category_Control.cull_order_mutex);
   if (Category_Control.cull_order_pos.JB_hard_queue_list_pos == -1) {
      Category_Control.cull_order_pos.JB_checkpoint_name_pos = lGetPosViaElem(job, JB_checkpoint_name, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_soft_resource_list_pos = lGetPosViaElem(job, JB_soft_resource_list, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_master_hard_queue_list_pos = lGetPosViaElem(job, JB_master_hard_queue_list, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_hard_queue_list_pos = lGetPosViaElem(job, JB_hard_queue_list, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_owner_pos = lGetPosViaElem(job, JB_owner, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_group_pos = lGetPosViaElem(job, JB_group, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_hard_resource_list_pos = lGetPosViaElem(job, JB_hard_resource_list, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_type_pos = lGetPosViaElem(job, JB_type, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_project_pos = lGetPosViaElem(job, JB_project, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_ar_pos = lGetPosViaElem(job, JB_ar, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_pe_pos = lGetPosViaElem(job, JB_pe, SGE_NO_ABORT);
      Category_Control.cull_order_pos.JB_range_pos = lGetPosViaElem(job, JB_pe_range, SGE_NO_ABORT);
   }
   sge_mutex_unlock("cull_order_mutex", SGE_FUNC, __LINE__, &Category_Control.cull_order_mutex);
#endif

   DTRACE;

   /*
   ** owner -> acl
   */
   owner = lGetPosString(job, lGetPosViaElem(job, JB_owner, SGE_NO_ABORT));
   
   DTRACE;

   group = lGetPosString(job, lGetPosViaElem(job, JB_group, SGE_NO_ABORT));

   DTRACE;

   sge_unparse_acl_dstring(category_str, owner, group, acl_list, "-U");

   DTRACE;
 
   /* 
   ** -u if referenced in resource quota sets
   */

   /* RD TODO: A possible performance enhancement is to split user and group inside category.
      Some users are only referenced by the unix group. Their jobs could be grouped
      together by referencing only the group in the category string
   */
   if (sge_user_is_referenced_in_rqs(rqs_list, lGetString(job, JB_owner), lGetString(job, JB_group), acl_list)) {
      if (sge_dstring_strlen(category_str) > 0) {
         sge_dstring_append(category_str, " ");
      }
      sge_dstring_append(category_str, "-u ");
      sge_dstring_append(category_str, lGetString(job, JB_owner));
   }

   DTRACE;

   /*
   ** -hard -q qlist
   */
   sge_unparse_queue_list_dstring(category_str, job, lGetPosViaElem(job, JB_hard_queue_list, SGE_NO_ABORT), "-q");  

   DTRACE;

   /*
   ** -masterq qlist
   */
   sge_unparse_queue_list_dstring(category_str, job, lGetPosViaElem(job, JB_master_hard_queue_list, SGE_NO_ABORT), "-masterq");

   DTRACE;

   /*
   ** -l rlist (hard resource list)
   */
   sge_unparse_resource_list_dstring(category_str, job, lGetPosViaElem(job, JB_hard_resource_list, SGE_NO_ABORT), "-l");

   DTRACE;
   
   /*
   ** -soft -l rlist
   */
   sge_unparse_resource_list_dstring(category_str, job, lGetPosViaElem(job, JB_soft_resource_list, SGE_NO_ABORT), "-soft -l");

   DTRACE;

   /*
   ** -pe pe_name pe_range
   */
   sge_unparse_pe_dstring(category_str, job, lGetPosViaElem(job, JB_pe, SGE_NO_ABORT), 
                          lGetPosViaElem(job, JB_pe_range, SGE_NO_ABORT), "-pe");

   DTRACE;

   /*
   ** -ckpt ckpt_name 
   */
   sge_unparse_string_option_dstring(category_str, job, lGetPosViaElem(job, JB_checkpoint_name, SGE_NO_ABORT), "-ckpt");

   DTRACE;

   /*
   ** interactive jobs
   */
   if (JOB_TYPE_IS_IMMEDIATE(lGetPosUlong(job, lGetPosViaElem(job, JB_type, SGE_NO_ABORT)))) {
      if (sge_dstring_strlen(category_str) > 0) {
         sge_dstring_append(category_str, " -I y");
      }
      else {
         sge_dstring_append(category_str, "-I y");
      }
   }

   DTRACE;
      
   /*
   ** project
   */
   {
      const char *project = lGetPosString(job, lGetPosViaElem(job, JB_project, SGE_NO_ABORT));

      const lListElem *prj;
      if (project && (prj=lGetElemStr(prj_list, PR_name, project)) && lGetBool(prj, PR_consider_with_categories)) {
         if (did_project)
            *did_project = true;
         sge_unparse_string_option_dstring(category_str, job, lGetPosViaElem(job, JB_project, SGE_NO_ABORT), "-P");
      } else
         if (did_project)
            *did_project = false;
   }

   DTRACE;

   /*
   ** -ar ar_id
   */
   sge_unparse_ulong_option_dstring(category_str, job, lGetPosViaElem(job, JB_ar, SGE_NO_ABORT), "-ar");  

   DRETURN_VOID;
}