On 14/09/2025 13:37, Simon Josefsson wrote:
Pádraig Brady <[email protected]> writes:

The attached 2 patches, add a new cpu-supports module,
and updates the crc-x86_64 module to use it.
This ensures that any users of the crc-x86_64 module
will honor the GLIBC_TUNABLES environment variable.
Specifically it will allow disabling of the hardware acceleration
used by crc-x86_64 using:

   export GLIBC_TUNABLES=glibc.cpu.hwcaps=-AVX

Note this is a general mechanism provided by glibc
to tune hardware acceleration within glibc and also
determines what libs are loaded with its dynamic dispatch mechanism:
On my "x86-64-v3" system for example:
...
+      if ((GLIBC_TUNABLES = getenv ("GLIBC_TUNABLES")))
+License:
+GPL

Ouch.

The crc module is a low-level module that is used by libraries.  Getenv
can be a complicated function, and didn't use to be thread-safe
everywhere and GPL is not LGPL-compatible.  It seems unfortunate that
this change makes it harder to use the crc-x86_64 optimization from
these low-level libraries, not simpler, so I'll have to drop the
optimization and only use the core 'crc' module instead for these
usages.  Or merely vendor a static copy the ~20 lines of code for the
CRC implementation where this module started from...
Well we can/should make cpu-supports LGPL.

I do think that most users would prefer the honoring of hwcaps by default.
I suppose we could have another crc-x86_64-nohwcap module
that one could use to avoid the hwcap checking?

Alternatively we could give more control
of the hwcap logic from cpu-supports.h with:

  #define HWCAPS_ENABLE   0
  #define HWCAPS_NO_CACHE 1
  #define HWCAPS_NO_CHECK 2

Then code users that care could:

  #include "cpu-supports.h"
  hwcaps_control = HWCAPS_NO_CHECK;

cheers,
Padraig

Reply via email to