diff options
| author | H. Peter Anvin <hpa@zytor.com> | 2012-02-08 00:09:05 -0500 |
|---|---|---|
| committer | H. Peter Anvin <hpa@zytor.com> | 2012-02-14 15:47:21 -0500 |
| commit | 8b3d1cda4f5ff0d7c2ae910ea8fd03493996912f (patch) | |
| tree | c03be096f3e8b3205e749277d7274ec5ea95fae7 /include | |
| parent | 2759e6512e0bd9f9a84e10f59fb71195e7ff9775 (diff) | |
posix_types: Remove fd_set macros
<asm/posix_types.h> includes a set of macros that operate on file
descriptors. Way long ago those were exported to user space, but
nowadays they are #ifdef __KERNEL__.
However, they are nothing but standard (nonatomic) bit operations, and
we already have optimized versions of bit operations in the kernel.
We can't include <linux/bitops.h> in <asm/posix_types.h> but we can
move the definitions to <linux/time.h> and define them there in terms
of standard kernel bitops.
[ v2: folds the following fixes in:
a) Stray space in __FD_SET(), reported by Andrew Morton
b) #include <linux/string.h> needed for memset(), reported by Tony Luck ]
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Link: http://lkml.kernel.org/r/1328677745-20121-22-git-send-email-hpa@zytor.com
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/asm-generic/posix_types.h | 72 | ||||
| -rw-r--r-- | include/linux/time.h | 24 |
2 files changed, 24 insertions, 72 deletions
diff --git a/include/asm-generic/posix_types.h b/include/asm-generic/posix_types.h index ac217600a9c7..e294fe66125b 100644 --- a/include/asm-generic/posix_types.h +++ b/include/asm-generic/posix_types.h | |||
| @@ -92,76 +92,4 @@ typedef char * __kernel_caddr_t; | |||
| 92 | typedef unsigned short __kernel_uid16_t; | 92 | typedef unsigned short __kernel_uid16_t; |
| 93 | typedef unsigned short __kernel_gid16_t; | 93 | typedef unsigned short __kernel_gid16_t; |
| 94 | 94 | ||
| 95 | #ifdef __KERNEL__ | ||
| 96 | |||
| 97 | #undef __FD_SET | ||
| 98 | static inline void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp) | ||
| 99 | { | ||
| 100 | unsigned long __tmp = __fd / __NFDBITS; | ||
| 101 | unsigned long __rem = __fd % __NFDBITS; | ||
| 102 | __fdsetp->fds_bits[__tmp] |= (1UL<<__rem); | ||
| 103 | } | ||
| 104 | |||
| 105 | #undef __FD_CLR | ||
| 106 | static inline void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp) | ||
| 107 | { | ||
| 108 | unsigned long __tmp = __fd / __NFDBITS; | ||
| 109 | unsigned long __rem = __fd % __NFDBITS; | ||
| 110 | __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem); | ||
| 111 | } | ||
| 112 | |||
| 113 | #undef __FD_ISSET | ||
| 114 | static inline int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p) | ||
| 115 | { | ||
| 116 | unsigned long __tmp = __fd / __NFDBITS; | ||
| 117 | unsigned long __rem = __fd % __NFDBITS; | ||
| 118 | return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0; | ||
| 119 | } | ||
| 120 | |||
| 121 | /* | ||
| 122 | * This will unroll the loop for the normal constant case (8 ints, | ||
| 123 | * for a 256-bit fd_set) | ||
| 124 | */ | ||
| 125 | #undef __FD_ZERO | ||
| 126 | static inline void __FD_ZERO(__kernel_fd_set *__p) | ||
| 127 | { | ||
| 128 | unsigned long *__tmp = __p->fds_bits; | ||
| 129 | int __i; | ||
| 130 | |||
| 131 | if (__builtin_constant_p(__FDSET_LONGS)) { | ||
| 132 | switch (__FDSET_LONGS) { | ||
| 133 | case 16: | ||
| 134 | __tmp[ 0] = 0; __tmp[ 1] = 0; | ||
| 135 | __tmp[ 2] = 0; __tmp[ 3] = 0; | ||
| 136 | __tmp[ 4] = 0; __tmp[ 5] = 0; | ||
| 137 | __tmp[ 6] = 0; __tmp[ 7] = 0; | ||
| 138 | __tmp[ 8] = 0; __tmp[ 9] = 0; | ||
| 139 | __tmp[10] = 0; __tmp[11] = 0; | ||
| 140 | __tmp[12] = 0; __tmp[13] = 0; | ||
| 141 | __tmp[14] = 0; __tmp[15] = 0; | ||
| 142 | return; | ||
| 143 | |||
| 144 | case 8: | ||
| 145 | __tmp[ 0] = 0; __tmp[ 1] = 0; | ||
| 146 | __tmp[ 2] = 0; __tmp[ 3] = 0; | ||
| 147 | __tmp[ 4] = 0; __tmp[ 5] = 0; | ||
| 148 | __tmp[ 6] = 0; __tmp[ 7] = 0; | ||
| 149 | return; | ||
| 150 | |||
| 151 | case 4: | ||
| 152 | __tmp[ 0] = 0; __tmp[ 1] = 0; | ||
| 153 | __tmp[ 2] = 0; __tmp[ 3] = 0; | ||
| 154 | return; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | __i = __FDSET_LONGS; | ||
| 158 | while (__i) { | ||
| 159 | __i--; | ||
| 160 | *__tmp = 0; | ||
| 161 | __tmp++; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 165 | #endif /* __KERNEL__ */ | ||
| 166 | |||
| 167 | #endif /* __ASM_GENERIC_POSIX_TYPES_H */ | 95 | #endif /* __ASM_GENERIC_POSIX_TYPES_H */ |
diff --git a/include/linux/time.h b/include/linux/time.h index b3061782dec3..93277a0b2293 100644 --- a/include/linux/time.h +++ b/include/linux/time.h | |||
| @@ -4,8 +4,11 @@ | |||
| 4 | #include <linux/types.h> | 4 | #include <linux/types.h> |
| 5 | 5 | ||
| 6 | #ifdef __KERNEL__ | 6 | #ifdef __KERNEL__ |
| 7 | # include <linux/bitops.h> | ||
| 7 | # include <linux/cache.h> | 8 | # include <linux/cache.h> |
| 9 | # include <linux/posix_types.h> | ||
| 8 | # include <linux/seqlock.h> | 10 | # include <linux/seqlock.h> |
| 11 | # include <linux/string.h> | ||
| 9 | # include <linux/math64.h> | 12 | # include <linux/math64.h> |
| 10 | #endif | 13 | #endif |
| 11 | 14 | ||
| @@ -256,6 +259,27 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) | |||
| 256 | a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); | 259 | a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); |
| 257 | a->tv_nsec = ns; | 260 | a->tv_nsec = ns; |
| 258 | } | 261 | } |
| 262 | |||
| 263 | static inline void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp) | ||
| 264 | { | ||
| 265 | __set_bit(__fd, __fdsetp->fds_bits); | ||
| 266 | } | ||
| 267 | |||
| 268 | static inline void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp) | ||
| 269 | { | ||
| 270 | __clear_bit(__fd, __fdsetp->fds_bits); | ||
| 271 | } | ||
| 272 | |||
| 273 | static inline int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__fdsetp) | ||
| 274 | { | ||
| 275 | return test_bit(__fd, __fdsetp->fds_bits); | ||
| 276 | } | ||
| 277 | |||
| 278 | static inline void __FD_ZERO(__kernel_fd_set *__fdsetp) | ||
| 279 | { | ||
| 280 | memset(__fdsetp->fds_bits, 0, sizeof __fdsetp->fds_bits); | ||
| 281 | } | ||
| 282 | |||
| 259 | #endif /* __KERNEL__ */ | 283 | #endif /* __KERNEL__ */ |
| 260 | 284 | ||
| 261 | #define NFDBITS __NFDBITS | 285 | #define NFDBITS __NFDBITS |
