GNU bug report logs -
#63496
process-attributes returns incorrect start, etime, and pcpu attributes when run inside a lxc container
Previous Next
Reported by: Scott Zimmermann <sczimmer <at> gmail.com>
Date: Sun, 14 May 2023 07:58:02 UTC
Severity: normal
Tags: confirmed
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 63496 in the body.
You can then email your comments to 63496 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Sun, 14 May 2023 07:58:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Scott Zimmermann <sczimmer <at> gmail.com>:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org.
(Sun, 14 May 2023 07:58:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
in src/sysdep.c line 3475:
Lisp_Object boot = Ftime_subtract (now, uptime);
it calculates the boot time for linux based on the uptime. Inside lxc
containers, /proc/uptime is the uptime of the container rather than of
the host system. However in /proc/[PID]/stat, starttime is the time
since system boot, of the host system, not since the container started.
This leads to emacs computing incorrect values for start, etime, and
pcpu for processes.
I think it should get the boot time from "btime" in /proc/stat, this is
what ps does, which shows correct times for processes inside the
container. If this sounds like an appropriate fix I'm happy to write and
test a patch for it.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Thu, 18 May 2023 11:12:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 63496 <at> debbugs.gnu.org (full text, mbox):
> Date: Sat, 13 May 2023 19:57:08 +0200
> From: Scott Zimmermann <sczimmer <at> gmail.com>
>
> in src/sysdep.c line 3475:
> Lisp_Object boot = Ftime_subtract (now, uptime);
>
> it calculates the boot time for linux based on the uptime. Inside lxc
> containers, /proc/uptime is the uptime of the container rather than of
> the host system. However in /proc/[PID]/stat, starttime is the time
> since system boot, of the host system, not since the container started.
> This leads to emacs computing incorrect values for start, etime, and
> pcpu for processes.
>
> I think it should get the boot time from "btime" in /proc/stat, this is
> what ps does, which shows correct times for processes inside the
> container. If this sounds like an appropriate fix I'm happy to write and
> test a patch for it.
Paul and Andreas, any comments?
Patches to implement the change would be welcome, of course.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Thu, 18 May 2023 21:18:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 63496 <at> debbugs.gnu.org (full text, mbox):
On 5/18/23 04:12, Eli Zaretskii wrote:
>> Date: Sat, 13 May 2023 19:57:08 +0200
>> From: Scott Zimmermann<sczimmer <at> gmail.com>
>> I think it should get the boot time from "btime" in /proc/stat, this is
>> what ps does, which shows correct times for processes inside the
>> container. If this sounds like an appropriate fix I'm happy to write and
>> test a patch for it.
Thanks, that sounds good.
Added tag(s) confirmed.
Request was from
Stefan Kangas <stefankangas <at> gmail.com>
to
control <at> debbugs.gnu.org.
(Mon, 11 Sep 2023 18:12:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Sat, 14 Jun 2025 12:43:04 GMT)
Full text and
rfc822 format available.
Message #16 received at 63496 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Took a bit to get around to it, but I finally made a patch.
El 18/05/23 a las 17:17, Paul Eggert escribió:
> On 5/18/23 04:12, Eli Zaretskii wrote:
>>> Date: Sat, 13 May 2023 19:57:08 +0200
>>> From: Scott Zimmermann<sczimmer <at> gmail.com>
>
>>> I think it should get the boot time from "btime" in /proc/stat, this is
>>> what ps does, which shows correct times for processes inside the
>>> container. If this sounds like an appropriate fix I'm happy to write and
>>> test a patch for it.
>
> Thanks, that sounds good.
[0001-Fix-get_up_time-inside-containers-using-lxcfs-bug-63.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Mon, 16 Jun 2025 02:26:01 GMT)
Full text and
rfc822 format available.
Message #19 received at 63496 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 2025-06-13 19:38, Scott Zimmermann wrote:
> Took a bit to get around to it, but I finally made a patch.
Thanks, but I now see an issue: Emacs gets the boot time in three
different places and I suspect this issue comes up in all three places.
The other two places use Gnulib's boot-time module, so I changed this
one to do that too, by installing the attached patch.
Does this fix your bug? If not, most likely we need to propagate
something like your patch into Gnulib.
[0001-process-attributes-now-uses-get_boot_time.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Tue, 17 Jun 2025 02:38:03 GMT)
Full text and
rfc822 format available.
Message #22 received at 63496 <at> debbugs.gnu.org (full text, mbox):
[[[ To any NSA and FBI agents reading my email: please consider ]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
What is a "lac" container?
--
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Tue, 17 Jun 2025 04:51:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 63496 <at> debbugs.gnu.org (full text, mbox):
lxc containers are: https://linuxcontainers.org/lxc/
specifically the problem was caused by lxcfs
(https://linuxcontainers.org/lxcfs/) which mounted on top of
/proc/uptime with the uptime of the container rather than of the host
system. But the starttime reported by /proc/pid/stat was still time
since the host system booted. Arguably it's a problem with lxcfs, but
still ps and top and anything else I tried in the container did report
correct process information, so I figured emacs could too.
Unfortunately I think now with Gnulib it will be wrong in slightly more
containers than before. Gnulib is first checking /var/run/utmp. In lxc
containers without lxcfs where /proc/uptime was the host uptime and
emacs would have been correct before, /var/run/utmp contains the boot
time of the container.
Fortunately in docker which is probably by far the most common
container, emacs is correct. At least in the default debian docker
images, /var/run/utmp doesn't exist and neither do any of the
/.../random-seed files it looks for in get_linux_boot_time_fallback, but
the `clock_gettime (CLOCK_BOOTTIME, p_uptime)` it tries in
get_linux_boot_time_final_fallback does returns the host uptime. In the
comment to get_linux_boot_time_final_fallback it says it's the fallback
because it's wrong 'if the system is running in a virtual machine and
this VM has been put into "saved" or "sleep" state and then resumed.'
But it seems the starttime reported by /proc/pid/stat is also affected
the same way if a VM is paused. I ran in a qemu vm:
cat /proc/self/stat | cut -d' ' -f 22
then paused it for a minute and then ran it again, and the starttime of
the new process was only seconds later rather than a minute+ later. The
value returned by that command is in seconds * (getconf CLK_TCK). So it
seems that for computing process attributes, using CLOCK_BOOTTIME is
consistent with /proc/pid/stat and will give correct results in VMs that
get paused, and in containers. But reading /var/run/utmp won't be
correct for containers that have it, or for VMs that have been paused.
I'm not sure if it affects the other uses of Gnulib because maybe they
do want the boot time of the container? But just for computing process
attributes it needs to be something consistent with the starttime
returned by /proc/pid/stat. Maybe for computing process attributes it
could call emacs' existing get_linux_uptime function that uses
CLOCK_BOOTTIME?
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Wed, 18 Jun 2025 00:25:02 GMT)
Full text and
rfc822 format available.
Message #28 received at 63496 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 2025-06-16 21:50, Scott Zimmermann wrote:
> I'm not sure if it affects the other uses of Gnulib because maybe they
> do want the boot time of the container?
I looked at those other uses and I think they're better off as-is, with
the container boot time.
> Maybe for computing process attributes it
> could call emacs' existing get_linux_uptime function that uses
> CLOCK_BOOTTIME?
get_linux_uptime is private to Gnulib. But yes, we can use its idea -
good suggestion. At first I installed into master a patch[1] using
/proc/stat as you originally suggested. But after thinking about it,
CLOCK_BOOTTIME is better here, so I installed a further patch[2] using
your new suggestion.
To help review, attached is the combination of the three patches I've
recently installed in this area, as generated by "git diff
ebdad09c5a0a822acb52ec58b3319d77d156f0ce..037fb02135ab5b5d96e1167b9333d6a3a2acad11
-- src/sysdep.c".
Please give the latest version a try.
[1]:
https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=73cebbb87b72effb948f0d73e756a0dc0c55b71c
[2]:
https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?id=037fb02135ab5b5d96e1167b9333d6a3a2acad11
[process-attributes.diff (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#63496; Package
emacs.
(Thu, 19 Jun 2025 19:13:02 GMT)
Full text and
rfc822 format available.
Message #31 received at 63496 <at> debbugs.gnu.org (full text, mbox):
Great, thanks! It looks good, now emacs `M-x proced` shows correct
results in my container, the same information as ps.
Using CLOCK_BOOTTIME is definitely simpler than parsing btime out of
/proc/stat, but I think they're actually equivalent, if someone knows
the details of the different times reported by linux please comment I'm
happy to learn. I'm too lazy to go spelunking in the linux source to
tell for sure, but I found a thread
(https://bugzilla.redhat.com/show_bug.cgi?id=132062) where someone says:
> Since the kernel's btime is not a static number (I believe that it is
calculated by subtracting the kernel's uptime from the current time)
When I pause a VM, immediately after resuming the btime is the same, but
after a couple minutes it gets updated and increases by the time the VM
was paused. So I think the btime is equal to (current time - uptime
reported by CLOCK_BOOTTIME).
El 17/06/25 a las 20:24, Paul Eggert escribió:
> On 2025-06-16 21:50, Scott Zimmermann wrote:
>
>> I'm not sure if it affects the other uses of Gnulib because maybe they
>> do want the boot time of the container?
>
> I looked at those other uses and I think they're better off as-is, with
> the container boot time.
>
>
>> Maybe for computing process attributes it could call emacs' existing
>> get_linux_uptime function that uses CLOCK_BOOTTIME?
>
> get_linux_uptime is private to Gnulib. But yes, we can use its idea -
> good suggestion. At first I installed into master a patch[1] using /
> proc/stat as you originally suggested. But after thinking about it,
> CLOCK_BOOTTIME is better here, so I installed a further patch[2] using
> your new suggestion.
>
> To help review, attached is the combination of the three patches I've
> recently installed in this area, as generated by "git diff
> ebdad09c5a0a822acb52ec58b3319d77d156f0ce..037fb02135ab5b5d96e1167b9333d6a3a2acad11 -- src/sysdep.c".
>
> Please give the latest version a try.
>
> [1]: https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?
> id=73cebbb87b72effb948f0d73e756a0dc0c55b71c
> [2]: https://cgit.git.savannah.gnu.org/cgit/emacs.git/commit/?
> id=037fb02135ab5b5d96e1167b9333d6a3a2acad11
Reply sent
to
Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility.
(Thu, 19 Jun 2025 19:20:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Scott Zimmermann <sczimmer <at> gmail.com>:
bug acknowledged by developer.
(Thu, 19 Jun 2025 19:20:02 GMT)
Full text and
rfc822 format available.
Message #36 received at 63496-done <at> debbugs.gnu.org (full text, mbox):
On 2025-06-19 12:12, Scott Zimmermann wrote:
> Great, thanks! It looks good, now emacs `M-x proced` shows correct
> results in my container, the same information as ps.
Thanks for checking; closing the bug report.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org.
(Fri, 18 Jul 2025 11:24:09 GMT)
Full text and
rfc822 format available.
This bug report was last modified 124 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.