xref: /freebsd/sys/contrib/ck/include/ck_md.h (revision bc02c18c486fce2ca23b428a9e89b4eb3bb48da3)
15ac7aafeSOlivier Houchard /*
2*271ce402SOlivier Houchard  * Copyright 2018 Samy Al Bahra.
35ac7aafeSOlivier Houchard  * All rights reserved.
45ac7aafeSOlivier Houchard  *
55ac7aafeSOlivier Houchard  * Redistribution and use in source and binary forms, with or without
65ac7aafeSOlivier Houchard  * modification, are permitted provided that the following conditions
75ac7aafeSOlivier Houchard  * are met:
85ac7aafeSOlivier Houchard  * 1. Redistributions of source code must retain the above copyright
95ac7aafeSOlivier Houchard  *    notice, this list of conditions and the following disclaimer.
105ac7aafeSOlivier Houchard  * 2. Redistributions in binary form must reproduce the above copyright
115ac7aafeSOlivier Houchard  *    notice, this list of conditions and the following disclaimer in the
125ac7aafeSOlivier Houchard  *    documentation and/or other materials provided with the distribution.
135ac7aafeSOlivier Houchard  *
145ac7aafeSOlivier Houchard  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
155ac7aafeSOlivier Houchard  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
165ac7aafeSOlivier Houchard  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
175ac7aafeSOlivier Houchard  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
185ac7aafeSOlivier Houchard  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
195ac7aafeSOlivier Houchard  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
205ac7aafeSOlivier Houchard  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
215ac7aafeSOlivier Houchard  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
225ac7aafeSOlivier Houchard  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
235ac7aafeSOlivier Houchard  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
245ac7aafeSOlivier Houchard  * SUCH DAMAGE.
255ac7aafeSOlivier Houchard  *
26*271ce402SOlivier Houchard  * $FreeBSD: head/sys/contrib/ck/include/ck_md.h 329388 2018-02-16 17:50:06Z cog
27*271ce402SOlivier Houchard net $
28*271ce402SOlivier Houchard  */
29*271ce402SOlivier Houchard 
30*271ce402SOlivier Houchard /*
31*271ce402SOlivier Houchard  * This header file is meant for use of Concurrency Kit in the FreeBSD kernel.
325ac7aafeSOlivier Houchard  */
335ac7aafeSOlivier Houchard 
345ac7aafeSOlivier Houchard #ifndef CK_MD_H
355ac7aafeSOlivier Houchard #define CK_MD_H
365ac7aafeSOlivier Houchard 
37*271ce402SOlivier Houchard #include <sys/param.h>
38*271ce402SOlivier Houchard 
39*271ce402SOlivier Houchard #ifndef _KERNEL
40*271ce402SOlivier Houchard #error This header file is meant for the FreeBSD kernel.
41*271ce402SOlivier Houchard #endif /* _KERNEL */
42*271ce402SOlivier Houchard 
435ac7aafeSOlivier Houchard #ifndef CK_MD_CACHELINE
44*271ce402SOlivier Houchard /*
45*271ce402SOlivier Houchard  * FreeBSD's CACHE_LINE macro is a compile-time maximum cache-line size for an
46*271ce402SOlivier Houchard  * architecture, defined to be 128 bytes by default on x86*. Even in presence
47*271ce402SOlivier Houchard  * of adjacent sector prefetch, this doesn't make sense from a modeling
48*271ce402SOlivier Houchard  * perspective.
49*271ce402SOlivier Houchard  */
50*271ce402SOlivier Houchard #if defined(__amd64__) || defined(__i386__)
515ac7aafeSOlivier Houchard #define CK_MD_CACHELINE (64)
52*271ce402SOlivier Houchard #else
53*271ce402SOlivier Houchard #define CK_MD_CACHELINE	(CACHE_LINE_SIZE)
54*271ce402SOlivier Houchard #endif /* !__amd64__ && !__i386__ */
55*271ce402SOlivier Houchard #endif /* CK_MD_CACHELINE */
565ac7aafeSOlivier Houchard 
575ac7aafeSOlivier Houchard #ifndef CK_MD_PAGESIZE
58*271ce402SOlivier Houchard #define CK_MD_PAGESIZE (PAGE_SIZE)
595ac7aafeSOlivier Houchard #endif
605ac7aafeSOlivier Houchard 
61*271ce402SOlivier Houchard /*
62*271ce402SOlivier Houchard  * Once FreeBSD has a mechanism to detect RTM, this can be enabled and RTM
63*271ce402SOlivier Houchard  * facilities can be called. These facilities refer to TSX.
64*271ce402SOlivier Houchard  */
655ac7aafeSOlivier Houchard #ifndef CK_MD_RTM_DISABLE
665ac7aafeSOlivier Houchard #define CK_MD_RTM_DISABLE
675ac7aafeSOlivier Houchard #endif /* CK_MD_RTM_DISABLE */
685ac7aafeSOlivier Houchard 
69*271ce402SOlivier Houchard /*
70*271ce402SOlivier Houchard  * Do not enable pointer-packing-related (VMA) optimizations in kernel-space.
71*271ce402SOlivier Houchard  */
725ac7aafeSOlivier Houchard #ifndef CK_MD_POINTER_PACK_DISABLE
735ac7aafeSOlivier Houchard #define CK_MD_POINTER_PACK_DISABLE
745ac7aafeSOlivier Houchard #endif /* CK_MD_POINTER_PACK_DISABLE */
755ac7aafeSOlivier Houchard 
76*271ce402SOlivier Houchard /*
77*271ce402SOlivier Houchard  * The following would be used for pointer-packing tricks, disabled for the
78*271ce402SOlivier Houchard  * kernel.
79*271ce402SOlivier Houchard  */
805ac7aafeSOlivier Houchard #ifndef CK_MD_VMA_BITS_UNKNOWN
815ac7aafeSOlivier Houchard #define CK_MD_VMA_BITS_UNKNOWN
825ac7aafeSOlivier Houchard #endif /* CK_MD_VMA_BITS_UNKNOWN */
835ac7aafeSOlivier Houchard 
84*271ce402SOlivier Houchard /*
85*271ce402SOlivier Houchard  * Do not enable double operations in kernel-space.
86*271ce402SOlivier Houchard  */
878f87df16SOlivier Houchard #ifndef CK_PR_DISABLE_DOUBLE
888f87df16SOlivier Houchard #define CK_PR_DISABLE_DOUBLE
898f87df16SOlivier Houchard #endif /* CK_PR_DISABLE_DOUBLE */
908f87df16SOlivier Houchard 
91*271ce402SOlivier Houchard /*
92*271ce402SOlivier Houchard  * If building for a uni-processor target, then enable the uniprocessor
93*271ce402SOlivier Houchard  * feature flag. This, among other things, will remove the lock prefix.
94*271ce402SOlivier Houchard  */
95*271ce402SOlivier Houchard #ifndef SMP
96*271ce402SOlivier Houchard #define CK_MD_UMP
97*271ce402SOlivier Houchard #endif /* SMP */
98*271ce402SOlivier Houchard 
99*271ce402SOlivier Houchard /*
100*271ce402SOlivier Houchard  * Disable the use of compiler builtin functions.
101*271ce402SOlivier Houchard  */
102*271ce402SOlivier Houchard #define CK_MD_CC_BUILTIN_DISABLE 1
1035ac7aafeSOlivier Houchard 
1045ac7aafeSOlivier Houchard /*
1055ac7aafeSOlivier Houchard  * CK expects those, which are normally defined by the build system.
1065ac7aafeSOlivier Houchard  */
1075ac7aafeSOlivier Houchard #if defined(__i386__) && !defined(__x86__)
1085ac7aafeSOlivier Houchard #define __x86__
109*271ce402SOlivier Houchard /*
110*271ce402SOlivier Houchard  * If x86 becomes more relevant, we may want to consider importing in
111*271ce402SOlivier Houchard  * __mbk() to avoid potential issues around false sharing.
112*271ce402SOlivier Houchard  */
113a72c9dc5SOlivier Houchard #define CK_MD_TSO
114*271ce402SOlivier Houchard #define CK_MD_SSE_DISABLE 1
115a72c9dc5SOlivier Houchard #elif defined(__amd64__)
116a72c9dc5SOlivier Houchard #define CK_MD_TSO
1175ac7aafeSOlivier Houchard #elif defined(__powerpc64__) && !defined(__ppc64__)
1185ac7aafeSOlivier Houchard #define __ppc64__
1195ac7aafeSOlivier Houchard #elif defined(__powerpc__) && !defined(__ppc__)
1205ac7aafeSOlivier Houchard #define __ppc__
1215ac7aafeSOlivier Houchard #endif
122a72c9dc5SOlivier Houchard 
123*271ce402SOlivier Houchard /* If no memory model has been defined, assume RMO. */
124a72c9dc5SOlivier Houchard #if !defined(CK_MD_RMO) && !defined(CK_MD_TSO) && !defined(CK_MD_PSO)
125a72c9dc5SOlivier Houchard #define CK_MD_RMO
126a72c9dc5SOlivier Houchard #endif
127a72c9dc5SOlivier Houchard 
128*271ce402SOlivier Houchard #define CK_VERSION "0.7.0"
129*271ce402SOlivier Houchard #define CK_GIT_SHA "db5db44"
130*271ce402SOlivier Houchard 
1315ac7aafeSOlivier Houchard #endif /* CK_MD_H */
132