Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F168944056
D58580.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D58580.id.diff
View Options
diff --git a/sys/sys/_atomic_subword.h b/sys/sys/_atomic_subword.h
--- a/sys/sys/_atomic_subword.h
+++ b/sys/sys/_atomic_subword.h
@@ -201,21 +201,42 @@
}
#endif
-#undef _ATOMIC_WORD_ALIGNED
-#undef _ATOMIC_BYTE_SHIFT
-#undef _ATOMIC_HWORD_SHIFT
+#ifndef atomic_set_8
+static __inline void
+atomic_set_8(volatile uint8_t *p, uint8_t bit)
+{
+ uint32_t *addr;
+ int shift;
+
+ addr = _ATOMIC_WORD_ALIGNED(p);
+ shift = _ATOMIC_BYTE_SHIFT(p);
+ atomic_set_32(addr, (uint32_t)bit << shift);
+}
+#endif
#ifndef atomic_set_16
static __inline void
atomic_set_16(volatile uint16_t *p, uint16_t bit)
{
- uint16_t v;
+ uint32_t *addr;
+ int shift;
+
+ addr = _ATOMIC_WORD_ALIGNED(p);
+ shift = _ATOMIC_HWORD_SHIFT(p);
+ atomic_set_32(addr, (uint32_t)bit << shift);
+}
+#endif
+
+#ifndef atomic_clear_8
+static __inline void
+atomic_clear_8(volatile uint8_t *p, uint8_t bit)
+{
+ uint32_t *addr;
+ int shift;
- v = atomic_load_16(p);
- for (;;) {
- if (atomic_fcmpset_16(p, &v, v | bit))
- break;
- }
+ addr = _ATOMIC_WORD_ALIGNED(p);
+ shift = _ATOMIC_BYTE_SHIFT(p);
+ atomic_clear_32(addr, (uint32_t)bit << shift);
}
#endif
@@ -223,14 +244,17 @@
static __inline void
atomic_clear_16(volatile uint16_t *p, uint16_t bit)
{
- uint16_t v;
+ uint32_t *addr;
+ int shift;
- v = atomic_load_16(p);
- for (;;) {
- if (atomic_fcmpset_16(p, &v, v & ~bit))
- break;
- }
+ addr = _ATOMIC_WORD_ALIGNED(p);
+ shift = _ATOMIC_HWORD_SHIFT(p);
+ atomic_clear_32(addr, (uint32_t)bit << shift);
}
#endif
+#undef _ATOMIC_WORD_ALIGNED
+#undef _ATOMIC_BYTE_SHIFT
+#undef _ATOMIC_HWORD_SHIFT
+
#endif /* _SYS__ATOMIC_SUBWORD_H_ */
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c
--- a/sys/vm/vm_page.c
+++ b/sys/vm/vm_page.c
@@ -5378,67 +5378,33 @@
void
vm_page_bits_set(vm_page_t m, vm_page_bits_t *bits, vm_page_bits_t set)
{
-
#if PAGE_SIZE == 32768
atomic_set_64((uint64_t *)bits, set);
#elif PAGE_SIZE == 16384
atomic_set_32((uint32_t *)bits, set);
-#elif (PAGE_SIZE == 8192) && defined(atomic_set_16)
+#elif PAGE_SIZE == 8192
atomic_set_16((uint16_t *)bits, set);
-#elif (PAGE_SIZE == 4096) && defined(atomic_set_8)
+#elif PAGE_SIZE == 4096
atomic_set_8((uint8_t *)bits, set);
-#else /* PAGE_SIZE <= 8192 */
- uintptr_t addr;
- int shift;
-
- addr = (uintptr_t)bits;
- /*
- * Use a trick to perform a 32-bit atomic on the
- * containing aligned word, to not depend on the existence
- * of atomic_{set, clear}_{8, 16}.
- */
- shift = addr & (sizeof(uint32_t) - 1);
-#if BYTE_ORDER == BIG_ENDIAN
- shift = (sizeof(uint32_t) - sizeof(vm_page_bits_t) - shift) * NBBY;
#else
- shift *= NBBY;
+#error unhandled page size
#endif
- addr &= ~(sizeof(uint32_t) - 1);
- atomic_set_32((uint32_t *)addr, set << shift);
-#endif /* PAGE_SIZE */
}
static inline void
vm_page_bits_clear(vm_page_t m, vm_page_bits_t *bits, vm_page_bits_t clear)
{
-
#if PAGE_SIZE == 32768
atomic_clear_64((uint64_t *)bits, clear);
#elif PAGE_SIZE == 16384
atomic_clear_32((uint32_t *)bits, clear);
-#elif (PAGE_SIZE == 8192) && defined(atomic_clear_16)
+#elif PAGE_SIZE == 8192
atomic_clear_16((uint16_t *)bits, clear);
-#elif (PAGE_SIZE == 4096) && defined(atomic_clear_8)
+#elif PAGE_SIZE == 4096
atomic_clear_8((uint8_t *)bits, clear);
-#else /* PAGE_SIZE <= 8192 */
- uintptr_t addr;
- int shift;
-
- addr = (uintptr_t)bits;
- /*
- * Use a trick to perform a 32-bit atomic on the
- * containing aligned word, to not depend on the existence
- * of atomic_{set, clear}_{8, 16}.
- */
- shift = addr & (sizeof(uint32_t) - 1);
-#if BYTE_ORDER == BIG_ENDIAN
- shift = (sizeof(uint32_t) - sizeof(vm_page_bits_t) - shift) * NBBY;
#else
- shift *= NBBY;
+#error unhandled page size
#endif
- addr &= ~(sizeof(uint32_t) - 1);
- atomic_clear_32((uint32_t *)addr, clear << shift);
-#endif /* PAGE_SIZE */
}
static inline vm_page_bits_t
@@ -5456,45 +5422,21 @@
old = *bits;
while (atomic_fcmpset_32(bits, &old, newbits) == 0);
return (old);
-#elif (PAGE_SIZE == 8192) && defined(atomic_fcmpset_16)
+#elif PAGE_SIZE == 8192
uint16_t old;
old = *bits;
while (atomic_fcmpset_16(bits, &old, newbits) == 0);
return (old);
-#elif (PAGE_SIZE == 4096) && defined(atomic_fcmpset_8)
+#elif PAGE_SIZE == 4096
uint8_t old;
old = *bits;
while (atomic_fcmpset_8(bits, &old, newbits) == 0);
return (old);
-#else /* PAGE_SIZE <= 4096*/
- uintptr_t addr;
- uint32_t old, new, mask;
- int shift;
-
- addr = (uintptr_t)bits;
- /*
- * Use a trick to perform a 32-bit atomic on the
- * containing aligned word, to not depend on the existence
- * of atomic_{set, swap, clear}_{8, 16}.
- */
- shift = addr & (sizeof(uint32_t) - 1);
-#if BYTE_ORDER == BIG_ENDIAN
- shift = (sizeof(uint32_t) - sizeof(vm_page_bits_t) - shift) * NBBY;
#else
- shift *= NBBY;
+#error unhandled page size
#endif
- addr &= ~(sizeof(uint32_t) - 1);
- mask = VM_PAGE_BITS_ALL << shift;
-
- old = *bits;
- do {
- new = old & ~mask;
- new |= newbits << shift;
- } while (atomic_fcmpset_32((uint32_t *)addr, &old, new) == 0);
- return (old >> shift);
-#endif /* PAGE_SIZE */
}
/*
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Aug 31, 9:28 PM (6 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
37715520
Default Alt Text
D58580.id.diff (4 KB)
Attached To
Mode
D58580: atomic: Implement atomic_{set,clear}_8 in _atomic_subword.h
Attached
Detach File
Event Timeline
Log In to Comment