From mboxrd@z Thu Jan 1 00:00:00 1970 From: laijs@cn.fujitsu.com (Lai Jiangshan) Date: Wed, 16 Nov 2011 17:26:02 +0800 Subject: [ltt-dev] [PATCH 9/9] change strategy for AR_RANDOM In-Reply-To: <20111115113551.GH16701@Krystal> References: <1321246259-21223-1-git-send-email-laijs@cn.fujitsu.com> <1321246259-21223-10-git-send-email-laijs@cn.fujitsu.com> <20111115113551.GH16701@Krystal> Message-ID: <4EC381AA.1080102@cn.fujitsu.com> On 11/15/2011 07:35 PM, Mathieu Desnoyers wrote: > * Lai Jiangshan (laijs at cn.fujitsu.com) wrote: >> Signed-off-by: Lai Jiangshan >> --- >> tests/test_urcu_hash.c | 34 ++++++++++++++++++++++++++++++++-- >> 1 files changed, 32 insertions(+), 2 deletions(-) >> >> diff --git a/tests/test_urcu_hash.c b/tests/test_urcu_hash.c >> index 964a4e1..f07f0d4 100644 >> --- a/tests/test_urcu_hash.c >> +++ b/tests/test_urcu_hash.c >> @@ -540,6 +540,37 @@ void free_node_cb(struct rcu_head *head) >> free(node); >> } >> >> +static inline >> +int thr_writer_add(void) >> +{ >> + static __thread int addremove_thread; >> + unsigned addremove_random; >> + >> + if (add_only) >> + return 1; >> + >> + if (addremove == AR_ADD) >> + return 1; >> + >> + if (addremove == AR_REMOVE) >> + return 0; >> + >> + addremove_random = test_rand_get_bits(2); >> + if (addremove_random < 2) >> + return addremove_random; >> + >> + while (caa_unlikely(!addremove_thread)) >> + addremove_thread = test_rand_get_bits(16) - (1UL << 15); >> + >> + if (addremove_thread > 0) { >> + addremove_thread--; >> + return 1; >> + } else { >> + addremove_thread++; >> + return 0; >> + } > > Can you explain what this part of the change does ? It only change the behavior when AR_RANDOM. I want to test this case: add a lot of nodes to the hash table but delete seldom in period in a thread. delete add > I am slightly > uncomfortable about a while () loop in there too that depends on random > results. > I can change to if (caa_unlikely(!addremove_thread)) { addremove_thread = test_rand_get_bits(16) - (1UL << 15); if (caa_unlikely(!addremove_thread)) return test_rand_get_bits(1); } Thanks, Lai