~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/srun/task_state.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************\
 
2
 * src/srun/task_state.c - task state container
 
3
 * $Id$
 
4
 *****************************************************************************
 
5
 *  Copyright (C) 2002 The Regents of the University of California.
 
6
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
 
7
 *  Written by Mark Grondona <mgrondona@llnl.gov>.
 
8
 *  CODE-OCEC-09-009. All rights reserved.
 
9
 *
 
10
 *  This file is part of SLURM, a resource management program.
 
11
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
12
 *  Please also read the included file: DISCLAIMER.
 
13
 *
 
14
 *  SLURM is free software; you can redistribute it and/or modify it under
 
15
 *  the terms of the GNU General Public License as published by the Free
 
16
 *  Software Foundation; either version 2 of the License, or (at your option)
 
17
 *  any later version.
 
18
 *
 
19
 *  In addition, as a special exception, the copyright holders give permission
 
20
 *  to link the code of portions of this program with the OpenSSL library under
 
21
 *  certain conditions as described in each individual source file, and
 
22
 *  distribute linked combinations including the two. You must obey the GNU
 
23
 *  General Public License in all respects for all of the code used other than
 
24
 *  OpenSSL. If you modify file(s) with this exception, you may extend this
 
25
 *  exception to your version of the file(s), but you are not obligated to do
 
26
 *  so. If you do not wish to do so, delete this exception statement from your
 
27
 *  version.  If you delete this exception statement from all source files in
 
28
 *  the program, then also delete it here.
 
29
 *
 
30
 *  SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
 
31
 *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
32
 *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
33
 *  details.
 
34
 *
 
35
 *  You should have received a copy of the GNU General Public License along
 
36
 *  with SLURM; if not, write to the Free Software Foundation, Inc.,
 
37
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
 
38
\*****************************************************************************/
 
39
 
 
40
#ifdef HAVE_CONFIG_H
 
41
#  include "config.h"
 
42
#endif
 
43
 
 
44
#include <string.h>
 
45
 
 
46
#include "src/common/xmalloc.h"
 
47
#include "src/common/bitstring.h"
 
48
#include "src/common/xassert.h"
 
49
 
 
50
#include "src/srun/task_state.h"
 
51
 
 
52
struct task_state_struct {
 
53
        int n_tasks;
 
54
        int n_started;
 
55
        int n_abnormal;
 
56
        int n_exited;
 
57
        unsigned int first_exit:1;
 
58
        unsigned int first_abnormal_exit:1;
 
59
        bitstr_t *start_failed;
 
60
        bitstr_t *running;
 
61
        bitstr_t *normal_exit;
 
62
        bitstr_t *abnormal_exit;
 
63
};
 
64
 
 
65
task_state_t task_state_create (int ntasks)
 
66
{
 
67
        task_state_t ts = xmalloc (sizeof (*ts));
 
68
 
 
69
        /* ts is zero filled by xmalloc() */
 
70
        ts->n_tasks = ntasks;
 
71
        ts->running = bit_alloc (ntasks);
 
72
        ts->start_failed = bit_alloc (ntasks);
 
73
        ts->normal_exit = bit_alloc (ntasks);
 
74
        ts->abnormal_exit = bit_alloc (ntasks);
 
75
 
 
76
        return (ts);
 
77
}
 
78
 
 
79
void task_state_destroy (task_state_t ts)
 
80
{
 
81
        if (ts == NULL)
 
82
                return;
 
83
        if (ts->start_failed)
 
84
                bit_free (ts->start_failed);
 
85
        if (ts->running)
 
86
                bit_free (ts->running);
 
87
        if (ts->normal_exit)
 
88
                bit_free (ts->normal_exit);
 
89
        if (ts->abnormal_exit)
 
90
                bit_free (ts->abnormal_exit);
 
91
        xfree (ts);
 
92
}
 
93
 
 
94
static const char *_task_state_type_str (task_state_type_t t)
 
95
{
 
96
        switch (t) {
 
97
        case TS_START_SUCCESS:
 
98
                return ("TS_START_SUCCESS");
 
99
        case TS_START_FAILURE:
 
100
                return ("TS_START_FAILURE");
 
101
        case TS_NORMAL_EXIT:
 
102
                return ("TS_NORMAL_EXIT");
 
103
        case TS_ABNORMAL_EXIT:
 
104
                return ("TS_ABNORMAL_EXIT");
 
105
        }
 
106
        return ("Unknown");
 
107
}
 
108
 
 
109
void task_state_update (task_state_t ts, int taskid, task_state_type_t t)
 
110
{
 
111
        xassert (ts != NULL);
 
112
        xassert (taskid >= 0);
 
113
        xassert (taskid < ts->n_tasks);
 
114
 
 
115
        debug3("task_state_update(taskid=%d, %s)",
 
116
               taskid, _task_state_type_str (t));
 
117
 
 
118
        switch (t) {
 
119
        case TS_START_SUCCESS:
 
120
                bit_set (ts->running, taskid);
 
121
                ts->n_started++;
 
122
                break;
 
123
        case TS_START_FAILURE:
 
124
                bit_set (ts->start_failed, taskid);
 
125
                break;
 
126
        case TS_NORMAL_EXIT:
 
127
                bit_set (ts->normal_exit, taskid);
 
128
                bit_clear (ts->running, taskid);
 
129
                ts->n_exited++;
 
130
                break;
 
131
        case TS_ABNORMAL_EXIT:
 
132
                bit_clear (ts->running, taskid);
 
133
                bit_set (ts->abnormal_exit, taskid);
 
134
                ts->n_exited++;
 
135
                ts->n_abnormal++;
 
136
                break;
 
137
        }
 
138
 
 
139
        xassert ((bit_set_count(ts->abnormal_exit) +
 
140
                  bit_set_count(ts->normal_exit)) == ts->n_exited);
 
141
}
 
142
 
 
143
int task_state_first_exit (task_state_t ts)
 
144
{
 
145
        if (!ts->first_exit && ts->n_exited) {
 
146
                ts->first_exit = 1;
 
147
                return (1);
 
148
        }
 
149
        return (0);
 
150
}
 
151
 
 
152
int task_state_first_abnormal_exit (task_state_t ts)
 
153
{
 
154
        if (!ts->first_abnormal_exit && ts->n_abnormal) {
 
155
                ts->first_abnormal_exit = 1;
 
156
                return (1);
 
157
        }
 
158
        return (0);
 
159
}
 
160
 
 
161
static void _do_log_msg (bitstr_t *b, log_f fn, const char *msg)
 
162
{
 
163
        char buf [65536];
 
164
        char *s = bit_set_count (b) == 1 ? "" : "s";
 
165
        (*fn) ("task%s %s: %s\n", s, bit_fmt (buf, sizeof(buf), b), msg);
 
166
}
 
167
 
 
168
void task_state_print (task_state_t ts, log_f fn)
 
169
{
 
170
        bitstr_t *unseen = bit_alloc (ts->n_tasks);
 
171
 
 
172
        if (bit_set_count (ts->start_failed)) {
 
173
                _do_log_msg (ts->start_failed, fn, "failed to start");
 
174
                bit_or (unseen, ts->start_failed);
 
175
        }
 
176
        if (bit_set_count (ts->running)) {
 
177
                _do_log_msg (ts->running, fn, "running");
 
178
                bit_or (unseen, ts->running);
 
179
        }
 
180
        if (bit_set_count (ts->abnormal_exit)) {
 
181
                _do_log_msg (ts->abnormal_exit, fn, "exited abnormally");
 
182
                bit_or (unseen, ts->abnormal_exit);
 
183
        }
 
184
        if (bit_set_count (ts->normal_exit)) {
 
185
                _do_log_msg (ts->normal_exit, fn, "exited");
 
186
                bit_or (unseen, ts->normal_exit);
 
187
        }
 
188
        bit_not (unseen);
 
189
        if (bit_set_count (unseen))
 
190
                _do_log_msg (unseen, fn, "unknown");
 
191
        bit_free (unseen);
 
192
}
 
193