Commit graph

288498 commits

Author SHA1 Message Date
Robert Clausecker 14289e973f lib/libc/amd64/string: add strncmp scalar, baseline implementation
The scalar implementation is fairly straightforward and merely unrolled
four times.  The baseline implementation closely follows D41971 with
appropriate extensions and extra code paths to pay attention to string
length.

Performance is quite good.  We beat both glibc (except for very long
strings, but they likely use AVX which we don't) and Bionic (except for
medium-sized aligned strings, where we are still in the same ballpark).

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D42122
2023-12-25 14:55:13 +01:00
Robert Clausecker 459ddefcc9 lib/libc/tests/string: add unit tests for strncmp(3)
These are patterned after the previously added (D41970)
strcmp tests, but are extended to check for various length
conditions.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D42122
2023-12-25 14:55:08 +01:00
Robert Clausecker 8b60e1fdbe share/man/man7/simd.7: document amd64 SIMD use for strpbrk()
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision: https://reviews.freebsd.org/D41980
2023-12-25 14:55:04 +01:00
Robert Clausecker f4fc317c36 lib/libc/amd64/string: implement strpbrk() through strcspn()
This lets us use our optimised strcspn() routine for strpbrk() calls.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D41980
2023-12-25 14:54:58 +01:00
Robert Clausecker 47adb1e012 share/man/man7/simd.7: document new amd64 baseline strcmp()
Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D41971
2023-12-25 14:54:50 +01:00
Robert Clausecker bca25680b9 lib/libc/amd64/string/strcmp.S: add baseline implementation
This is the most complicated one so far.  The basic idea is to process
the bulk of the string in aligned blocks of 16 bytes such that one
string runs ahead and the other runs behind.  The string that runs ahead
is checked for NUL bytes, the one that runs behind is compared with the
corresponding chunk of the string that runs ahead.  This trades an extra
load per iteration for the very complicated block-reassembly needed in
the other implementations (bionic, glibc).  On the flip side, we need
two code paths depending on the relative alignment of the two buffers.

The initial part of the string is compared directly if it is known not
to cross a page boundary.  Otherwise, a complex slow path to avoid
crossing into unmapped memory commences.

Performance-wise we beat bionic for misaligned strings (i.e. the strings
do not share an alignment offset) and reach comparable performance for
aligned strings.  glibc is a bit better as it has a special kernel for
AVX-512, where this stuff is a bit easier to do.

Sponsored by:	The FreeBSD Foundation
Tested by:	developers@, exp-run
Approved by:	mjg
MFC after:	1 month
MFC to:		stable/14
PR:		275785
Differential Revision:	https://reviews.freebsd.org/D41971
2023-12-25 14:54:33 +01:00
Alexander Motin 13037eaabe ig4: Actively use FIFO thresholds
Before every wait for FIFO interrupt set how much data/space do we
want to see there.  Previous code was not using it for receive, as
result aggregating interrupts only within processing latency.  The
new code needs only one interrupt per transfer per FIFO length.

On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this
reduces the interrupt rate per device down to 2 per sample or 16-20
per second when idle and 120-160 per second when actively touched.

MFC after:	1 month
2023-12-24 18:18:11 -05:00
Vladimir Kondratyev dbca442414 LinuxKPI: Constify src parameter of bitmap_copy
in bitmap_from_arr32() to fix build on 32 bit archs.

Sponsored by:	Serenity Cyber Security, LLC
Fixes:	5ae2e6f913 ("LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()")
MFC after:	1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev 73ccd188c4 LinuxKPI: Define ioread64() in linux/io.h only on 64 bit archs.
32 bit archs includes nonatomic version from linux/io-64-nonatomic-*.h

Sponsored by:   Serenity Cyber Security, LLC
Fixes:		dcfc983373 ("LinuxKPI: Implement ioread64()")
MFC after:      1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev b4efc62776 LinuxKPI: Do not use explicit context in FPU sections on powerpc64
It is not supported yet.

Sponsored by:	Serenity Cyber Security, LLC
Fixes:	5a3bd28167 ("LinuxKPI: Add explicit software context to FPU sections")
MFC after:	1 week
2023-12-24 15:48:06 +03:00
Vladimir Kondratyev 9bf957fc9b Bump __FreeBSD_version after LinuxKPI changes.
Sponsored by:	Serenity Cyber Security, LLC
2023-12-24 11:20:01 +03:00
Vladimir Kondratyev 5a3bd28167 LinuxKPI: Add explicit software context to FPU sections
Amdgpu driver does a lot of memory allocations in FPU-protected sections
of code for certain display cores, e.g. for DCN30. This does not work
currently on FreeBSD as its malloc function can not be run within a
critical section. Allocate memory for FPU context to overcome such
restriction.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu (previous version), markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42822
2023-12-24 11:20:01 +03:00
Vladimir Kondratyev 04952a9456 LinuxKPI: Add acpi_dev_present() function.
acpi_dev_present detects that a given ACPI device is present based on
Hardware ID, Unique ID and Hardware Revision of the device.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42823
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev 808ae4e29b LinuxKPI: Add pcie_capability_clear_and_set_word() function
It does a Read-Modify-Write operation using clear and set bitmasks on
PCI Express Capability Register at pos. As certain PCI Express
Capability Registers are accessed concurrently in RMW fashion, hence
require locking which is handled transparently to the caller.

Sponsored by:	Serenity CyberSecurity, LLC
Reviewed by:	manu, bz
MFC after:	1 week
MFC TODO:	Move pcie_cap_lock to bottom to preserve KBI compatibility
Differential Revision:	https://reviews.freebsd.org/D42821
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev b8c88a6175 LinuxKPI: Add x86_vendor field to struct cpuinfo_x86
and initialize it at linuxkpi module load.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42820
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev 730387b64e LinuxKPI: Add linux/apple-gmux.h
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42819
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev c58ddc2546 LinuxKPI: Rename linux_list_add to __list_add() in linux/list.h
to match Linux

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42818
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev 9903d83d67 LinuxKPI: Add linux/ioport.h header
Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42817
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev 7f88d742e5 LinuxKPI: Add get_random_u64() function
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42816
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev 2b037743a7 LinuxKPI: Add linux/dynamic_debug.h header
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42815
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev 745067c585 LinuxKPI: Add acpi_video_backlight_use_native()
We assume that backlight (in Linux term) is always "native".

Also stub acpi_video_register_backlight()

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42814
2023-12-24 11:20:00 +03:00
Vladimir Kondratyev 5ae2e6f913 LinuxKPI: Add bitmap_intersects(), bitmap_from_arr32()
and bitmap_shift_right() functions to linux/bitmap.h

They perform calculation of two bitmaps intersection,
copying the contents of u32 array of bits to bitmap and
logical right shifting of the bits in a bitmap.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42812
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev 1b2f43a742 LinuxKPI: Add cancel_work() function.
Cancel a work not waiting for it to finish.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42811
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev 64e30cba3f LinuxKPI: Add write_seqcount_invalidate() and seqprop_sequence()
functions to linux/seqlock.h

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42810
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev a39ed121ea LinuxKPI: Chase for new "name" argument of register_shrinker()
Linux uses it only if SHRINKER_DEBUG config option is enabled. Ignore it.

Sponsored by:	Serenity Cyber Security, LLC
Reviewers:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42809
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev c7312643b7 LinuxKPI: Add ida_alloc_min()
ida_alloc_min() allocates an unused ID. between min and INT_MAX.

While here allow end parameter of ida_simple_get() be larger than
INT_MAX. Linux caps the value to INT_MAX.

Sponsored by:	Serenity Cyber Security, LLC
Reviewers:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42806
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev af787b8e8b LinuxKPI: Add IOMEM_ERR_PTR() to linux/io.h
The function creates an error pointer.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42805
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev e964da1415 LinuxKPI: Add ktime_get_raw_fast_ns() to linux/ktime.h
It is implemented like ktime_get_raw_ns() function but uses less
precise getnanouptime() call.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42804
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev 66f9a98335 LinuxKPI: Add xa_(un)lock_irq to linux/xarray.h
On FreeBSD they are equal to non-irq version.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42803
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev 206e9fea75 LinuxKPI: Add asm/hypervisor.h header
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42802
2023-12-24 11:19:59 +03:00
Vladimir Kondratyev dcfc983373 LinuxKPI: Implement ioread64()
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42801
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev f8ab2f5bae LinuxKPI: Add linux/iosys-map.h header
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42799
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev 1bce29bcf1 LinuxKPI: Add some header pollution and dummy headers
required by recent drm-kmod to be succesfully compiled.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
Obtained from:	OpenBSD (partially)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42798
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev c612e3c262 LinuxKPI: Add xen/xen.h header
It contains proxy-implementation of xen_initial_domain() and
xen_pv_domain() required by latest drm-kmod.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42797
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev fa862482fb LinuxKPI: Split linux/container_of.h off from linux/kernel.h
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:      1 week
Differential Revision:	https://reviews.freebsd.org/D42796
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev 31ef29091b LinuxKPI: Add static_assert() macro
And move it along BUILD_BUG family in to
linux/build_bug.h to match Linux.

Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42800
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev a012599653 LinuxKPI: Implement dev_dbg_once() macro
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42795
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev ae1084ff01 LinuxKPI: Add str_on_off and other helpers to linux/string_helpers.h
Sponsored by:	Serenity Cyber Security, LLC
Reviewed by:	manu, bz, imp (previous version)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42794
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev 5e6bddfc43 LinuxKPI: Add video/vga.h header
Sponsored by:	Serenity Cyber Security, LLC
Obtained from:	OpenBSD
Reviewed by:	manu, bz
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42793
2023-12-24 11:19:58 +03:00
Vladimir Kondratyev 96ab16ebab LinuxKPI: Remove sys/rman.h include from LKPI headers.
sys/rman.h defines `resource` structure which conflicts with the Linux
structure of the same name. To fix that remove reference to sys/rman.h
from linux/pci.h and move resource management code to linux_pci.c.
Update consumers which were depending on linux/pci.h pollution.

No functional changes intended.

Sponsored by:	Serenity Cyber Security, LLC
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D42792
2023-12-24 11:19:57 +03:00
Jason A. Harmening 0ee1cd6da9 vm_page.h: tweak page-busied assertion macros
Fix incorrect macro name and include the value of curthread in the
panic message where relevant.
2023-12-23 23:20:13 -06:00
Jason A. Harmening 2619c5ccfe Avoid waiting on physical allocations that can't possibly be satisfied
- Change vm_page_reclaim_contig[_domain] to return an errno instead
  of a boolean.  0 indicates a successful reclaim, ENOMEM indicates
  lack of available memory to reclaim, with any other error (currently
  only ERANGE) indicating that reclamation is impossible for the
  specified address range.  Change all callers to only follow
  up with vm_page_wait* in the ENOMEM case.

- Introduce vm_domainset_iter_ignore(), which marks the specified
  domain as unavailable for further use by the iterator.  Use this
  function to ignore domains that can't possibly satisfy a physical
  allocation request.  Since WAITOK allocations run the iterators
  repeatedly, this avoids the possibility of infinitely spinning
  in domain iteration if no available domain can satisfy the
  allocation request.

PR:		274252
Reported by:	kevans
Tested by:	kevans
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D42706
2023-12-23 23:01:40 -06:00
Alexander Motin 1a3ee6002f acpi_lid: Remove duplicate events
Remove extra acpi_UserNotify() call per event.  Filter duplicate
notifications received from ACPI without actual status change.

Without this on my Dell XPS 13 9310 I saw 4 devd events for either
open or close, now only one.

MFC after:	1 month
2023-12-23 21:33:51 -05:00
Alexander Motin 68e457df02 iichid(4): Restore/increase sampling rate
My previous commit by reducing precision reduced the sampling rate
from 60Hz to 40Hz on idle system.  Return it back to 60-80Hz range,
that should be good for mouse smoothness on 60Hz displays.

MFC after:	1 months
2023-12-23 19:10:49 -05:00
Alexander Motin 9c9d7fdd9f ig4: Fix FIFO depths detection
At least on my Tiger Lake-LP queue depth detection failed before the
ig4iic_set_config() call, resulting in no FIFO use.  Moving it after
solves the problem, getting proper 64 bytes size.

On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this
by few times reduces context switch rate in the driver, and probably
also improves the I2C bus utilization.

MFC after:	1 month
2023-12-23 19:02:49 -05:00
Alexander Motin a74df3f96e iicbb: Fix pause_sbt() arguments order
It should make pause interval less strict.

While there, add cpu_spinwait() into a tight spin wait loop to burn
less power and let other SMT thread work more.

MFC after:	1 month
2023-12-23 18:58:51 -05:00
Yuji Hagiwara 553ed8e38b mlx4(5): fix driver initialization
After netlinkification, ether_ifattach() requires ifmedia_init() to be
done before it.

PR:	275897
MFC after:	1 week
2023-12-23 22:53:02 +02:00
Xin LI 906748d208 newsyslog(8): Add option to globally override compression method.
Historically, newsyslog compressed rotated log files to save disk space.
This was useful in the early days. However, with modern file systems like
ZFS offering native compression, and with the availability of larger hard
drives, the benefits of additional compression have become less significant.
This is particularly true considering the inconvenience of decompressing
log files when searching for specific patterns.

Additionally, the original implementation of compression methods was not
future-proof.  As a result, we have redefined the J, X, Y, Z flags to
signify "treat the file as compressible" rather than "compress the file
with that specific method."

A new command-line option, -c, has been introduced to allow overriding
these settings in a more future-proof way. The available choices are:

 * none			 - do not compress, regardless of flag.
 * legacy		 - historical behavior: J=bzip2, X=xz, Y=zstd, Z=gzip.
 * bzip2, xz, zstd, gzip - apply the specified compression method.

Currently, the default is set to 'legacy' to preserve historical behavior.
However, our intention is to change this default to 'none' in FreeBSD 15.0.

Additionally, this update changes the default settings for zstd to use
multithreading and long-range options, better aligning with its intended
use.

Inspired by D42961 .

Reviewed by:	debdrup (earlier version, mdoc(7))
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D43165
2023-12-22 22:46:33 -08:00
Alexander Motin 8c86b98124 iichid(4): Improve idle sampling hysteresis
In sampling mode some devices return same data indefinitely even if
there is nothing to report.  Previous idle hysteresis implementation
activated only when device returned no data, so some devices ended up
polled at fast rate all the time.  This new implementation compares
each new report with the previous, and, if they are identical, after
reaching threshold also drop sampling rate to slow.

On my Dell XPS 13 9310 with iichid(4) touchscreen and touchpad this
reduces idle power consumption by ~0.5W by reducing number of context
switches in the driver from ~4000 to ~700 per second when not touched.

MFC after:	1 month
2023-12-22 22:50:52 -05:00
Philip Paeps eebb9c2cae contrib/tzdata: import tzdata 2023d
Changes: https://github.com/eggert/tz/blob/2023d/NEWS

MFC after:	1 day
2023-12-23 09:51:01 +08:00