git: 24a7d1392823 - stable/13 - cpuset: Adapt sched_affinity compat shims to the stable/13

From: Dmitry Chagin <dchagin_at_FreeBSD.org>
Date: Mon, 20 Feb 2023 17:29:02 UTC
The branch stable/13 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=24a7d13928234ff989bdbf8a5f1397b94f086bdd

commit 24a7d13928234ff989bdbf8a5f1397b94f086bdd
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-02-20 17:28:36 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-02-20 17:28:36 +0000

    cpuset: Adapt sched_affinity compat shims to the stable/13
    
    Use compat shims to run the stable/13 world on a kernels which
    does not support CPU_WHICH_TIDPID.
    
    This is direct commit to the stable/13.
    
    Reviewed by:            kib
    Differential Revision:  https://reviews.freebsd.org/D38677
---
 lib/libc/gen/sched_getaffinity.c | 6 ++++--
 lib/libc/gen/sched_setaffinity.c | 6 ++++--
 sys/sys/param.h                  | 1 +
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/lib/libc/gen/sched_getaffinity.c b/lib/libc/gen/sched_getaffinity.c
index fce47fbfc0d2..0275a2190afa 100644
--- a/lib/libc/gen/sched_getaffinity.c
+++ b/lib/libc/gen/sched_getaffinity.c
@@ -38,9 +38,11 @@ int
 sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset)
 {
 	cpuwhich_t which;
-	int error;
+	int error, osrel;
 
-	if (__getosreldate() < P_OSREL_TIDPID) {
+	osrel = __getosreldate();
+	if (osrel < P_OSREL_TIDPID_13 || (osrel < P_OSREL_TIDPID &&
+	    P_OSREL_MAJOR(osrel) == P_OSREL_MAJOR(P_OSREL_TIDPID))) {
 		if (pid == 0 || pid > _PID_MAX)
 			which = CPU_WHICH_TID;
 		else
diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c
index b878e1affc41..7fbebbfe6b6e 100644
--- a/lib/libc/gen/sched_setaffinity.c
+++ b/lib/libc/gen/sched_setaffinity.c
@@ -41,10 +41,12 @@ sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset)
 	static int mp_maxid;
 	cpuwhich_t which;
 	cpuset_t c;
-	int error, lbs, cpu;
+	int error, lbs, cpu, osrel;
 	size_t len, sz;
 
-	if (__getosreldate() < P_OSREL_TIDPID) {
+        osrel = __getosreldate();
+	if (osrel < P_OSREL_TIDPID_13 || (osrel < P_OSREL_TIDPID &&
+	    P_OSREL_MAJOR(osrel) == P_OSREL_MAJOR(P_OSREL_TIDPID))) {
 		if (pid == 0 || pid > _PID_MAX)
 			which = CPU_WHICH_TID;
 		else
diff --git a/sys/sys/param.h b/sys/sys/param.h
index d2fbad6c127b..6c95088e783d 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -92,6 +92,7 @@
 #define	P_OSREL_CK_INODE		1300005
 #define	P_OSREL_POWERPC_NEW_AUX_ARGS	1300070
 #define	P_OSREL_TIDPID			1400079
+#define	P_OSREL_TIDPID_13		1302501
 
 #define	P_OSREL_MAJOR(x)		((x) / 100000)
 #endif