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

« back to all changes in this revision

Viewing changes to src/plugins/task/affinity/affinity.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:
5
5
 *  Copyright (C) 2005-2006 Hewlett-Packard Development Company, L.P.
6
6
 *  
7
7
 *  This file is part of SLURM, a resource management program.
8
 
 *  For details, see <http://www.llnl.gov/linux/slurm/>.
 
8
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
9
 *  Please also read the included file: DISCLAIMER.
9
10
 *  
10
11
 *  SLURM is free software; you can redistribute it and/or modify it under
11
12
 *  the terms of the GNU General Public License as published by the Free
67
68
                        units = "_cores";
68
69
                else if (job->cpu_bind_type & CPU_BIND_TO_SOCKETS)
69
70
                        units = "_sockets";
 
71
                else if (job->cpu_bind_type & CPU_BIND_TO_LDOMS)
 
72
                        units = "_ldoms";
70
73
                else
71
74
                        units = "";
72
75
                if (job->cpu_bind_type & CPU_BIND_RANK) {
75
78
                        bind_type = "MAP ";
76
79
                } else if (job->cpu_bind_type & CPU_BIND_MASK) {
77
80
                        bind_type = "MASK";
 
81
                } else if (job->cpu_bind_type & CPU_BIND_LDRANK) {
 
82
                        bind_type = "LDRANK";
 
83
                } else if (job->cpu_bind_type & CPU_BIND_LDMAP) {
 
84
                        bind_type = "LDMAP ";
 
85
                } else if (job->cpu_bind_type & CPU_BIND_LDMASK) {
 
86
                        bind_type = "LDMASK";
78
87
                } else if (job->cpu_bind_type & (~CPU_BIND_VERBOSE)) {
79
88
                        bind_type = "UNK ";
80
89
                } else {
95
104
                        status);
96
105
}
97
106
 
 
107
/* If HAVE_NUMA, create mask for given ldom.
 
108
 * Otherwise create mask for given socket
 
109
 */
 
110
static int _bind_ldom(uint32_t ldom, cpu_set_t *mask)
 
111
{
 
112
#ifdef HAVE_NUMA
 
113
        int c, maxcpus, nnid = 0;
 
114
        int nmax = numa_max_node();
 
115
        if (nmax > 0)
 
116
                nnid = ldom % (nmax+1);
 
117
        debug3("task/affinity: binding to NUMA node %d", nnid);
 
118
        maxcpus = conf->sockets * conf->cores * conf->threads;
 
119
        for (c = 0; c < maxcpus; c++) {
 
120
                if (slurm_get_numa_node(c) == nnid)
 
121
                        CPU_SET(c, mask);
 
122
        }
 
123
        return true;
 
124
#else
 
125
        uint16_t s, sid  = ldom % conf->sockets;
 
126
        uint16_t i, cpus = conf->cores * conf->threads;
 
127
        if (!conf->block_map)
 
128
                return false;
 
129
        for (s = sid * cpus; s < (sid+1) * cpus; s++) {
 
130
                i = s % conf->block_map_size;
 
131
                CPU_SET(conf->block_map[i], mask);
 
132
        }
 
133
        return true;
 
134
#endif
 
135
}
 
136
 
98
137
int get_cpuset(cpu_set_t *mask, slurmd_job_t *job)
99
138
{
100
 
        int nummasks, maskid, i;
 
139
        int nummasks, maskid, i, threads;
101
140
        char *curstr, *selstr;
102
141
        char mstr[1 + CPU_SETSIZE / 4];
103
 
        int local_id = job->envtp->localid;
 
142
        uint32_t local_id = job->envtp->localid;
104
143
        char buftype[1024];
105
144
 
106
145
        slurm_sprint_cpu_bind_type(buftype, job->cpu_bind_type);
113
152
        }
114
153
 
115
154
        if (job->cpu_bind_type & CPU_BIND_RANK) {
116
 
                CPU_SET(job->envtp->localid % job->cpus, mask);
 
155
                threads = MAX(conf->threads, 1);
 
156
                CPU_SET(job->envtp->localid % (job->cpus*threads), mask);
117
157
                return true;
118
158
        }
 
159
        
 
160
        if (job->cpu_bind_type & CPU_BIND_LDRANK) {
 
161
                /* if HAVE_NUMA then bind this task ID to it's corresponding
 
162
                 * locality domain ID. Otherwise, bind this task ID to it's
 
163
                 * corresponding socket ID */
 
164
                return _bind_ldom(local_id, mask);
 
165
        }
119
166
 
120
167
        if (!job->cpu_bind)
121
168
                return false;
180
227
                CPU_SET(mycpu, mask);
181
228
                return true;
182
229
        }
 
230
        
 
231
        if (job->cpu_bind_type & CPU_BIND_LDMASK) {
 
232
                /* if HAVE_NUMA bind this task to the locality domains
 
233
                 * identified in mstr. Otherwise bind this task to the
 
234
                 * sockets identified in mstr */
 
235
                int len = strlen(mstr);
 
236
                char *ptr = mstr + len - 1;
 
237
                uint32_t base = 0;
 
238
 
 
239
                curstr = mstr;
 
240
                /* skip 0x, it's all hex anyway */
 
241
                if (len > 1 && !memcmp(mstr, "0x", 2L))
 
242
                        curstr += 2;
 
243
                while (ptr >= curstr) {
 
244
                        char val = char_to_val(*ptr);
 
245
                        if (val == (char) -1)
 
246
                                return false;
 
247
                        if (val & 1)
 
248
                                _bind_ldom(base, mask);
 
249
                        if (val & 2)
 
250
                                _bind_ldom(base + 1, mask);
 
251
                        if (val & 4)
 
252
                                _bind_ldom(base + 2, mask);
 
253
                        if (val & 8)
 
254
                                _bind_ldom(base + 3, mask);
 
255
                        len--;
 
256
                        ptr--;
 
257
                        base += 4;
 
258
                }
 
259
                return true;
 
260
        }
 
261
        
 
262
        if (job->cpu_bind_type & CPU_BIND_LDMAP) {
 
263
                /* if HAVE_NUMA bind this task to the given locality
 
264
                 * domain. Otherwise bind this task to the given
 
265
                 * socket */
 
266
                uint32_t myldom = 0;
 
267
                if (strncmp(mstr, "0x", 2) == 0) {
 
268
                        myldom = strtoul (&(mstr[2]), NULL, 16);
 
269
                } else {
 
270
                        myldom = strtoul (mstr, NULL, 10);
 
271
                }
 
272
                return _bind_ldom(myldom, mask);
 
273
        }
183
274
 
184
275
        return false;
185
276
}
198
289
        rval = sched_setaffinity(pid, mask);
199
290
#  endif
200
291
#endif
201
 
        if (rval)
202
 
                verbose("sched_setaffinity(%d,%d,0x%s) failed with status %d",
203
 
                                pid, size, cpuset_to_str(mask, mstr), rval);
 
292
        if (rval) {
 
293
                verbose("sched_setaffinity(%d,%d,0x%s) failed: %m",
 
294
                        pid, size, cpuset_to_str(mask, mstr));
 
295
        }
204
296
        return (rval);
205
297
}
206
298
 
219
311
        rval = sched_getaffinity(pid, mask);
220
312
#  endif
221
313
#endif
222
 
        if (rval)
 
314
        if (rval) {
223
315
                verbose("sched_getaffinity(%d,%d,0x%s) failed with status %d",
224
316
                                pid, size, cpuset_to_str(mask, mstr), rval);
225
 
 
226
 
        debug3("sched_getaffinity(%d) = 0x%s", pid, cpuset_to_str(mask, mstr));
 
317
        } else {
 
318
                debug3("sched_getaffinity(%d) = 0x%s",
 
319
                       pid, cpuset_to_str(mask, mstr));
 
320
        }
227
321
        return (rval);
228
322
}