Lines Matching +full:0 +full:xa
18 * @xa is used to refer to the entire xarray.
31 static inline unsigned int xa_lock_type(const struct xarray *xa) in xa_lock_type() argument
33 return (__force unsigned int)xa->xa_flags & 3; in xa_lock_type()
56 static inline bool xa_track_free(const struct xarray *xa) in xa_track_free() argument
58 return xa->xa_flags & XA_FLAGS_TRACK_FREE; in xa_track_free()
61 static inline bool xa_zero_busy(const struct xarray *xa) in xa_zero_busy() argument
63 return xa->xa_flags & XA_FLAGS_ZERO_BUSY; in xa_zero_busy()
66 static inline void xa_mark_set(struct xarray *xa, xa_mark_t mark) in xa_mark_set() argument
68 if (!(xa->xa_flags & XA_FLAGS_MARK(mark))) in xa_mark_set()
69 xa->xa_flags |= XA_FLAGS_MARK(mark); in xa_mark_set()
72 static inline void xa_mark_clear(struct xarray *xa, xa_mark_t mark) in xa_mark_clear() argument
74 if (xa->xa_flags & XA_FLAGS_MARK(mark)) in xa_mark_clear()
75 xa->xa_flags &= ~(XA_FLAGS_MARK(mark)); in xa_mark_clear()
115 } while (0)
126 unsigned int mark = 0; in xas_squash_marks()
188 entry = xa_head(xas->xa); in xas_start()
204 void *entry = xa_entry(xas->xa, node, offset); in xas_descend()
209 entry = xa_entry(xas->xa, node, offset); in xas_descend()
241 if (node->shift == 0) in xas_load()
303 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in xas_nomem()
325 __must_hold(xas->xa->xa_lock) in __xas_nomem()
327 unsigned int lock_type = xa_lock_type(xas->xa); in __xas_nomem()
333 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in __xas_nomem()
371 if (xas->xa->xa_flags & XA_FLAGS_ACCOUNT) in xas_alloc()
390 node->count = 0; in xas_alloc()
391 node->nr_values = 0; in xas_alloc()
393 node->array = xas->xa; in xas_alloc()
409 * multi-index entry at index 0, the calculation is a little more complex
432 return 0; in max_index()
438 struct xarray *xa = xas->xa; in xas_shrink() local
447 entry = xa_entry_locked(xa, node, 0); in xas_shrink()
452 if (xa_is_zero(entry) && xa_zero_busy(xa)) in xas_shrink()
456 RCU_INIT_POINTER(xa->xa_head, entry); in xas_shrink()
457 if (xa_track_free(xa) && !node_get_mark(node, 0, XA_FREE_MARK)) in xas_shrink()
458 xa_mark_clear(xa, XA_FREE_MARK); in xas_shrink()
460 node->count = 0; in xas_shrink()
461 node->nr_values = 0; in xas_shrink()
463 RCU_INIT_POINTER(node->slots[0], XA_RETRY_ENTRY); in xas_shrink()
477 * Attempts to delete the @xas->xa_node. This will fail if xa->node has
491 parent = xa_parent_locked(xas->xa, node); in xas_delete_node()
497 xas->xa->xa_head = NULL; in xas_delete_node()
524 unsigned int offset = 0; in xas_free_nodes()
528 void *entry = xa_entry_locked(xas->xa, node, offset); in xas_free_nodes()
532 offset = 0; in xas_free_nodes()
541 parent = xa_parent_locked(xas->xa, node); in xas_free_nodes()
543 node->count = 0; in xas_free_nodes()
544 node->nr_values = 0; in xas_free_nodes()
560 struct xarray *xa = xas->xa; in xas_expand() local
562 unsigned int shift = 0; in xas_expand()
566 if (max == 0) in xas_expand()
567 return 0; in xas_expand()
578 xa_mark_t mark = 0; in xas_expand()
588 RCU_INIT_POINTER(node->slots[0], head); in xas_expand()
592 if (xa_track_free(xa) && mark == XA_FREE_MARK) { in xas_expand()
594 if (!xa_marked(xa, XA_FREE_MARK)) { in xas_expand()
595 node_clear_mark(node, 0, XA_FREE_MARK); in xas_expand()
596 xa_mark_set(xa, XA_FREE_MARK); in xas_expand()
598 } else if (xa_marked(xa, mark)) { in xas_expand()
599 node_set_mark(node, 0, mark); in xas_expand()
611 xa_to_node(head)->offset = 0; in xas_expand()
615 rcu_assign_pointer(xa->xa_head, head); in xas_expand()
640 struct xarray *xa = xas->xa; in xas_create() local
648 entry = xa_head_locked(xa); in xas_create()
650 if (!entry && xa_zero_busy(xa)) in xas_create()
653 if (shift < 0) in xas_create()
657 entry = xa_head_locked(xa); in xas_create()
658 slot = &xa->xa_head; in xas_create()
665 entry = xa_entry_locked(xa, node, offset); in xas_create()
668 shift = 0; in xas_create()
669 entry = xa_head_locked(xa); in xas_create()
670 slot = &xa->xa_head; in xas_create()
679 if (xa_track_free(xa)) in xas_create()
712 xas->xa_shift = 0; in xas_create_range()
713 xas->xa_sibs = 0; in xas_create_range()
725 xas->xa_node = xa_parent_locked(xas->xa, node); in xas_create_range()
727 if (node->offset != 0) in xas_create_range()
755 if (count < 0) in update_node()
775 void __rcu **slot = &xas->xa->xa_head; in xas_store()
777 int count = 0; in xas_store()
778 int values = 0; in xas_store()
793 xas->xa_sibs = 0; in xas_store()
832 next = xa_entry_locked(xas->xa, node, ++offset); in xas_store()
859 return xa_marked(xas->xa, mark); in xas_get_mark()
885 node = xa_parent_locked(xas->xa, node); in xas_set_mark()
888 if (!xa_marked(xas->xa, mark)) in xas_set_mark()
889 xa_mark_set(xas->xa, mark); in xas_set_mark()
917 node = xa_parent_locked(xas->xa, node); in xas_clear_mark()
920 if (xa_marked(xas->xa, mark)) in xas_clear_mark()
921 xa_mark_clear(xas->xa, mark); in xas_clear_mark()
938 xa_mark_t mark = 0; in xas_init_marks()
941 if (xa_track_free(xas->xa) && mark == XA_FREE_MARK) in xas_init_marks()
955 unsigned int marks = 0; in node_get_marks()
1020 node->array = xas->xa; in xas_split_alloc()
1021 for (i = 0; i < XA_CHUNK_SIZE; i++) { in xas_split_alloc()
1022 if ((i & mask) == 0) { in xas_split_alloc()
1031 } while (sibs-- > 0); in xas_split_alloc()
1057 int values = 0; in xas_split()
1075 XA_CHUNK_SIZE : 0; in xas_split()
1126 if (!xa_is_sibling(xa_entry(xas->xa, node, offset))) in xas_pause()
1130 if (xas->xa_index == 0) in xas_pause()
1161 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_prev()
1167 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_prev()
1200 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in __xas_next()
1206 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in __xas_next()
1258 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find()
1262 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find()
1265 xas->xa_offset = 0; in xas_find()
1317 entry = xa_head(xas->xa); in xas_find_marked()
1322 if (xa_marked(xas->xa, mark)) in xas_find_marked()
1334 xas->xa_node = xa_parent(xas->xa, xas->xa_node); in xas_find_marked()
1342 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1361 entry = xa_entry(xas->xa, xas->xa_node, xas->xa_offset); in xas_find_marked()
1362 if (!entry && !(xa_track_free(xas->xa) && mark == XA_FREE_MARK)) in xas_find_marked()
1420 xas->xa_node = xa_parent_locked(xas->xa, xas->xa_node); in xas_find_conflict()
1425 curr = xa_entry_locked(xas->xa, xas->xa_node, ++xas->xa_offset); in xas_find_conflict()
1430 xas->xa_offset = 0; in xas_find_conflict()
1431 curr = xa_entry_locked(xas->xa, xas->xa_node, 0); in xas_find_conflict()
1443 * @xa: XArray.
1447 * Return: The entry at @index in @xa.
1449 void *xa_load(struct xarray *xa, unsigned long index) in xa_load() argument
1451 XA_STATE(xas, xa, index); in xa_load()
1477 * @xa: XArray.
1487 void *__xa_erase(struct xarray *xa, unsigned long index) in __xa_erase() argument
1489 XA_STATE(xas, xa, index); in __xa_erase()
1496 * @xa: XArray.
1506 void *xa_erase(struct xarray *xa, unsigned long index) in xa_erase() argument
1510 xa_lock(xa); in xa_erase()
1511 entry = __xa_erase(xa, index); in xa_erase()
1512 xa_unlock(xa); in xa_erase()
1520 * @xa: XArray.
1533 void *__xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) in __xa_store() argument
1535 XA_STATE(xas, xa, index); in __xa_store()
1540 if (xa_track_free(xa) && !entry) in __xa_store()
1545 if (xa_track_free(xa)) in __xa_store()
1555 * @xa: XArray.
1570 void *xa_store(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) in xa_store() argument
1574 xa_lock(xa); in xa_store()
1575 curr = __xa_store(xa, index, entry, gfp); in xa_store()
1576 xa_unlock(xa); in xa_store()
1584 * @xa: XArray.
1598 void *__xa_cmpxchg(struct xarray *xa, unsigned long index, in __xa_cmpxchg() argument
1601 XA_STATE(xas, xa, index); in __xa_cmpxchg()
1611 if (xa_track_free(xa) && entry && !curr) in __xa_cmpxchg()
1622 * @xa: XArray.
1633 * Return: 0 if the store succeeded. -EBUSY if another entry was present.
1636 int __xa_insert(struct xarray *xa, unsigned long index, void *entry, gfp_t gfp) in __xa_insert() argument
1638 XA_STATE(xas, xa, index); in __xa_insert()
1650 if (xa_track_free(xa)) in __xa_insert()
1665 unsigned int shift = 0; in xas_set_range()
1671 while ((first & XA_CHUNK_MASK) == 0) { in xas_set_range()
1695 * @xa: XArray.
1711 void *xa_store_range(struct xarray *xa, unsigned long first, in xa_store_range() argument
1714 XA_STATE(xas, xa, 0); in xa_store_range()
1749 * @xa: XArray.
1752 * Return: A number between 0 and 63 indicating the order of the entry.
1754 int xa_get_order(struct xarray *xa, unsigned long index) in xa_get_order() argument
1756 XA_STATE(xas, xa, index); in xa_get_order()
1758 int order = 0; in xa_get_order()
1790 * @xa: XArray.
1796 * Finds an empty entry in @xa between @limit.min and @limit.max,
1802 * Return: 0 on success, -ENOMEM if memory could not be allocated or
1805 int __xa_alloc(struct xarray *xa, u32 *id, void *entry, in __xa_alloc() argument
1808 XA_STATE(xas, xa, 0); in __xa_alloc()
1812 if (WARN_ON_ONCE(!xa_track_free(xa))) in __xa_alloc()
1835 * @xa: XArray.
1842 * Finds an empty entry in @xa between @limit.min and @limit.max,
1850 * Return: 0 if the allocation succeeded without wrapping. 1 if the
1854 int __xa_alloc_cyclic(struct xarray *xa, u32 *id, void *entry, in __xa_alloc_cyclic() argument
1861 ret = __xa_alloc(xa, id, entry, limit, gfp); in __xa_alloc_cyclic()
1862 if ((xa->xa_flags & XA_FLAGS_ALLOC_WRAPPED) && ret == 0) { in __xa_alloc_cyclic()
1863 xa->xa_flags &= ~XA_FLAGS_ALLOC_WRAPPED; in __xa_alloc_cyclic()
1867 if (ret < 0 && limit.min > min) { in __xa_alloc_cyclic()
1869 ret = __xa_alloc(xa, id, entry, limit, gfp); in __xa_alloc_cyclic()
1870 if (ret == 0) in __xa_alloc_cyclic()
1874 if (ret >= 0) { in __xa_alloc_cyclic()
1876 if (*next == 0) in __xa_alloc_cyclic()
1877 xa->xa_flags |= XA_FLAGS_ALLOC_WRAPPED; in __xa_alloc_cyclic()
1885 * @xa: XArray.
1893 void __xa_set_mark(struct xarray *xa, unsigned long index, xa_mark_t mark) in __xa_set_mark() argument
1895 XA_STATE(xas, xa, index); in __xa_set_mark()
1905 * @xa: XArray.
1911 void __xa_clear_mark(struct xarray *xa, unsigned long index, xa_mark_t mark) in __xa_clear_mark() argument
1913 XA_STATE(xas, xa, index); in __xa_clear_mark()
1923 * @xa: XArray.
1933 bool xa_get_mark(struct xarray *xa, unsigned long index, xa_mark_t mark) in xa_get_mark() argument
1935 XA_STATE(xas, xa, index); in xa_get_mark()
1955 * @xa: XArray.
1963 void xa_set_mark(struct xarray *xa, unsigned long index, xa_mark_t mark) in xa_set_mark() argument
1965 xa_lock(xa); in xa_set_mark()
1966 __xa_set_mark(xa, index, mark); in xa_set_mark()
1967 xa_unlock(xa); in xa_set_mark()
1973 * @xa: XArray.
1981 void xa_clear_mark(struct xarray *xa, unsigned long index, xa_mark_t mark) in xa_clear_mark() argument
1983 xa_lock(xa); in xa_clear_mark()
1984 __xa_clear_mark(xa, index, mark); in xa_clear_mark()
1985 xa_unlock(xa); in xa_clear_mark()
1991 * @xa: XArray.
1996 * Finds the entry in @xa which matches the @filter, and has the lowest
2006 void *xa_find(struct xarray *xa, unsigned long *indexp, in xa_find() argument
2009 XA_STATE(xas, xa, *indexp); in xa_find()
2041 * @xa: XArray.
2046 * Finds the entry in @xa which matches the @filter and has the lowest
2056 void *xa_find_after(struct xarray *xa, unsigned long *indexp, in xa_find_after() argument
2059 XA_STATE(xas, xa, *indexp + 1); in xa_find_after()
2062 if (xas.xa_index == 0) in xa_find_after()
2091 unsigned int i = 0; in xas_extract_present()
2110 unsigned int i = 0; in xas_extract_marked()
2127 * @xa: The source XArray to copy from.
2153 unsigned int xa_extract(struct xarray *xa, void **dst, unsigned long start, in xa_extract() argument
2156 XA_STATE(xas, xa, start); in xa_extract()
2159 return 0; in xa_extract()
2177 .xa = node->array, in xa_delete_node()
2192 * @xa: XArray.
2200 void xa_destroy(struct xarray *xa) in xa_destroy() argument
2202 XA_STATE(xas, xa, 0); in xa_destroy()
2208 entry = xa_head_locked(xa); in xa_destroy()
2209 RCU_INIT_POINTER(xa->xa_head, NULL); in xa_destroy()
2211 if (xa_zero_busy(xa)) in xa_destroy()
2212 xa_mark_clear(xa, XA_FREE_MARK); in xa_destroy()
2237 for (i = 0; i < XA_MAX_MARKS; i++) in xa_dump_node()
2238 for (j = 0; j < XA_MARK_LONGS; j++) in xa_dump_node()
2248 pr_info("0-%lu: ", ~0UL); in xa_dump_index()
2261 if (shift == 0) { in xa_dump_entry()
2267 for (i = 0; i < XA_CHUNK_SIZE; i++) in xa_dump_entry()
2272 pr_cont("value %ld (0x%lx) [%px]\n", xa_to_value(entry), in xa_dump_entry()
2286 void xa_dump(const struct xarray *xa) in xa_dump() argument
2288 void *entry = xa->xa_head; in xa_dump()
2289 unsigned int shift = 0; in xa_dump()
2291 pr_info("xarray: %px head %px flags %x marks %d %d %d\n", xa, entry, in xa_dump()
2292 xa->xa_flags, xa_marked(xa, XA_MARK_0), in xa_dump()
2293 xa_marked(xa, XA_MARK_1), xa_marked(xa, XA_MARK_2)); in xa_dump()
2296 xa_dump_entry(entry, 0, shift); in xa_dump()