/
select_cons_tres.c
1271 lines (1114 loc) · 38.1 KB
/
select_cons_tres.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************\
* select_cons_tres.c - Resource selection plugin supporting Trackable
* RESources (TRES) policies.
*****************************************************************************
* Copyright (C) 2018 SchedMD LLC
* Derived in large part from select/cons_res plugin
*
* This file is part of Slurm, a resource management program.
* For details, see <https://slurm.schedmd.com/>.
* Please also read the included file: DISCLAIMER.
*
* Slurm is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* In addition, as a special exception, the copyright holders give permission
* to link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two. You must obey the GNU
* General Public License in all respects for all of the code used other than
* OpenSSL. If you modify file(s) with this exception, you may extend this
* exception to your version of the file(s), but you are not obligated to do
* so. If you do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source files in
* the program, then also delete it here.
*
* Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with Slurm; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\*****************************************************************************/
#include "config.h"
#define _GNU_SOURCE
#include <inttypes.h>
#include <string.h>
#include "src/common/slurm_xlator.h"
#include "src/common/assoc_mgr.h"
#include "src/common/xstring.h"
#include "src/slurmctld/gres_ctld.h"
#include "select_cons_tres.h"
#include "job_test.h"
#include "dist_tasks.h"
#define _DEBUG 0 /* Enables module specific debugging */
#define NODEINFO_MAGIC 0x8a5d
/* These are defined here so when we link with something other than
* the slurmctld we will have these symbols defined. They will get
* overwritten when linking with the slurmctld.
*/
#if defined (__APPLE__)
extern slurm_conf_t slurm_conf __attribute__((weak_import));
extern node_record_t **node_record_table_ptr __attribute__((weak_import));
extern List part_list __attribute__((weak_import));
extern List job_list __attribute__((weak_import));
extern int node_record_count __attribute__((weak_import));
extern time_t last_node_update __attribute__((weak_import));
extern switch_record_t *switch_record_table __attribute__((weak_import));
extern int switch_record_cnt __attribute__((weak_import));
extern bitstr_t *avail_node_bitmap __attribute__((weak_import));
extern int slurmctld_tres_cnt __attribute__((weak_import));
extern slurmctld_config_t slurmctld_config __attribute__((weak_import));
extern bitstr_t *idle_node_bitmap __attribute__((weak_import));
extern list_t *cluster_license_list __attribute__((weak_import));
#else
slurm_conf_t slurm_conf;
node_record_t **node_record_table_ptr;
List part_list;
List job_list;
int node_record_count;
time_t last_node_update;
switch_record_t *switch_record_table;
int switch_record_cnt;
bitstr_t *avail_node_bitmap;
int slurmctld_tres_cnt = 0;
slurmctld_config_t slurmctld_config;
bitstr_t *idle_node_bitmap;
list_t *cluster_license_list;
#endif
/* init common global variables */
bool backfill_busy_nodes = false;
int bf_window_scale = 0;
bool gang_mode = false;
bool have_dragonfly = false;
bool pack_serial_at_end = false;
bool preempt_by_part = false;
bool preempt_by_qos = false;
bool spec_cores_first = false;
bool topo_optional = false;
struct select_nodeinfo {
uint16_t magic; /* magic number */
uint16_t alloc_cpus;
uint64_t alloc_memory;
uint64_t *tres_alloc_cnt; /* array of tres counts allocated.
NOT PACKED */
char *tres_alloc_fmt_str; /* formatted str of allocated tres */
double tres_alloc_weighted; /* weighted number of tres allocated. */
};
/*
* These variables are required by the generic plugin interface. If they
* are not found in the plugin, the plugin loader will ignore it.
*
* plugin_name - a string giving a human-readable description of the
* plugin. There is no maximum length, but the symbol must refer to
* a valid string.
*
* plugin_type - a string suggesting the type of the plugin or its
* applicability to a particular form of data or method of data handling.
* If the low-level plugin API is used, the contents of this string are
* unimportant and may be anything. Slurm uses the higher-level plugin
* interface which requires this string to be of the form
*
* <application>/<method>
*
* where <application> is a description of the intended application of
* the plugin (e.g., "select" for Slurm node selection) and <method>
* is a description of how this plugin satisfies that application. Slurm will
* only load select plugins if the plugin_type string has a
* prefix of "select/".
*
* plugin_version - an unsigned 32-bit integer containing the Slurm version
* (major.minor.micro combined into a single number).
*/
const char plugin_name[] = "Trackable RESources (TRES) Selection plugin";
const char plugin_type[] = "select/cons_tres";
const uint32_t plugin_id = SELECT_PLUGIN_CONS_TRES;
const uint32_t plugin_version = SLURM_VERSION_NUMBER;
const uint32_t pstate_version = 7; /* version control on saved state */
const uint16_t nodeinfo_magic = 0x8a5d;
/* Global variables */
static job_resources_t *_create_job_resources(int node_cnt)
{
job_resources_t *job_resrcs_ptr;
job_resrcs_ptr = create_job_resources();
job_resrcs_ptr->cpu_array_reps = xcalloc(node_cnt, sizeof(uint32_t));
job_resrcs_ptr->cpu_array_value = xcalloc(node_cnt, sizeof(uint16_t));
job_resrcs_ptr->cpus = xcalloc(node_cnt, sizeof(uint16_t));
job_resrcs_ptr->cpus_used = xcalloc(node_cnt, sizeof(uint16_t));
job_resrcs_ptr->memory_allocated = xcalloc(node_cnt, sizeof(uint64_t));
job_resrcs_ptr->memory_used = xcalloc(node_cnt, sizeof(uint64_t));
job_resrcs_ptr->nhosts = node_cnt;
return job_resrcs_ptr;
}
static void _dump_job_res(struct job_resources *job)
{
char str[64];
if (job->core_bitmap)
bit_fmt(str, sizeof(str), job->core_bitmap);
else
sprintf(str, "[no core_bitmap]");
info("DEBUG: Dump job_resources: nhosts %u core_bitmap %s",
job->nhosts, str);
}
/*
* Check if there are no allocatable sockets with the given configuration due to
* core specialization.
* NOTE: this assumes the caller already checked CR_SOCKET is configured and
* AllowSpecResourceUsage=NO.
*/
static void _check_allocatable_sockets(node_record_t *node_ptr)
{
if (node_ptr->cpu_spec_list != NULL) {
bool socket_without_spec_cores = false;
bitstr_t *cpu_spec_bitmap = bit_alloc(node_ptr->cpus);
int cpu_socket = node_ptr->cores * node_ptr->threads;
bit_unfmt(cpu_spec_bitmap, node_ptr->cpu_spec_list);
for (int i = 0; i < node_ptr->tot_sockets; i++) {
if (!bit_set_count_range(cpu_spec_bitmap,
i * cpu_socket,
(i + 1) * cpu_socket)) {
socket_without_spec_cores = true;
break;
}
}
FREE_NULL_BITMAP(cpu_spec_bitmap);
if (!socket_without_spec_cores)
fatal("NodeName=%s configuration doesn't allow to run jobs. SelectTypeParameteres=CR_Socket and CPUSpecList=%s uses cores from all sockets while AllowSpecResourcesUsage=NO, which makes the node non-usable. Please fix your slurm.conf",
node_ptr->name, node_ptr->cpu_spec_list);
} else if (node_ptr->core_spec_cnt >
((node_ptr->tot_sockets - 1) * node_ptr->cores))
fatal("NodeName=%s configuration doesn't allow to run jobs. SelectTypeParameteres=CR_Socket and CoreSpecCount=%d uses cores from all sockets while AllowSpecResourcesUsage=NO, which makes the node non-usable. Please fix your slurm.conf",
node_ptr->name, node_ptr->core_spec_cnt);
}
/*
* init() is called when the plugin is loaded, before any other functions
* are called. Put global initialization here.
*/
extern int init(void)
{
if (xstrcasestr(slurm_conf.topology_param, "dragonfly"))
have_dragonfly = true;
if (xstrcasestr(slurm_conf.topology_param, "TopoOptional"))
topo_optional = true;
if (slurm_conf.preempt_mode & PREEMPT_MODE_GANG)
gang_mode = true;
else
gang_mode = false;
verbose("%s loaded", plugin_type);
return SLURM_SUCCESS;
}
extern int fini(void)
{
if (slurm_conf.debug_flags & DEBUG_FLAG_SELECT_TYPE)
info("%s shutting down ...", plugin_type);
else
verbose("%s shutting down ...", plugin_type);
node_data_destroy(select_node_usage);
select_node_usage = NULL;
part_data_destroy_res(select_part_record);
select_part_record = NULL;
cr_fini_global_core_data();
return SLURM_SUCCESS;
}
extern int select_p_state_save(char *dir_name)
{
/* nothing to save */
return SLURM_SUCCESS;
}
/* This is Part 2 of a 4-part procedure which can be found in
* src/slurmctld/read_config.c. See select_p_node_init for the
* whole story.
*/
extern int select_p_state_restore(char *dir_name)
{
/* nothing to restore */
return SLURM_SUCCESS;
}
/* This is Part 3 of a 4-part procedure which can be found in
* src/slurmctld/read_config.c. See select_p_node_init for the
* whole story.
*/
extern int select_p_job_init(List job_list)
{
/* nothing to initialize for jobs */
return SLURM_SUCCESS;
}
/* This is Part 1 of a 4-part procedure which can be found in
* src/slurmctld/read_config.c. The whole story goes like this:
*
* Step 1: select_g_node_init : initializes the global node arrays
* Step 2: select_g_state_restore : NO-OP - nothing to restore
* Step 3: select_g_job_init : NO-OP - nothing to initialize
* Step 4: select_g_select_nodeinfo_set: called from reset_job_bitmaps() with
* each valid recovered job_ptr AND from
* select_nodes(), this procedure adds
* job data to the 'select_part_record'
* global array
*/
extern int select_p_node_init(void)
{
char *preempt_type, *tmp_ptr;
int i;
node_record_t *node_ptr;
if (!slurm_conf.select_type_param) {
info("%s SelectTypeParameters not specified, using default value: CR_Core_Memory",
plugin_type);
slurm_conf.select_type_param = (CR_CORE | CR_MEMORY);
}
if (!(slurm_conf.select_type_param & (CR_CPU | CR_CORE | CR_SOCKET))) {
fatal("Invalid SelectTypeParameters: %s (%u), "
"You need at least CR_(CPU|CORE|SOCKET)*",
select_type_param_string(slurm_conf.select_type_param),
slurm_conf.select_type_param);
}
preempt_for_licenses = false;
if (xstrcasestr(slurm_conf.preempt_params, "reclaim_licenses"))
preempt_for_licenses = true;
preempt_strict_order = false;
if (xstrcasestr(slurm_conf.preempt_params, "strict_order") ||
xstrcasestr(slurm_conf.sched_params, "preempt_strict_order"))
preempt_strict_order = true;
preempt_reorder_cnt = 1;
if ((tmp_ptr = xstrcasestr(slurm_conf.preempt_params,
"reorder_count=")))
preempt_reorder_cnt = atoi(tmp_ptr + 14);
else if ((tmp_ptr = xstrcasestr(slurm_conf.sched_params,
"preempt_reorder_count=")))
preempt_reorder_cnt = atoi(tmp_ptr + 22);
if (preempt_reorder_cnt < 0) {
error("Invalid PreemptParameters reorder_count: %d",
preempt_reorder_cnt);
preempt_reorder_cnt = 1; /* Use default value */
}
if ((tmp_ptr = xstrcasestr(slurm_conf.sched_params,
"bf_window_linear="))) {
bf_window_scale = atoi(tmp_ptr + 17);
if (bf_window_scale <= 0) {
error("Invalid SchedulerParameters bf_window_linear: %d",
bf_window_scale);
bf_window_scale = 0; /* Use default value */
}
} else
bf_window_scale = 0;
if (xstrcasestr(slurm_conf.sched_params, "pack_serial_at_end"))
pack_serial_at_end = true;
else
pack_serial_at_end = false;
if (xstrcasestr(slurm_conf.sched_params, "spec_cores_first"))
spec_cores_first = true;
else
spec_cores_first = false;
if (xstrcasestr(slurm_conf.sched_params, "bf_busy_nodes"))
backfill_busy_nodes = true;
else
backfill_busy_nodes = false;
preempt_type = slurm_get_preempt_type();
preempt_by_part = false;
preempt_by_qos = false;
if (preempt_type) {
if (xstrcasestr(preempt_type, "partition"))
preempt_by_part = true;
if (xstrcasestr(preempt_type, "qos"))
preempt_by_qos = true;
xfree(preempt_type);
}
/* initial global core data structures */
select_state_initializing = true;
cr_init_global_core_data(node_record_table_ptr, node_record_count);
node_data_destroy(select_node_usage);
select_node_usage = xcalloc(node_record_count,
sizeof(node_use_record_t));
for (i = 0; (node_ptr = next_node(&i)); i++) {
if ((slurm_conf.select_type_param & CR_SOCKET) &&
(slurm_conf.conf_flags & CTL_CONF_ASRU) == 0)
_check_allocatable_sockets(node_ptr);
select_node_usage[node_ptr->index].node_state =
NODE_CR_AVAILABLE;
gres_node_state_dealloc_all(node_ptr->gres_list);
}
part_data_create_array();
node_data_dump();
return SLURM_SUCCESS;
}
/*
* select_p_job_test - Given a specification of scheduling requirements,
* identify the nodes which "best" satisfy the request.
* "best" is defined as either a minimal number of consecutive nodes
* or if sharing resources then sharing them with a job of similar size.
* IN/OUT job_ptr - pointer to job being considered for initiation,
* set's start_time when job expected to start
* IN/OUT node_bitmap - usable nodes are set on input, nodes not required to
* satisfy the request are cleared, other left set
* IN min_nodes - minimum count of nodes
* IN max_nodes - maximum count of nodes (0==don't care)
* IN req_nodes - requested (or desired) count of nodes
* IN mode - SELECT_MODE_RUN_NOW (0): try to schedule job now
* SELECT_MODE_TEST_ONLY (1): test if job can ever run
* SELECT_MODE_WILL_RUN (2): determine when and where job can run
* IN preemptee_candidates - List of pointers to jobs which can be preempted.
* IN/OUT preemptee_job_list - Pointer to list of job pointers. These are the
* jobs to be preempted to initiate the pending job. Not set
* if mode==SELECT_MODE_TEST_ONLY or input pointer is NULL.
* IN resv_exc_ptr - Various TRES which the job can NOT use.
* RET zero on success, EINVAL otherwise
*/
extern int select_p_job_test(job_record_t *job_ptr, bitstr_t *node_bitmap,
uint32_t min_nodes, uint32_t max_nodes,
uint32_t req_nodes, uint16_t mode,
List preemptee_candidates,
List *preemptee_job_list,
resv_exc_t *resv_exc_ptr)
{
int rc;
xassert(node_bitmap);
xassert(resv_exc_ptr);
debug2("evaluating %pJ", job_ptr);
if (!job_ptr->details)
return EINVAL;
#if _DEBUG
if (resv_exc_ptr->exc_cores) {
int i;
char tmp[128];
for (i = 0; i < next_node(&i); i++) {
if (!resv_exc_ptr->exc_cores[i])
continue;
bit_fmt(tmp, sizeof(tmp), resv_exc_ptr->exc_cores[i]);
error("IN exc_cores[%d] %s", i, tmp);
}
}
#endif
rc = job_test(job_ptr, node_bitmap, min_nodes, max_nodes,
req_nodes, mode, preemptee_candidates,
preemptee_job_list, resv_exc_ptr);
return rc;
}
extern int select_p_job_begin(job_record_t *job_ptr)
{
return SLURM_SUCCESS;
}
extern int select_p_job_ready(job_record_t *job_ptr)
{
node_record_t *node_ptr;
if (!IS_JOB_RUNNING(job_ptr) && !IS_JOB_SUSPENDED(job_ptr)) {
/* Gang scheduling might suspend job immediately */
return 0;
}
if (!job_ptr->node_bitmap)
return READY_NODE_STATE;
for (int i = 0; (node_ptr = next_node_bitmap(job_ptr->node_bitmap, &i));
i++) {
if (IS_NODE_POWERED_DOWN(node_ptr) ||
IS_NODE_POWERING_UP(node_ptr))
return 0;
}
return READY_NODE_STATE;
}
extern int select_p_job_expand(job_record_t *from_job_ptr,
job_record_t *to_job_ptr)
{
job_resources_t *from_job_resrcs_ptr, *to_job_resrcs_ptr,
*new_job_resrcs_ptr;
int first_bit, last_bit, i, node_cnt;
bool from_node_used, to_node_used;
int from_node_offset, to_node_offset, new_node_offset;
bitstr_t *tmp_bitmap, *tmp_bitmap2;
xassert(from_job_ptr);
xassert(from_job_ptr->details);
xassert(to_job_ptr);
xassert(to_job_ptr->details);
if (from_job_ptr->job_id == to_job_ptr->job_id) {
error("attempt to merge %pJ with self",
from_job_ptr);
return SLURM_ERROR;
}
from_job_resrcs_ptr = from_job_ptr->job_resrcs;
if ((from_job_resrcs_ptr == NULL) ||
(from_job_resrcs_ptr->cpus == NULL) ||
(from_job_resrcs_ptr->core_bitmap == NULL) ||
(from_job_resrcs_ptr->node_bitmap == NULL)) {
error("%pJ lacks a job_resources struct",
from_job_ptr);
return SLURM_ERROR;
}
to_job_resrcs_ptr = to_job_ptr->job_resrcs;
if ((to_job_resrcs_ptr == NULL) ||
(to_job_resrcs_ptr->cpus == NULL) ||
(to_job_resrcs_ptr->core_bitmap == NULL) ||
(to_job_resrcs_ptr->node_bitmap == NULL)) {
error("%pJ lacks a job_resources struct",
to_job_ptr);
return SLURM_ERROR;
}
if (to_job_ptr->gres_list_req) {
/* Can't reset gres/mps fields today */
error("%pJ has allocated GRES", to_job_ptr);
return SLURM_ERROR;
}
if (from_job_ptr->gres_list_req) {
/* Can't reset gres/mps fields today */
error("%pJ has allocated GRES", from_job_ptr);
return SLURM_ERROR;
}
(void) job_res_rm_job(select_part_record, select_node_usage, NULL,
from_job_ptr, JOB_RES_ACTION_NORMAL, NULL);
(void) job_res_rm_job(select_part_record, select_node_usage, NULL,
to_job_ptr, JOB_RES_ACTION_NORMAL, NULL);
if (to_job_resrcs_ptr->core_bitmap_used)
bit_clear_all(to_job_resrcs_ptr->core_bitmap_used);
tmp_bitmap = bit_copy(to_job_resrcs_ptr->node_bitmap);
bit_or(tmp_bitmap, from_job_resrcs_ptr->node_bitmap);
tmp_bitmap2 = bit_copy(to_job_ptr->node_bitmap);
bit_or(tmp_bitmap2, from_job_ptr->node_bitmap);
bit_and(tmp_bitmap, tmp_bitmap2);
FREE_NULL_BITMAP(tmp_bitmap2);
node_cnt = bit_set_count(tmp_bitmap);
new_job_resrcs_ptr = _create_job_resources(node_cnt);
new_job_resrcs_ptr->ncpus = from_job_resrcs_ptr->ncpus +
to_job_resrcs_ptr->ncpus;
new_job_resrcs_ptr->node_req = to_job_resrcs_ptr->node_req;
new_job_resrcs_ptr->node_bitmap = tmp_bitmap;
new_job_resrcs_ptr->nodes = bitmap2node_name(new_job_resrcs_ptr->
node_bitmap);
new_job_resrcs_ptr->whole_node = to_job_resrcs_ptr->whole_node;
new_job_resrcs_ptr->threads_per_core =
to_job_resrcs_ptr->threads_per_core;
new_job_resrcs_ptr->cr_type = to_job_resrcs_ptr->cr_type;
build_job_resources(new_job_resrcs_ptr);
to_job_ptr->total_cpus = 0;
first_bit = MIN(bit_ffs(from_job_resrcs_ptr->node_bitmap),
bit_ffs(to_job_resrcs_ptr->node_bitmap));
last_bit = MAX(bit_fls(from_job_resrcs_ptr->node_bitmap),
bit_fls(to_job_resrcs_ptr->node_bitmap));
from_node_offset = to_node_offset = new_node_offset = -1;
for (i = first_bit; i <= last_bit; i++) {
from_node_used = to_node_used = false;
if (bit_test(from_job_resrcs_ptr->node_bitmap, i)) {
from_node_used = bit_test(from_job_ptr->node_bitmap,i);
from_node_offset++;
}
if (bit_test(to_job_resrcs_ptr->node_bitmap, i)) {
to_node_used = bit_test(to_job_ptr->node_bitmap, i);
to_node_offset++;
}
if (!from_node_used && !to_node_used)
continue;
new_node_offset++;
if (from_node_used) {
/*
* Merge alloc info from both "from" and "to" jobs,
* leave "from" job with no allocated CPUs or memory
*
* The following fields should be zero:
* from_job_resrcs_ptr->cpus_used[from_node_offset]
* from_job_resrcs_ptr->memory_used[from_node_offset];
*/
new_job_resrcs_ptr->cpus[new_node_offset] =
from_job_resrcs_ptr->cpus[from_node_offset];
from_job_resrcs_ptr->cpus[from_node_offset] = 0;
new_job_resrcs_ptr->memory_allocated[new_node_offset] =
from_job_resrcs_ptr->
memory_allocated[from_node_offset];
job_resources_bits_copy(new_job_resrcs_ptr,
new_node_offset,
from_job_resrcs_ptr,
from_node_offset);
}
if (to_node_used) {
/*
* Merge alloc info from both "from" and "to" jobs
*
* DO NOT double count the allocated CPUs in partition
* with Shared nodes
*/
new_job_resrcs_ptr->cpus[new_node_offset] +=
to_job_resrcs_ptr->cpus[to_node_offset];
new_job_resrcs_ptr->cpus_used[new_node_offset] +=
to_job_resrcs_ptr->cpus_used[to_node_offset];
new_job_resrcs_ptr->memory_allocated[new_node_offset]+=
to_job_resrcs_ptr->
memory_allocated[to_node_offset];
new_job_resrcs_ptr->memory_used[new_node_offset] +=
to_job_resrcs_ptr->memory_used[to_node_offset];
job_resources_bits_copy(new_job_resrcs_ptr,
new_node_offset,
to_job_resrcs_ptr,
to_node_offset);
if (from_node_used) {
/* Adjust CPU count for shared CPUs */
int from_core_cnt, to_core_cnt, new_core_cnt;
from_core_cnt = count_job_resources_node(
from_job_resrcs_ptr,
from_node_offset);
to_core_cnt = count_job_resources_node(
to_job_resrcs_ptr,
to_node_offset);
new_core_cnt = count_job_resources_node(
new_job_resrcs_ptr,
new_node_offset);
if ((from_core_cnt + to_core_cnt) !=
new_core_cnt) {
new_job_resrcs_ptr->
cpus[new_node_offset] *=
new_core_cnt;
new_job_resrcs_ptr->
cpus[new_node_offset] /=
(from_core_cnt + to_core_cnt);
}
}
}
if (to_job_ptr->details->whole_node == 1) {
to_job_ptr->total_cpus +=
node_record_table_ptr[i]->cpus_efctv;
} else {
to_job_ptr->total_cpus += new_job_resrcs_ptr->
cpus[new_node_offset];
}
}
build_job_resources_cpu_array(new_job_resrcs_ptr);
gres_ctld_job_merge(from_job_ptr->gres_list_req,
from_job_resrcs_ptr->node_bitmap,
to_job_ptr->gres_list_req,
to_job_resrcs_ptr->node_bitmap);
/* copy the allocated gres */
gres_ctld_job_merge(from_job_ptr->gres_list_alloc,
from_job_resrcs_ptr->node_bitmap,
to_job_ptr->gres_list_alloc,
to_job_resrcs_ptr->node_bitmap);
/* Now swap data: "new" -> "to" and clear "from" */
free_job_resources(&to_job_ptr->job_resrcs);
to_job_ptr->job_resrcs = new_job_resrcs_ptr;
to_job_ptr->cpu_cnt = to_job_ptr->total_cpus;
to_job_ptr->details->min_cpus = to_job_ptr->total_cpus;
to_job_ptr->details->max_cpus = to_job_ptr->total_cpus;
from_job_ptr->total_cpus = 0;
from_job_resrcs_ptr->ncpus = 0;
from_job_ptr->details->min_cpus = 0;
from_job_ptr->details->max_cpus = 0;
from_job_ptr->total_nodes = 0;
from_job_resrcs_ptr->nhosts = 0;
from_job_ptr->node_cnt = 0;
from_job_ptr->details->min_nodes = 0;
to_job_ptr->total_nodes = new_job_resrcs_ptr->nhosts;
to_job_ptr->node_cnt = new_job_resrcs_ptr->nhosts;
bit_or(to_job_ptr->node_bitmap, from_job_ptr->node_bitmap);
bit_clear_all(from_job_ptr->node_bitmap);
bit_clear_all(from_job_resrcs_ptr->node_bitmap);
xfree(to_job_ptr->nodes);
to_job_ptr->nodes = xstrdup(new_job_resrcs_ptr->nodes);
xfree(from_job_ptr->nodes);
from_job_ptr->nodes = xstrdup("");
xfree(from_job_resrcs_ptr->nodes);
from_job_resrcs_ptr->nodes = xstrdup("");
(void) job_res_add_job(to_job_ptr, JOB_RES_ACTION_NORMAL);
return SLURM_SUCCESS;
}
extern int select_p_job_resized(job_record_t *job_ptr, node_record_t *node_ptr)
{
part_res_record_t *part_record_ptr = select_part_record;
node_use_record_t *node_usage = select_node_usage;
struct job_resources *job = job_ptr->job_resrcs;
part_res_record_t *p_ptr;
int i, n;
List gres_list;
bool old_job = false;
xassert(job_ptr);
xassert(job_ptr->magic == JOB_MAGIC);
if (!job || !job->core_bitmap) {
error("%pJ has no job_resrcs info",
job_ptr);
return SLURM_ERROR;
}
debug3("%pJ node %s",
job_ptr, node_ptr->name);
if (job_ptr->start_time < slurmctld_config.boot_time)
old_job = true;
if (slurm_conf.debug_flags & DEBUG_FLAG_SELECT_TYPE)
_dump_job_res(job);
/* subtract memory */
for (i = 0, n = 0; next_node_bitmap(job->node_bitmap, &i); i++) {
if (i != node_ptr->index) {
n++;
continue;
}
if (job->cpus[n] == 0) {
info("attempt to remove node %s from %pJ again",
node_ptr->name, job_ptr);
return SLURM_SUCCESS;
}
if (node_usage[i].gres_list)
gres_list = node_usage[i].gres_list;
else
gres_list = node_ptr->gres_list;
gres_ctld_job_dealloc(job_ptr->gres_list_alloc, gres_list, n,
job_ptr->job_id, node_ptr->name,
old_job, true);
gres_node_state_log(gres_list, node_ptr->name);
if (node_usage[i].alloc_memory < job->memory_allocated[n]) {
error("node %s memory is underallocated (%"PRIu64"-%"PRIu64") for %pJ",
node_ptr->name,
node_usage[i].alloc_memory,
job->memory_allocated[n], job_ptr);
node_usage[i].alloc_memory = 0;
} else
node_usage[i].alloc_memory -= job->memory_allocated[n];
extract_job_resources_node(job, n);
break;
}
if (IS_JOB_SUSPENDED(job_ptr))
return SLURM_SUCCESS; /* No cores allocated to the job now */
/* subtract cores, reconstruct rows with remaining jobs */
if (!job_ptr->part_ptr) {
error("removed %pJ does not have a partition assigned",
job_ptr);
return SLURM_ERROR;
}
for (p_ptr = part_record_ptr; p_ptr; p_ptr = p_ptr->next) {
if (p_ptr->part_ptr == job_ptr->part_ptr)
break;
}
if (!p_ptr) {
error("removed %pJ could not find part %s",
job_ptr, job_ptr->part_ptr->name);
return SLURM_ERROR;
}
if (!p_ptr->row)
return SLURM_SUCCESS;
/* look for the job in the partition's job_list */
n = 0;
for (i = 0; i < p_ptr->num_rows; i++) {
uint32_t j;
for (j = 0; j < p_ptr->row[i].num_jobs; j++) {
if (p_ptr->row[i].job_list[j] != job)
continue;
debug3("found %pJ in part %s row %u",
job_ptr,
p_ptr->part_ptr->name, i);
/* found job - we're done, don't actually remove */
n = 1;
i = p_ptr->num_rows;
break;
}
}
if (n == 0) {
error("could not find %pJ in partition %s",
job_ptr, p_ptr->part_ptr->name);
return SLURM_ERROR;
}
/* some node of job removed from core-bitmap, so rebuild core bitmaps */
part_data_build_row_bitmaps(p_ptr, NULL);
/*
* Adjust the node_state of the node removed from this job.
* If all cores are now available, set node_state = NODE_CR_AVAILABLE
*/
if (node_usage[node_ptr->index].node_state >= job->node_req) {
node_usage[node_ptr->index].node_state -= job->node_req;
} else {
error("node_state miscount");
node_usage[node_ptr->index].node_state = NODE_CR_AVAILABLE;
}
return SLURM_SUCCESS;
}
extern int select_p_job_fini(job_record_t *job_ptr)
{
xassert(job_ptr);
xassert(job_ptr->magic == JOB_MAGIC);
log_flag(SELECT_TYPE, "%pJ", job_ptr);
job_res_rm_job(select_part_record, select_node_usage, NULL,
job_ptr, JOB_RES_ACTION_NORMAL, NULL);
return SLURM_SUCCESS;
}
/* NOTE: This function is not called with gang scheduling because it
* needs to track how many jobs are running or suspended on each node.
* This sum is compared with the partition's OverSubscribe parameter */
extern int select_p_job_suspend(job_record_t *job_ptr, bool indf_susp)
{
xassert(job_ptr);
xassert(job_ptr->magic == JOB_MAGIC);
if (indf_susp)
log_flag(SELECT_TYPE, "%pJ indf_susp",
job_ptr);
else
log_flag(SELECT_TYPE, "%pJ",
job_ptr);
if (!indf_susp)
return SLURM_SUCCESS;
return job_res_rm_job(select_part_record, select_node_usage, NULL,
job_ptr, JOB_RES_ACTION_RESUME, NULL);
}
/* See NOTE with select_p_job_suspend() above */
extern int select_p_job_resume(job_record_t *job_ptr, bool indf_susp)
{
xassert(job_ptr);
xassert(job_ptr->magic == JOB_MAGIC);
if (indf_susp)
log_flag(SELECT_TYPE, "%pJ indf_susp",
job_ptr);
else
log_flag(SELECT_TYPE, "%pJ",
job_ptr);
if (!indf_susp)
return SLURM_SUCCESS;
return job_res_add_job(job_ptr, JOB_RES_ACTION_RESUME);
}
extern bitstr_t *select_p_step_pick_nodes(job_record_t *job_ptr,
select_jobinfo_t *jobinfo,
uint32_t node_count,
bitstr_t **avail_nodes)
{
return NULL;
}
/* Unused for this plugin */
extern int select_p_step_start(step_record_t *step_ptr)
{
return SLURM_SUCCESS;
}
/* Unused for this plugin */
extern int select_p_step_finish(step_record_t *step_ptr, bool killing_step)
{
return SLURM_SUCCESS;
}
extern int select_p_select_nodeinfo_pack(select_nodeinfo_t *nodeinfo,
buf_t *buffer,
uint16_t protocol_version)
{
select_nodeinfo_t *nodeinfo_empty = NULL;
if (!nodeinfo) {
/*
* We should never get here,
* but avoid abort with bad data structures
*/
error("nodeinfo is NULL");
nodeinfo_empty = xmalloc(sizeof(select_nodeinfo_t));
nodeinfo = nodeinfo_empty;
}
if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
pack16(nodeinfo->alloc_cpus, buffer);
pack64(nodeinfo->alloc_memory, buffer);
packstr(nodeinfo->tres_alloc_fmt_str, buffer);
packdouble(nodeinfo->tres_alloc_weighted, buffer);
}
xfree(nodeinfo_empty);
return SLURM_SUCCESS;
}
extern select_nodeinfo_t *select_p_select_nodeinfo_alloc(void)
{
select_nodeinfo_t *nodeinfo = xmalloc(sizeof(select_nodeinfo_t));
nodeinfo->magic = nodeinfo_magic;
return nodeinfo;
}
extern int select_p_select_nodeinfo_free(select_nodeinfo_t *nodeinfo)
{
if (nodeinfo) {
if (nodeinfo->magic != nodeinfo_magic) {
error("nodeinfo magic bad");
return EINVAL;
}
xfree(nodeinfo->tres_alloc_cnt);
xfree(nodeinfo->tres_alloc_fmt_str);
xfree(nodeinfo);
}
return SLURM_SUCCESS;
}
extern int select_p_select_nodeinfo_unpack(select_nodeinfo_t **nodeinfo,
buf_t *buffer,
uint16_t protocol_version)
{
uint32_t uint32_tmp;
select_nodeinfo_t *nodeinfo_ptr = NULL;
nodeinfo_ptr = select_p_select_nodeinfo_alloc();
*nodeinfo = nodeinfo_ptr;
if (protocol_version >= SLURM_MIN_PROTOCOL_VERSION) {
safe_unpack16(&nodeinfo_ptr->alloc_cpus, buffer);
safe_unpack64(&nodeinfo_ptr->alloc_memory, buffer);
safe_unpackstr_xmalloc(&nodeinfo_ptr->tres_alloc_fmt_str,
&uint32_tmp, buffer);
safe_unpackdouble(&nodeinfo_ptr->tres_alloc_weighted, buffer);
}
return SLURM_SUCCESS;
unpack_error:
error("error unpacking here");
select_p_select_nodeinfo_free(nodeinfo_ptr);
*nodeinfo = NULL;
return SLURM_ERROR;
}
extern int select_p_select_nodeinfo_set_all(void)
{
static time_t last_set_all = 0;
part_res_record_t *p_ptr;
node_record_t *node_ptr = NULL;
int i, n;
uint32_t alloc_cpus, alloc_cores, total_node_cores, efctv_node_cores;
bitstr_t **alloc_core_bitmap = NULL;
List gres_list;
/*
* only set this once when the last_node_update is newer than
* the last time we set things up.
*/
if (last_set_all && (last_node_update < last_set_all)) {
debug2("Node data hasn't changed since %ld",
(long)last_set_all);
return SLURM_NO_CHANGE_IN_DATA;
}
last_set_all = last_node_update;
/*
* Build core bitmap array representing all cores allocated to all
* active jobs (running or preempted jobs)
*/
for (p_ptr = select_part_record; p_ptr; p_ptr = p_ptr->next) {
if (!p_ptr->row)
continue;
for (i = 0; i < p_ptr->num_rows; i++) {
if (!p_ptr->row[i].row_bitmap)
continue;
if (!alloc_core_bitmap) {
alloc_core_bitmap =
copy_core_array(
p_ptr->row[i].row_bitmap);
} else {
core_array_or(alloc_core_bitmap,
p_ptr->row[i].row_bitmap);
}
}
}
for (n = 0; (node_ptr = next_node(&n)); n++) {