hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/kernel/tsacct.c
....@@ -1,19 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * tsacct.c - System accounting over taskstats interface
34 *
45 * Copyright (C) Jay Lan, <jlan@sgi.com>
5
- *
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
176 */
187
198 #include <linux/kernel.h>
....@@ -35,6 +24,7 @@
3524 const struct cred *tcred;
3625 u64 utime, stime, utimescaled, stimescaled;
3726 u64 delta;
27
+ time64_t btime;
3828
3929 BUILD_BUG_ON(TS_COMM_LEN < TASK_COMM_LEN);
4030
....@@ -43,9 +33,11 @@
4333 /* Convert to micro seconds */
4434 do_div(delta, NSEC_PER_USEC);
4535 stats->ac_etime = delta;
46
- /* Convert to seconds for btime */
47
- do_div(delta, USEC_PER_SEC);
48
- stats->ac_btime = get_seconds() - delta;
36
+ /* Convert to seconds for btime (note y2106 limit) */
37
+ btime = ktime_get_real_seconds() - div_u64(delta, USEC_PER_SEC);
38
+ stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX);
39
+ stats->ac_btime64 = btime;
40
+
4941 if (tsk->flags & PF_EXITING)
5042 stats->ac_exitcode = tsk->exit_code;
5143 if (thread_group_leader(tsk) && (tsk->flags & PF_FORKNOEXEC))