~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/atomic/gen-atomic-fallback.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/atomic/gen-atomic-fallback.sh (Version linux-6.12-rc7) and /scripts/atomic/gen-atomic-fallback.sh (Version linux-5.3.18)


  1 #!/bin/sh                                           1 #!/bin/sh
  2 # SPDX-License-Identifier: GPL-2.0                  2 # SPDX-License-Identifier: GPL-2.0
  3                                                     3 
  4 ATOMICDIR=$(dirname $0)                             4 ATOMICDIR=$(dirname $0)
  5                                                     5 
  6 . ${ATOMICDIR}/atomic-tbl.sh                        6 . ${ATOMICDIR}/atomic-tbl.sh
  7                                                     7 
  8 #gen_template_fallback(template, meta, pfx, na      8 #gen_template_fallback(template, meta, pfx, name, sfx, order, atomic, int, args...)
  9 gen_template_fallback()                             9 gen_template_fallback()
 10 {                                                  10 {
 11         local template="$1"; shift                 11         local template="$1"; shift
 12         local meta="$1"; shift                     12         local meta="$1"; shift
 13         local pfx="$1"; shift                      13         local pfx="$1"; shift
 14         local name="$1"; shift                     14         local name="$1"; shift
 15         local sfx="$1"; shift                      15         local sfx="$1"; shift
 16         local order="$1"; shift                    16         local order="$1"; shift
 17         local atomic="$1"; shift                   17         local atomic="$1"; shift
 18         local int="$1"; shift                      18         local int="$1"; shift
 19                                                    19 
                                                   >>  20         local atomicname="${atomic}_${pfx}${name}${sfx}${order}"
                                                   >>  21 
 20         local ret="$(gen_ret_type "${meta}" "$     22         local ret="$(gen_ret_type "${meta}" "${int}")"
 21         local retstmt="$(gen_ret_stmt "${meta}     23         local retstmt="$(gen_ret_stmt "${meta}")"
 22         local params="$(gen_params "${int}" "$     24         local params="$(gen_params "${int}" "${atomic}" "$@")"
 23         local args="$(gen_args "$@")"              25         local args="$(gen_args "$@")"
 24                                                    26 
 25         . ${template}                          !!  27         if [ ! -z "${template}" ]; then
 26 }                                              !!  28                 printf "#ifndef ${atomicname}\n"
 27                                                !!  29                 . ${template}
 28 #gen_order_fallback(meta, pfx, name, sfx, orde !!  30                 printf "#define ${atomicname} ${atomicname}\n"
 29 gen_order_fallback()                           !!  31                 printf "#endif\n\n"
 30 {                                              !!  32         fi
 31         local meta="$1"; shift                 << 
 32         local pfx="$1"; shift                  << 
 33         local name="$1"; shift                 << 
 34         local sfx="$1"; shift                  << 
 35         local order="$1"; shift                << 
 36                                                << 
 37         local tmpl_order=${order#_}            << 
 38         local tmpl="${ATOMICDIR}/fallbacks/${t << 
 39         gen_template_fallback "${tmpl}" "${met << 
 40 }                                                  33 }
 41                                                    34 
 42 #gen_proto_fallback(meta, pfx, name, sfx, orde     35 #gen_proto_fallback(meta, pfx, name, sfx, order, atomic, int, args...)
 43 gen_proto_fallback()                               36 gen_proto_fallback()
 44 {                                                  37 {
 45         local meta="$1"; shift                     38         local meta="$1"; shift
 46         local pfx="$1"; shift                      39         local pfx="$1"; shift
 47         local name="$1"; shift                     40         local name="$1"; shift
 48         local sfx="$1"; shift                      41         local sfx="$1"; shift
 49         local order="$1"; shift                    42         local order="$1"; shift
 50                                                    43 
 51         local tmpl="$(find_fallback_template "     44         local tmpl="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"
 52         gen_template_fallback "${tmpl}" "${met     45         gen_template_fallback "${tmpl}" "${meta}" "${pfx}" "${name}" "${sfx}" "${order}" "$@"
 53 }                                                  46 }
 54                                                    47 
 55 #gen_proto_order_variant(meta, pfx, name, sfx, !!  48 #gen_basic_fallbacks(basename)
 56 gen_proto_order_variant()                      !!  49 gen_basic_fallbacks()
                                                   >>  50 {
                                                   >>  51         local basename="$1"; shift
                                                   >>  52 cat << EOF
                                                   >>  53 #define ${basename}_acquire ${basename}
                                                   >>  54 #define ${basename}_release ${basename}
                                                   >>  55 #define ${basename}_relaxed ${basename}
                                                   >>  56 EOF
                                                   >>  57 }
                                                   >>  58 
                                                   >>  59 #gen_proto_order_variants(meta, pfx, name, sfx, atomic, int, args...)
                                                   >>  60 gen_proto_order_variants()
 57 {                                                  61 {
 58         local meta="$1"; shift                     62         local meta="$1"; shift
 59         local pfx="$1"; shift                      63         local pfx="$1"; shift
 60         local name="$1"; shift                     64         local name="$1"; shift
 61         local sfx="$1"; shift                      65         local sfx="$1"; shift
 62         local order="$1"; shift                !!  66         local atomic="$1"
 63         local atomic="$1"; shift               << 
 64         local int="$1"; shift                  << 
 65                                                    67 
 66         local atomicname="${atomic}_${pfx}${na << 
 67         local basename="${atomic}_${pfx}${name     68         local basename="${atomic}_${pfx}${name}${sfx}"
 68                                                    69 
 69         local template="$(find_fallback_templa     70         local template="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"
 70                                                    71 
 71         local ret="$(gen_ret_type "${meta}" "$ !!  72         # If we don't have relaxed atomics, then we don't bother with ordering fallbacks
 72         local retstmt="$(gen_ret_stmt "${meta} !!  73         # read_acquire and set_release need to be templated, though
 73         local params="$(gen_params "${int}" "$ !!  74         if ! meta_has_relaxed "${meta}"; then
 74         local args="$(gen_args "$@")"          !!  75                 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
 75                                                !!  76 
 76         gen_kerneldoc "raw_" "${meta}" "${pfx} !!  77                 if meta_has_acquire "${meta}"; then
                                                   >>  78                         gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
                                                   >>  79                 fi
                                                   >>  80 
                                                   >>  81                 if meta_has_release "${meta}"; then
                                                   >>  82                         gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
                                                   >>  83                 fi
 77                                                    84 
 78         printf "static __always_inline ${ret}\ << 
 79         printf "raw_${atomicname}(${params})\n << 
 80         printf "{\n"                           << 
 81                                                << 
 82         # Where there is no possible fallback, << 
 83         # and must be provided by arch code. A << 
 84         # make this obvious.                   << 
 85         #                                      << 
 86         # Ideally we'd error on a missing defi << 
 87         # define this order variant as a C fun << 
 88         # symbol.                              << 
 89         if [ -z ${template} ] && [ -z "${order << 
 90                 printf "\t${retstmt}arch_${ato << 
 91                 printf "}\n\n"                 << 
 92                 return                             85                 return
 93         fi                                         86         fi
 94                                                    87 
 95         printf "#if defined(arch_${atomicname} !!  88         printf "#ifndef ${basename}_relaxed\n"
 96         printf "\t${retstmt}arch_${atomicname} << 
 97                                                << 
 98         # Allow FULL/ACQUIRE/RELEASE ops to be << 
 99         if [ "${order}" != "_relaxed" ] && met << 
100                 printf "#elif defined(arch_${b << 
101                 gen_order_fallback "${meta}" " << 
102         fi                                     << 
103                                                << 
104         # Allow ACQUIRE/RELEASE/RELAXED ops to << 
105         if [ ! -z "${order}" ] && ! meta_is_im << 
106                 printf "#elif defined(arch_${b << 
107                 printf "\t${retstmt}arch_${bas << 
108         fi                                     << 
109                                                    89 
110         printf "#else\n"                       << 
111         if [ ! -z "${template}" ]; then            90         if [ ! -z "${template}" ]; then
112                 gen_proto_fallback "${meta}" " !!  91                 printf "#ifdef ${basename}\n"
113         else                                   << 
114                 printf "#error \"Unable to def << 
115         fi                                         92         fi
116                                                    93 
117         printf "#endif\n"                      !!  94         gen_basic_fallbacks "${basename}"
118         printf "}\n\n"                         << 
119 }                                              << 
120                                                << 
121                                                    95 
122 #gen_proto_order_variants(meta, pfx, name, sfx !!  96         if [ ! -z "${template}" ]; then
123 gen_proto_order_variants()                     !!  97                 printf "#endif /* ${atomic}_${pfx}${name}${sfx} */\n\n"
124 {                                              !!  98                 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
125         local meta="$1"; shift                 !!  99                 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
126         local pfx="$1"; shift                  !! 100                 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
127         local name="$1"; shift                 !! 101                 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@"
128         local sfx="$1"; shift                  << 
129         local atomic="$1"                      << 
130                                                << 
131         gen_proto_order_variant "${meta}" "${p << 
132                                                << 
133         if meta_has_acquire "${meta}"; then    << 
134                 gen_proto_order_variant "${met << 
135         fi                                        102         fi
136                                                   103 
137         if meta_has_release "${meta}"; then    !! 104         printf "#else /* ${basename}_relaxed */\n\n"
138                 gen_proto_order_variant "${met << 
139         fi                                     << 
140                                                   105 
141         if meta_has_relaxed "${meta}"; then    !! 106         gen_template_fallback "${ATOMICDIR}/fallbacks/acquire"  "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
142                 gen_proto_order_variant "${met !! 107         gen_template_fallback "${ATOMICDIR}/fallbacks/release"  "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
143         fi                                     !! 108         gen_template_fallback "${ATOMICDIR}/fallbacks/fence"  "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
144 }                                              << 
145                                                   109 
146 #gen_basic_fallbacks(basename)                 !! 110         printf "#endif /* ${basename}_relaxed */\n\n"
147 gen_basic_fallbacks()                          << 
148 {                                              << 
149         local basename="$1"; shift             << 
150 cat << EOF                                     << 
151 #define raw_${basename}_acquire arch_${basenam << 
152 #define raw_${basename}_release arch_${basenam << 
153 #define raw_${basename}_relaxed arch_${basenam << 
154 EOF                                            << 
155 }                                                 111 }
156                                                   112 
157 gen_order_fallbacks()                          !! 113 gen_xchg_fallbacks()
158 {                                                 114 {
159         local xchg="$1"; shift                    115         local xchg="$1"; shift
160                                                << 
161 cat <<EOF                                         116 cat <<EOF
162                                                !! 117 #ifndef ${xchg}_relaxed
163 #define raw_${xchg}_relaxed arch_${xchg}_relax !! 118 #define ${xchg}_relaxed         ${xchg}
164                                                !! 119 #define ${xchg}_acquire         ${xchg}
165 #ifdef arch_${xchg}_acquire                    !! 120 #define ${xchg}_release         ${xchg}
166 #define raw_${xchg}_acquire arch_${xchg}_acqui !! 121 #else /* ${xchg}_relaxed */
167 #else                                          !! 122 
168 #define raw_${xchg}_acquire(...) \\            !! 123 #ifndef ${xchg}_acquire
169         __atomic_op_acquire(arch_${xchg}, __VA !! 124 #define ${xchg}_acquire(...) \\
                                                   >> 125         __atomic_op_acquire(${xchg}, __VA_ARGS__)
170 #endif                                            126 #endif
171                                                   127 
172 #ifdef arch_${xchg}_release                    !! 128 #ifndef ${xchg}_release
173 #define raw_${xchg}_release arch_${xchg}_relea !! 129 #define ${xchg}_release(...) \\
174 #else                                          !! 130         __atomic_op_release(${xchg}, __VA_ARGS__)
175 #define raw_${xchg}_release(...) \\            << 
176         __atomic_op_release(arch_${xchg}, __VA << 
177 #endif                                            131 #endif
178                                                   132 
179 #ifdef arch_${xchg}                            !! 133 #ifndef ${xchg}
180 #define raw_${xchg} arch_${xchg}               !! 134 #define ${xchg}(...) \\
181 #else                                          !! 135         __atomic_op_fence(${xchg}, __VA_ARGS__)
182 #define raw_${xchg}(...) \\                    << 
183         __atomic_op_fence(arch_${xchg}, __VA_A << 
184 #endif                                            136 #endif
185                                                   137 
186 EOF                                            !! 138 #endif /* ${xchg}_relaxed */
187 }                                              << 
188                                                << 
189 gen_xchg_order_fallback()                      << 
190 {                                              << 
191         local xchg="$1"; shift                 << 
192         local order="$1"; shift                << 
193         local forder="${order:-_fence}"        << 
194                                                << 
195         printf "#if defined(arch_${xchg}${orde << 
196         printf "#define raw_${xchg}${order} ar << 
197                                                << 
198         if [ "${order}" != "_relaxed" ]; then  << 
199                 printf "#elif defined(arch_${x << 
200                 printf "#define raw_${xchg}${o << 
201                 printf "        __atomic_op${f << 
202         fi                                     << 
203                                                << 
204         if [ ! -z "${order}" ]; then           << 
205                 printf "#elif defined(arch_${x << 
206                 printf "#define raw_${xchg}${o << 
207         fi                                     << 
208                                                << 
209         printf "#else\n"                       << 
210         printf "extern void raw_${xchg}${order << 
211         printf "#define raw_${xchg}${order}(.. << 
212         printf "#endif\n\n"                    << 
213 }                                              << 
214                                                << 
215 gen_xchg_fallbacks()                           << 
216 {                                              << 
217         local xchg="$1"; shift                 << 
218                                                << 
219         for order in "" "_acquire" "_release"  << 
220                 gen_xchg_order_fallback "${xch << 
221         done                                   << 
222 }                                              << 
223                                                << 
224 gen_try_cmpxchg_fallback()                     << 
225 {                                              << 
226         local prefix="$1"; shift               << 
227         local cmpxchg="$1"; shift;             << 
228         local suffix="$1"; shift;              << 
229                                                   139 
230 cat <<EOF                                      << 
231 #define raw_${prefix}try_${cmpxchg}${suffix}(_ << 
232 ({ \\                                          << 
233         typeof(*(_ptr)) *___op = (_oldp), ___o << 
234         ___r = raw_${prefix}${cmpxchg}${suffix << 
235         if (unlikely(___r != ___o)) \\         << 
236                 *___op = ___r; \\              << 
237         likely(___r == ___o); \\               << 
238 })                                             << 
239 EOF                                               140 EOF
240 }                                                 141 }
241                                                   142 
242 gen_try_cmpxchg_order_fallback()               << 
243 {                                              << 
244         local cmpxchg="$1"; shift              << 
245         local order="$1"; shift                << 
246         local forder="${order:-_fence}"        << 
247                                                << 
248         printf "#if defined(arch_try_${cmpxchg << 
249         printf "#define raw_try_${cmpxchg}${or << 
250                                                << 
251         if [ "${order}" != "_relaxed" ]; then  << 
252                 printf "#elif defined(arch_try << 
253                 printf "#define raw_try_${cmpx << 
254                 printf "        __atomic_op${f << 
255         fi                                     << 
256                                                << 
257         if [ ! -z "${order}" ]; then           << 
258                 printf "#elif defined(arch_try << 
259                 printf "#define raw_try_${cmpx << 
260         fi                                     << 
261                                                << 
262         printf "#else\n"                       << 
263         gen_try_cmpxchg_fallback "" "${cmpxchg << 
264         printf "#endif\n\n"                    << 
265 }                                              << 
266                                                << 
267 gen_try_cmpxchg_order_fallbacks()              << 
268 {                                              << 
269         local cmpxchg="$1"; shift;             << 
270                                                << 
271         for order in "" "_acquire" "_release"  << 
272                 gen_try_cmpxchg_order_fallback << 
273         done                                   << 
274 }                                              << 
275                                                << 
276 gen_def_and_try_cmpxchg_fallback()             << 
277 {                                              << 
278         local prefix="$1"; shift               << 
279         local cmpxchg="$1"; shift              << 
280         local suffix="$1"; shift               << 
281                                                << 
282         printf "#define raw_${prefix}${cmpxchg << 
283         printf "#ifdef arch_${prefix}try_${cmp << 
284         printf "#define raw_${prefix}try_${cmp << 
285         printf "#else\n"                       << 
286         gen_try_cmpxchg_fallback "${prefix}" " << 
287         printf "#endif\n\n"                    << 
288 }                                              << 
289                                                << 
290 cat << EOF                                        143 cat << EOF
291 // SPDX-License-Identifier: GPL-2.0               144 // SPDX-License-Identifier: GPL-2.0
292                                                   145 
293 // Generated by $0                                146 // Generated by $0
294 // DO NOT MODIFY THIS FILE DIRECTLY               147 // DO NOT MODIFY THIS FILE DIRECTLY
295                                                   148 
296 #ifndef _LINUX_ATOMIC_FALLBACK_H                  149 #ifndef _LINUX_ATOMIC_FALLBACK_H
297 #define _LINUX_ATOMIC_FALLBACK_H                  150 #define _LINUX_ATOMIC_FALLBACK_H
298                                                   151 
299 #include <linux/compiler.h>                    << 
300                                                << 
301 EOF                                               152 EOF
302                                                   153 
303 for xchg in "xchg" "cmpxchg" "cmpxchg64" "cmpx !! 154 for xchg in "xchg" "cmpxchg" "cmpxchg64"; do
304         gen_xchg_fallbacks "${xchg}"              155         gen_xchg_fallbacks "${xchg}"
305 done                                              156 done
306                                                   157 
307 for cmpxchg in "cmpxchg" "cmpxchg64" "cmpxchg1 << 
308         gen_try_cmpxchg_order_fallbacks "${cmp << 
309 done                                           << 
310                                                << 
311 for cmpxchg in "cmpxchg" "cmpxchg64" "cmpxchg1 << 
312         gen_def_and_try_cmpxchg_fallback "" "$ << 
313 done                                           << 
314                                                << 
315 for cmpxchg in "cmpxchg"; do                   << 
316         gen_def_and_try_cmpxchg_fallback "sync << 
317 done                                           << 
318                                                << 
319 grep '^[a-z]' "$1" | while read name meta args    158 grep '^[a-z]' "$1" | while read name meta args; do
320         gen_proto "${meta}" "${name}" "atomic"    159         gen_proto "${meta}" "${name}" "atomic" "int" ${args}
321 done                                              160 done
322                                                   161 
323 cat <<EOF                                         162 cat <<EOF
                                                   >> 163 #define atomic_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))
                                                   >> 164 #define atomic_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))
                                                   >> 165 
324 #ifdef CONFIG_GENERIC_ATOMIC64                    166 #ifdef CONFIG_GENERIC_ATOMIC64
325 #include <asm-generic/atomic64.h>                 167 #include <asm-generic/atomic64.h>
326 #endif                                            168 #endif
327                                                   169 
328 EOF                                               170 EOF
329                                                   171 
330 grep '^[a-z]' "$1" | while read name meta args    172 grep '^[a-z]' "$1" | while read name meta args; do
331         gen_proto "${meta}" "${name}" "atomic6    173         gen_proto "${meta}" "${name}" "atomic64" "s64" ${args}
332 done                                              174 done
333                                                   175 
334 cat <<EOF                                         176 cat <<EOF
                                                   >> 177 #define atomic64_cond_read_acquire(v, c) smp_cond_load_acquire(&(v)->counter, (c))
                                                   >> 178 #define atomic64_cond_read_relaxed(v, c) smp_cond_load_relaxed(&(v)->counter, (c))
                                                   >> 179 
335 #endif /* _LINUX_ATOMIC_FALLBACK_H */             180 #endif /* _LINUX_ATOMIC_FALLBACK_H */
336 EOF                                               181 EOF
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php