1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved. 4 */ 5 6 /* 7 * Some old libcs (like glibc < 2.7) do not provide interfaces for 8 * dynamically sized cpu sets, but provide only static cpu_set_t type 9 * with no more than CPU_SETSIZE cpus in it. 10 * 11 * This file is a wrapper of the dynamic interfaces using the static ones. 12 * 13 * If the number of cpus available on the system is greater than 14 * CPU_SETSIZE, this interface will not work. Update libc in this case :) 15 */ 16 17 #define _GNU_SOURCE 18 #include <sched.h> 19 20 #ifndef LAPI_CPUSET_H__ 21 #define LAPI_CPUSET_H__ 22 23 #ifndef CPU_ALLOC 24 #define CPU_ALLOC(ncpus) malloc(sizeof(cpu_set_t)); \ 25 if (ncpus > CPU_SETSIZE) { \ 26 tst_brk(TCONF, \ 27 "Your libc does not support masks with %ld cpus", (long)ncpus); \ 28 } 29 #endif 30 31 #ifndef CPU_FREE 32 #define CPU_FREE(ptr) free(ptr) 33 #endif 34 35 #ifndef CPU_ALLOC_SIZE 36 #define CPU_ALLOC_SIZE(size) sizeof(cpu_set_t) 37 #endif 38 39 #ifndef CPU_ZERO_S 40 #define CPU_ZERO_S(size, mask) CPU_ZERO(mask) 41 #endif 42 43 #ifndef CPU_SET_S 44 #define CPU_SET_S(cpu, size, mask) CPU_SET(cpu, mask) 45 #endif 46 47 #ifndef CPU_ISSET_S 48 #define CPU_ISSET_S(cpu, size, mask) CPU_ISSET(cpu, mask) 49 #endif 50 51 #endif /* LAPI_CPUSET_H__ */ 52