Date: Fri, 29 Nov 2019 15:22:23 -0700 From: Ian Lepore <ian@freebsd.org> To: Peter Eriksson <pen@lysator.liu.se>, freebsd-current@freebsd.org Subject: Re: Best way to print something from the kernel at 1s intervals? Message-ID: <eeb5d1cda0dd6e9beff38fe04c179a328a229a29.camel@freebsd.org> In-Reply-To: <057870D3-B59E-47FB-A832-A72DC6F54AFA@lysator.liu.se> References: <E6B8A0DA-5F4D-4B08-A376-0AE65575A6F9@lysator.liu.se> <DA769610-A087-40C4-B903-ACF34388CDE8@gmail.com> <057870D3-B59E-47FB-A832-A72DC6F54AFA@lysator.liu.se>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2019-11-29 at 23:10 +0100, Peter Eriksson wrote:
> I love dtrace, but I seriously doubt that it could be used it for
> this. This is the absolutely last code that executes at kernel
> shutdown/reboot. All other processes are terminated when this is
> happening...
>
> Basically the code done in kern_reboot() (and stuff it calls) in
> /usr/src/sys/kern/kern_shutdown.c
>
> This code in kern_reboot():
> ...
> > EVENTHANDLER_INVOKE(shutdown_pre_sync, howto);
> >
> > /*
> > * Now sync filesystems
> > */
> > if (!cold && (howto & RB_NOSYNC) == 0 && once == 0) {
> > once = 1;
> > bufshutdown(show_busybufs);
> > }
> >
> > print_uptime();
> >
> > cngrab();
> >
> > /*
> > * Ok, now do things that assume all filesystem activity has
> > * been completed.
> > */
> > EVENTHANDLER_INVOKE(shutdown_post_sync, howto);
> >
> > if ((howto & (RB_HALT|RB_DUMP)) == RB_DUMP && !cold &&
> > !dumping)
> > doadump(TRUE);
> >
> > /* Now that we're going to really halt the system... */
> > EVENTHANDLER_INVOKE(shutdown_final, howto);
>
> What I’ve seen is that the three different EVENTHANDLER_INVOKE() all
> can cause a lot of calls that can take a long time. As can
> bufshutdown(), probably when it calls vfs_unmountall() to unmount all
> filesystems.
>
> We’re talking like 5-20 minutes (or more). I’ve not really timed it.
>
> I have a feeling it sometimes is due to transactions stored up in the
> ZFS filesystems that the system tries to “run” so it doesn’t have to
> do it at mount() time after the reboot. If I reset the machine while
> it is busy doing this then sometimes the “zfs mount -a” takes very
> long time at boot instead.
>
> Hmm.. I should be able to use the getnanouptime() call to get a
> “clock” to look for (it’s used in print_uptime()). As long as the
> clock isn’t stopped at this time in the shutdown sequence atleast :-)
>
> *Time to write some code and test this* :-)
>
If you want to throttle something to once a second (or some number of
integer seconds) the kernel has a global variable named time_sec, (in
sys/time.h), watch for it to change.
-- Ian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?eeb5d1cda0dd6e9beff38fe04c179a328a229a29.camel>
