]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | /* Copyright (C) 2005-2022 Free Software Foundation, Inc. |
953ff289 DN |
2 | Contributed by Richard Henderson <rth@redhat.com>. |
3 | ||
f1f3453e TS |
4 | This file is part of the GNU Offloading and Multi Processing Library |
5 | (libgomp). | |
953ff289 DN |
6 | |
7 | Libgomp is free software; you can redistribute it and/or modify it | |
748086b7 JJ |
8 | under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 3, or (at your option) | |
10 | any later version. | |
953ff289 DN |
11 | |
12 | Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
748086b7 | 14 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
953ff289 DN |
15 | more details. |
16 | ||
748086b7 JJ |
17 | Under Section 7 of GPL version 3, you are granted additional |
18 | permissions described in the GCC Runtime Library Exception, version | |
19 | 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | You should have received a copy of the GNU General Public License and | |
22 | a copy of the GCC Runtime Library Exception along with this program; | |
23 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | <http://www.gnu.org/licenses/>. */ | |
953ff289 DN |
25 | |
26 | /* Provide target-specific access to the futex system call. */ | |
27 | ||
c01ecafc | 28 | #ifdef __x86_64__ |
953ff289 DN |
29 | # ifndef SYS_futex |
30 | # define SYS_futex 202 | |
31 | # endif | |
32 | ||
5e40542f | 33 | static inline long |
c36ad24e | 34 | __futex_wait (int *addr, int futex_op, int val) |
953ff289 | 35 | { |
5e40542f | 36 | long res; |
953ff289 | 37 | |
c36ad24e | 38 | register void *timeout __asm ("r10") = NULL; |
953ff289 DN |
39 | __asm volatile ("syscall" |
40 | : "=a" (res) | |
c36ad24e UB |
41 | : "0" (SYS_futex), "D" (addr), "S" (futex_op), |
42 | "d" (val), "r" (timeout) | |
953ff289 | 43 | : "r11", "rcx", "memory"); |
c36ad24e | 44 | return res; |
953ff289 DN |
45 | } |
46 | ||
5e40542f | 47 | static inline long |
c36ad24e | 48 | __futex_wake (int *addr, int futex_op, int count) |
953ff289 | 49 | { |
5e40542f | 50 | long res; |
953ff289 DN |
51 | |
52 | __asm volatile ("syscall" | |
53 | : "=a" (res) | |
c36ad24e | 54 | : "0" (SYS_futex), "D" (addr), "S" (futex_op), |
a68ab351 | 55 | "d" (count) |
953ff289 | 56 | : "r11", "rcx", "memory"); |
c36ad24e | 57 | return res; |
953ff289 DN |
58 | } |
59 | #else | |
60 | # ifndef SYS_futex | |
61 | # define SYS_futex 240 | |
62 | # endif | |
63 | ||
5e40542f | 64 | static inline long |
c36ad24e UB |
65 | __futex_wait (int *addr, int futex_op, int val) |
66 | { | |
5e40542f | 67 | long res; |
c36ad24e UB |
68 | |
69 | void *timeout = NULL; | |
70 | __asm volatile ("int $0x80" | |
71 | : "=a" (res) | |
72 | : "0" (SYS_futex), "b" (addr), "c" (futex_op), | |
73 | "d" (val), "S" (timeout) | |
74 | : "memory"); | |
75 | return res; | |
76 | } | |
77 | ||
5e40542f | 78 | static inline long |
c36ad24e | 79 | __futex_wake (int *addr, int futex_op, int count) |
953ff289 | 80 | { |
5e40542f | 81 | long res; |
953ff289 DN |
82 | |
83 | __asm volatile ("int $0x80" | |
84 | : "=a" (res) | |
c36ad24e UB |
85 | : "0" (SYS_futex), "b" (addr), "c" (futex_op), |
86 | "d" (count) | |
953ff289 | 87 | : "memory"); |
c36ad24e UB |
88 | return res; |
89 | } | |
90 | #endif /* __x86_64__ */ | |
91 | ||
92 | static inline void | |
93 | futex_wait (int *addr, int val) | |
94 | { | |
5e40542f | 95 | long err = __futex_wait (addr, gomp_futex_wait, val); |
c36ad24e | 96 | |
5e40542f | 97 | if (__builtin_expect (err == -ENOSYS, 0)) |
a68ab351 JJ |
98 | { |
99 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
100 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
c36ad24e UB |
101 | |
102 | __futex_wait (addr, gomp_futex_wait, val); | |
a68ab351 | 103 | } |
953ff289 DN |
104 | } |
105 | ||
106 | static inline void | |
107 | futex_wake (int *addr, int count) | |
108 | { | |
5e40542f | 109 | long err = __futex_wake (addr, gomp_futex_wake, count); |
bb3caa35 | 110 | |
5e40542f | 111 | if (__builtin_expect (err == -ENOSYS, 0)) |
a68ab351 JJ |
112 | { |
113 | gomp_futex_wait &= ~FUTEX_PRIVATE_FLAG; | |
114 | gomp_futex_wake &= ~FUTEX_PRIVATE_FLAG; | |
c36ad24e UB |
115 | |
116 | __futex_wake (addr, gomp_futex_wake, count); | |
a68ab351 | 117 | } |
953ff289 | 118 | } |
a68ab351 JJ |
119 | |
120 | static inline void | |
121 | cpu_relax (void) | |
122 | { | |
68a12ef3 | 123 | __builtin_ia32_pause (); |
a68ab351 | 124 | } |