2 * Copyright (c) 2003,2004,2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * lwkt_token - Implement soft token locks.
38 * Tokens are locks which serialize a thread only while the thread is
39 * running. If the thread blocks all tokens are released, then reacquired
40 * when the thread resumes.
42 * This implementation requires no critical sections or spin locks, but
43 * does use atomic_cmpset_ptr().
45 * Tokens may be recursively acquired by the same thread. However the
46 * caller must be sure to release such tokens in reverse order.
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
52 #include <sys/rtprio.h>
53 #include <sys/queue.h>
54 #include <sys/sysctl.h>
56 #include <sys/kthread.h>
57 #include <machine/cpu.h>
60 #include <sys/spinlock.h>
62 #include <sys/thread2.h>
63 #include <sys/spinlock2.h>
64 #include <sys/mplock2.h>
67 #include <vm/vm_param.h>
68 #include <vm/vm_kern.h>
69 #include <vm/vm_object.h>
70 #include <vm/vm_page.h>
71 #include <vm/vm_map.h>
72 #include <vm/vm_pager.h>
73 #include <vm/vm_extern.h>
74 #include <vm/vm_zone.h>
76 #include <machine/stdarg.h>
77 #include <machine/smp.h>
79 extern int lwkt_sched_debug;
81 #ifndef LWKT_NUM_POOL_TOKENS
82 #define LWKT_NUM_POOL_TOKENS 4001 /* prime number */
85 static lwkt_token pool_tokens[LWKT_NUM_POOL_TOKENS];
87 #define TOKEN_STRING "REF=%p TOK=%p TD=%p"
88 #define TOKEN_ARGS lwkt_tokref_t ref, lwkt_token_t tok, struct thread *td
89 #define CONTENDED_STRING TOKEN_STRING " (contention started)"
90 #define UNCONTENDED_STRING TOKEN_STRING " (contention stopped)"
91 #if !defined(KTR_TOKENS)
92 #define KTR_TOKENS KTR_ALL
95 KTR_INFO_MASTER(tokens);
96 KTR_INFO(KTR_TOKENS, tokens, fail, 0, TOKEN_STRING, TOKEN_ARGS);
97 KTR_INFO(KTR_TOKENS, tokens, succ, 1, TOKEN_STRING, TOKEN_ARGS);
99 KTR_INFO(KTR_TOKENS, tokens, release, 2, TOKEN_STRING, TOKEN_ARGS);
100 KTR_INFO(KTR_TOKENS, tokens, remote, 3, TOKEN_STRING, TOKEN_ARGS);
101 KTR_INFO(KTR_TOKENS, tokens, reqremote, 4, TOKEN_STRING, TOKEN_ARGS);
102 KTR_INFO(KTR_TOKENS, tokens, reqfail, 5, TOKEN_STRING, TOKEN_ARGS);
103 KTR_INFO(KTR_TOKENS, tokens, drain, 6, TOKEN_STRING, TOKEN_ARGS);
104 KTR_INFO(KTR_TOKENS, tokens, contention_start, 7, CONTENDED_STRING, TOKEN_ARGS);
105 KTR_INFO(KTR_TOKENS, tokens, contention_stop, 7, UNCONTENDED_STRING, TOKEN_ARGS);
108 #define logtoken(name, ref) \
109 KTR_LOG(tokens_ ## name, ref, ref->tr_tok, curthread)
112 * Global tokens. These replace the MP lock for major subsystem locking.
113 * These tokens are initially used to lockup both global and individual
116 * Once individual structures get their own locks these tokens are used
117 * only to protect global lists & other variables and to interlock
118 * allocations and teardowns and such.
120 * The UP initializer causes token acquisition to also acquire the MP lock
121 * for maximum compatibility. The feature may be enabled and disabled at
122 * any time, the MP state is copied to the tokref when the token is acquired
123 * and will not race against sysctl changes.
125 struct lwkt_token mp_token = LWKT_TOKEN_INITIALIZER(mp_token);
126 struct lwkt_token pmap_token = LWKT_TOKEN_INITIALIZER(pmap_token);
127 struct lwkt_token dev_token = LWKT_TOKEN_INITIALIZER(dev_token);
128 struct lwkt_token vm_token = LWKT_TOKEN_INITIALIZER(vm_token);
129 struct lwkt_token vmspace_token = LWKT_TOKEN_INITIALIZER(vmspace_token);
130 struct lwkt_token kvm_token = LWKT_TOKEN_INITIALIZER(kvm_token);
131 struct lwkt_token proc_token = LWKT_TOKEN_INITIALIZER(proc_token);
132 struct lwkt_token tty_token = LWKT_TOKEN_INITIALIZER(tty_token);
133 struct lwkt_token vnode_token = LWKT_TOKEN_INITIALIZER(vnode_token);
134 struct lwkt_token vmobj_token = LWKT_TOKEN_INITIALIZER(vmobj_token);
136 static int lwkt_token_spin = 5;
137 SYSCTL_INT(_lwkt, OID_AUTO, token_spin, CTLFLAG_RW,
138 &lwkt_token_spin, 0, "Decontention spin loops");
139 static int lwkt_token_delay = 0;
140 SYSCTL_INT(_lwkt, OID_AUTO, token_delay, CTLFLAG_RW,
141 &lwkt_token_delay, 0, "Decontention spin delay in ns");
144 * The collision count is bumped every time the LWKT scheduler fails
145 * to acquire needed tokens in addition to a normal lwkt_gettoken()
148 SYSCTL_LONG(_lwkt, OID_AUTO, mp_collisions, CTLFLAG_RW,
149 &mp_token.t_collisions, 0, "Collision counter of mp_token");
150 SYSCTL_LONG(_lwkt, OID_AUTO, pmap_collisions, CTLFLAG_RW,
151 &pmap_token.t_collisions, 0, "Collision counter of pmap_token");
152 SYSCTL_LONG(_lwkt, OID_AUTO, dev_collisions, CTLFLAG_RW,
153 &dev_token.t_collisions, 0, "Collision counter of dev_token");
154 SYSCTL_LONG(_lwkt, OID_AUTO, vm_collisions, CTLFLAG_RW,
155 &vm_token.t_collisions, 0, "Collision counter of vm_token");
156 SYSCTL_LONG(_lwkt, OID_AUTO, vmspace_collisions, CTLFLAG_RW,
157 &vmspace_token.t_collisions, 0, "Collision counter of vmspace_token");
158 SYSCTL_LONG(_lwkt, OID_AUTO, kvm_collisions, CTLFLAG_RW,
159 &kvm_token.t_collisions, 0, "Collision counter of kvm_token");
160 SYSCTL_LONG(_lwkt, OID_AUTO, proc_collisions, CTLFLAG_RW,
161 &proc_token.t_collisions, 0, "Collision counter of proc_token");
162 SYSCTL_LONG(_lwkt, OID_AUTO, tty_collisions, CTLFLAG_RW,
163 &tty_token.t_collisions, 0, "Collision counter of tty_token");
164 SYSCTL_LONG(_lwkt, OID_AUTO, vnode_collisions, CTLFLAG_RW,
165 &vnode_token.t_collisions, 0, "Collision counter of vnode_token");
167 #ifdef DEBUG_LOCKS_LATENCY
169 static long tokens_add_latency;
170 SYSCTL_LONG(_debug, OID_AUTO, tokens_add_latency, CTLFLAG_RW,
171 &tokens_add_latency, 0,
172 "Add spinlock latency");
177 static int _lwkt_getalltokens_sorted(thread_t td);
181 * Acquire the initial mplock
183 * (low level boot only)
186 cpu_get_initial_mplock(void)
188 KKASSERT(mp_token.t_ref == NULL);
189 if (lwkt_trytoken(&mp_token) == FALSE)
190 panic("cpu_get_initial_mplock");
195 * Return a pool token given an address. Use a prime number to reduce
200 _lwkt_token_pool_lookup(void *ptr)
204 i = (u_int)(uintptr_t)ptr % LWKT_NUM_POOL_TOKENS;
205 return(&pool_tokens[i]);
209 * Initialize a tokref_t prior to making it visible in the thread's
214 _lwkt_tokref_init(lwkt_tokref_t ref, lwkt_token_t tok, thread_t td, long excl)
217 ref->tr_count = excl;
222 * Attempt to acquire a shared or exclusive token. Returns TRUE on success,
225 * If TOK_EXCLUSIVE is set in mode we are attempting to get an exclusive
226 * token, otherwise are attempting to get a shared token.
228 * If TOK_EXCLREQ is set in mode this is a blocking operation, otherwise
229 * it is a non-blocking operation (for both exclusive or shared acquisions).
233 _lwkt_trytokref(lwkt_tokref_t ref, thread_t td, long mode)
240 KASSERT(((mode & TOK_EXCLREQ) == 0 || /* non blocking */
241 td->td_gd->gd_intr_nesting_level == 0 ||
242 panic_cpu_gd == mycpu),
243 ("Attempt to acquire token %p not already "
244 "held in hard code section", tok));
246 if (mode & TOK_EXCLUSIVE) {
248 * Attempt to get an exclusive token
251 count = tok->t_count;
252 oref = tok->t_ref; /* can be NULL */
254 if ((count & ~TOK_EXCLREQ) == 0) {
256 * It is possible to get the exclusive bit.
257 * We must clear TOK_EXCLREQ on successful
260 if (atomic_cmpset_long(&tok->t_count, count,
261 (count & ~TOK_EXCLREQ) |
263 KKASSERT(tok->t_ref == NULL);
268 } else if ((count & TOK_EXCLUSIVE) &&
269 oref >= &td->td_toks_base &&
270 oref < td->td_toks_stop) {
272 * Our thread already holds the exclusive
273 * bit, we treat this tokref as a shared
274 * token (sorta) to make the token release
277 * NOTE: oref cannot race above if it
278 * happens to be ours, so we're good.
279 * But we must still have a stable
280 * variable for both parts of the
283 * NOTE: Since we already have an exclusive
284 * lock and don't need to check EXCLREQ
285 * we can just use an atomic_add here
287 atomic_add_long(&tok->t_count, TOK_INCR);
288 ref->tr_count &= ~TOK_EXCLUSIVE;
290 } else if ((mode & TOK_EXCLREQ) &&
291 (count & TOK_EXCLREQ) == 0) {
293 * Unable to get the exclusive bit but being
294 * asked to set the exclusive-request bit.
295 * Since we are going to retry anyway just
296 * set the bit unconditionally.
298 atomic_set_long(&tok->t_count, TOK_EXCLREQ);
302 * Unable to get the exclusive bit and not
303 * being asked to set the exclusive-request
304 * (aka lwkt_trytoken()), or EXCLREQ was
314 * Attempt to get a shared token. Note that TOK_EXCLREQ
315 * for shared tokens simply means the caller intends to
316 * block. We never actually set the bit in tok->t_count.
319 count = tok->t_count;
320 oref = tok->t_ref; /* can be NULL */
322 if ((count & (TOK_EXCLUSIVE/*|TOK_EXCLREQ*/)) == 0) {
323 /* XXX EXCLREQ should work */
325 * It is possible to get the token shared.
327 if (atomic_cmpset_long(&tok->t_count, count,
332 } else if ((count & TOK_EXCLUSIVE) &&
333 oref >= &td->td_toks_base &&
334 oref < td->td_toks_stop) {
336 * We own the exclusive bit on the token so
337 * we can in fact also get it shared.
339 atomic_add_long(&tok->t_count, TOK_INCR);
343 * We failed to get the token shared
354 _lwkt_trytokref_spin(lwkt_tokref_t ref, thread_t td, long mode)
358 if (_lwkt_trytokref(ref, td, mode)) {
359 #ifdef DEBUG_LOCKS_LATENCY
361 for (j = tokens_add_latency; j > 0; --j)
366 for (spin = lwkt_token_spin; spin > 0; --spin) {
367 if (lwkt_token_delay)
368 tsc_delay(lwkt_token_delay);
371 if (_lwkt_trytokref(ref, td, mode)) {
372 #ifdef DEBUG_LOCKS_LATENCY
374 for (j = tokens_add_latency; j > 0; --j)
384 * Release a token that we hold.
388 _lwkt_reltokref(lwkt_tokref_t ref, thread_t td)
395 count = tok->t_count;
397 if (tok->t_ref == ref) {
399 * We are an exclusive holder. We must clear tr_ref
400 * before we clear the TOK_EXCLUSIVE bit. If we are
401 * unable to clear the bit we must restore
404 KKASSERT(count & TOK_EXCLUSIVE);
406 if (atomic_cmpset_long(&tok->t_count, count,
407 count & ~TOK_EXCLUSIVE)) {
414 * We are a shared holder
416 KKASSERT(count & TOK_COUNTMASK);
417 if (atomic_cmpset_long(&tok->t_count, count,
428 * Obtain all the tokens required by the specified thread on the current
429 * cpu, return 0 on failure and non-zero on success. If a failure occurs
430 * any partially acquired tokens will be released prior to return.
432 * lwkt_getalltokens is called by the LWKT scheduler to re-acquire all
433 * tokens that the thread had to release when it switched away.
435 * If spinning is non-zero this function acquires the tokens in a particular
436 * order to deal with potential deadlocks. We simply use address order for
439 * Called from a critical section.
442 lwkt_getalltokens(thread_t td, int spinning)
448 return(_lwkt_getalltokens_sorted(td));
451 * Acquire tokens in forward order, assign or validate tok->t_ref.
453 for (scan = &td->td_toks_base; scan < td->td_toks_stop; ++scan) {
457 * Only try really hard on the last token
459 if (scan == td->td_toks_stop - 1) {
460 if (_lwkt_trytokref_spin(scan, td, scan->tr_count))
463 if (_lwkt_trytokref(scan, td, scan->tr_count))
468 * Otherwise we failed to acquire all the tokens.
469 * Release whatever we did get.
471 KASSERT(tok->t_desc, ("token %p is not initialized", tok));
472 strncpy(td->td_gd->gd_cnt.v_token_name,
474 sizeof(td->td_gd->gd_cnt.v_token_name) - 1);
476 if (lwkt_sched_debug > 0) {
478 kprintf("toka %p %s %s\n",
479 tok, tok->t_desc, td->td_comm);
481 td->td_wmesg = tok->t_desc;
483 while (--scan >= &td->td_toks_base)
484 _lwkt_reltokref(scan, td);
492 * Release all tokens owned by the specified thread on the current cpu.
494 * This code is really simple. Even in cases where we own all the tokens
495 * note that t_ref may not match the scan for recursively held tokens which
496 * are held deeper in the stack, or for the case where a lwkt_getalltokens()
499 * Tokens are released in reverse order to reduce chasing race failures.
501 * Called from a critical section.
504 lwkt_relalltokens(thread_t td)
509 * Weird order is to try to avoid a panic loop
511 if (td->td_toks_have) {
512 scan = td->td_toks_have;
513 td->td_toks_have = NULL;
515 scan = td->td_toks_stop;
517 while (--scan >= &td->td_toks_base)
518 _lwkt_reltokref(scan, td);
522 * This is the decontention version of lwkt_getalltokens(). The tokens are
523 * acquired in address-sorted order to deal with any deadlocks. Ultimately
524 * token failures will spin into the scheduler and get here.
526 * Called from critical section
530 _lwkt_getalltokens_sorted(thread_t td)
532 lwkt_tokref_t sort_array[LWKT_MAXTOKENS];
540 * Sort the token array. Yah yah, I know this isn't fun.
542 * NOTE: Recursively acquired tokens are ordered the same as in the
543 * td_toks_array so we can always get the earliest one first.
546 scan = &td->td_toks_base;
547 while (scan < td->td_toks_stop) {
548 for (j = 0; j < i; ++j) {
549 if (scan->tr_tok < sort_array[j]->tr_tok)
553 bcopy(sort_array + j, sort_array + j + 1,
554 (i - j) * sizeof(lwkt_tokref_t));
556 sort_array[j] = scan;
563 * Acquire tokens in forward order, assign or validate tok->t_ref.
565 for (i = 0; i < n; ++i) {
566 scan = sort_array[i];
570 * Only try really hard on the last token
572 if (scan == td->td_toks_stop - 1) {
573 if (_lwkt_trytokref_spin(scan, td, scan->tr_count))
576 if (_lwkt_trytokref(scan, td, scan->tr_count))
581 * Otherwise we failed to acquire all the tokens.
582 * Release whatever we did get.
584 if (lwkt_sched_debug > 0) {
586 kprintf("tokb %p %s %s\n",
587 tok, tok->t_desc, td->td_comm);
589 td->td_wmesg = tok->t_desc;
592 scan = sort_array[i];
593 _lwkt_reltokref(scan, td);
600 * We were successful, there is no need for another core to signal
607 * Get a serializing token. This routine can block.
610 lwkt_gettoken(lwkt_token_t tok)
612 thread_t td = curthread;
615 ref = td->td_toks_stop;
616 KKASSERT(ref < &td->td_toks_end);
619 _lwkt_tokref_init(ref, tok, td, TOK_EXCLUSIVE|TOK_EXCLREQ);
623 * Taking an exclusive token after holding it shared will
624 * livelock. Scan for that case and assert.
628 for (tk = &td->td_toks_base; tk < ref; tk++) {
629 if (tk->tr_tok != tok)
633 if (tk->tr_count & TOK_EXCLUSIVE)
636 /* We found only shared instances of this token if found >0 here */
637 KASSERT((found == 0), ("Token %p s/x livelock", tok));
641 if (_lwkt_trytokref_spin(ref, td, TOK_EXCLUSIVE|TOK_EXCLREQ))
645 * Give up running if we can't acquire the token right now.
647 * Since the tokref is already active the scheduler now
648 * takes care of acquisition, so we need only call
651 * Since we failed this was not a recursive token so upon
652 * return tr_tok->t_ref should be assigned to this specific
655 td->td_wmesg = tok->t_desc;
658 td->td_toks_have = td->td_toks_stop - 1;
661 KKASSERT(tok->t_ref == ref);
665 * Similar to gettoken but we acquire a shared token instead of an exclusive
669 lwkt_gettoken_shared(lwkt_token_t tok)
671 thread_t td = curthread;
674 ref = td->td_toks_stop;
675 KKASSERT(ref < &td->td_toks_end);
678 _lwkt_tokref_init(ref, tok, td, TOK_EXCLREQ);
682 * Taking a pool token in shared mode is a bad idea; other
683 * addresses deeper in the call stack may hash to the same pool
684 * token and you may end up with an exclusive-shared livelock.
685 * Warn in this condition.
687 if ((tok >= &pool_tokens[0]) &&
688 (tok < &pool_tokens[LWKT_NUM_POOL_TOKENS]))
689 kprintf("Warning! Taking pool token %p in shared mode\n", tok);
693 if (_lwkt_trytokref_spin(ref, td, TOK_EXCLREQ))
697 * Give up running if we can't acquire the token right now.
699 * Since the tokref is already active the scheduler now
700 * takes care of acquisition, so we need only call
703 * Since we failed this was not a recursive token so upon
704 * return tr_tok->t_ref should be assigned to this specific
707 td->td_wmesg = tok->t_desc;
710 td->td_toks_have = td->td_toks_stop - 1;
716 * Attempt to acquire a token, return TRUE on success, FALSE on failure.
718 * We setup the tokref in case we actually get the token (if we switch later
719 * it becomes mandatory so we set TOK_EXCLREQ), but we call trytokref without
720 * TOK_EXCLREQ in case we fail.
723 lwkt_trytoken(lwkt_token_t tok)
725 thread_t td = curthread;
728 ref = td->td_toks_stop;
729 KKASSERT(ref < &td->td_toks_end);
732 _lwkt_tokref_init(ref, tok, td, TOK_EXCLUSIVE|TOK_EXCLREQ);
734 if (_lwkt_trytokref(ref, td, TOK_EXCLUSIVE))
738 * Failed, unpend the request
748 lwkt_gettoken_hard(lwkt_token_t tok)
755 lwkt_getpooltoken(void *ptr)
759 tok = _lwkt_token_pool_lookup(ptr);
765 * Release a serializing token.
767 * WARNING! All tokens must be released in reverse order. This will be
771 lwkt_reltoken(lwkt_token_t tok)
773 thread_t td = curthread;
777 * Remove ref from thread token list and assert that it matches
778 * the token passed in. Tokens must be released in reverse order.
780 ref = td->td_toks_stop - 1;
781 KKASSERT(ref >= &td->td_toks_base && ref->tr_tok == tok);
782 _lwkt_reltokref(ref, td);
784 td->td_toks_stop = ref;
788 lwkt_reltoken_hard(lwkt_token_t tok)
795 * It is faster for users of lwkt_getpooltoken() to use the returned
796 * token and just call lwkt_reltoken(), but for convenience we provide
797 * this function which looks the token up based on the ident.
800 lwkt_relpooltoken(void *ptr)
802 lwkt_token_t tok = _lwkt_token_pool_lookup(ptr);
807 * Return a count of the number of token refs the thread has to the
808 * specified token, whether it currently owns the token or not.
811 lwkt_cnttoken(lwkt_token_t tok, thread_t td)
816 for (scan = &td->td_toks_base; scan < td->td_toks_stop; ++scan) {
817 if (scan->tr_tok == tok)
824 * Pool tokens are used to provide a type-stable serializing token
825 * pointer that does not race against disappearing data structures.
827 * This routine is called in early boot just after we setup the BSP's
828 * globaldata structure.
831 lwkt_token_pool_init(void)
835 for (i = 0; i < LWKT_NUM_POOL_TOKENS; ++i)
836 lwkt_token_init(&pool_tokens[i], "pool");
840 lwkt_token_pool_lookup(void *ptr)
842 return (_lwkt_token_pool_lookup(ptr));
846 * Initialize a token.
849 lwkt_token_init(lwkt_token_t tok, const char *desc)
853 tok->t_collisions = 0;
858 lwkt_token_uninit(lwkt_token_t tok)
864 * Exchange the two most recent tokens on the tokref stack. This allows
865 * you to release a token out of order.
867 * We have to be careful about the case where the top two tokens are
868 * the same token. In this case tok->t_ref will point to the deeper
869 * ref and must remain pointing to the deeper ref. If we were to swap
870 * it the first release would clear the token even though a second
871 * ref is still present.
873 * Only exclusively held tokens contain a reference to the tokref which
874 * has to be flipped along with the swap.
877 lwkt_token_swap(void)
879 lwkt_tokref_t ref1, ref2;
880 lwkt_token_t tok1, tok2;
882 thread_t td = curthread;
886 ref1 = td->td_toks_stop - 1;
887 ref2 = td->td_toks_stop - 2;
888 KKASSERT(ref1 >= &td->td_toks_base);
889 KKASSERT(ref2 >= &td->td_toks_base);
893 count1 = ref1->tr_count;
894 count2 = ref2->tr_count;
898 ref1->tr_count = count2;
900 ref2->tr_count = count1;
901 if (tok1->t_ref == ref1)
903 if (tok2->t_ref == ref2)