stats.h (0cce284537fb42d9c28b9b31038ffc9b464555f5) | stats.h (b18b6a9cef7f30e9a8b7738d5fc8d568cf660855) |
---|---|
1 2#ifdef CONFIG_SCHEDSTATS 3 4/* 5 * Expects runqueue lock to be held for atomicity of update 6 */ 7static inline void 8rq_sched_info_arrive(struct rq *rq, unsigned long long delta) --- 158 unchanged lines hidden (view full) --- 167 168/* 169 * The following are functions that support scheduler-internal time accounting. 170 * These functions are generally called at the timer tick. None of this depends 171 * on CONFIG_SCHEDSTATS. 172 */ 173 174/** | 1 2#ifdef CONFIG_SCHEDSTATS 3 4/* 5 * Expects runqueue lock to be held for atomicity of update 6 */ 7static inline void 8rq_sched_info_arrive(struct rq *rq, unsigned long long delta) --- 158 unchanged lines hidden (view full) --- 167 168/* 169 * The following are functions that support scheduler-internal time accounting. 170 * These functions are generally called at the timer tick. None of this depends 171 * on CONFIG_SCHEDSTATS. 172 */ 173 174/** |
175 * cputimer_running - return true if cputimer is running | 175 * get_running_cputimer - return &tsk->signal->cputimer if cputimer is running |
176 * 177 * @tsk: Pointer to target task. 178 */ | 176 * 177 * @tsk: Pointer to target task. 178 */ |
179static inline bool cputimer_running(struct task_struct *tsk) 180 | 179#ifdef CONFIG_POSIX_TIMERS 180static inline 181struct thread_group_cputimer *get_running_cputimer(struct task_struct *tsk) |
181{ 182 struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; 183 184 /* Check if cputimer isn't running. This is accessed without locking. */ 185 if (!READ_ONCE(cputimer->running)) | 182{ 183 struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; 184 185 /* Check if cputimer isn't running. This is accessed without locking. */ 186 if (!READ_ONCE(cputimer->running)) |
186 return false; | 187 return NULL; |
187 188 /* 189 * After we flush the task's sum_exec_runtime to sig->sum_sched_runtime 190 * in __exit_signal(), we won't account to the signal struct further 191 * cputime consumed by that task, even though the task can still be 192 * ticking after __exit_signal(). 193 * 194 * In order to keep a consistent behaviour between thread group cputime 195 * and thread group cputimer accounting, lets also ignore the cputime 196 * elapsing after __exit_signal() in any thread group timer running. 197 * 198 * This makes sure that POSIX CPU clocks and timers are synchronized, so 199 * that a POSIX CPU timer won't expire while the corresponding POSIX CPU 200 * clock delta is behind the expiring timer value. 201 */ 202 if (unlikely(!tsk->sighand)) | 188 189 /* 190 * After we flush the task's sum_exec_runtime to sig->sum_sched_runtime 191 * in __exit_signal(), we won't account to the signal struct further 192 * cputime consumed by that task, even though the task can still be 193 * ticking after __exit_signal(). 194 * 195 * In order to keep a consistent behaviour between thread group cputime 196 * and thread group cputimer accounting, lets also ignore the cputime 197 * elapsing after __exit_signal() in any thread group timer running. 198 * 199 * This makes sure that POSIX CPU clocks and timers are synchronized, so 200 * that a POSIX CPU timer won't expire while the corresponding POSIX CPU 201 * clock delta is behind the expiring timer value. 202 */ 203 if (unlikely(!tsk->sighand)) |
203 return false; | 204 return NULL; |
204 | 205 |
205 return true; | 206 return cputimer; |
206} | 207} |
208#else 209static inline 210struct thread_group_cputimer *get_running_cputimer(struct task_struct *tsk) 211{ 212 return NULL; 213} 214#endif |
|
207 208/** 209 * account_group_user_time - Maintain utime for a thread group. 210 * 211 * @tsk: Pointer to task structure. 212 * @cputime: Time value by which to increment the utime field of the 213 * thread_group_cputime structure. 214 * 215 * If thread group time is being maintained, get the structure for the 216 * running CPU and update the utime field there. 217 */ 218static inline void account_group_user_time(struct task_struct *tsk, 219 cputime_t cputime) 220{ | 215 216/** 217 * account_group_user_time - Maintain utime for a thread group. 218 * 219 * @tsk: Pointer to task structure. 220 * @cputime: Time value by which to increment the utime field of the 221 * thread_group_cputime structure. 222 * 223 * If thread group time is being maintained, get the structure for the 224 * running CPU and update the utime field there. 225 */ 226static inline void account_group_user_time(struct task_struct *tsk, 227 cputime_t cputime) 228{ |
221 struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; | 229 struct thread_group_cputimer *cputimer = get_running_cputimer(tsk); |
222 | 230 |
223 if (!cputimer_running(tsk)) | 231 if (!cputimer) |
224 return; 225 226 atomic64_add(cputime, &cputimer->cputime_atomic.utime); 227} 228 229/** 230 * account_group_system_time - Maintain stime for a thread group. 231 * 232 * @tsk: Pointer to task structure. 233 * @cputime: Time value by which to increment the stime field of the 234 * thread_group_cputime structure. 235 * 236 * If thread group time is being maintained, get the structure for the 237 * running CPU and update the stime field there. 238 */ 239static inline void account_group_system_time(struct task_struct *tsk, 240 cputime_t cputime) 241{ | 232 return; 233 234 atomic64_add(cputime, &cputimer->cputime_atomic.utime); 235} 236 237/** 238 * account_group_system_time - Maintain stime for a thread group. 239 * 240 * @tsk: Pointer to task structure. 241 * @cputime: Time value by which to increment the stime field of the 242 * thread_group_cputime structure. 243 * 244 * If thread group time is being maintained, get the structure for the 245 * running CPU and update the stime field there. 246 */ 247static inline void account_group_system_time(struct task_struct *tsk, 248 cputime_t cputime) 249{ |
242 struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; | 250 struct thread_group_cputimer *cputimer = get_running_cputimer(tsk); |
243 | 251 |
244 if (!cputimer_running(tsk)) | 252 if (!cputimer) |
245 return; 246 247 atomic64_add(cputime, &cputimer->cputime_atomic.stime); 248} 249 250/** 251 * account_group_exec_runtime - Maintain exec runtime for a thread group. 252 * 253 * @tsk: Pointer to task structure. 254 * @ns: Time value by which to increment the sum_exec_runtime field 255 * of the thread_group_cputime structure. 256 * 257 * If thread group time is being maintained, get the structure for the 258 * running CPU and update the sum_exec_runtime field there. 259 */ 260static inline void account_group_exec_runtime(struct task_struct *tsk, 261 unsigned long long ns) 262{ | 253 return; 254 255 atomic64_add(cputime, &cputimer->cputime_atomic.stime); 256} 257 258/** 259 * account_group_exec_runtime - Maintain exec runtime for a thread group. 260 * 261 * @tsk: Pointer to task structure. 262 * @ns: Time value by which to increment the sum_exec_runtime field 263 * of the thread_group_cputime structure. 264 * 265 * If thread group time is being maintained, get the structure for the 266 * running CPU and update the sum_exec_runtime field there. 267 */ 268static inline void account_group_exec_runtime(struct task_struct *tsk, 269 unsigned long long ns) 270{ |
263 struct thread_group_cputimer *cputimer = &tsk->signal->cputimer; | 271 struct thread_group_cputimer *cputimer = get_running_cputimer(tsk); |
264 | 272 |
265 if (!cputimer_running(tsk)) | 273 if (!cputimer) |
266 return; 267 268 atomic64_add(ns, &cputimer->cputime_atomic.sum_exec_runtime); 269} | 274 return; 275 276 atomic64_add(ns, &cputimer->cputime_atomic.sum_exec_runtime); 277} |