Sat Dec 22 20:49:04 2018 UTC ()
- add rcsid
- don't define DEBUG
- protect function used in KASSERT with DIAGNOSTIC not DEBUG


(christos)
diff -r1.1 -r1.2 src/sys/kern/subr_thmap.c

cvs diff -r1.1 -r1.2 src/sys/kern/subr_thmap.c (expand / switch to unified diff)

--- src/sys/kern/subr_thmap.c 2018/12/16 14:06:56 1.1
+++ src/sys/kern/subr_thmap.c 2018/12/22 20:49:04 1.2
@@ -1,13 +1,15 @@ @@ -1,13 +1,15 @@
 1/* $NetBSD: subr_thmap.c,v 1.2 2018/12/22 20:49:04 christos Exp $ */
 2
1/*- 3/*-
2 * Copyright (c) 2018 Mindaugas Rasiukevicius <rmind at noxt eu> 4 * Copyright (c) 2018 Mindaugas Rasiukevicius <rmind at noxt eu>
3 * All rights reserved. 5 * All rights reserved.
4 * 6 *
5 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
7 * are met: 9 * are met:
8 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
13 * 15 *
@@ -75,54 +77,58 @@ @@ -75,54 +77,58 @@
75 * 77 *
76 * References: 78 * References:
77 * 79 *
78 * W. Litwin, 1981, Trie Hashing. 80 * W. Litwin, 1981, Trie Hashing.
79 * Proceedings of the 1981 ACM SIGMOD, p. 19-29 81 * Proceedings of the 1981 ACM SIGMOD, p. 19-29
80 * https://dl.acm.org/citation.cfm?id=582322 82 * https://dl.acm.org/citation.cfm?id=582322
81 * 83 *
82 * P. L. Lehman and S. B. Yao. 84 * P. L. Lehman and S. B. Yao.
83 * Efficient locking for concurrent operations on B-trees. 85 * Efficient locking for concurrent operations on B-trees.
84 * ACM TODS, 6(4):650-670, 1981 86 * ACM TODS, 6(4):650-670, 1981
85 * https://www.csd.uoc.gr/~hy460/pdf/p650-lehman.pdf 87 * https://www.csd.uoc.gr/~hy460/pdf/p650-lehman.pdf
86 */ 88 */
87 89
 90
88#ifdef _KERNEL 91#ifdef _KERNEL
89#include <sys/cdefs.h> 92#include <sys/cdefs.h>
90#include <sys/param.h> 93#include <sys/param.h>
91#include <sys/types.h> 94#include <sys/types.h>
92#include <sys/thmap.h> 95#include <sys/thmap.h>
93#include <sys/kmem.h> 96#include <sys/kmem.h>
94#include <sys/lock.h> 97#include <sys/lock.h>
95#include <sys/atomic.h> 98#include <sys/atomic.h>
96#include <sys/hash.h> 99#include <sys/hash.h>
 100#define THMAP_RCSID(a) __KERNEL_RCSID(0, a)
97#else 101#else
98#include <stdio.h> 102#include <stdio.h>
99#include <stdlib.h> 103#include <stdlib.h>
100#include <stdbool.h> 104#include <stdbool.h>
101#include <stddef.h> 105#include <stddef.h>
102#include <inttypes.h> 106#include <inttypes.h>
103#include <string.h> 107#include <string.h>
104#include <limits.h> 108#include <limits.h>
 109#define THMAP_RCSID(a) __RCSID(a)
105 110
106#include "thmap.h" 111#include "thmap.h"
107#include "utils.h" 112#include "utils.h"
108#endif 113#endif
109 114
 115THMAP_RCSID($NetBSD: subr_thmap.c,v 1.2 2018/12/22 20:49:04 christos Exp $);
 116
110/* 117/*
111 * NetBSD kernel wrappers 118 * NetBSD kernel wrappers
112 */ 119 */
113#ifdef _KERNEL 120#ifdef _KERNEL
114#define ASSERT KASSERT 121#define ASSERT KASSERT
115#define DEBUG 1 
116#define atomic_thread_fence(x) x 122#define atomic_thread_fence(x) x
117#define memory_order_stores membar_producer() 123#define memory_order_stores membar_producer()
118#define memory_order_loads membar_consumer() 124#define memory_order_loads membar_consumer()
119#define atomic_cas_32_p(p, e, n) (atomic_cas_32((p), (e), (n)) == (e)) 125#define atomic_cas_32_p(p, e, n) (atomic_cas_32((p), (e), (n)) == (e))
120#define atomic_cas_ptr_p(p, e, n) \ 126#define atomic_cas_ptr_p(p, e, n) \
121 (atomic_cas_ptr((p), (void *)(e), (void *)(n)) == (e)) 127 (atomic_cas_ptr((p), (void *)(e), (void *)(n)) == (e))
122#define atomic_exchange atomic_swap_ptr 128#define atomic_exchange atomic_swap_ptr
123#define murmurhash3 murmurhash2 129#define murmurhash3 murmurhash2
124#endif 130#endif
125 131
126/* 132/*
127 * The root level fanout is 64 (indexed by the last 6 bits of the hash 133 * The root level fanout is 64 (indexed by the last 6 bits of the hash
128 * value XORed with the length). Each subsequent level, represented by 134 * value XORed with the length). Each subsequent level, represented by
@@ -235,27 +241,27 @@ free_wrapper(uintptr_t addr, size_t len) @@ -235,27 +241,27 @@ free_wrapper(uintptr_t addr, size_t len)
235{ 241{
236 kmem_intr_free((void *)addr, len); 242 kmem_intr_free((void *)addr, len);
237} 243}
238 244
239static const thmap_ops_t thmap_default_ops = { 245static const thmap_ops_t thmap_default_ops = {
240 .alloc = alloc_wrapper, 246 .alloc = alloc_wrapper,
241 .free = free_wrapper 247 .free = free_wrapper
242}; 248};
243 249
244/* 250/*
245 * NODE LOCKING. 251 * NODE LOCKING.
246 */ 252 */
247 253
248#ifdef DEBUG 254#ifdef DIAGNOSTIC
249static inline bool 255static inline bool
250node_locked_p(const thmap_inode_t *node) 256node_locked_p(const thmap_inode_t *node)
251{ 257{
252 return (node->state & NODE_LOCKED) != 0; 258 return (node->state & NODE_LOCKED) != 0;
253} 259}
254#endif 260#endif
255 261
256static void 262static void
257lock_node(thmap_inode_t *node) 263lock_node(thmap_inode_t *node)
258{ 264{
259 unsigned bcount = SPINLOCK_BACKOFF_MIN; 265 unsigned bcount = SPINLOCK_BACKOFF_MIN;
260 uint32_t s; 266 uint32_t s;
261again: 267again: