Make CPU_SET macros compliant with other implementations

The introduction of <sched.h> improved compatibility with some 3rd
party software, but caused the configure scripts of some ports to
assume that they were run in a GLIBC compatible environment.

Parts of sched.h were made conditional on -D_WITH_CPU_SET_T being
added to ports, but there still were compatibility issues due to
invalid assumptions made in autoconfigure scripts.

The differences between the FreeBSD version of macros like CPU_AND,
CPU_OR, etc. and the GLIBC versions was in the number of arguments:
FreeBSD used a 2-address scheme (one source argument is also used as
the destination of the operation), while GLIBC uses a 3-adderess
scheme (2 source operands and a separately passed destination).

The GLIBC scheme provides a super-set of the functionality of the
FreeBSD macros, since it does not prevent passing the same variable
as source and destination arguments. In code that wanted to preserve
both source arguments, the FreeBSD macros required a temporary copy of
one of the source arguments.

This patch set allows to unconditionally provide functions and macros
expected by 3rd party software written for GLIBC based systems, but
breaks builds of externally maintained sources that use any of the
following macros: CPU_AND, CPU_ANDNOT, CPU_OR, CPU_XOR.

One contributed driver (contrib/ofed/libmlx5) has been patched to
support both the old and the new CPU_OR signatures. If this commit
is merged to -STABLE, the version test will have to be extended to
cover more ranges.

Ports that have added -D_WITH_CPU_SET_T to build on -CURRENT do
no longer require that option.

The FreeBSD version has been bumped to 1400046 to reflect this
incompatible change.

Reviewed by:	kib
MFC after:	2 weeks
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D33451
This commit is contained in:
Stefan Eßer 2021-12-30 12:20:32 +01:00 committed by Sebastian Huber
parent 6af6e29552
commit e927f541f7
4 changed files with 15 additions and 10 deletions

View File

@ -32,7 +32,7 @@
#include <sys/cpuset.h>
#include <stdlib.h>
cpu_set_t *__cpuset_alloc(int num_cpus)
cpu_set_t *__cpuset_alloc(size_t num_cpus)
{
return (cpu_set_t *)malloc(CPU_ALLOC_SIZE(num_cpus));
}

View File

@ -1,4 +1,4 @@
/*-
#/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2008, Jeffrey Roberson <jeff@freebsd.org>
@ -49,4 +49,11 @@
__BITSET_DEFINE(_cpuset, CPU_SETSIZE);
typedef struct _cpuset cpuset_t;
#ifndef _KERNEL
__BEGIN_DECLS
cpuset_t *__cpuset_alloc(size_t set_size);
void __cpuset_free(cpuset_t *ptr);
__END_DECLS
#endif
#endif /* !_SYS__CPUSET_H_ */

View File

@ -315,8 +315,6 @@
/*
* Dynamically allocate a bitset.
*/
#define __BITSET_ALLOC(_s, mt, mf) malloc(__BITSET_SIZE((_s)), mt, (mf))
#define BIT_AND(_s, d, s) __BIT_AND(_s, d, s)
#define BIT_AND2(_s, d, s1, s2) __BIT_AND2(_s, d, s1, s2)
#define BIT_ANDNOT(_s, d, s) __BIT_ANDNOT(_s, d, s)
@ -354,7 +352,11 @@
#define BIT_XOR2(_s, d, s1, s2) __BIT_XOR2(_s, d, s1, s2)
#define BIT_ZERO(_s, p) __BIT_ZERO(_s, p)
#define BITSET_ALLOC(_s, mt, mf) __BITSET_ALLOC(_s, mt, mf)
#if defined(_KERNEL)
#define BITSET_ALLOC(_s, mt, mf) malloc(__BITSET_SIZE((_s)), mt, (mf))
#define BITSET_FREE(p, mt) free(p, mt)
#endif /* _KERNEL */
#define BITSET_FSET(n) __BITSET_FSET(n)
#define BITSET_SIZE(_s) __BITSET_SIZE(_s)
#define BITSET_T_INITIALIZER(x) __BITSET_T_INITIALIZER(x)

View File

@ -71,14 +71,10 @@ typedef cpuset_t cpu_set_t;
#define _cpu_set_bits(_setsize) (8 * (_setsize))
#define CPU_ALLOC_SIZE(_num_cpus) (sizeof(long) * __bitset_words(_num_cpus))
#define CPU_ALLOC_SIZE(_s) __BITSET_SIZE(_s)
__BEGIN_DECLS
cpu_set_t *__cpuset_alloc(int num_cpus);
void __cpuset_free(cpu_set_t *set);
static __inline cpu_set_t *CPU_ALLOC(int num_cpus)
{
return __cpuset_alloc(num_cpus);