~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/daemons/qmaster/sge_thread_event_master.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
 * 
 
3
 *  The Contents of this file are made available subject to the terms of
 
4
 *  the Sun Industry Standards Source License Version 1.2
 
5
 * 
 
6
 *  Sun Microsystems Inc., March, 2001
 
7
 * 
 
8
 * 
 
9
 *  Sun Industry Standards Source License Version 1.2
 
10
 *  =================================================
 
11
 *  The contents of this file are subject to the Sun Industry Standards
 
12
 *  Source License Version 1.2 (the "License"); You may not use this file
 
13
 *  except in compliance with the License. You may obtain a copy of the
 
14
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
15
 * 
 
16
 *  Software provided under this License is provided on an "AS IS" basis,
 
17
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
18
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
19
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
20
 *  See the License for the specific provisions governing your rights and
 
21
 *  obligations concerning the Software.
 
22
 * 
 
23
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
24
 * 
 
25
 *   Copyright: 2003 by Sun Microsystems, Inc.
 
26
 * 
 
27
 *   All Rights Reserved.
 
28
 * 
 
29
 ************************************************************************/
 
30
/*___INFO__MARK_END__*/
 
31
 
 
32
#include <signal.h>
 
33
#include <pthread.h>
 
34
#include <string.h>
 
35
#include <errno.h>
 
36
#include <fcntl.h>
 
37
 
 
38
#include "basis_types.h"
 
39
#include "sge_qmaster_threads.h"
 
40
#include "sgermon.h"
 
41
#include "sge_mt_init.h"
 
42
#include "sge_prog.h"
 
43
#include "sge_log.h"
 
44
#include "sge_unistd.h"
 
45
#include "sge_answer.h"
 
46
#include "setup_qmaster.h"
 
47
#include "sge_security.h"
 
48
#include "sge_manop.h"
 
49
#include "sge_mtutil.h"
 
50
#include "sge_lock.h"
 
51
#include "sge_qmaster_process_message.h"
 
52
#include "sge_event_master.h"
 
53
#include "sge_persistence_qmaster.h"
 
54
#include "sge_reporting_qmaster.h"
 
55
#include "sge_qmaster_timed_event.h"
 
56
#include "sge_host_qmaster.h"
 
57
#include "sge_userprj_qmaster.h"
 
58
#include "sge_give_jobs.h"
 
59
#include "sge_all_listsL.h"
 
60
#include "sge_calendar_qmaster.h"
 
61
#include "sge_time.h"
 
62
#include "lock.h"
 
63
#include "qmaster_heartbeat.h"
 
64
#include "shutdown.h"
 
65
#include "sge_spool.h"
 
66
#include "cl_commlib.h"
 
67
#include "sge_uidgid.h"
 
68
#include "sge_bootstrap.h"
 
69
#include "msg_common.h"
 
70
#include "msg_qmaster.h"
 
71
#include "msg_daemons_common.h"
 
72
#include "msg_utilib.h"  /* remove once 'sge_daemonize_qmaster' did become 'sge_daemonize' */
 
73
#include "sge.h"
 
74
#include "sge_qmod_qmaster.h"
 
75
#include "reschedule.h"
 
76
#include "sge_job_qmaster.h"
 
77
#include "sge_profiling.h"
 
78
#include "sgeobj/sge_conf.h"
 
79
#include "qm_name.h"
 
80
#include "setup_path.h"
 
81
#include "sge_advance_reservation_qmaster.h"
 
82
#include "sge_sched_process_events.h"
 
83
#include "sge_follow.h"
 
84
 
 
85
#include "gdi/sge_gdi_packet.h"
 
86
 
 
87
#include "uti/sge_os.h"
 
88
#include "uti/sge_thread_ctrl.h"
 
89
 
 
90
#include "sge_thread_main.h"
 
91
#include "sge_thread_timer.h"
 
92
#include "sge_thread_event_master.h"
 
93
#include "sge_qmaster_timed_event.h"
 
94
#include "sge_qmaster_heartbeat.h"
 
95
#include "sge_persistence_qmaster.h"
 
96
 
 
97
static void
 
98
sge_event_master_cleanup_monitor(monitoring_t *monitor)
 
99
{
 
100
   DENTER(TOP_LAYER, "sge_event_master_cleanup_monitor");
 
101
   sge_monitor_free(monitor);
 
102
   DRETURN_VOID;
 
103
}
 
104
 
 
105
static void
 
106
sge_event_master_cleanup_report_list(lList **list)
 
107
{
 
108
   DENTER(TOP_LAYER, "sge_event_master_cleanup_monitor");
 
109
   lFreeList(list);
 
110
   DRETURN_VOID;
 
111
}
 
112
 
 
113
void 
 
114
sge_event_master_initialize(sge_gdi_ctx_class_t *ctx)
 
115
{
 
116
   cl_thread_settings_t* dummy_thread_p = NULL;
 
117
   dstring thread_name = DSTRING_INIT;
 
118
 
 
119
   DENTER(TOP_LAYER, "sge_event_master_initialize");
 
120
 
 
121
   DPRINTF(("event master functionality has been initialized\n"));
 
122
 
 
123
   sge_dstring_sprintf(&thread_name, "%s%03d", threadnames[DELIVERER_THREAD], 0);
 
124
   cl_thread_list_setup(&(Main_Control.event_master_thread_pool), "event master thread pool");
 
125
   cl_thread_list_create_thread(Main_Control.event_master_thread_pool, &dummy_thread_p,
 
126
                                NULL, sge_dstring_get_string(&thread_name), 0, 
 
127
                                sge_event_master_main, NULL, NULL);
 
128
   sge_dstring_free(&thread_name);
 
129
   DRETURN_VOID;
 
130
}
 
131
 
 
132
void
 
133
sge_event_master_terminate(void)
 
134
{
 
135
   cl_thread_settings_t* thread = NULL;
 
136
 
 
137
   DENTER(TOP_LAYER, "sge_event_master_terminate");
 
138
 
 
139
   thread = cl_thread_list_get_first_thread(Main_Control.event_master_thread_pool);
 
140
   while (thread != NULL) {
 
141
      DPRINTF((SFN" gets canceled\n", thread->thread_name));
 
142
      cl_thread_list_delete_thread(Main_Control.event_master_thread_pool, thread);
 
143
      thread = cl_thread_list_get_first_thread(Main_Control.event_master_thread_pool);
 
144
   }  
 
145
   DPRINTF(("all "SFN" threads terminated\n", threadnames[DELIVERER_THREAD]));
 
146
 
 
147
   DRETURN_VOID;
 
148
}
 
149
 
 
150
void *
 
151
sge_event_master_main(void *arg)
 
152
{
 
153
   bool do_endlessly = true;
 
154
   cl_thread_settings_t *thread_config = (cl_thread_settings_t*)arg;
 
155
   sge_gdi_ctx_class_t *ctx = NULL;
 
156
   monitoring_t monitor;
 
157
 
 
158
   lListElem *report = NULL;
 
159
   lList *report_list = NULL;
 
160
   time_t next_prof_output = 0;
 
161
 
 
162
   DENTER(TOP_LAYER, "sge_event_master_main");
 
163
 
 
164
   DPRINTF(("started"));
 
165
   cl_thread_func_startup(thread_config);
 
166
   sge_monitor_init(&monitor, thread_config->thread_name, EDT_EXT, EMT_WARNING, EMT_ERROR);
 
167
   sge_qmaster_thread_init(&ctx, QMASTER, DELIVERER_THREAD, true);
 
168
 
 
169
   /* register at profiling module */
 
170
   set_thread_name(pthread_self(), "Deliver Thread");
 
171
   conf_update_thread_profiling("Deliver Thread");
 
172
 
 
173
   report_list = lCreateListHash("report list", REP_Type, false);
 
174
   report = lCreateElem(REP_Type);
 
175
   lSetUlong(report, REP_type, NUM_REP_REPORT_EVENTS);
 
176
   lSetHost(report, REP_host, ctx->get_qualified_hostname(ctx));
 
177
   lAppendElem(report_list, report);
 
178
 
 
179
   while (do_endlessly) {
 
180
      int execute = 0;
 
181
 
 
182
      thread_start_stop_profiling();
 
183
 
 
184
      /*
 
185
       * did a new event arrive which has a flush time of 0 seconds?
 
186
       */
 
187
      MONITOR_IDLE_TIME(sge_event_master_wait_next(), (&monitor), mconf_get_monitor_time(), 
 
188
                        mconf_is_monitor_message());
 
189
 
 
190
      MONITOR_MESSAGES((&monitor));
 
191
      MONITOR_EDT_COUNT((&monitor));
 
192
      MONITOR_CLIENT_COUNT((&monitor), lGetNumberOfElem(Event_Master_Control.clients));
 
193
 
 
194
      sge_event_master_process_requests(&monitor);
 
195
      sge_event_master_send_events(ctx, report, report_list, &monitor);
 
196
      sge_monitor_output(&monitor);
 
197
 
 
198
      thread_output_profiling("event master thread profiling summary:\n",
 
199
                              &next_prof_output);
 
200
 
 
201
      /* pthread cancelation point */
 
202
      pthread_cleanup_push((void (*)(void *))sge_event_master_cleanup_monitor,
 
203
                           (void *)&monitor);
 
204
      pthread_cleanup_push((void (*)(void *))sge_event_master_cleanup_report_list,
 
205
                           (void *)&report_list);
 
206
      cl_thread_func_testcancel(thread_config);
 
207
      pthread_cleanup_pop(execute); 
 
208
      pthread_cleanup_pop(execute); 
 
209
      if (sge_thread_has_shutdown_started()) {
 
210
         DPRINTF(("waiting for termination\n"));
 
211
         sleep(1);
 
212
      }
 
213
   }
 
214
 
 
215
   /*
 
216
    * Don't add cleanup code here. It will never be executed. Instead register
 
217
    * a cleanup function with pthread_cleanup_push()/pthread_cleanup_pop() before 
 
218
    * and after the call of cl_thread_func_testcancel()
 
219
    */
 
220
 
 
221
   DRETURN(NULL);
 
222
}
 
223