History log of /freebsd-current/sys/kern/kern_ktr.c
Revision Date Author Comments
# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# c84c5e00 18-Jul-2022 Mitchell Horne <mhorne@FreeBSD.org>

ddb: annotate some commands with DB_CMD_MEMSAFE

This is not completely exhaustive, but covers a large majority of
commands in the tree.

Reviewed by: markj
Sponsored by: Juniper Networks, Inc.
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D35583


# 6fed89b1 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

kern: clean up empty lines in .c and .h files


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# 879e0604 11-Jan-2020 Mateusz Guzik <mjg@FreeBSD.org>

Add KERNEL_PANICKED macro for use in place of direct panicstr tests


# 2e43efd0 06-Mar-2019 John Baldwin <jhb@FreeBSD.org>

Drop "All rights reserved" from my copyright statements.

Reviewed by: rgrimes
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D19485


# 305bb04e 14-Jan-2019 Xin LI <delphij@FreeBSD.org>

Use TD_IS_IDLETHREAD instead of unrolled version.

MFC after: 2 weeks


# 8a36da99 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/kern: adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# f3fed043 14-Aug-2017 Conrad Meyer <cem@FreeBSD.org>

Fix a couple of comment typos

No functional change.

Submitted by: Anton Rang <anton.rang AT isilon.com>
Sponsored by: Dell EMC Isilon


# f9c2ec64 31-Jan-2016 Andrew Turner <andrew@FreeBSD.org>

Fix the logic in the ddb command 'show ktr /a'. Prior to r118269 it would
print until cncheckc returned a non -1, i.e. a character had been entered.
After this change it would print only if cncheckc returned a character.
As this was before each call to db_mach_vtrace the normal outcome was
nothing was printed.

With this change 'show ktr /a' will now keep printing until the user stops
the command with a key press, or there is no more entries to print.


# 45005f79 30-Dec-2015 Marius Strobl <marius@FreeBSD.org>

- (Ab)use udivx for dividing the u_int pc_cpuid when implementing
CPU_ISSET(), CPU_SET etc. in sparc64 asm. This approach has the
benefit of not clobbering %y, allowing to revert r222827 and
partially r222828.
- In r222828, CATR() already was changed to use the equivalent of
PCPU_GET(cpuid) instead of the MD module ID for KTR_CPU, so
belatedly also catch up with the C side of ktr(9). Originally,
in r203838 CATR() was moved away from directly reading the
module ID or equivalent as that became impractical with other
CPU types than USI/II supported. With r222828 in place, per-CPU
data generally is set up soon enough, though, that employing
PCPU things in ktr(9) also for use during early stages works.
- Unfortunately, an exception to the latter is the ktr(9) use
in pmap_bootstrap(), which actually is run so early that even
checking for bootverbose being set via the loader doesn't work.
Consequently, replace the ktr(9) use in pmap_bootstrap() with
OF_printf(9) and put it under #ifdef DIAGNOSTIC instead.

MFC after: 3 days


# 21119d06 22-May-2015 John Baldwin <jhb@FreeBSD.org>

Expand ktr_mask to be a 64-bit unsigned integer.

The mask does not really need to be updated with atomic operations and
the downside of losing races during transitions is not great (it is
not marked volatile, so those races are pretty wide open as it is).

Differential Revision: https://reviews.freebsd.org/D2595
Reviewed by: emaste, neel, rpaulo
MFC after: 2 weeks


# 054b57a7 02-Jul-2014 Marcel Moolenaar <marcel@FreeBSD.org>

Drop KTR records when we're in the debugger so that the debugger isn't
changing or overwriting the trace buffer. When KTR is enabled for things
like traps or pmap functions, the amount of logging can be substantial.


# 4813ad54 28-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Compile fixes:

Remove duplicate "debug_ktr.mask" sysctl definition.
Remove now unused variable from "kern_ktr.c".
This fixes build of "ktr" which was broken by r267961.

Let the default value for "vm_kmem_size_scale" be zero. It is setup
after that the sysctl has been initialized from "getenv()" in the
"kmeminit()" function to equal the "VM_KMEM_SIZE_MAX" value, if
zero. On Sparc64 the "VM_KMEM_SIZE_MAX" macro is not a constant. This
fixes build of Sparc64 which was broken by r267961.

Add a special macro to dynamically create SYSCTL root nodes, because
root nodes have a special parent. This fixes build of existing OFED
module and CANBUS module for pc98 which was broken by r267961.

Add missing "sysctl.h" includes to get the needed sysctl header file
declarations. This is needed after r267961.

MFC after: 2 weeks


# af3b2549 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Pull in r267961 and r267973 again. Fix for issues reported will follow.


# 37a107a4 27-Jun-2014 Glen Barber <gjb@FreeBSD.org>

Revert r267961, r267973:

These changes prevent sysctl(8) from returning proper output,
such as:

1) no output from sysctl(8)
2) erroneously returning ENOMEM with tools like truss(1)
or uname(1)
truss: can not get etype: Cannot allocate memory


# 3da1cf1e 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after: 2 weeks
Sponsored by: Mellanox Technologies


# d6543c67 22-Mar-2014 Neel Natu <neel@FreeBSD.org>

Don't lose track of the KTR entries copied from 'ktr_buf_init[]' to the
dynamically allocated 'ktr_buf[]'.

The memcpy arranges 'ktr_buf[]' such that the latest KTR entry is at
'KTR_BOOT_ENTRIES - 1'.


# e432d5f6 05-Feb-2014 John Baldwin <jhb@FreeBSD.org>

Drop the 3rd clause from all 3 clause BSD licenses where I am the sole
holder to convert them to 2 clause BSD licenses.

MFC after: 1 week


# c43b08dc 08-Feb-2013 Andriy Gapon <avg@FreeBSD.org>

ktr: correctly handle possible wrap-around in the boot buffer

Older entries should be 'before' newer entries in the new buffer too
and there should be no zero-filled gap between them.

Pointed out by: jhb
MFC after: 3 days
X-MFC with: r246282


# c8199bc9 04-Feb-2013 Andriy Gapon <avg@FreeBSD.org>

ktr: prevent possible footshooting with KTR_ENTRIES and KTR_BOOT_ENTRIES

Suggested by: adrian
MFC after: 14 days
X-MFC with: r246282


# f85ed124 04-Feb-2013 Andriy Gapon <avg@FreeBSD.org>

ktr: copy content from the early static buffer if KTR_ENTRIES !=
KTR_BOOT_ENTRIES

Reported by: glebius, jhb
Pointyhat to: avg
MFC after: 14 days
X-MFC with: r246282


# 36b7dde4 03-Feb-2013 Andriy Gapon <avg@FreeBSD.org>

allow for large KTR_ENTRIES values by allocating ktr_buf using malloc(9)

Only during very early boot, before malloc(9) is functional (SI_SUB_KMEM),
the static ktr_buf_init is used. Size of the static buffer is determined
by a new kernel option KTR_BOOT_ENTRIES. Its default value is 1024.

This commit builds on top of r243046.

Reviewed by: alc
MFC after: 17 days


# 3356d129 06-Dec-2012 Alfred Perlstein <alfred@FreeBSD.org>

Use uint instead of int for flags exported via sysctl.


# 28d91af3 14-Nov-2012 Jeff Roberson <jeff@FreeBSD.org>

- Implement run-time expansion of the KTR buffer via sysctl.
- Implement a function to ensure that all preempted threads have switched
back out at least once. Use this to make sure there are no stale
references to the old ktr_buf or the lock profiling buffers before
updating them.

Reviewed by: marius (sparc64 parts), attilio (earlier patch)
Sponsored by: EMC / Isilon Storage Division


# d4a2ab8c 30-Aug-2012 Attilio Rao <attilio@FreeBSD.org>

Post r222812 KTR_CPUMASK started being initialized only as a tunable
handler and not more statically.

Unfortunately, it seems that this is not ideal for new platform bringup
and boot low level development (which needs ktr_cpumask to be effective
before tunables can be setup).

Because of this, add a way to statically initialize cpusets, by passing
an list of initializers, divided by commas. Also, provide a way to enforce
an all-set mask, for above mentioned initializers.

This imposes some differences on how KTR_CPUMASK is setup now as a
kernel option, and in particular this makes the words specifications
backward wrt. what is currently in -CURRENT. In order to avoid mismatches
between KTR_CPUMASK definition and other way to setup the mask
(tunable, sysctl) and to print it, change the ordering how
cpusetobj_print() and cpusetobj_scan() acquire the words belonging
to the set.
Please give a look to sys/conf/NOTES in order to understand how the
new format is supposed to work.

Also, ktr manpages will be updated shortly by gjb which volountereed
for this.

This patch won't be merged because it changes a POLA (at least
from the theoretical standpoint) and this is however a patch that
proves to be effective only in development environments.

Requested by: rpaulo
Reviewed by: jeff, rpaulo


# 6e465ac7 30-Jul-2012 Davide Italiano <davide@FreeBSD.org>

Until now KTR_ENTRIES, which defines the size of circular buffer used in
ktr(4), was constrained to be a power of two. Remove this constraint and
update sys/conf/NOTES accordingly.

Reviewed by: jhb
Approved by: gnn (mentor)
Sponsored by: Google Summer of Code 2012


# dc15eac0 01-Jan-2012 Ed Schouten <ed@FreeBSD.org>

Use strchr() and strrchr().

It seems strchr() and strrchr() are used more often than index() and
rindex(). Therefore, simply migrate all kernel code to use it.

For the XFS code, remove an empty line to make the code identical to
the code in the Linux kernel.


# 6472ac3d 07-Nov-2011 Ed Schouten <ed@FreeBSD.org>

Mark all SYSCTL_NODEs static that have no corresponding SYSCTL_DECLs.

The SYSCTL_NODE macro defines a list that stores all child-elements of
that node. If there's no SYSCTL_DECL macro anywhere else, there's no
reason why it shouldn't be static.


# e3709597 31-May-2011 Attilio Rao <attilio@FreeBSD.org>

Fix KTR_CPUMASK in order to accept a string representing a cpuset_t.
This introduce all the underlying support for making this possible (via
the function cpusetobj_strscan() and keeps ktr_cpumask exported. sparc64
implements its own assembly primitives for tracing events and needs to
properly check it. Anyway the sparc64 logic is not implemented yet due
to lack of knowledge (by me) and time (by marius), but it is just a
matter of using ktr_cpumask when possible.

Tested and fixed by: pluknet
Reviewed by: marius


# d0984adc 31-May-2011 Attilio Rao <attilio@FreeBSD.org>

Revert a change that crept in during MFC.


# 217e1c0e 23-May-2011 Attilio Rao <attilio@FreeBSD.org>

Revert a patch that unvolountary sneaked in while I was MFCing.


# de5b1952 25-Feb-2011 Alexander Leidinger <netchild@FreeBSD.org>

Add some FEATURE macros for various features (AUDIT/CAM/IPC/KTR/MAC/NFS/NTP/
PMC/SYSV/...).

No FreeBSD version bump, the userland application to query the features will
be committed last and can serve as an indication of the availablility if
needed.

Sponsored by: Google Summer of Code 2010
Submitted by: kibab
Reviewed by: arch@ (parts by rwatson, trasz, jhb)
X-MFC after: to be determined in last commit with code from this project


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 4e55157f 21-Jul-2010 Attilio Rao <attilio@FreeBSD.org>

Probabilly defaulting to KTR_GEN is not the right decision when KTR_MASK
is not defined at all because KTR_GEN is still a valid class and some
traces may fit in. Default to 0, instead, and block any tracing.

As long as this is a POLA violation (some thirdy-part code, even if
that may be a questionable choice, could be rely on that feature) a
MFC possibility might be carefully evaluated.

Sponsored by: Sandvine Incorporated


# 94a04272 14-Apr-2010 Julian Elischer <julian@FreeBSD.org>

Change the semantics of the debug.ktr.alq_enable control so that when you
disable alq, it acts as if alq had not been enabled in the build.
in other words, the rest of ktr is still available for use.
If you really don't want that as well, set the mask to 0.

MFC after:3 weeks


# 1b25979b 11-Mar-2010 John Baldwin <jhb@FreeBSD.org>

Style fixes.

Submitted by: bde


# dff8e0b7 10-Mar-2010 John Baldwin <jhb@FreeBSD.org>

Add descriptions for debug.ktr sysctl nodes.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 484cc85e 09-Sep-2006 Robert Watson <rwatson@FreeBSD.org>

Remove slightly oddly placed suser() call from the KTR/ALQ setup sysctl:
it was present only in the enable path, not the disable path, which one
presumes would be equally of interest. Either way, it was not needed,
as the sysctl framework already calls suser() if the operation is a
write operation, which configuration requests are.

Sponsored by: nCircle Network Security, Inc.


# 19e9205a 12-Jul-2006 John Baldwin <jhb@FreeBSD.org>

Simplify the pager support in DDB. Allowing different db commands to
install custom pager functions didn't actually happen in practice (they
all just used the simple pager and passed in a local quit pointer). So,
just hardcode the simple pager as the only pager and make it set a global
db_pager_quit flag that db commands can check when the user hits 'q' (or a
suitable variant) at the pager prompt. Also, now that it's easy to do so,
enable paging by default for all ddb commands. Any command that wishes to
honor the quit flag can do so by checking db_pager_quit. Note that the
pager can also be effectively disabled by setting $lines to 0.

Other fixes:
- 'show idt' on i386 and pc98 now actually checks the quit flag and
terminates early.
- 'show intr' now actually checks the quit flag and terminates early.


# 13516104 27-Jan-2006 John Baldwin <jhb@FreeBSD.org>

Whitespace.


# bef4bf1a 27-Jan-2006 John Baldwin <jhb@FreeBSD.org>

Add a new sysctl, debug.ktr.clear. If you write a non-zero value to this
sysctl then it will clear the KTR buffer. Note that if you have active
KTR traces at the same time as a clear operation the behavior is undefined,
though it shouldn't panic.


# 6b815557 25-Jan-2006 John Baldwin <jhb@FreeBSD.org>

Axe KTR_ALQ_MASK now that KTR_WITNESS is off unless you hack an #ifdef
in subr_witness.c. I did add a comment in subr_witness.c noting that
KTR_WITNESS is incompatible with KTR_ALQ.


# 37ee2d8d 10-Jun-2005 Jeff Roberson <jeff@FreeBSD.org>

- Add curthread to the state that ktr is saving. The extra information is
well worth the bloat.
- Change the formatting of 'show ktr' slightly to accommodate the
additional field. Remove a tab from the verbose output and place the
actual trace data after a : so it is more easy to understand which
part is the event and which is part of the record.


# e551d452 15-Apr-2005 Robert Watson <rwatson@FreeBSD.org>

Modify the alq(9) alq_open() API to accept a file creation mode, rather
than defaulting the cmode argument to vn_open() to 0. Supply a default
argument of ALQ_DEFAULT_CMODE (0600) in current callers.

Discussed with/pointed out by: hmp
Reveiwed by: jeff, hmp
MFC after: 3 days


# d39d4a6e 01-Nov-2004 John Baldwin <jhb@FreeBSD.org>

- Change the ddb paging "support" to use a variable (db_lines_per_page) to
control the number of lines per page rather than a constant. The variable
can be examined and changed in ddb as '$lines'. Setting the variable to
0 will effectively turn off paging.
- Change db_putchar() to force out pending whitespace before outputting
newlines and carriage returns so that one can rub out content on the
current line via '\r \r' type strings.
- Change the simple pager to rub out the --More-- prompt explicitly when
the routine exits.
- Add some aliases to the simple pager to make it more compatible with
more(1): 'e' and 'j' do a single line. 'd' does half a page, and
'f' does a full page.

MFC after: 1 month
Inspired by: kris


# b89daf89 20-Sep-2004 John Baldwin <jhb@FreeBSD.org>

Remove unused macro.


# 4da86f88 23-Jul-2004 Robert Watson <rwatson@FreeBSD.org>

Export KTR_COMPILE as a sysctl so you can easily check from user space
what event mask has been compiled into the kernel.


# 2b3c42a9 09-Sep-2003 John Baldwin <jhb@FreeBSD.org>

Update the license on this file to be a bit more sane.


# 80c09f69 02-Aug-2003 John Baldwin <jhb@FreeBSD.org>

Both 'c' an 'lines' are unused, the bogus init of lines was accidentally
left behind.


# 05a1bfa1 01-Aug-2003 David E. O'Brien <obrien@FreeBSD.org>

Fix kernel build -- 'c' was the unused var, not 'lines'.


# 3f2a1b06 31-Jul-2003 John Baldwin <jhb@FreeBSD.org>

Update the 'ps', 'show pci', and 'show ktr' ddb commands to use the new
pager callout instead of homerolling their own paging facility.


# 4b090e41 22-Jun-2003 Robert Watson <rwatson@FreeBSD.org>

Add an explicit credential argument to alq_open() to allow the caller to
specify what credential to use when authorizing vn_open() and later
write operations, rather than curthread->td_ucred.

When writing KTR traces to an ALQ, specify the credential of the thread
generating the sysctl request.

Obtained from: TrustedBSD Project
Sponsored by: DARPA, Network Associates Laboratories


# 677b542e 10-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID().


# 5e26dcb5 09-Jun-2003 John Baldwin <jhb@FreeBSD.org>

- Add a td_pflags field to struct thread for private flags accessed only by
curthread. Unlike td_flags, this field does not need any locking.
- Replace the td_inktr and td_inktrace variables with equivalent private
thread flags.
- Move TDF_OLDMASK over to the private flags field so it no longer requires
sched_lock.


# b1ac98d8 01-May-2003 Julian Elischer <julian@FreeBSD.org>

Move the flag that indicates an idle thread from the KSE to the thread.
It was always referenced via the thread anyhow.

Reviewed by: jhb (a LOOOOONG time ago)


# 4c6ffc94 11-Mar-2003 John Baldwin <jhb@FreeBSD.org>

Trim leading "../" sequences from filenames.


# fc718df7 22-Feb-2003 Jake Burkholder <jake@FreeBSD.org>

Add a /a modifier to the show ktr ddb command, which prints the whole trace
buffer without stopping. Useful if you just want to capture the output but
can't run ktrdump.


# a414302f 26-Sep-2002 Jeff Roberson <jeff@FreeBSD.org>

- Export the alq daemon thread pointer.
- Don't log ktr events from the alq daemon.


# abee588b 22-Sep-2002 Jeff Roberson <jeff@FreeBSD.org>

- Add support for logging KTR via ALQ. This is optional and enabled by the
KTR_ALQ config option.


# 98281c99 06-Apr-2002 Jake Burkholder <jake@FreeBSD.org>

Remove a stale comment.


# a9f5d338 06-Apr-2002 Jake Burkholder <jake@FreeBSD.org>

Include machine/ktr.h for sparc64 so we pick up KTR_CPU.


# 60a57b73 31-Mar-2002 Jake Burkholder <jake@FreeBSD.org>

ktr changes to improve performance and make writing a userland utility to
dump the trace buffer feasible.
- Remove KTR_EXTEND. This changes the format of the trace entries when
activated, making writing a userland tool which is not tied to a specific
kernel configuration difficult.
- Use get_cyclecount() for timestamps. nanotime() is much too heavy weight
and requires recursion protection due to ktr traces occuring as a result
of ktr traces. KTR_VERBOSE may still require recursion protection, which
is now conditional on it.
- Allow KTR_CPU to be overridden by MD code. This is so that it is possible
to trace early in startup before pcpu and/or curthread are setup.
- Add a version number for the ktr interface. A userland tool can check this
to detect mismatches.
- Use an array for the parameters to make decoding in userland easier.
- Add file and line recording to the non-extended traces now that the extended
version is no more.

These changes will break gdb macros to decode the extended version of the
trace buffer which are floating around. Users of these macros should either
use the show ktr command in ddb, or use the userland utility which can be run
on a core dump.

Approved by: jhb
Tested on: i386, sparc64


# c29824db 08-Mar-2002 John Baldwin <jhb@FreeBSD.org>

Read KTR_CPU into a temporary variable so that we use a consistent value
for both the cpumask check and the cpu entry field w/o needing to use
a critical section.


# 5e8af3b3 01-Jan-2002 Jake Burkholder <jake@FreeBSD.org>

Print parm6 too in the !KTR_EXTEND case.


# 7e1f6dfe 17-Dec-2001 John Baldwin <jhb@FreeBSD.org>

Modify the critical section API as follows:
- The MD functions critical_enter/exit are renamed to start with a cpu_
prefix.
- MI wrapper functions critical_enter/exit maintain a per-thread nesting
count and a per-thread critical section saved state set when entering
a critical section while at nesting level 0 and restored when exiting
to nesting level 0. This moves the saved state out of spin mutexes so
that interlocking spin mutexes works properly.
- Most low-level MD code that used critical_enter/exit now use
cpu_critical_enter/exit. MI code such as device drivers and spin
mutexes use the MI wrappers. Note that since the MI wrappers store
the state in the current thread, they do not have any return values or
arguments.
- mtx_intr_enable() is replaced with a constant CRITICAL_FORK which is
assigned to curthread->td_savecrit during fork_exit().

Tested on: i386, alpha


# 69e94957 13-Dec-2001 John Baldwin <jhb@FreeBSD.org>

Use a per-thread variable for keeping state when a thread is processing
a KTR log entry. Any KTR requests made while working on an entry are
ignored/discarded to prevent recursion. This is a better fix for the
hack to futz with the CPU mask and call getnanotime() if KTR_LOCK or
KTR_WITNESS was on. It also covers the actual formatting of the log entry
including dumping it to the display which the earlier hacks did not.


# 0bbc8826 11-Dec-2001 John Baldwin <jhb@FreeBSD.org>

Overhaul the per-CPU support a bit:

- The MI portions of struct globaldata have been consolidated into a MI
struct pcpu. The MD per-CPU data are specified via a macro defined in
machine/pcpu.h. A macro was chosen over a struct mdpcpu so that the
interface would be cleaner (PCPU_GET(my_md_field) vs.
PCPU_GET(md.md_my_md_field)).
- All references to globaldata are changed to pcpu instead. In a UP kernel,
this data was stored as global variables which is where the original name
came from. In an SMP world this data is per-CPU and ideally private to each
CPU outside of the context of debuggers. This also included combining
machine/globaldata.h and machine/globals.h into machine/pcpu.h.
- The pointer to the thread using the FPU on i386 was renamed from
npxthread to fpcurthread to be identical with other architectures.
- Make the show pcpu ddb command MI with a MD callout to display MD
fields.
- The globaldata_register() function was renamed to pcpu_init() and now
init's MI fields of a struct pcpu in addition to registering it with
the internal array and list.
- A pcpu_destroy() function was added to remove a struct pcpu from the
internal array and list.

Tested on: alpha, i386
Reviewed by: peter, jake


# 071087f3 10-Dec-2001 David E. O'Brien <obrien@FreeBSD.org>

Missed an assignment of arg6 in previous commit.


# b45df7b4 10-Dec-2001 David E. O'Brien <obrien@FreeBSD.org>

Adjust for the addition of CTR6.


# 1715f07d 25-Jun-2001 John Baldwin <jhb@FreeBSD.org>

- Replace the unused KTR_IDLELOOP trace class with a new KTR_WITNESS trace
class to trace witness events.
- Make the ktr_cpu field of ktr_entry be a standard field rather than one
present only in the KTR_EXTEND case.
- Move the default definition of KTR_ENTRIES from sys/ktr.h to
kern/kern_ktr.c. It has not been needed in the header file since KTR
was un-inlined.
- Minor include cleanup in kern/kern_ktr.c.
- Fiddle with the ktr_cpumask in ktr_tracepoint() to disable KTR events
on the current CPU while we are processing an event.
- Set the current CPU inside of the critical section to ensure we don't
migrate CPU's after the critical section but before we set the CPU.


# f41325db 13-Jun-2001 Peter Wemm <peter@FreeBSD.org>

With this commit, I hereby pronounce gensetdefs past its use-by date.

Replace the a.out emulation of 'struct linker_set' with something
a little more flexible. <sys/linker_set.h> now provides macros for
accessing elements and completely hides the implementation.

The linker_set.h macros have been on the back burner in various
forms since 1998 and has ideas and code from Mike Smith (SET_FOREACH()),
John Polstra (ELF clue) and myself (cleaned up API and the conversion
of the rest of the kernel to use it).

The macros declare a strongly typed set. They return elements with the
type that you declare the set with, rather than a generic void *.

For ELF, we use the magic ld symbols (__start_<setname> and
__stop_<setname>). Thanks to Richard Henderson <rth@redhat.com> for the
trick about how to force ld to provide them for kld's.

For a.out, we use the old linker_set struct.

NOTE: the item lists are no longer null terminated. This is why
the code impact is high in certain areas.

The runtime linker has a new method to find the linker set
boundaries depending on which backend format is in use.

linker sets are still module/kld unfriendly and should never be used
for anything that may be modular one day.

Reviewed by: eivind


# 09786698 07-Jun-2001 Peter Wemm <peter@FreeBSD.org>

"Fix" the previous initial attempt at fixing TUNABLE_INT(). This time
around, use a common function for looking up and extracting the tunables
from the kernel environment. This saves duplicating the same function
over and over again. This way typically has an overhead of 8 bytes + the
path string, versus about 26 bytes + the path string.


# 4422746f 06-Jun-2001 Peter Wemm <peter@FreeBSD.org>

Back out part of my previous commit. This was a last minute change
and I botched testing. This is a perfect example of how NOT to do
this sort of thing. :-(


# 81930014 06-Jun-2001 Peter Wemm <peter@FreeBSD.org>

Make the TUNABLE_*() macros look and behave more consistantly like the
SYSCTL_*() macros. TUNABLE_INT_DECL() was an odd name because it didn't
actually declare the int, which is what the name suggests it would do.


# 0006681f 27-Mar-2001 John Baldwin <jhb@FreeBSD.org>

Switch from save/disable/restore_intr() to critical_enter/exit().


# 62d654c1 20-Feb-2001 John Baldwin <jhb@FreeBSD.org>

- In the KTR_EXTEND case, use a const char * to point to the passed in
filename insteada of copying the first 32 characters of it.
- Add in const modifiers for the passed in format strings and filenames
and their respective members in the ktr_entry struct.


# 591faa2e 20-Feb-2001 John Baldwin <jhb@FreeBSD.org>

- Abolish the 'show ktr_first' and 'show ktr_next' commands.
- Add pager capability to the 'show ktr' command. It functions much like
'ps': Enter at the prompt displays one more entry, Space displays
another page, and any other key quits.


# 1aa97cde 09-Feb-2001 John Baldwin <jhb@FreeBSD.org>

Work around some sizeof(long) != sizeof(int) bogons.


# cd85c9e1 09-Feb-2001 John Baldwin <jhb@FreeBSD.org>

Change the ktr ddb commands to be show commands. The commands are now as
follows:
- show ktr_first display the first entry
- show ktr_next display the next entry
- show ktr display the entire buffer

The /v modifiers continue to work as described previously.

Requested by: bde


# ef73ae4b 09-Jan-2001 Jake Burkholder <jake@FreeBSD.org>

Use PCPU_GET, PCPU_PTR and PCPU_SET to access all per-cpu variables
other then curproc.


# a0a7328b 05-Jan-2001 John Baldwin <jhb@FreeBSD.org>

- Move all of the KTR sysctl's under a new debug.ktr mib.
- Provide TUNABLE_INT() hooks for ktr_cpumask, ktr_mask, and ktr_verbose
so that they can be set from the loader by their respective sysctl names.
For example, to turn on KTR_INTR and KTR_PROC in ktr_mask, one could
stick 'debug.ktr.mask="0x1200"' in /boot/loader.conf.


# 7fcd0cb3 28-Dec-2000 Greg Lehey <grog@FreeBSD.org>

Partially revert revision 1.7: Only use getnanotime instead of
nanotime if we would run into trouble with nanotime (i.e. if we are
tracing KTR_LOCK).

Reviewed by: jhb


# de362218 14-Dec-2000 John Baldwin <jhb@FreeBSD.org>

Add in MI implementations of the KTR trace buffer ddb commands. The
commands have also been slightly updated as follows:
- Use ktr_idx to find the newest entry rather than walking the buffer
comparing timespecs. Timespecs are not always unique after the change
to use getnanotime(9).
- Add a new verbose setting. When the verbose setting is on, then the
timestamp is printed with each message. If KTR_EXTEND is on, then the
filename and line number are output as well. By default this option is
off. It can be turned on with the 'v' modifier passed to the 'tbuf'
and 'tall' commands. For the 'tnext' command, the 'v' modifier toggles
the verbose mode.
- Only display the cpu number for each message on SMP systems.
- Don't display anything for an empty entry that hasn't been used yet.


# d664747b 11-Dec-2000 John Baldwin <jhb@FreeBSD.org>

- Don't bother taking a trace message if we have panic'd since doing so
can lead to further panics.
- Call getnanotime() instead of nanotime() for the timestamp. nanotime()
is more precise, but it also calls into the timer code, which results
in mutex operations on the i386 arch. If KTR_LOCK is turned on, then
ktr_tracepoint() recurses on itself until it exhausts the kernel stack.
Eventually this should change to use get_cyclecount() instead, but that
can't happen if get_cyclecount() is calling nanotime() instead of
getnanotime().


# 0959cc66 21-Nov-2000 John Baldwin <jhb@FreeBSD.org>

Ahem, fix the disclaimer portion of the copyright so it disclaim's the
voices in my head. You can sue the voices in Bill Paul's head all you
want.

Noticed by: jhb


# 22f1b342 15-Nov-2000 John Baldwin <jhb@FreeBSD.org>

Make ktr_verbose a bit more useful:
- On SMP systems display the cpu number with each message
- If ktr_verbose > 1, then include the filename and line number with each
trace message


# 20af769e 10-Nov-2000 John Baldwin <jhb@FreeBSD.org>

Don't overwrite the filename for KTR_EXTEND with "../../kern/kern_ktr.c".


# bf619f95 10-Nov-2000 John Baldwin <jhb@FreeBSD.org>

Fix SMP kernel compiles by #include'ing machine/globals.h to get the
cpuid variable.


# d8f03321 06-Nov-2000 John Baldwin <jhb@FreeBSD.org>

- Remove much of the inlining of the KTR tracepoints into a ktr_tracepoint()
function declared in kern_ktr.c. The only inline checks left are the
checks that compare KTR_COMPILE with the supplied mask and thus should
be optimized away into either nothing or a direct call to ktr_tracepoint().
- Move several KTR-related options to opt_ktr.h now that they are only
needed by kern_ktr.c and not by ktr.h.
- Add in the ktr_verbose functionality if KTR_EXTEND is turned on. If the
global variable 'ktr_verbose' is non-zero, then KTR messages will be
dumped to the console. This variable can be set by either kernel code
or via the 'debug.ktr_verbose' sysctl. It defaults to off unless the
KTR_VERBOSE kernel option is specified in which case it defaults to on.
This can be useful when the machine locks up spinning in a loop with
interrupts disabled as you might be able to see what it is doing when it
locks up.

Requested by: phk


# 62ae6c89 06-Sep-2000 Jason Evans <jasone@FreeBSD.org>

Add KTR, a facility that logs kernel events in order to to facilitate
debugging.

Acquired from: BSDi (BSD/OS)
Submitted by: dfr, grog, jake, jhb