Re: Best way to print something from the kernel at 1s intervals?

From: Ian Lepore <ian_at_freebsd.org>
Date: Fri, 29 Nov 2019 15:22:23 -0700
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
Received on Fri Nov 29 2019 - 21:22:29 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:22 UTC