]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/log
FreeBSD/FreeBSD.git
5 years agoMFV: r334448
Jung-uk Kim [Mon, 4 Jun 2018 22:26:47 +0000 (22:26 +0000)]
MFV: r334448

Import ACPICA 20180531.

5 years agopmc stat: fix offset of specified counter
Matt Macy [Mon, 4 Jun 2018 21:42:21 +0000 (21:42 +0000)]
pmc stat: fix offset of specified counter

5 years agoindent(1): fix buildworld after r334632
Piotr Pawel Stefaniak [Mon, 4 Jun 2018 21:21:55 +0000 (21:21 +0000)]
indent(1): fix buildworld after r334632

Fix
error: comparison of integers of different signs: 'int' and 'unsigned long'
by casting nitems() to int.

Reported by: mjg

5 years agolibpmc: improve arg checking
Matt Macy [Mon, 4 Jun 2018 21:17:46 +0000 (21:17 +0000)]
libpmc: improve arg checking

5 years agolibpmc / stat: use westmere supported counter
Matt Macy [Mon, 4 Jun 2018 21:17:42 +0000 (21:17 +0000)]
libpmc / stat: use westmere supported counter

5 years agohwpmc: don't defer user callchain capture completion to ast
Matt Macy [Mon, 4 Jun 2018 21:17:30 +0000 (21:17 +0000)]
hwpmc: don't defer user callchain capture completion to ast

5 years agoindent(1): add --version option
Piotr Pawel Stefaniak [Mon, 4 Jun 2018 21:05:56 +0000 (21:05 +0000)]
indent(1): add --version option

There exist multi-platform programs that check indent's version in order to
know what they can expect from it. GNU indent provides that via --version,
so implement the same option here.

5 years agoindent(1): remove the STACKSIZE macro and all of its use
Piotr Pawel Stefaniak [Mon, 4 Jun 2018 20:39:58 +0000 (20:39 +0000)]
indent(1): remove the STACKSIZE macro and all of its use

It conflicts with a system-provided macro of the same name on another OS.

5 years agoindent(1): remove static const char copyright[]
Piotr Pawel Stefaniak [Mon, 4 Jun 2018 20:24:31 +0000 (20:24 +0000)]
indent(1): remove static const char copyright[]

It repeats what is already said in the heading comment and it's optimized out
so serves no purpose.

5 years agoindent(1): replace BSD bcopy() with C memmove()
Piotr Pawel Stefaniak [Mon, 4 Jun 2018 19:47:24 +0000 (19:47 +0000)]
indent(1): replace BSD bcopy() with C memmove()

5 years agoRegen after r334626.
Mark Johnston [Mon, 4 Jun 2018 19:36:47 +0000 (19:36 +0000)]
Regen after r334626.

5 years agoReimplement brk() and sbrk() to avoid the use of _end.
Mark Johnston [Mon, 4 Jun 2018 19:35:15 +0000 (19:35 +0000)]
Reimplement brk() and sbrk() to avoid the use of _end.

Previously, libc.so would initialize its notion of the break address
using _end, a special symbol emitted by the static linker following
the bss section.  Compatibility issues between lld and ld.bfd could
cause the wrong definition of _end (libc.so's definition rather than
that of the executable) to be used, breaking the brk()/sbrk()
interface.

Avoid this problem and future interoperability issues by simply not
relying on _end.  Instead, modify the break() system call to return
the kernel's view of the current break address, and have libc
initialize its state using an extra syscall upon the first use of the
interface.  As a side effect, this appears to fix brk()/sbrk() usage
in executables run with rtld direct exec, since the kernel and libc.so
no longer maintain separate views of the process' break address.

PR: 228574
Reviewed by: kib (previous version)
MFC after: 2 months
Differential Revision: https://reviews.freebsd.org/D15663

5 years agoCorrectly handle the padding for IPv6-AH, as specified by RFC4302
Conrad Meyer [Mon, 4 Jun 2018 18:51:06 +0000 (18:51 +0000)]
Correctly handle the padding for IPv6-AH, as specified by RFC4302

The RFC specifies that under IPv6 the complete AH header must be 64 bit
aligned, and under IPv4, 32 bit aligned. Prior to this change, we (along
with other BSDs and MacOS) had violated this requirement.

This makes it possible to set up IPv6-AH between Linux and BSD, and also
probably between Windows and BSD.

PR: 222684
Reported and tested by: Jason Mader <jasonmader AT gmail.com>
Obtained from: NetBSD xform_ah.c 1.105
(b939fe2483972eb43d71bf990cfb7f26dece7839 NetBSD/src on GH)
by Maxime Villard
MFC after: 35.2731 hours
Relnotes: probably (breaks ipv6 compat with older FreeBSD/NetBSD/MacOS)
Sponsored by: Dell EMC Isilon

5 years agostr(r)chr: Replace union abuse with __DECONST
Conrad Meyer [Mon, 4 Jun 2018 18:47:14 +0000 (18:47 +0000)]
str(r)chr: Replace union abuse with __DECONST

Writing one union member and reading another is technically illegal C,
although we do it in many places in the tree.  Use the __DECONST macro
instead, which is (technically) a valid C construct.

Trivial style(9) cleanups to touched lines while here.

Sponsored by: Dell EMC Isilon

5 years agohwpmc: remove gratuitous curthread checks
Matt Macy [Mon, 4 Jun 2018 17:49:34 +0000 (17:49 +0000)]
hwpmc: remove gratuitous curthread checks

5 years agoCorrect the description of vm_pageout_scan_inactive() after r334508.
Mark Johnston [Mon, 4 Jun 2018 16:46:36 +0000 (16:46 +0000)]
Correct the description of vm_pageout_scan_inactive() after r334508.

Reported by: alc

5 years agoUse a single, consistent approach to returning success versus failure in
Alan Cox [Mon, 4 Jun 2018 16:28:06 +0000 (16:28 +0000)]
Use a single, consistent approach to returning success versus failure in
vm_map_madvise().  Previously, vm_map_madvise() used a traditional Unix-
style "return (0);" to indicate success in the common case, but Mach-
style return values in the edge cases.  Since KERN_SUCCESS equals zero,
the only problem with this inconsistency was stylistic.  vm_map_madvise()
has exactly two callers in the entire source tree, and only one of them
cares about the return value.  That caller, kern_madvise(), can be
simplified if vm_map_madvise() consistently uses Unix-style return
values.

Since vm_map_madvise() uses the variable modify_map as a Boolean, make it
one.

Eliminate a redundant error check from kern_madvise().  Add a comment
explaining where the check is performed.

Explicitly note that exec_release_args_kva() doesn't care about
vm_map_madvise()'s return value.  Since MADV_FREE is passed as the
behavior, the return value will always be zero.

Reviewed by: kib, markj
MFC after: 7 days

5 years agoSort GCC warning flags and remove duplicates.
Ruslan Bukin [Mon, 4 Jun 2018 16:21:18 +0000 (16:21 +0000)]
Sort GCC warning flags and remove duplicates.

Sponsored by: DARPA, AFRL

5 years agoFix build: ignore a GCC 7.2.0 warning which says that third argument of
Ruslan Bukin [Mon, 4 Jun 2018 16:20:22 +0000 (16:20 +0000)]
Fix build: ignore a GCC 7.2.0 warning which says that third argument of
memset(3) should contain the number of elements multiplied by the element
size.

Sponsored by: DARPA, AFRL

5 years agoAlign UMA data to 128 byte cacheline size
Justin Hibbits [Mon, 4 Jun 2018 15:44:17 +0000 (15:44 +0000)]
Align UMA data to 128 byte cacheline size

Suggested by: mjg

5 years agoMove /sys symlink creating out of etc/Makefile.
Brad Davis [Mon, 4 Jun 2018 15:17:24 +0000 (15:17 +0000)]
Move /sys symlink creating out of etc/Makefile.

This is prep for etc/Makefile going away.

Approved by: bapt (mentor)

5 years agoFix the NUMA build for non-x86 platforms.
Mark Johnston [Mon, 4 Jun 2018 14:56:02 +0000 (14:56 +0000)]
Fix the NUMA build for non-x86 platforms.

acpi_map_pxm_to_vm_domainid() is currently implemented only on x86.

MFC after: 1 week

5 years agoSet kernelname in bootconfig to the kernel file
Justin Hibbits [Mon, 4 Jun 2018 14:42:13 +0000 (14:42 +0000)]
Set kernelname in bootconfig to the kernel file

Summary:
The kernel reads 'kernelname' to set the kern.bootfile sysctl.  By setting this,
'make installkernel' will backup the running kernel as appropriate.

Reviewed by: nwhitehorn
Differential Revision: https://reviews.freebsd.org/D15660

5 years agoRevert r334586 since I now think __unused is the better way to handle this.
Rick Macklem [Mon, 4 Jun 2018 11:35:04 +0000 (11:35 +0000)]
Revert r334586 since I now think __unused is the better way to handle this.

5 years agopmc filter: avoid spurious gcc uninitialized warning
Matt Macy [Mon, 4 Jun 2018 06:30:35 +0000 (06:30 +0000)]
pmc filter: avoid spurious gcc uninitialized warning

5 years agotop(1): some nitpicks
Eitan Adler [Mon, 4 Jun 2018 05:27:00 +0000 (05:27 +0000)]
top(1): some nitpicks

- prefer fully spelled names to "u_long"
- fix speeling

5 years agoupdate pmc_pmu_idx_get_by_event signature for !x86
Matt Macy [Mon, 4 Jun 2018 05:04:40 +0000 (05:04 +0000)]
update pmc_pmu_idx_get_by_event signature for !x86

5 years agopmc: add filter command
Matt Macy [Mon, 4 Jun 2018 04:59:48 +0000 (04:59 +0000)]
pmc: add filter command

pmc filter allows the user to select event types, threads, and processes from
a sample.

% pmcstat -S unhalted_core_cycles -S llc-misses -S -S  resource_stalls.any -O pmc.log
% pmc filter -e llc-misses pmc.log pmc-llc-misses.log
% pmc filter -e unhalted_core_cycles -t 100339  pmc.log pmc-core-cycles.log
etc...
% pmcstat -R pmc-core-cycles.log -G pmc-core-cycles.stacks

5 years agotop(1): include what you use
Eitan Adler [Mon, 4 Jun 2018 04:59:32 +0000 (04:59 +0000)]
top(1): include what you use

- Change headers to more closely match what we use
- use more standard functions instead of bzero, bcmp, bcopy
- Add myself to authors.

Tested with: base clang (amd64), gcc 9 (amd64), base clang (i386), base
gcc (mips)

5 years agotop(1): Prefer memcpy over bcopy
Eitan Adler [Mon, 4 Jun 2018 04:59:24 +0000 (04:59 +0000)]
top(1): Prefer memcpy over bcopy

5 years agohwpmc: fix fixed counters checks
Matt Macy [Mon, 4 Jun 2018 04:49:06 +0000 (04:49 +0000)]
hwpmc: fix fixed counters checks

5 years agotop(1): Use strsep instead of homegrown alternative
Eitan Adler [Mon, 4 Jun 2018 03:16:24 +0000 (03:16 +0000)]
top(1): Use strsep instead of homegrown alternative

This replaces some complex, and not quite correct logic, with a more
common strsep pattern.

Reviewed by: mmacy (older version)

5 years agohwpmc: ABI fixes
Matt Macy [Mon, 4 Jun 2018 02:05:48 +0000 (02:05 +0000)]
hwpmc: ABI fixes
- increase pmc cpuid field from 8 to 12 bits
- add cpuid version string to initialize entry in the log
  so that filter can identify which counter index an
  event name maps to
- GC unused config flags
- make fixed counter assignment more robust as well as the
  changes needed to be properly identified for filter

5 years agohwpmc: support sampling both kernel and user stacks when interrupted in kernel
Matt Macy [Mon, 4 Jun 2018 01:10:23 +0000 (01:10 +0000)]
hwpmc: support sampling both kernel and user stacks when interrupted in kernel

This adds the -U options to pmcstat which will attribute in-kernel samples
back to the user stack that invoked the system call. It is not the default,
because when looking at kernel profiles it is generally more desirable to
merge all instances of a given system call together.

Although heavily revised, this change is directly derived from D7350 by
Jonathan T. Looney.

Obtained from: jtl
Sponsored by: Juniper Networks, Limelight Networks

5 years agodwatch(1): Update manual to reference actual release
Devin Teske [Sun, 3 Jun 2018 23:49:02 +0000 (23:49 +0000)]
dwatch(1): Update manual to reference actual release

MFC after: 3 days
X-MFC-to: stable/11
Sponsored by: Smule, Inc.

5 years agotop(1): another pass of cleanup
Eitan Adler [Sun, 3 Jun 2018 23:40:54 +0000 (23:40 +0000)]
top(1): another pass of cleanup

- avoid the need to call a function to get size of known array. I'll
likely re-arrange some of the indirect in a later to avoid the magic
constants.
- use correct type
- add const
- replace caddr_t with void*. This corrects an alignment warning.
- remove duplicated include from immediately prior commit

Under base clang we're now down to:
- 3 warning in top.c, 1 warning in mahcine.c,  4 warning in display.c,
- 1 warning in utils.c

Tested with base clang, gcc7, gcc9, base gcc (mips)

5 years agoaudit(4): add tests for the cl audit class
Alan Somers [Sun, 3 Jun 2018 23:36:29 +0000 (23:36 +0000)]
audit(4): add tests for the cl audit class

The only syscalls in this class are close, closefrom, munmap, and revoke.

Submitted by: aniketp
MFC after: 2 weeks
Sponsored by: Google, Inc. (GSoC 2018)
Differential Revision: https://reviews.freebsd.org/D15650

5 years agotop(1): top warnings and cleanup
Eitan Adler [Sun, 3 Jun 2018 22:42:54 +0000 (22:42 +0000)]
top(1): top warnings and cleanup

- Add const where helpful
- add missing 'static' for file-local functions
- use nitems where possible
- convert manual abort() to assert
- use strndup instead of homegrown version

Tested with clang, gcc7, and gcc9

5 years agoindent(1): new option -lpl
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 21:40:38 +0000 (21:40 +0000)]
indent(1): new option -lpl

With -lpl, code surrounded by parentheses in continuation lines is lined up
even if it would extend past the right margin.

With -nlpl (the default), such a line that would extend past the right
margin is moved left to keep it within the margin, if that does not require
placing it to the left of the prevailing indentation level.

These switches have no effect if -nlp is selected.

Submitted by: Tom Lane

5 years agoindent(1): revert introduction of -lpl
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 21:34:29 +0000 (21:34 +0000)]
indent(1): revert introduction of -lpl

That was committed with the wrong message. Will be re-added.

5 years agoindent(1): new option -lpl (always line up to parenthesis)
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 20:59:59 +0000 (20:59 +0000)]
indent(1): new option -lpl (always line up to parenthesis)

With -lp, if a line has an opening paren which is not closed on that line,
then continuation lines will be lined up to start at the character position
just after the opening paren.

Submitted by: Tom Lane

5 years agoindent(1): manual page corretions
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 20:48:58 +0000 (20:48 +0000)]
indent(1): manual page corretions

Add missing options, synchronize syntax summary with the actual option list,
and other fixes.

Submitted by: Tom Lane

5 years agoFix a gcc8 warning about a write only variable.
Rick Macklem [Sun, 3 Jun 2018 19:46:44 +0000 (19:46 +0000)]
Fix a gcc8 warning about a write only variable.

gcc8 warns that "verf" was set but not used. This was because the code
that uses it is disabled via a "#if 0".
This patch adds a "#if 0" to the variable's declaration and assignment
to get rid of the warning.
This way the code could be re-enabled without difficulty.

Requested by: mmacy
MFC after: 2 weeks

5 years agohwpmc: ensure that mapin updates are synchronous
Matt Macy [Sun, 3 Jun 2018 19:37:17 +0000 (19:37 +0000)]
hwpmc: ensure that mapin updates are synchronous

5 years agopmc: remove assert that is invalid in interrupt context
Matt Macy [Sun, 3 Jun 2018 19:37:09 +0000 (19:37 +0000)]
pmc: remove assert that is invalid in interrupt context

5 years agoindent(1): if an identifier can be either a typedef name or as a struct
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 19:05:20 +0000 (19:05 +0000)]
indent(1): if an identifier can be either a typedef name or as a struct
member, it is taken as the latter

5 years agoindent(1): if the token is a "[" then neither of the blocks is relevant
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 18:38:03 +0000 (18:38 +0000)]
indent(1): if the token is a "[" then neither of the blocks is relevant

5 years agoindent(1): don't add a space after a label
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 18:34:36 +0000 (18:34 +0000)]
indent(1): don't add a space after a label

It's not needed and it fools pr_comment().

5 years agoindent(1): ignore null characters from input
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 18:32:11 +0000 (18:32 +0000)]
indent(1): ignore null characters from input

5 years agoindent(1): don't overflow di_stack[]
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 18:29:20 +0000 (18:29 +0000)]
indent(1): don't overflow di_stack[]

5 years agoindent(1): improve CHECK_SIZE_ macros
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 18:19:41 +0000 (18:19 +0000)]
indent(1): improve CHECK_SIZE_ macros

Rewrite the macros so that they take a parameter. Consumers use it to signal
how much room in the buffer they need; this lets them do that once when
required space is known instead of doing the check once every loop step.

Also take the parameter value into consideration when resizing the buffer;
the requested space may be larger than the constant 400 bytes that the
previous version used - now it's the sum of those two values.

On the consumer side, don't copy strings byte by byte - use memcpy().

Deduplicate code that copied base 2, base 8 and base 16 literals.

Don't advance the e_token pointer once the token has been copied into
s_token. This allows easy calculation of the token's length.

5 years agoindent(1): remove troff output support
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 17:55:50 +0000 (17:55 +0000)]
indent(1): remove troff output support

The troff output in indent was invented at Sun and the online documentation
for some post-SunOS operating system includes this:
The usual way to  get  a  troffed listing is with the command
                       indent -troff program.c | troff -mindent

The indent manual page in FreeBSD 1.0 already lacks that information and
troff -mindent complains about not being able to find the macro file.
It seems that the file did exist on SunOS and was supposed to be imported
into 4.3BSD together with the feature, but that has never happened.

Removal of troff output support simplifies a lot of indent's code.

vgrind(1) seems to be a promising replacement.

5 years agoindent(1): avoid resetting last_bl to a bogus value when reallocating
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 17:11:01 +0000 (17:11 +0000)]
indent(1): avoid resetting last_bl to a bogus value when reallocating
underlying buffer

5 years agoindent(1): the check for buffer overflow has to be done before copy
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 17:07:56 +0000 (17:07 +0000)]
indent(1): the check for buffer overflow has to be done before copy

5 years agoindent(1): use errx() instead of abort()
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 17:05:55 +0000 (17:05 +0000)]
indent(1): use errx() instead of abort()

5 years agoindent(1): limit character classification functions' input to unsigned char
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 17:03:55 +0000 (17:03 +0000)]
indent(1): limit character classification functions' input to unsigned char

5 years agoindent(1): recognize more type names
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 16:52:30 +0000 (16:52 +0000)]
indent(1): recognize more type names

Most are from C99.

5 years agoindent(1): don't format function declarations as variables
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 16:42:58 +0000 (16:42 +0000)]
indent(1): don't format function declarations as variables

5 years agoindent(1): remove is_procname.
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 16:27:40 +0000 (16:27 +0000)]
indent(1): remove is_procname.

It was a shorthand for checking if ps.procname is a non-empty string; the
same can be done with ps.procname[0] which avoids the need for updating
is_procname after every call to lexi().

5 years agoindent(1): disjoint parser state from lexi()
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 16:21:15 +0000 (16:21 +0000)]
indent(1): disjoint parser state from lexi()

The function is sometimes used as a look-ahead, so ideally it should bear
no information about parser state.

5 years agoindent(1): improve handling of boxed comments indentation
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 15:28:55 +0000 (15:28 +0000)]
indent(1): improve handling of boxed comments indentation

The trick is to copy everything from the start of the line into the buffer
that stores newlines and comments until indent finds a brace or an else.
pr_comment() will use that information to calculate the original indentation
of the boxed comment.

This requires storing two pieces of information: the real start of the
buffer (sc_buf) and the start of the comment (save_com).

5 years agoindent(1): improve predictability of lexi()
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 14:13:11 +0000 (14:13 +0000)]
indent(1): improve predictability of lexi()

lexi() reads the input stream and categorizes the next token. indent will
sometimes buffer up a sequence of tokens in order rearrange them. That is
needed for properly cuddling else or placing braces correctly according to
the chosen style (KNF vs Allman) when comments are around. The loop that
buffers tokens up uses lexi() to decide if it's time to stop buffering. Then
the temporary buffer is used to feed lexi() the same tokens again, this time
for normal processing.

The problem is that lexi() apart from recognizing the token, can change
a lot of information about the current state, for example ps.last_nl,
ps.keyword, buf_ptr. It also abandons leading whitespace, which is needed
mainly for comment-related considerations. So the call to lexi() while
tokens are buffered up and categorized can change the state before they're
read again for normal processing which may easily result in changing
interpretation of the current state and lead to incorrect output.

To work around the problems:
1) copy the whitespace into the save_com buffer so that it will be read
again when processed
2) trick lexi() into modifying a temporary copy of the parser state instead
of the original.

5 years agoindent(1): improve handling of comments and newlines between "if (...)" or
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 14:03:20 +0000 (14:03 +0000)]
indent(1): improve handling of comments and newlines between "if (...)" or
"while (...)" and "else" or "{"

* Don't flush newlines - there can be multiple of them and they can happen
before a token that isn't else or {. Instead, always store them in save_com.
* Don't dump the buffer's contents on newline assuming that there is only
one comment before else or {.
* Avoid producing surplus newlines, especially before else when -ce is on.
* When -bl is on, don't treat { as a comment (was implemented by falling
through "case lbrace:" to "case comment:").

This commit fixes the above, but exposes another bug and thus breaks several
other tests. Another commit will make them pass again.

5 years agotop(1): restore size for kern.cp_times
Eitan Adler [Sun, 3 Jun 2018 13:41:23 +0000 (13:41 +0000)]
top(1): restore size for kern.cp_times

Restore last minute change that broke top(1).

5 years agoindent(1): remove undocumented and rather useless option (-ps)
Piotr Pawel Stefaniak [Sun, 3 Jun 2018 13:40:58 +0000 (13:40 +0000)]
indent(1): remove undocumented and rather useless option (-ps)

It's used to treat the "->" access operator as a binary operator and put
space characters around it.

5 years ago[evdev] Sync event codes with Linux kernel 4.16
Vladimir Kondratyev [Sun, 3 Jun 2018 10:53:10 +0000 (10:53 +0000)]
[evdev] Sync event codes with Linux kernel 4.16

MFC after: 2 weeks

5 years agotop(1): Only use NO_WERROR for base gcc
Eitan Adler [Sun, 3 Jun 2018 06:02:31 +0000 (06:02 +0000)]
top(1): Only use NO_WERROR for base gcc

This is what was intended. If statements are hard.

5 years agotop(1): partial revert of r334517
Eitan Adler [Sun, 3 Jun 2018 05:20:11 +0000 (05:20 +0000)]
top(1): partial revert of r334517

In fixing issues with uid > INT_MAX, I broke the uid without username
case. The latter is more important so return the old state.

Discussed with: allanjude

5 years agotop(1): remove chdir to /
Eitan Adler [Sun, 3 Jun 2018 05:07:46 +0000 (05:07 +0000)]
top(1): remove chdir to /

While this came out of a conversation in IRC, it turn out that some
people don't like it. Since this was a courtesy feature, just remove it.

5 years agotop(1): use greater warnings
Eitan Adler [Sun, 3 Jun 2018 05:07:39 +0000 (05:07 +0000)]
top(1): use greater warnings

One of the downsides of using numeric WARNS is that if we only have a
single type of issue we get no protection from other changes.  For
example, we got no warning for missing variable declaration, due to
the issues with "const".

For this utility, explicitly list out the warnings which are failing.
They should still be fixed, so only reduce them to warning instead of
error.

Tested with: clang base (amd64, i386), gcc6, gcc7, gcc9, gcc base (mips)

5 years agoRevert r326083, it doesn't behave as expected.
Justin Hibbits [Sun, 3 Jun 2018 03:53:11 +0000 (03:53 +0000)]
Revert r326083, it doesn't behave as expected.

Even though there do appear to be more artificial frames, with 12, stack
traces no longer list at all.  Revert until a better, more stable value can
be determined.

5 years agotop(1): misc minor improvements
Eitan Adler [Sun, 3 Jun 2018 02:58:53 +0000 (02:58 +0000)]
top(1): misc minor improvements

- use bool instead of int [0]
- use calloc correctly [0]
(this also caught an incorrect sizeof argument) [1]
- use size_t over int [2]
- correct style

Reported by: pfg [0], scan-build [1], gcc [2]

6 years agopty.3: Add a HISTORY section
Alan Somers [Sat, 2 Jun 2018 22:40:16 +0000 (22:40 +0000)]
pty.3: Add a HISTORY section

These functions were first added in 4.3 BSD-Reno, according to
http://unix.superglobalmegacorp.com/ and the CSRG svn repository.

Reviewed by: bcr, bjk
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D15652

6 years agoRemove an unused argument to turnstile_unpend.
Mateusz Guzik [Sat, 2 Jun 2018 22:37:53 +0000 (22:37 +0000)]
Remove an unused argument to turnstile_unpend.

PR: 228694
Submitted by: Julian Pszczołowski <julian.pszczolowski@gmail.com>

6 years agomalloc: try to use builtins for zeroing at the callsite
Mateusz Guzik [Sat, 2 Jun 2018 22:20:09 +0000 (22:20 +0000)]
malloc: try to use builtins for zeroing at the callsite

Plenty of allocation sites pass M_ZERO and sizes which are small and known
at compilation time. Handling them internally in malloc loses this information
and results in avoidable calls to memset.

Instead, let the compiler take the advantage of it whenever possible.

Discussed with: jeff

6 years agotop(1): Fix two speeling errors I introduced
Eitan Adler [Sat, 2 Jun 2018 22:12:57 +0000 (22:12 +0000)]
top(1): Fix two speeling errors I introduced

6 years agotop(1): chdir to / as init; remove unneeded comment
Eitan Adler [Sat, 2 Jun 2018 22:06:27 +0000 (22:06 +0000)]
top(1): chdir to / as init; remove unneeded comment

- chdir to / to allow unmounting of wd
- remove warning about running top(1) as setuid. If this is a concern we
should just drop privs instead.

6 years agotop(1): cleanup memory allocation and warnings
Eitan Adler [Sat, 2 Jun 2018 21:40:45 +0000 (21:40 +0000)]
top(1): cleanup memory allocation and warnings

- Prefer calloc over malloc. This is more predicable and we're not in a
performance sensitive context. [1]
- Remove bogus comment (obsolete from prior commit). [2]
- Remove void casts and type casts of NULL
- Remove redundant declaration of 'quit'
- Add additional const

Reported by: kib [1], vangyzen [2]

6 years agoIncluded VSX registers in powerpc core dumps
Justin Hibbits [Sat, 2 Jun 2018 20:28:58 +0000 (20:28 +0000)]
Included VSX registers in powerpc core dumps

Summary: Included VSX registers in powerpc core dumps (both kernel and gcore)

Submitted by: Luis Pires
Differential Revision: https://reviews.freebsd.org/D15512

6 years agoamd64: add a mild depessimization to rep mov/stos users
Mateusz Guzik [Sat, 2 Jun 2018 20:14:43 +0000 (20:14 +0000)]
amd64: add a mild depessimization to rep mov/stos users

Currently all the primitives are waiting for a rewrite, tidy them up in the
meantime.

Vast majority of cases pass sizes which are multiple of 8. Which means the
following rep stosb/movb has nothing to do. Turns out testing first if there
is anything to do is a big win across the board (cpus with and without ERMS,
Intel and AMD) while not pessimizing the case where there is work to do.

Sample results for zeroing 64 bytes (ops/second):
Ryzen Threadripper 1950X 91433212 -> 147265741
Intel(R) Xeon(R) CPU X5675 @ 3.07GHz 90714044 -> 121992888

bzero and bcopy are on their way out and were not modified. Nothing in the
tree uses them.

6 years agoAdded ptrace support for reading/writing powerpc VSX registers
Justin Hibbits [Sat, 2 Jun 2018 19:17:11 +0000 (19:17 +0000)]
Added ptrace support for reading/writing powerpc VSX registers

Summary:
Added ptrace support for getting/setting the remaining part of the VSX registers
(the part that's not already covered by FPR or VR registers).

This is necessary to add support for VSX registers in debuggers.

Submitted by: Luis Pires
Differential Revision: https://reviews.freebsd.org/D15458

6 years agoUse __builtin for various mem* and b* (e.g. bzero) routines.
Mateusz Guzik [Sat, 2 Jun 2018 18:03:35 +0000 (18:03 +0000)]
Use __builtin for various mem* and b* (e.g. bzero) routines.

Some of the routines were using artificially limited builtin already,
drop the explicit limit.

The use of builtins allows quite often allows the compiler to elide the call
or most zeroing to begin with. For instance, if the target object is 32 bytes
in size and gets zeroed + has 16 bytes initialized, the compiler can just
add code to zero out the rest.

Note not all the primites have asm variants and some of the existing ones
are not optimized. Maintaines are strongly encourage to take a look
(regardless of this change).

6 years agolibkern: tidy up memset
Mateusz Guzik [Sat, 2 Jun 2018 17:57:09 +0000 (17:57 +0000)]
libkern: tidy up memset

1. Remove special-casing of 0 as it just results in an extra function call.
This is clearly pessimal.
2. Drop the inline stuff. For the most part it is much better served with
__builtin_memset (coming later).
3. Move the declaration to systm.h to match other funcs.

Archs are encouraged to implement the variant for their own platform so that
this implementation can be dropped.

6 years agoDon't overflow a buffer if we receive an INIT or INIT-ACK chunk
Michael Tuexen [Sat, 2 Jun 2018 16:28:10 +0000 (16:28 +0000)]
Don't overflow a buffer if we receive an INIT or INIT-ACK chunk
without a RANDOM parameter but with a CHUNKS or HMAC-ALGO parameter.
Please note that sending this combination violates the specification.

Thnanks to Ronald E. Crane for reporting the issue for the userland
stack.

MFC after: 3 days

6 years agotop: add -p option and p command to only show a single process
Roman Bogorodskiy [Sat, 2 Jun 2018 15:52:18 +0000 (15:52 +0000)]
top: add -p option and p command to only show a single process

Allow to show only a single process specified by PID. This could
be done either by running top like 'top -p PID' or using the 'p' command
inside top.

Reviewed by: eadler
Approved by: eadler
Obtained from: OpenBSD
Differential Revision: https://reviews.freebsd.org/D15501

6 years agoImprove defaults for per-CPU kernel console colors, especially with 2
Bruce Evans [Sat, 2 Jun 2018 14:07:27 +0000 (14:07 +0000)]
Improve defaults for per-CPU kernel console colors, especially with 2
or 4 CPUs.  Add a compile-time option SC_KERNEL_CONS_ATTRS to control the
defaults.

Default to color numbers in reverse order to CPU numbers (instead of
in the same order with white first and wrapping to dark grey), so that
the brightest bright colors are used first.  Don't use dark grey at all;
replace it by dark green.

Syscons has too many compile-time options, but this one is needed in
in case the defaults give something like white on white, or the user
really hates this feature and can't wait to turn it off in rc.

MFC after: next release?

6 years agoUse per-CPU attributes earlier.
Bruce Evans [Sat, 2 Jun 2018 10:36:30 +0000 (10:36 +0000)]
Use per-CPU attributes earlier.

The per-CPU ts is not initialized early, so the global kernel ts is used
early, but it ony has 1 (normal) attribute.  Switch this to the per-CPU
attribute.

The difference is most visible with EARLY_AP_STARTUP.

Change to using the curcpu macro instead of PCPU_GET(cpuid) in 2 places for
the above and in 1 other place in my old code in syscons.  The function-like
spelling is perhaps better for indicating that curcpu is volatile (unlike
curthread), but for CPU attributes volatility is a feature.

6 years agoOops, the last minute reduction in the clobber list for i386
Bruce Evans [Sat, 2 Jun 2018 09:59:27 +0000 (09:59 +0000)]
Oops, the last minute reduction in the clobber list for i386
MCOUNT_OVERHEAD() in r334522 was too agressive.  Only mcount exit
preserves %eax and %edx.

6 years agoUse stpcpy instead of home grown solution
Eitan Adler [Sat, 2 Jun 2018 08:46:09 +0000 (08:46 +0000)]
Use stpcpy instead of home grown solution

6 years agoFix low-level locking during panics.
Bruce Evans [Sat, 2 Jun 2018 08:38:59 +0000 (08:38 +0000)]
Fix low-level locking during panics.

The SCHEDULER_STOPPED() hack breaks locking generally, and
mtx_trylock_*() especially.  When mtx_trylock_*() returns nonzero,
naive code version here trusts it to have worked.  But when
SCHEDULER_STOPPED() is true, mtx_trylock_*() returns 1 without doing
anything.  Then mtx_unlock_*() crashes especially badly attempting to
unlock iff the error is detected, since mutex unlocking functions don't
check SCHEDULER_STOPPED().

syscons already didn't trust mtx_trylock_spin(), but it was missing the
logic to turn on sp->kdb_locked when turning off sp->mtx_locked during
panics.  It also used panicstr instead of SCHEDULER_LOCKED because I
thought that panicstr was more fragile.  They only differ for a window
of lines in panic(), and in broken cases where stop_cpus_hard() in panic()
didn't work.

6 years agotop(1): remove wrapper around putchar
Eitan Adler [Sat, 2 Jun 2018 07:44:53 +0000 (07:44 +0000)]
top(1): remove wrapper around putchar

This appears to have been written for portability which we no longer
need.

6 years agotop(1): const poison part 2
Eitan Adler [Sat, 2 Jun 2018 07:44:50 +0000 (07:44 +0000)]
top(1): const poison part 2

Further reduce the number of warnings emitted by gcc.

6 years agoFinish COMPAT_AOUT support for amd64. It wasn't in any amd64 or MI
Bruce Evans [Sat, 2 Jun 2018 06:40:15 +0000 (06:40 +0000)]
Finish COMPAT_AOUT support for amd64.  It wasn't in any amd64 or MI
file in /sys/conf, so was unavailable in configurations that don't use
modules, and was not testable or notable in NOTES.  Its normal
configuration (not using a module) is still silently deprecated in
aout(4) by not mentioning it there.

Update i386 NOTES for COMPAT_AOUT.  It is not i386-only, or even very MD.
Sort its entry better.

Finish gzip configuration (but not support) for amd64.  gzip is really
gzipped aout.  It is currently broken even for i386 (a call to vm fails).
amd64 has always attempted to configure and test it, but it depends on
COMPAT_AOUT (as noted).  The bug that it depends on unconfigured files
was not detected since it is configured as a device.  All other optional
image activators are configured properly using an option.

6 years agoFix high resolution kernel profiling just enough to not crash at boot
Bruce Evans [Sat, 2 Jun 2018 05:48:44 +0000 (05:48 +0000)]
Fix high resolution kernel profiling just enough to not crash at boot
time, especially for SMP.  If configured, it turns itself on at boot
time for calibration, so is fragile even if never otherwise used.

Both types of kernel profiling were supposed to use a global spinlock
in the SMP case.  If hi-res profiling is configured (but not necessarily
used), this was supposed to be optimized by only using it when
necessary, and slightly more efficiently, in asm.  But it was not done
at all for mcount entry where it is necessary.  This caused crashes
in the SMP case when either type of profiling was enabled.  For mcount
exit, it only caused wrong times.  The times were wrongest with an
i8254 timer since using that requires exclusive access to the hardware.
The i8254 timer was too slow to use here 20 years ago and is much less
usable now, but it is the default for the SMP case since TSCs weren't
invariant when SMP was new.  Do the locking in all hi-res SMP cases for
simplicity.

Calibration uses special asms, and the clobber lists in these were sort
of inverted.  They contained the arg and return registers which are not
clobbered, but on amd64 they didn't contain the residue of the call-used
registers which may be clobbered (%r10 and %r11).  This usually caused
hangs at boot time.  This usually affected even the UP case.

6 years agotop(1): const poison
Eitan Adler [Sat, 2 Jun 2018 04:37:37 +0000 (04:37 +0000)]
top(1): const poison

top(1) has a number of issues with writing to const strings. Begin
helping this along by marking easy cases as const.

6 years agoFix recent breakages of kernel profiling, mostly on i386 (high resolution
Bruce Evans [Sat, 2 Jun 2018 04:25:09 +0000 (04:25 +0000)]
Fix recent breakages of kernel profiling, mostly on i386 (high resolution
kernel profiling remains broken).

memmove() was broken using ALTENTRY().  ALTENTRY() is only different from
ENTRY() in the profiling case, and its use in that case was sort of
backwards.  The backwardness magically turned memmove() into memcpy()
instead of completely breaking it.  Only the high resolution parts of
profiling itself were broken.  Use ordinary ENTRY() for memmove().
Turn bcopy() into a tail call to memmove() to reduce complications.
This gives slightly different pessimizations and profiling lossage.
The pessimizations are minimized by not using a frame pointer() for
bcopy().

Calls to profiling functions from exception trampolines were not
relocated.  This caused crashes on the first exception.  Fix this using
function pointers.

Addresses of exception handlers in trampolines were not relocated.  This
caused unknown offsets in the profiling data.  Relocate by abusing
setidt_disp as for pmc although this is slower than necessary and
requires namespace pollution.  pmc seems to be missing some relocations.
Stack traces and lots of other things in debuggers need similar relocations.

Most user addresses were misclassified as unknown kernel addresses and
then ignored.  Treat all unknown addresses as user. Now only user
addresses in the kernel text range are significantly misclassified (as
known kernel addresses).

The ibrs functions didn't preserve enough registers.  This is the only
recent breakage on amd64.  Although these functions are written in
asm, in the profiling case they call profiling functions which are
mostly for the C ABI, so they only have to save call-used registers.
They also have to save arg and return registers in some cases and
actually save them in all cases to reduce complications.  They end up
saving all registers except %ecx on i386 and %r10 and %r11 on amd64.
Saving these is only needed for 1 caller on each of amd64 and i386.
Save them there.  This is slightly simpler.

Remove saving %ecx in handle_ibrs_exit on i386.  Both handle_ibrs_entry
and handle_ibrs_exit use %ecx, but only the latter needed to or did
save it.  But saving it there doesn't work for the profiling case.

amd64 has more automatic saving of the most common scratch registers
%rax, %rcx and %rdx (its complications for %r10 are from unusual use
of %r10 by SYSCALL).  Thus profiling of handle_ibrs_exit_rs() was not
broken, and I didn't simplify the saving by moving the saving of these
registers from it to the caller.

6 years agotop(1): clean up a bit
Eitan Adler [Sat, 2 Jun 2018 04:20:42 +0000 (04:20 +0000)]
top(1): clean up a bit

- remove unused defines
- use standard defines for STDOUT
- don't cast for memset
- avoid using (void) cast

6 years agotop(1): help scan-build along a bit
Eitan Adler [Sat, 2 Jun 2018 04:08:52 +0000 (04:08 +0000)]
top(1): help scan-build along a bit

Teach scan-build that some arrays are larger than zero, and thus not to
warn.

6 years agotop(1): Use uid_t for uid rather than 'int'
Eitan Adler [Sat, 2 Jun 2018 03:54:50 +0000 (03:54 +0000)]
top(1): Use uid_t for uid rather than 'int'

Remove unneeded define while here.

6 years agotop(1): Remove now-invalid NOTE
Eitan Adler [Sat, 2 Jun 2018 03:33:02 +0000 (03:33 +0000)]
top(1): Remove now-invalid NOTE