@@ -225,22 +225,14 @@ static inline void __update_gt_cputime(atomic64_t *cputime, u64 sum_cputime)
225225 }
226226}
227227
228- static void update_gt_cputime (struct task_cputime_atomic * cputime_atomic , struct task_cputime * sum )
228+ static void update_gt_cputime (struct task_cputime_atomic * cputime_atomic ,
229+ struct task_cputime * sum )
229230{
230231 __update_gt_cputime (& cputime_atomic -> utime , sum -> utime );
231232 __update_gt_cputime (& cputime_atomic -> stime , sum -> stime );
232233 __update_gt_cputime (& cputime_atomic -> sum_exec_runtime , sum -> sum_exec_runtime );
233234}
234235
235- /* Sample task_cputime_atomic values in "atomic_timers", store results in "times". */
236- static inline void sample_cputime_atomic (struct task_cputime * times ,
237- struct task_cputime_atomic * atomic_times )
238- {
239- times -> utime = atomic64_read (& atomic_times -> utime );
240- times -> stime = atomic64_read (& atomic_times -> stime );
241- times -> sum_exec_runtime = atomic64_read (& atomic_times -> sum_exec_runtime );
242- }
243-
244236/**
245237 * thread_group_sample_cputime - Sample cputime for a given task
246238 * @tsk: Task for which cputime needs to be started
@@ -252,20 +244,19 @@ static inline void sample_cputime_atomic(struct task_cputime *times,
252244 *
253245 * Updates @times with an uptodate sample of the thread group cputimes.
254246 */
255- void thread_group_sample_cputime (struct task_struct * tsk ,
256- struct task_cputime * times )
247+ void thread_group_sample_cputime (struct task_struct * tsk , u64 * samples )
257248{
258249 struct thread_group_cputimer * cputimer = & tsk -> signal -> cputimer ;
259250
260251 WARN_ON_ONCE (!cputimer -> running );
261252
262- sample_cputime_atomic ( times , & cputimer -> cputime_atomic );
253+ proc_sample_cputime_atomic ( & cputimer -> cputime_atomic , samples );
263254}
264255
265256/**
266257 * thread_group_start_cputime - Start cputime and return a sample
267258 * @tsk: Task for which cputime needs to be started
268- * @iimes : Storage for time samples
259+ * @samples : Storage for time samples
269260 *
270261 * The thread group cputime accouting is avoided when there are no posix
271262 * CPU timers armed. Before starting a timer it's required to check whether
@@ -274,14 +265,14 @@ void thread_group_sample_cputime(struct task_struct *tsk,
274265 *
275266 * Updates @times with an uptodate sample of the thread group cputimes.
276267 */
277- static void
278- thread_group_start_cputime (struct task_struct * tsk , struct task_cputime * times )
268+ static void thread_group_start_cputime (struct task_struct * tsk , u64 * samples )
279269{
280270 struct thread_group_cputimer * cputimer = & tsk -> signal -> cputimer ;
281- struct task_cputime sum ;
282271
283272 /* Check if cputimer isn't running. This is accessed without locking. */
284273 if (!READ_ONCE (cputimer -> running )) {
274+ struct task_cputime sum ;
275+
285276 /*
286277 * The POSIX timer interface allows for absolute time expiry
287278 * values through the TIMER_ABSTIME flag, therefore we have
@@ -299,7 +290,15 @@ thread_group_start_cputime(struct task_struct *tsk, struct task_cputime *times)
299290 */
300291 WRITE_ONCE (cputimer -> running , true);
301292 }
302- sample_cputime_atomic (times , & cputimer -> cputime_atomic );
293+ proc_sample_cputime_atomic (& cputimer -> cputime_atomic , samples );
294+ }
295+
296+ static void __thread_group_cputime (struct task_struct * tsk , u64 * samples )
297+ {
298+ struct task_cputime ct ;
299+
300+ thread_group_cputime (tsk , & ct );
301+ store_samples (samples , ct .stime , ct .utime , ct .sum_exec_runtime );
303302}
304303
305304/*
@@ -313,28 +312,18 @@ static u64 cpu_clock_sample_group(const clockid_t clkid, struct task_struct *p,
313312 bool start )
314313{
315314 struct thread_group_cputimer * cputimer = & p -> signal -> cputimer ;
316- struct task_cputime cputime ;
315+ u64 samples [ CPUCLOCK_MAX ] ;
317316
318317 if (!READ_ONCE (cputimer -> running )) {
319318 if (start )
320- thread_group_start_cputime (p , & cputime );
319+ thread_group_start_cputime (p , samples );
321320 else
322- thread_group_cputime (p , & cputime );
321+ __thread_group_cputime (p , samples );
323322 } else {
324- sample_cputime_atomic ( & cputime , & cputimer -> cputime_atomic );
323+ proc_sample_cputime_atomic ( & cputimer -> cputime_atomic , samples );
325324 }
326325
327- switch (clkid ) {
328- case CPUCLOCK_PROF :
329- return cputime .utime + cputime .stime ;
330- case CPUCLOCK_VIRT :
331- return cputime .utime ;
332- case CPUCLOCK_SCHED :
333- return cputime .sum_exec_runtime ;
334- default :
335- WARN_ON_ONCE (1 );
336- }
337- return 0 ;
326+ return samples [clkid ];
338327}
339328
340329static int posix_cpu_clock_get (const clockid_t clock , struct timespec64 * tp )
@@ -889,9 +878,7 @@ static void check_process_timers(struct task_struct *tsk,
889878{
890879 struct signal_struct * const sig = tsk -> signal ;
891880 struct posix_cputimer_base * base = sig -> posix_cputimers .bases ;
892- u64 utime , ptime , virt_expires , prof_expires ;
893- u64 sum_sched_runtime , sched_expires ;
894- struct task_cputime cputime ;
881+ u64 virt_exp , prof_exp , sched_exp , samples [CPUCLOCK_MAX ];
895882 unsigned long soft ;
896883
897884 /*
@@ -911,30 +898,29 @@ static void check_process_timers(struct task_struct *tsk,
911898 * Collect the current process totals. Group accounting is active
912899 * so the sample can be taken directly.
913900 */
914- sample_cputime_atomic (& cputime , & sig -> cputimer .cputime_atomic );
915- utime = cputime .utime ;
916- ptime = utime + cputime .stime ;
917- sum_sched_runtime = cputime .sum_exec_runtime ;
918-
919- prof_expires = check_timers_list (& base [CPUCLOCK_PROF ].cpu_timers ,
920- firing , ptime );
921- virt_expires = check_timers_list (& base [CPUCLOCK_VIRT ].cpu_timers ,
922- firing , utime );
923- sched_expires = check_timers_list (& base [CPUCLOCK_SCHED ].cpu_timers ,
924- firing , sum_sched_runtime );
901+ proc_sample_cputime_atomic (& sig -> cputimer .cputime_atomic , samples );
902+
903+ prof_exp = check_timers_list (& base [CPUCLOCK_PROF ].cpu_timers ,
904+ firing , samples [CPUCLOCK_PROF ]);
905+ virt_exp = check_timers_list (& base [CPUCLOCK_VIRT ].cpu_timers ,
906+ firing , samples [CPUCLOCK_VIRT ]);
907+ sched_exp = check_timers_list (& base [CPUCLOCK_SCHED ].cpu_timers ,
908+ firing , samples [CPUCLOCK_SCHED ]);
925909
926910 /*
927911 * Check for the special case process timers.
928912 */
929- check_cpu_itimer (tsk , & sig -> it [CPUCLOCK_PROF ], & prof_expires , ptime ,
930- SIGPROF );
931- check_cpu_itimer (tsk , & sig -> it [CPUCLOCK_VIRT ], & virt_expires , utime ,
932- SIGVTALRM );
913+ check_cpu_itimer (tsk , & sig -> it [CPUCLOCK_PROF ], & prof_exp ,
914+ samples [CPUCLOCK_PROF ], SIGPROF );
915+ check_cpu_itimer (tsk , & sig -> it [CPUCLOCK_VIRT ], & virt_exp ,
916+ samples [CPUCLOCK_PROF ], SIGVTALRM );
917+
933918 soft = task_rlimit (tsk , RLIMIT_CPU );
934919 if (soft != RLIM_INFINITY ) {
935- unsigned long psecs = div_u64 ( ptime , NSEC_PER_SEC ) ;
920+ u64 softns , ptime = samples [ CPUCLOCK_PROF ] ;
936921 unsigned long hard = task_rlimit_max (tsk , RLIMIT_CPU );
937- u64 x ;
922+ unsigned long psecs = div_u64 (ptime , NSEC_PER_SEC );
923+
938924 if (psecs >= hard ) {
939925 /*
940926 * At the hard limit, we just die.
@@ -961,14 +947,14 @@ static void check_process_timers(struct task_struct *tsk,
961947 sig -> rlim [RLIMIT_CPU ].rlim_cur = soft ;
962948 }
963949 }
964- x = soft * NSEC_PER_SEC ;
965- if (!prof_expires || x < prof_expires )
966- prof_expires = x ;
950+ softns = soft * NSEC_PER_SEC ;
951+ if (!prof_exp || softns < prof_exp )
952+ prof_exp = softns ;
967953 }
968954
969- base [CPUCLOCK_PROF ].nextevt = prof_expires ;
970- base [CPUCLOCK_VIRT ].nextevt = virt_expires ;
971- base [CPUCLOCK_SCHED ].nextevt = sched_expires ;
955+ base [CPUCLOCK_PROF ].nextevt = prof_exp ;
956+ base [CPUCLOCK_VIRT ].nextevt = virt_exp ;
957+ base [CPUCLOCK_SCHED ].nextevt = sched_exp ;
972958
973959 if (expiry_cache_is_zero (& sig -> posix_cputimers ))
974960 stop_process_timers (sig );
0 commit comments