Tue Jan 28 22:20:45 2020 UTC ()
gang_lookup_scan(): if a dense scan and the first sibling doesn't match,
the scan is finished.


(ad)
diff -r1.22 -r1.23 src/common/lib/libc/gen/radixtree.c

cvs diff -r1.22 -r1.23 src/common/lib/libc/gen/radixtree.c (expand / switch to unified diff)

--- src/common/lib/libc/gen/radixtree.c 2020/01/28 16:33:34 1.22
+++ src/common/lib/libc/gen/radixtree.c 2020/01/28 22:20:45 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: radixtree.c,v 1.22 2020/01/28 16:33:34 ad Exp $ */ 1/* $NetBSD: radixtree.c,v 1.23 2020/01/28 22:20:45 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c)2011,2012,2013 YAMAMOTO Takashi, 4 * Copyright (c)2011,2012,2013 YAMAMOTO Takashi,
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -102,37 +102,37 @@ @@ -102,37 +102,37 @@
102 * leaf nodes with the given tag. To reduce amount of nodes to visit for 102 * leaf nodes with the given tag. To reduce amount of nodes to visit for
103 * these functions, this implementation keeps tagging information in internal 103 * these functions, this implementation keeps tagging information in internal
104 * intermediate nodes and quickly skips uninterested parts of a tree. 104 * intermediate nodes and quickly skips uninterested parts of a tree.
105 * 105 *
106 * A tree has RADIX_TREE_TAG_ID_MAX independent tag spaces, each of which are 106 * A tree has RADIX_TREE_TAG_ID_MAX independent tag spaces, each of which are
107 * identified by an zero-origin numbers, tagid. For the current implementation, 107 * identified by an zero-origin numbers, tagid. For the current implementation,
108 * RADIX_TREE_TAG_ID_MAX is 2. A set of tags is described as a bitmask tagmask, 108 * RADIX_TREE_TAG_ID_MAX is 2. A set of tags is described as a bitmask tagmask,
109 * which is a bitwise OR of (1 << tagid). 109 * which is a bitwise OR of (1 << tagid).
110 */ 110 */
111 111
112#include <sys/cdefs.h> 112#include <sys/cdefs.h>
113 113
114#if defined(_KERNEL) || defined(_STANDALONE) 114#if defined(_KERNEL) || defined(_STANDALONE)
115__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.22 2020/01/28 16:33:34 ad Exp $"); 115__KERNEL_RCSID(0, "$NetBSD: radixtree.c,v 1.23 2020/01/28 22:20:45 ad Exp $");
116#include <sys/param.h> 116#include <sys/param.h>
117#include <sys/errno.h> 117#include <sys/errno.h>
118#include <sys/pool.h> 118#include <sys/pool.h>
119#include <sys/radixtree.h> 119#include <sys/radixtree.h>
120#include <lib/libkern/libkern.h> 120#include <lib/libkern/libkern.h>
121#if defined(_STANDALONE) 121#if defined(_STANDALONE)
122#include <lib/libsa/stand.h> 122#include <lib/libsa/stand.h>
123#endif /* defined(_STANDALONE) */ 123#endif /* defined(_STANDALONE) */
124#else /* defined(_KERNEL) || defined(_STANDALONE) */ 124#else /* defined(_KERNEL) || defined(_STANDALONE) */
125__RCSID("$NetBSD: radixtree.c,v 1.22 2020/01/28 16:33:34 ad Exp $"); 125__RCSID("$NetBSD: radixtree.c,v 1.23 2020/01/28 22:20:45 ad Exp $");
126#include <assert.h> 126#include <assert.h>
127#include <errno.h> 127#include <errno.h>
128#include <stdbool.h> 128#include <stdbool.h>
129#include <stdlib.h> 129#include <stdlib.h>
130#include <string.h> 130#include <string.h>
131#if 1 131#if 1
132#define KASSERT assert 132#define KASSERT assert
133#else 133#else
134#define KASSERT(a) /* nothing */ 134#define KASSERT(a) /* nothing */
135#endif 135#endif
136#endif /* defined(_KERNEL) || defined(_STANDALONE) */ 136#endif /* defined(_KERNEL) || defined(_STANDALONE) */
137 137
138#include <sys/radixtree.h> 138#include <sys/radixtree.h>
@@ -833,54 +833,36 @@ gang_lookup_scan(struct radix_tree *t, s @@ -833,54 +833,36 @@ gang_lookup_scan(struct radix_tree *t, s
833scan_siblings: 833scan_siblings:
834 /* 834 /*
835 * try to find the next matching non-NULL sibling. 835 * try to find the next matching non-NULL sibling.
836 */ 836 */
837 if (lastidx == 0) { 837 if (lastidx == 0) {
838 /* 838 /*
839 * the root has no siblings. 839 * the root has no siblings.
840 * we've done. 840 * we've done.
841 */ 841 */
842 KASSERT(vpp == &t->t_root); 842 KASSERT(vpp == &t->t_root);
843 break; 843 break;
844 } 844 }
845 n = path_node(t, path, lastidx - 1); 845 n = path_node(t, path, lastidx - 1);
846 /* 
847 * we used to have an integer counter in the node, and this 
848 * optimization made sense then, even though marginal. it 
849 * no longer provides benefit with the structure cache line 
850 * aligned and the counter replaced by an unrolled sequence 
851 * testing the pointers in batch. 
852 */ 
853#if 0 
854 if (*vpp != NULL && radix_tree_node_count_ptrs(n) == 1) { 
855 /* 
856 * optimization; if the node has only a single pointer 
857 * and we've already visited it, there's no point to 
858 * keep scanning in this node. 
859 */ 
860 goto no_siblings; 
861 } 
862#endif /* 0 */ 
863 for (i = vpp - n->n_ptrs + step; i != guard; i += step) { 846 for (i = vpp - n->n_ptrs + step; i != guard; i += step) {
864 KASSERT(i < RADIX_TREE_PTR_PER_NODE); 847 KASSERT(i < RADIX_TREE_PTR_PER_NODE);
865 if (entry_match_p(n->n_ptrs[i], tagmask)) { 848 if (entry_match_p(n->n_ptrs[i], tagmask)) {
866 vpp = &n->n_ptrs[i]; 849 vpp = &n->n_ptrs[i];
867 break; 850 break;
 851 } else if (dense) {
 852 return nfound;
868 } 853 }
869 } 854 }
870 if (i == guard) { 855 if (i == guard) {
871#if 0 
872no_siblings: 
873#endif /* 0 */ 
874 /* 856 /*
875 * not found. go to parent. 857 * not found. go to parent.
876 */ 858 */
877 lastidx--; 859 lastidx--;
878 vpp = path_pptr(t, path, lastidx); 860 vpp = path_pptr(t, path, lastidx);
879 goto scan_siblings; 861 goto scan_siblings;
880 } 862 }
881descend: 863descend:
882 /* 864 /*
883 * following the left-most (or right-most in the case of 865 * following the left-most (or right-most in the case of
884 * reverse scan) child node, decend until reaching the leaf or 866 * reverse scan) child node, decend until reaching the leaf or
885 * an non-matching entry. 867 * an non-matching entry.
886 */ 868 */