Commit Graph

20704 Commits

Author SHA1 Message Date
Mark Johnston 27e8401c46 bitset: Reimplement BIT_FOREACH_IS(SET|CLR)
Eliminate the nested loops and re-implement following a suggestion from
rlibby.

Add some simple regression tests.

Reviewed by:	rlibby, kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32472
2022-06-22 10:15:26 +02:00
Mark Johnston 96ddb4055e Revert "cpuset(9): Add CPU_FOREACH_IS(SET|CLR) and modify consumers to use it"
This reverts commit 9068f6ea697b1b28ad1326a4c7a9ba86f08b985e.

The underlying macro needs to be reworked to avoid problems with control
flow statements.

Reported by:	rlibby
2022-06-22 10:15:26 +02:00
Mark Johnston 112245b78f cpuset(9): Add CPU_FOREACH_IS(SET|CLR) and modify consumers to use it
This implementation is faster and doesn't modify the cpuset, so it lets
us avoid some unnecessary copying as well.  No functional change
intended.

Reviewed by:	cem, kib, jhb
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32029
2022-06-22 10:15:26 +02:00
Mark Johnston 37a3e59636 bitset(9): Introduce BIT_FOREACH_ISSET and BIT_FOREACH_ISCLR
These allow one to non-destructively iterate over the set or clear bits
in a bitset.  The motivation is that we have several code fragments
which iterate over a CPU set like this:

while ((cpu = CPU_FFS(&cpus)) != 0) {
	cpu--;
	CPU_CLR(cpu, &cpus);
	<do something>;
}

This is slow since CPU_FFS begins the search at the beginning of the
bitset each time.  On amd64 and arm64, CPU sets have size 256, so there
are four limbs in the bitset and we do a lot of unnecessary scanning.

A second problem is that this is destructive, so code which needs to
preserve the original set has to make a copy.  In particular, we have
quite a few functions which take a cpuset_t parameter by value, meaning
that each call has to copy the 32 byte cpuset_t.

The new macros address both problems.

Reviewed by:	cem, kib
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32028
2022-06-22 10:15:26 +02:00
Patrick Kelsey 7c03cdf47e iflib: Improve mapping of TX/RX queues to CPUs
iflib now supports mapping each (TX,RX) queue pair to the same CPU
(default), to separate CPUs, or to a pair of physical and logical CPUs
that share the same L2 cache.  The mapping mechanism supports unequal
numbers of TX and RX queues, with the excess queues always being
mapped to consecutive physical CPUs.  When the platform cannot
distinguish between physical and logical CPUs, all are treated as
physical CPUs.  See the comment on get_cpuid_for_queue() for the
entire matrix.

The following device-specific tunables influence the mapping process:
dev.<device>.<unit>.iflib.core_offset       (existing)
dev.<device>.<unit>.iflib.separate_txrx     (existing)
dev.<device>.<unit>.iflib.use_logical_cores (new)

The following new, read-only sysctls provide visibility of the mapping
results:
dev.<device>.<unit>.iflib.{t,r}xq<n>.cpu

When an iflib driver allocates TX softirqs without providing reference
RX IRQs, iflib now binds those TX softirqs to CPUs using the above
mapping mechanism (that is, treats them as if they were TX IRQs).
Previously, such bindings were left up to the grouptaskqueue code and
thus fell outside of the iflib CPU mapping strategy.

Reviewed by:	kbowling
Tested by:	olivier, pkelsey
MFC after:	3 weeks
Differential Revision:	https://reviews.freebsd.org/D24094
2022-06-22 10:15:26 +02:00
Ryan Libby fb0a5865e4 bitset: implement BIT_TEST_CLR_ATOMIC & BIT_TEST_SET_ATOMIC
That is, provide wrappers around the atomic_testandclear and
atomic_testandset primitives.

Submitted by:	jeff
Reviewed by:	cem, kib, markj
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D22702
2022-06-22 10:15:26 +02:00
D Scott Phillips 9d50b44689 bitset: expand bit index type to `long`
An upcoming patch to use the bitset macros for tracking vm page
dump information could conceivably need more than INT_MAX bits.
Expand the bit type to long so that the extra range is available
on 64-bit platforms where it would most likely be needed.

CPUSET_COUNT and DOMAINSET_COUNT are also modified to remain of
type `int`.

Reviewed by:	kib, markj
Approved by:	scottl (implicit)
MFC after:	1 week
Sponsored by:	Ampere Computing, Inc.
Differential Revision:	https://reviews.freebsd.org/D26190
2022-06-22 10:15:26 +02:00
D Scott Phillips 4c5b7bec97 bitset: add BIT_FFS_AT() for finding the first bit set greater than a start bit
Reviewed by:	kib
Approved by:	scottl (implicit)
MFC after:	1 week
Sponsored by:	Ampere Computing, Inc.
Differential Revision:	https://reviews.freebsd.org/D26128
2022-06-22 10:15:26 +02:00
Konstantin Belousov 5e7a2b174a Fix undefined behavior: left-shifting into the sign bit.
Reviewed by:	dim, markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D22898
2022-06-22 10:15:26 +02:00
Ryan Libby de1380c36b bitset: rename confusing macro NAND to ANDNOT
s/BIT_NAND/BIT_ANDNOT/, and for CPU and DOMAINSET too.  The actual
implementation is "and not" (or "but not"), i.e. A but not B.
Fortunately this does appear to be what all existing callers want.

Don't supply a NAND (not (A and B)) operation at this time.

Discussed with:	jeff
Reviewed by:	cem
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D22791
2022-06-22 10:15:26 +02:00
Ryan Libby 96c645a0b1 bitset: avoid pessimized code when bitset size is not constant
We have a couple optimizations for when the bitset is known to be just
one word.  But with dynamically sized bitsets, it was actually more work
to determine the size than just to do the necessary computation.  Now,
only use the optimization when the size is known to be constant.

Reviewed by:	markj
Discussed with:	jeff
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D22639
2022-06-22 10:15:26 +02:00
Jeff Roberson a6bd733db9 Use a precise bit count for the slab free items in UMA.
This significantly shrinks embedded slab structures.

Reviewed by:	markj, rlibby (prior version)
Differential Revision:	https://reviews.freebsd.org/D22584
2022-06-22 10:15:26 +02:00
Sebastian Huber a13a044c17 RTEMS: Remove FreeBSD version tags 2022-06-22 10:14:38 +02:00
Sebastian Huber e84814b3e4 Regenerate configure and newlib.hin
In commit b0cb9f85ca the regeneration of the
configure and newlib.hin files was missing.
2022-06-21 08:56:33 +02:00
Takashi Yano fe10e8f03a Cygwin: console: Handle setting very long window title correctly.
- Previously, the console code could not handle escape sequence
  setting window title longer than 256 byte correctly. This patch
  fixes the issue.
  Addresses: https://cygwin.com/pipermail/cygwin/2022-June/251662.html
2022-06-19 18:02:09 +09:00
Takashi Yano fdbd153932 Cygwin: console: Retain ENABLE_VIRTUAL_TERMIANL_PROCESSING flag.
- Currently, ENABLE_VIRTUAL_TERMINAL_PROCESSING flag is disabled
  unconditionally when exiting from cygwin. This causes ANSI escape
  sequence disabled in Windows Terminal where it is enables by
  default. This patch retains that flag if it is originally enabled.
2022-06-14 21:11:56 +09:00
Ken Brown ddce45112d Cygwin: restore one more '#ifdef __x86_64__' 2022-06-11 08:56:08 -04:00
Ken Brown bbfe79fb72 Cygwin: restore '#ifdef __x86_64__' for CPU-specific code
Commit e1ce752a1d, "Cygwin: remove miscellaneous 32-bit code", removed
most occurrences of '#ifdef __x86_64__'.  Restore those occurrences
that guarded code specific to the AMD64 processor, and #error out if
the processor is different.  This will make it easier to find
AMD64-specific code if we ever want to add support for a different
64-bit processor (e.g., ARM64).
2022-06-10 16:38:34 -04:00
Sebastian Huber b0cb9f85ca Use global stdio streams for all configurations
The _REENT_GLOBAL_STDIO_STREAMS was introduced by commit
668a4c8722 in 2017.  Since then it was enabled by
default for RTEMS.  Recently, the option was enabled for Cygwin which
previously used an alternative implementation to use global stdio streams.

In Newlib, the stdio streams are defined to thread-specific pointers
_reent::_stdin, _reent::_stdout and _reent::_stderr.  If the option is disabled
(the default for most systems), then these pointers are initialized to
thread-specific FILE objects which use file descriptors 0, 1, and 2,
respectively.  There are at least three problems with this:

(1) The thread-specific FILE objects are closed by _reclaim_reent().  This
    leads to problems with language run-time libraries that provide wrappers to
    the C/POSIX stdio streams (for example C++ and Ada), since they use the
    thread-specific FILE objects of the initialization thread.  In case the
    initialization thread is deleted, then they use freed memory.

(2) Since thread-specific FILE objects are used with a common output device via
    file descriptors 0, 1 and 2, the locking at FILE object level cannot ensure
    atomicity of the output, e.g. a call to printf().

(3) There are resource managment issues, see:

    https://sourceware.org/pipermail/newlib/2022/019558.html

    https://bugs.linaro.org/show_bug.cgi?id=5841

This patch enables the _REENT_GLOBAL_STDIO_STREAMS behaviour for all Newlib
configurations and removes the option.  This removes a couple of #ifdef blocks.
2022-06-10 20:13:52 +02:00
Sebastian Huber c4d4439c42 Fix __fp_lock_all() and __fp_unlock_all()
For _REENT_GLOBAL_STDIO_STREAMS, lock/unlock all FILE objects.  In the
repository, this function is only used by Cygwin during process forks.  Since
Cygwin enabled _REENT_GLOBAL_STDIO_STREAMS recently, without this fix no FILE
object at all was locked.
2022-06-10 20:13:52 +02:00
Mark Geisert aa460cc0ca Cygwin: Have gmondump support ssp-generated gmon.out
Cygwin tool ssp generates gmon.out files with different address
resolution than other tools do. Two address bytes per bucket rather than
the usual four address bytes. Gprof can deal with the difference but
gmondump can't because the latter's gmon.out header validation fails.

- Remove the offending portion of the header validation code.
- Make sure all code can handle differing address resolutions.
- Display address resolution in verbose data dumps.
- Change "rawarc" to "struct rawarc" in certain sizeof expressions to
  avoid buffer overrun faults.
- When "-v" (verbose) is specified, note when there is missing bucket
  data or rawarc data.
2022-06-10 12:12:26 +02:00
Sebastian Huber 866f6c909f Clarify struct _reent comment 2022-06-08 10:42:31 +02:00
Sebastian Huber 14fc9be234 Fix __sglue inititialization
Do not initialize __sglue with the FILE objects of _GLOBAL_REENT to avoid a
double use in the !_REENT_SMALL and !_REENT_GLOBAL_STDIO_STREAMS configurations
which didn't use a thread-specific reentrancy structure.
2022-06-07 21:28:25 +02:00
Ken Brown 07cf763095 Cygwin: restore two instances of __stdcall
In the previous commit, __stdcall was removed from _dll_crt0 in
winsup.h and dcrt0.cc but not in lib/cygwin_crt0.c.  For consistency,
restore the first two occurrences of __stdcall.  We could instead
remove it from the declaration in lib/cygwin_crt0.c, but this might
appear to affect binary compatibility, even though it really doesn't.
2022-06-07 13:46:31 -04:00
Ken Brown 30c5411d07 Cygwin: remove most occurrences of __stdcall and __cdecl
These have no effect on x86_64.  Retain a few occurrences of __cdecl
in files imported from other sources.

Also retain all occurrences of WINAPI, even though the latter is
simply a macro that expands to __stdcall.  Most of these occurrences
are associated with Windows API functions, and removing them might
make the code confusing instead of simpler.
2022-06-06 12:00:45 -04:00
Ken Brown cb4b4548c8 Cygwin: remove ntsecapi.h
This was a wrapper for w32api/ntsecapi.h.  It was introduced to fix a
bug that only affected 32-bit Cygwin, so it is no longer needed.
2022-06-06 10:44:01 -04:00
Ken Brown 1f8235f6ba Cygwin: child_info.h: remove declaration of init_child_info
The function was removed long ago, but its declaration remained.
2022-06-06 10:16:48 -04:00
Jon Turney f36dd40275
Cygwin: Drop use of loadlib.h in regtool
Link directly with RegDeleteKeyExW(), available since Vista.

(It's unclear the LoadLibrary wrapper was ever doing anything useful
here, as (i) DLL lookup in PATH was avoided as advapi32 is already
loaded into the process, and (ii) advapi32 is a 'known DLL' which is
only ever loaded from system directory)
2022-06-06 11:21:44 +01:00
Jon Turney f344134a19
Cygwin: Drop pointless loadlib.h includes in utilities
These utilities used to LoadLibrary()/GetProcAddress(), but don't
anymore.
2022-06-06 11:21:43 +01:00
Ken Brown e1ce752a1d Cygwin: remove miscellaneous 32-bit code 2022-05-29 17:54:32 -04:00
Ken Brown b1e304cbd3 Cygwin: remove 32-bit only clipboard code 2022-05-29 17:45:52 -04:00
Ken Brown f6bb8bfaa0 Cygwin: remove some 32-bit only environment code 2022-05-29 17:45:52 -04:00
Ken Brown 3e917daec1 Cygwin: remove some 32-bit only path conversion functions 2022-05-29 17:45:52 -04:00
Ken Brown 2126f966ae Cygwin: remove regparm.h
This file defines the macros __reg1, __reg2, and __reg3, which are
defined to be empty on 64-bit Cygwin.  Remove all occurrences of these
macros.
2022-05-29 17:45:52 -04:00
Ken Brown 2d9b48760c Cygwin: simplify some function names
Remove "32" or "64" from each of the following names: acl32,
aclcheck32, aclfrommode32, aclfrompbits32, aclfromtext32, aclsort32,
acltomode32, acltopbits32, acltotext32, facl32, fchown32, fcntl64,
fstat64, _fstat64, _fstat64_r, ftruncate64, getgid32, getgrent32,
getgrgid32, getgrnam32, getgroups32, getpwuid32, getpwuid_r32,
getuid32, getuid32, initgroups32, lseek64, lstat64, mknod32, mmap64,
setegid32, seteuid32, setgid32, setgroups32, setregid32, setreuid32,
setuid32, stat64, _stat64_r, truncate64.

Remove prototypes and macro definitions of these names.

Remove "#ifndef __INSIDE_CYGWIN__" from some headers so that the new
names will be available when compiling Cygwin.

Remove aliases that are no longer needed.

Include <unistd.h> in fhandler_clipboard.cc for the declarations of
geteuid and getegid.
2022-05-29 17:45:52 -04:00
Ken Brown 7c0de0af97 Cygwin: remove some 32-bit-only function definitions
Remove the definitions of the following: acl, aclcheck, aclfrommode,
aclfrompbits, aclfromtext, aclsort, acltomode, acltopbits, acltotext,
chown, fchown, _fcntl, fstat, _fstat_r, ftruncate, getegid, geteuid, getgid,
getgrent, getgrgid, getgrnam, getgroups, getpwduid, getpwuid,
getpwuid_r, getuid, initgroups, lacl, lacl32, lchown, lseek, lstat,
mknod, mmap, setegid, seteuid, setgid, setgroups, setregid, setreuid,
setuid, stat, _stat_r, truncate.

[For most of these, the corresponding 64-bit entry points are obtained
by exporting aliases.  For example, acl is an alias for acl32, and
truncate is an alias for truncate64.]

Remove the following structs and all code using them (which is 32-bit
only): __stat32, __group16, __flock32, __aclent16_t.

Remove the typedefs of __blkcnt32_t __dev16_t, __ino32_t, which are
used only in code that has been removed.

Put the typedefs of __uid16_t and __gid16_t in one header, instead of
one header if __INSIDE_CYGWIN__ is defined and a different header
otherwise.
2022-05-29 17:45:52 -04:00
Ken Brown 98180795de Cygwin: document last bug fix 2022-05-29 17:42:06 -04:00
Takashi Yano 871ca7ba64 Cygwin: cygheap: Fix the issue of cygwin1.dll in the root directory.
- After the commit 6d898f43, cygwin fails to start if cygwin1.dll
  is placed in the root directory. This patch fixes the issue.
Addresses: https://cygwin.com/pipermail/cygwin/2022-May/251548.html
2022-05-28 23:16:21 +09:00
jdoubleu e93bb6f985 Add test cases for parser errors after reworked parsing behavior. 2022-05-27 11:42:49 -04:00
Jeff Johnston 2dbdf66b91 Modify tzset_r.c to handle errors
- change __tzset_r so errors end up setting the timezone to
  unnamed UTC
2022-05-27 11:05:11 -04:00
Brian Inglis 9af21ada23 fhandler_proc.cc(format_proc_cpuinfo): add Linux 5.18 cpuinfo flags
0x80000008:0 EBX:31 brs		AMD Branch Sampling available
0x80000022:0 EAX:0  perfmon_v2	AMD ExtPerfMonAndDbg Performance Monitoring Version 2
0x00000021:0 EBX|EDX|ECX=="IntelTDX    " tdx_guest Intel Trust Domain Extensions- Guest Support
2022-05-25 13:11:40 -04:00
Ken Brown 2f8ba40046 Cygwin: fix mknod (64-bit only)
The current definition of mknod in syscalls.cc has a third argument of
type __dev16_t instead of dev_t.  Fix this on 64-bit Cygwin by making
the existing mknod 32-bit only and then exporting mknod as an alias
for mknod32.  (No fix is needed on 32-bit because mknod is redirected
to mknod32 via NEW_FUNCTIONS in Makefile.am.)

Addresses: https://cygwin.com/pipermail/cygwin-developers/2022-May/012589.html
2022-05-23 08:16:40 -04:00
Sebastian Huber 03e815a91b Use weak reference for _REENT_SMALL
Avoid a strong reference to __sfp[] for _impure_data.  The __sfp[] is linked in
if __sinit() is used for example.
2022-05-19 19:01:49 +02:00
Sebastian Huber 382550072b Fix __sFILE::_lock initialization
The __sFILE::_lock member is present if __SINGLE_THREAD__ is not defined.  In
this case, it is initialized in __sfp().  It is a bug to do it sometimes also
in std().
2022-05-19 19:01:49 +02:00
Corinna Vinschen 1b86dd7d8c Cygwin: make sure exec'ed process exists early in process list
killpg(pgid, 0) (or kill_pgrp(pgid, si_signo=0), in signal.cc)
fails (returns -1) even when there is a process in the process
group pgid, if the process is in the middle of spawnve(), see

  https://cygwin.com/pipermail/cygwin/2022-May/251479.html

When exec'ing a process the assumption is that the exec'ed process creates its
own symlink (in pinfo::thisproc() in pinfo.cc). If the exec'ing process
calls NtClose on it's own winpid symlink, but the exec'ed process didn't
progress enough into initialization, there's a slim chance that neither
the exec'ing process, nor the exec'ed process has a winpid symlink
attached.

Always create the winpid symlink in spawn.cc, even for exec'ed Cygwin
processes.  Make sure to dup the handle into the new process, and stop
creating the winpid symlink in exec'ed processes.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-05-19 10:46:41 +02:00
Takashi Yano 1559f7f458 Cygwin: Use two pass parse for tlsoffsets generation.
- The commit "Cygwin: fix new sigfe.o generation in optimized case"
  fixed the wrong tlsoffsets generation by adding -O0 to compile
  options. Current gentls_offsets expects entry of "start_offset"
  is the first entry in the assembler code. However, without -O0,
  entry of "start_offset" goes to the last entry for some reason.
  Currently, -O0 can prevents assembler code from reversing the
  order of the entries, however, there is no guarantee that it will
  retain the order of the entries in the future.

  This patch makes gentls_offsets parse the assembler code in the
  two pass to omit -O0 option dependency.
2022-05-19 04:03:16 +09:00
Jia-Wei Chen 12d07e1ddd newlib: libc: reent.h: remove unnecessary parentheses
The compiler warns the double parentheses are unnecessary in some
target, and cause fail cases when doing some testcases in regression.

gcc/testsuite/g++.dg/warn/Wstringop-overflow-6.C

Remove the unnecessary parentheses will fix it. See more details in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85775

Same like in commit 0542583129,
Author: Maxim Blinov <maxim.blinov@embecosm.com>
Date:   Thu Jul 22 22:41:42 2021 +0100

     Remove unneccesary parenthesis around declarator

Thanks for Sebastian Huber's remind!
2022-05-18 12:37:27 +02:00
Sebastian Huber 2faeaf50fd Use global atexit data for all configurations
For the exit processing only members of _GLOBAL_REENT were used by default.  If
the _REENT_GLOBAL_ATEXIT option was enabled, then the data structures were
provided through dedicated global objects.  Make this option the default.
Remove the option.  Rename struct _reent members _atexit and _atexit0 to
_reserved_6 and _reserved_7, respectively.  Provide them only if
_REENT_BACKWARD_BINARY_COMPAT is defined.
2022-05-18 07:45:09 +02:00
Sebastian Huber 9035e406cb Optional struct _reent::_new::_unused
Rename struct _reent::_new::_unused members _nextf and _nmalloc to _reserved_3
and _reserved_4, respectively.   Rename struct _reent::_new member _unused to
_reserved_5.  Provide them only if _REENT_BACKWARD_BINARY_COMPAT is defined.

Remove unused _N_LISTS define.
2022-05-18 07:45:09 +02:00
Sebastian Huber 84d8b9d1b3 Optional struct _reent::_new::_reent::_unused_rand
Rename struct _reent member _unused_rand to _reserved_2.  Provide it only if
_REENT_BACKWARD_BINARY_COMPAT is defined.
2022-05-18 07:45:09 +02:00