1 /*****************************************************************************\
2  *  acct_policy.h - definitions of functions in acct_policy.c
3  *****************************************************************************
4  *  Copyright (C) 2008 Lawrence Livermore National Security.
5  *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6  *  Written by Morris Jette <jette@llnl.gov> et. al.
7  *  CODE-OCEC-09-009. All rights reserved.
8  *
9  *  This file is part of Slurm, a resource management program.
10  *  For details, see <https://slurm.schedmd.com/>.
11  *  Please also read the included file: DISCLAIMER.
12  *
13  *  Slurm is free software; you can redistribute it and/or modify it under
14  *  the terms of the GNU General Public License as published by the Free
15  *  Software Foundation; either version 2 of the License, or (at your option)
16  *  any later version.
17  *
18  *  In addition, as a special exception, the copyright holders give permission
19  *  to link the code of portions of this program with the OpenSSL library under
20  *  certain conditions as described in each individual source file, and
21  *  distribute linked combinations including the two. You must obey the GNU
22  *  General Public License in all respects for all of the code used other than
23  *  OpenSSL. If you modify file(s) with this exception, you may extend this
24  *  exception to your version of the file(s), but you are not obligated to do
25  *  so. If you do not wish to do so, delete this exception statement from your
26  *  version.  If you delete this exception statement from all source files in
27  *  the program, then also delete it here.
28  *
29  *  Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
30  *  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
31  *  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
32  *  details.
33  *
34  *  You should have received a copy of the GNU General Public License along
35  *  with Slurm; if not, write to the Free Software Foundation, Inc.,
36  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
37 \*****************************************************************************/
38 
39 #ifndef _HAVE_ACCT_POLICY_H
40 #define _HAVE_ACCT_POLICY_H
41 
42 #include "src/common/list.h"
43 
44 /*
45  * acct_policy_add_job_submit - Note that a job has been submitted for
46  *	accounting policy purposes.
47  */
48 extern void acct_policy_add_job_submit(job_record_t *job_ptr);
49 
50 /*
51  * acct_policy_remove_job_submit - Note that a job has finished (might
52  *      not had started or been allocated resources) for accounting
53  *      policy purposes.
54  */
55 extern void acct_policy_remove_job_submit(job_record_t *job_ptr);
56 
57 /*
58  * acct_policy_job_begin - Note that a job is starting for accounting
59  *	policy purposes.
60  */
61 extern void acct_policy_job_begin(job_record_t *job_ptr);
62 
63 /*
64  * acct_policy_job_fini - Note that a job is completing for accounting
65  *	policy purposes.
66  */
67 extern void acct_policy_job_fini(job_record_t *job_ptr);
68 
69 /*
70  * acct_policy_alter_job - if resources change on a job this needs to
71  * be called after they have been validated, but before they actually
72  * do.  Each of the resources can be changed one at a time.  If no
73  * change happens on a resouce just put old values in for the new.
74  * At the time of writing this function any node or cpu size change
75  * while running was already handled in the job_pre|post_resize_acctg functions.
76  */
77 extern void acct_policy_alter_job(job_record_t *job_ptr,
78 				  uint32_t new_time_limit);
79 
80 /*
81  * acct_policy_validate - validate that a job request can be satisfied without
82  * exceeding any association or QOS limit.
83  * job_desc IN - job descriptor being submitted
84  * part_ptr IN - pointer to (one) partition to which the job is being submitted
85  * assoc_in IN - pointer to association to which the job is being submitted
86  * qos_ptr IN - pointer to QOS to which the job is being submitted
87  * state_reason OUT - if non-NULL, set to reason for rejecting the job
88  * acct_policy_limit_set IN/OUT - limits set for the job, pre-allocated storage
89  *		is filled in by acct_policy_validate
90  * update_call IN - true if request to update existing job request
91  * RET true if valid
92  */
93 extern bool acct_policy_validate(job_desc_msg_t *job_desc,
94 				 part_record_t *part_ptr,
95 				 slurmdb_assoc_rec_t *assoc_in,
96 				 slurmdb_qos_rec_t *qos_ptr,
97 				 uint32_t *state_reason,
98 				 acct_policy_limit_set_t *acct_policy_limit_set,
99 				 bool update_call);
100 
101 /*
102  * acct_policy_validate_het_job - validate that a hetjob as a whole (all
103  * components at once) can be satisfied without exceeding any association or
104  * QOS limit.
105  * submit_job_list IN - list of job_record_t entries (already created)
106  * RET true if valid
107  */
108 extern bool acct_policy_validate_het_job(List submit_job_list);
109 
110 /*
111  * acct_policy_job_runnable_pre_select - Determine of the specified
112  *	job can execute right now or not depending upon accounting
113  *	policy (e.g. running job limit for this association). If the
114  *	association limits prevent the job from ever running (lowered
115  *	limits since job submission), then cancel the job.
116  */
117 extern bool acct_policy_job_runnable_pre_select(job_record_t *job_ptr,
118 						bool assoc_mgr_locked);
119 
120 /*
121  * acct_policy_job_runnable_post_select - After nodes have been
122  *	selected for the job verify the counts don't exceed aggregated limits.
123  */
124 extern bool acct_policy_job_runnable_post_select(job_record_t *job_ptr,
125 						 uint64_t *tres_req_cnt,
126 						 bool assoc_mgr_locked);
127 
128 /*
129  * Determine of the specified job can execute right now or is currently
130  * blocked by an association or QOS limit. Does not re-validate job state.
131  */
132 extern bool acct_policy_job_runnable_state(job_record_t *job_ptr);
133 
134 /*
135  * Using the limits on the job get the max nodes possible.
136  */
137 extern uint32_t acct_policy_get_max_nodes(job_record_t *job_ptr,
138 					  uint32_t *wait_reason);
139 
140 /*
141  * acct_policy_update_pending_job - Make sure the limits imposed on a
142  *	job on submission are correct after an update to a qos or
143  *	association.  If the association/qos limits prevent
144  *	the job from ever running (lowered limits since job submission),
145  *	then cancel the job.
146  */
147 extern int acct_policy_update_pending_job(job_record_t *job_ptr);
148 
149 /*
150  * acct_policy_job_runnable - Determine of the specified job has timed
151  *	out based on it's QOS or association. Returns True if job is
152  *	timed out and sets job_ptr->state_reason = FAIL_TIMEOUT;
153  */
154 extern bool acct_policy_job_time_out(job_record_t *job_ptr);
155 
156 /*
157  * acct_policy_handle_accrue_time - Set accrue time if we are under a limit.  If
158  * we are a task array we will also split off things to handle them
159  * individually.
160  */
161 extern int acct_policy_handle_accrue_time(job_record_t *job_ptr,
162 					  bool assoc_mgr_locked);
163 
164 /*
165  * acct_policy_add_accrue_time - Implicitly add job to the accrue_cnt of the
166  * assoc and QOS of the job/part.
167  */
168 extern void acct_policy_add_accrue_time(job_record_t *job_ptr,
169 					bool assoc_mgr_locked);
170 
171 extern void acct_policy_remove_accrue_time(job_record_t *job_ptr,
172 					   bool assoc_mgr_locked);
173 
174 extern uint32_t acct_policy_get_prio_thresh(job_record_t *job_ptr,
175 					    bool assoc_mgr_locked);
176 
177 /*
178  * acct_policy_get_preemptable_time - get the time the job becomes preemptable
179  * 	based on conf and qos PreemptExemptTime
180  */
181 extern time_t acct_policy_get_preemptable_time(job_record_t *job_ptr);
182 
183 /*
184  * acct_policy_is_job_preemptable - Check if job is preemptable checking
185  * 	global conf and qos options PreemptExemptTime
186  * 	returns true if job is *exempt* from preemption
187  */
188 extern bool acct_policy_is_job_preempt_exempt(job_record_t *job_ptr);
189 
190 extern void acct_policy_set_qos_order(job_record_t *job_ptr,
191 				      slurmdb_qos_rec_t **qos_ptr_1,
192 				      slurmdb_qos_rec_t **qos_ptr_2);
193 
194 extern slurmdb_used_limits_t *acct_policy_get_acct_used_limits(
195 	List *acct_limit_list, char *acct);
196 
197 extern slurmdb_used_limits_t *acct_policy_get_user_used_limits(
198 	 List *user_limit_list, uint32_t user_id);
199 
200 #endif /* !_HAVE_ACCT_POLICY_H */
201