]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libbenchmark/src/libbenchmark_benchmarks_btree_au_readn_writen/libbenchmark_benchmarks_btree_au_windows_mutex_readn_writen.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libbenchmark / src / libbenchmark_benchmarks_btree_au_readn_writen / libbenchmark_benchmarks_btree_au_windows_mutex_readn_writen.c
1 /***** includes *****/
2 #include "libbenchmark_benchmarks_btree_au_internal.h"
3
4 /***** structs *****/
5 struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element
6 {
7   lfds710_pal_uint_t
8     datum;
9
10   struct libbenchmark_datastructure_btree_au_windows_mutex_element
11     be;
12 };
13
14 struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_thread_benchmark_state
15 {
16   lfds710_pal_uint_t
17     operation_count,
18     per_thread_prng_seed;
19 };
20
21 struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_numa_benchmark_state
22 {
23   lfds710_pal_uint_t
24     *element_key_array,
25     number_element_keys;
26
27   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element
28     *bme;
29
30   struct libbenchmark_datastructure_btree_au_windows_mutex_state
31     *bs;
32 };
33
34 struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_overall_benchmark_state
35 {
36   enum libbenchmark_topology_numa_mode
37     numa_mode;
38
39   lfds710_pal_uint_t
40     *element_key_array,
41     number_element_keys;
42
43   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element
44     *bme;
45
46   struct libbenchmark_datastructure_btree_au_windows_mutex_state
47     *bs;
48 };
49
50 /***** private prototypes *****/
51 static int key_compare_function( void const *new_key, void const *existing_key );
52
53
54
55
56
57 /****************************************************************************/
58 void libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_init( struct libbenchmark_topology_state *ts,
59                                                                       struct lfds710_list_aso_state *logical_processor_set,
60                                                                       struct libshared_memory_state *ms,
61                                                                       enum libbenchmark_topology_numa_mode numa_mode,
62                                                                       struct libbenchmark_threadset_state *tsets )
63 {
64   enum libbenchmark_datastructure_btree_au_windows_mutex_insert_result
65     ir;
66
67   lfds710_pal_uint_t
68     index = 0,
69     loop,
70     number_logical_processors,
71     number_benchmark_elements,
72     number_logical_processors_in_numa_node,
73     largest_number_logical_processors_in_numa_node = 0,
74     total_number_benchmark_elements;
75
76   struct lfds710_list_asu_element
77     *lasue = NULL,
78     *lasue_lp;
79
80   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_overall_benchmark_state
81     *obs;
82
83   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_numa_benchmark_state
84     *ptns;
85
86   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_thread_benchmark_state
87     *ptbs;
88
89   struct libbenchmark_datastructure_btree_au_windows_mutex_state
90     *bs = NULL;
91
92   struct libbenchmark_prng_state
93     ps;
94
95   struct libbenchmark_threadset_per_numa_state
96     *pns,
97     *largest_pns = NULL;
98
99   struct libbenchmark_threadset_per_thread_state
100     *pts;
101
102   struct libbenchmark_topology_node_state
103     *numa_node_for_lp;
104
105   LFDS710_PAL_ASSERT( ts != NULL );
106   LFDS710_PAL_ASSERT( logical_processor_set != NULL );
107   LFDS710_PAL_ASSERT( ms != NULL );
108   // TRD : numa_mode can be any value in its range
109   LFDS710_PAL_ASSERT( tsets != NULL );
110
111   lfds710_list_aso_query( logical_processor_set, LFDS710_LIST_ASO_QUERY_GET_POTENTIALLY_INACCURATE_COUNT, NULL, (void *) &number_logical_processors );
112
113   libbenchmark_threadset_init( tsets, ts, logical_processor_set, ms, libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_thread, NULL );
114
115   total_number_benchmark_elements = number_logical_processors * 1024;
116
117   obs = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_overall_benchmark_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
118
119   LIBBENCHMARK_PRNG_INIT( ps, LFDS710_PRNG_SEED );
120
121   switch( numa_mode )
122   {
123     case LIBBENCHMARK_TOPOLOGY_NUMA_MODE_SMP:
124       bs = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_datastructure_btree_au_windows_mutex_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
125       libbenchmark_datastructure_btree_au_windows_mutex_init( bs, key_compare_function, LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_EXISTING_KEY_FAIL, NULL );
126
127       obs->bme = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element) * total_number_benchmark_elements, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
128       obs->element_key_array = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(lfds710_pal_uint_t) * total_number_benchmark_elements, sizeof(lfds710_pal_uint_t) );
129
130       for( loop = 0 ; loop < total_number_benchmark_elements ; loop++ )
131         do
132         {
133           LIBBENCHMARK_PRNG_GENERATE( ps, obs->bme[loop].datum );
134           obs->element_key_array[loop] = obs->bme[loop].datum;
135
136           LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_SET_KEY_IN_ELEMENT( *bs, obs->bme[loop].be, &obs->bme[loop] );
137           LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_SET_VALUE_IN_ELEMENT( *bs, obs->bme[loop].be, &obs->bme[loop] );
138           ir = libbenchmark_datastructure_btree_au_windows_mutex_insert( bs, &obs->bme[loop].be, NULL );
139         }
140         while( ir == LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_INSERT_RESULT_FAILURE_EXISTING_KEY );
141
142       lasue = NULL;
143
144       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue) )
145       {
146         pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
147         ptbs = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_thread_benchmark_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
148         LIBBENCHMARK_PRNG_GENERATE( ps, ptbs->per_thread_prng_seed );
149         pts->users_per_thread_state = ptbs;
150       }
151     break;
152
153     case LIBBENCHMARK_TOPOLOGY_NUMA_MODE_NUMA:
154       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
155       {
156         pns = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
157
158         lasue_lp = NULL;
159         number_logical_processors_in_numa_node = 0;
160
161         while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue_lp) )
162         {
163           pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue_lp );
164
165           libbenchmark_topology_query( ts, LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMA_NODE_FOR_LOGICAL_PROCESSOR, pts->tns_lp, &numa_node_for_lp );
166
167           if( LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID(*numa_node_for_lp) == pns->numa_node_id )
168             number_logical_processors_in_numa_node++;
169         }
170
171         if( number_logical_processors_in_numa_node > largest_number_logical_processors_in_numa_node )
172           largest_pns = pns;
173       }
174
175       bs = libshared_memory_alloc_from_specific_node( ms, largest_pns->numa_node_id, sizeof(struct libbenchmark_datastructure_btree_au_windows_mutex_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
176       libbenchmark_datastructure_btree_au_windows_mutex_init( bs, key_compare_function, LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_EXISTING_KEY_FAIL, NULL );
177
178       obs->element_key_array = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(lfds710_pal_uint_t) * total_number_benchmark_elements, sizeof(lfds710_pal_uint_t) );
179
180       lasue = NULL;
181
182       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
183       {
184         pns = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
185
186         /* TRD : for each NUMA node, figure out how many LPs in the current set are in that NUMA node
187                  and allocate then the correct number of elements from this NUMA node (1024 per LP)
188         */
189
190         lasue_lp = NULL;
191         number_logical_processors_in_numa_node = 0;
192
193         while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue_lp) )
194         {
195           pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue_lp );
196
197           libbenchmark_topology_query( ts, LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMA_NODE_FOR_LOGICAL_PROCESSOR, pts->tns_lp, &numa_node_for_lp );
198
199           if( LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID(*numa_node_for_lp) == pns->numa_node_id )
200             number_logical_processors_in_numa_node++;
201         }
202
203         number_benchmark_elements = number_logical_processors_in_numa_node * 1024;
204
205         ptns = libshared_memory_alloc_from_specific_node( ms, pns->numa_node_id, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_numa_benchmark_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
206         ptns->element_key_array = libshared_memory_alloc_from_specific_node( ms, pns->numa_node_id, sizeof(lfds710_pal_uint_t) * total_number_benchmark_elements, sizeof(lfds710_pal_uint_t) );
207         ptns->number_element_keys = total_number_benchmark_elements;
208
209         ptns->bme = libshared_memory_alloc_from_specific_node( ms, pns->numa_node_id, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element) * number_benchmark_elements, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
210
211         for( loop = 0 ; loop < number_benchmark_elements ; loop++, index++ )
212           do
213           {
214             LIBBENCHMARK_PRNG_GENERATE( ps, ptns->bme[loop].datum );
215             obs->element_key_array[index] = ptns->bme[loop].datum;
216
217             LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_SET_KEY_IN_ELEMENT( *bs, ptns->bme[loop].be, &ptns->bme[loop] );
218             LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_SET_VALUE_IN_ELEMENT( *bs, ptns->bme[loop].be, &ptns->bme[loop] );
219             ir = libbenchmark_datastructure_btree_au_windows_mutex_insert( bs, &ptns->bme[loop].be, NULL );
220           }
221           while( ir == LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_INSERT_RESULT_FAILURE_EXISTING_KEY );
222
223         pns->users_per_numa_state = ptns;
224       }
225
226       // TRD : now copy over into each NUMA node state the element_key_array
227       lasue = NULL;
228
229       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
230       {
231         pns = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
232         ptns = pns->users_per_numa_state;
233
234         for( loop = 0 ; loop < total_number_benchmark_elements ; loop++ )
235           ptns->element_key_array[loop] = obs->element_key_array[loop];         
236       }
237
238       lasue = NULL;
239
240       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue) )
241       {
242         pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
243         ptbs = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_thread_benchmark_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
244         LIBBENCHMARK_PRNG_GENERATE( ps, ptbs->per_thread_prng_seed );
245         LIBBENCHMARK_PRNG_MURMURHASH3_MIXING_FUNCTION( ptbs->per_thread_prng_seed );
246         pts->users_per_thread_state = ptbs;
247       }
248     break;
249
250     case LIBBENCHMARK_TOPOLOGY_NUMA_MODE_NUMA_BUT_NOT_USED:
251       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
252       {
253         pns = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
254
255         lasue_lp = NULL;
256         number_logical_processors_in_numa_node = 0;
257
258         while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue_lp) )
259         {
260           pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue_lp );
261
262           libbenchmark_topology_query( ts, LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMA_NODE_FOR_LOGICAL_PROCESSOR, pts->tns_lp, &numa_node_for_lp );
263
264           if( LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID(*numa_node_for_lp) == pns->numa_node_id )
265             number_logical_processors_in_numa_node++;
266         }
267
268         if( number_logical_processors_in_numa_node > largest_number_logical_processors_in_numa_node )
269           largest_pns = pns;
270       }
271
272       bs = libshared_memory_alloc_from_specific_node( ms, largest_pns->numa_node_id, sizeof(struct libbenchmark_datastructure_btree_au_windows_mutex_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
273       libbenchmark_datastructure_btree_au_windows_mutex_init( bs, key_compare_function, LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_EXISTING_KEY_FAIL, NULL );
274
275       obs->element_key_array = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(lfds710_pal_uint_t) * total_number_benchmark_elements, sizeof(lfds710_pal_uint_t) );
276
277       lasue = NULL;
278
279       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
280       {
281         pns = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
282
283         /* TRD : for each NUMA node, figure out how many LPs in the current set are in that NUMA node
284                  and allocate then the correct number of elements from this NUMA node (1024 per LP)
285         */
286
287         lasue_lp = NULL;
288         number_logical_processors_in_numa_node = 0;
289
290         while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue_lp) )
291         {
292           pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue_lp );
293
294           libbenchmark_topology_query( ts, LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMA_NODE_FOR_LOGICAL_PROCESSOR, pts->tns_lp, &numa_node_for_lp );
295
296           if( LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID(*numa_node_for_lp) == pns->numa_node_id )
297             number_logical_processors_in_numa_node++;
298         }
299
300         number_benchmark_elements = number_logical_processors_in_numa_node * 1024;
301
302         ptns = libshared_memory_alloc_from_specific_node( ms, pns->numa_node_id, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_numa_benchmark_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
303         ptns->element_key_array = libshared_memory_alloc_from_specific_node( ms, pns->numa_node_id, sizeof(lfds710_pal_uint_t) * total_number_benchmark_elements, sizeof(lfds710_pal_uint_t) );
304         ptns->number_element_keys = total_number_benchmark_elements;
305
306         // TRD : everyone stores their elements in the same NUMA node
307         ptns->bme = libshared_memory_alloc_from_specific_node( ms, largest_pns->numa_node_id, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element) * number_benchmark_elements, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
308
309         for( loop = 0 ; loop < number_benchmark_elements ; loop++, index++ )
310           do
311           {
312             LIBBENCHMARK_PRNG_GENERATE( ps, ptns->bme[loop].datum );
313             obs->element_key_array[index] = ptns->bme[loop].datum;
314
315             LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_SET_KEY_IN_ELEMENT( *bs, ptns->bme[loop].be, &ptns->bme[loop] );
316             LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_SET_VALUE_IN_ELEMENT( *bs, ptns->bme[loop].be, &ptns->bme[loop] );
317             ir = libbenchmark_datastructure_btree_au_windows_mutex_insert( bs, &ptns->bme[loop].be, NULL );
318           }
319           while( ir == LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_INSERT_RESULT_FAILURE_EXISTING_KEY );
320
321         pns->users_per_numa_state = ptns;
322       }
323
324       // TRD : now copy over into each NUMA node state the element_key_array
325       lasue = NULL;
326
327       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
328       {
329         pns = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
330         ptns = pns->users_per_numa_state;
331
332         for( loop = 0 ; loop < total_number_benchmark_elements ; loop++ )
333           ptns->element_key_array[loop] = obs->element_key_array[loop];         
334       }
335
336       lasue = NULL;
337
338       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue) )
339       {
340         pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
341         ptbs = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_thread_benchmark_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
342         LIBBENCHMARK_PRNG_GENERATE( ps, ptbs->per_thread_prng_seed );
343         LIBBENCHMARK_PRNG_MURMURHASH3_MIXING_FUNCTION( ptbs->per_thread_prng_seed );
344         pts->users_per_thread_state = ptbs;
345       }
346     break;
347   }
348
349   obs->number_element_keys = total_number_benchmark_elements;
350   obs->bs = bs;
351   obs->numa_mode = numa_mode;
352
353   tsets->users_threadset_state = obs;
354
355   return;
356 }
357
358
359
360
361
362 /****************************************************************************/
363 libshared_pal_thread_return_t LIBSHARED_PAL_THREAD_CALLING_CONVENTION libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_thread( void *libbenchmark_threadset_per_thread_state )
364 {
365   int long long unsigned
366     current_time = 0,
367     end_time,
368     time_units_per_second;
369
370   lfds710_pal_uint_t
371     *element_key_array = NULL,
372     index,
373     number_element_keys = 0,
374     operation_count = 0,
375     random_value,
376     time_loop = 0;
377
378   struct libbenchmark_prng_state
379     ps;
380
381   struct libbenchmark_datastructure_btree_au_windows_mutex_element
382     *existing_be;
383
384   struct libbenchmark_datastructure_btree_au_windows_mutex_state
385     *bs;
386
387   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_thread_benchmark_state
388     *ptbs;
389
390   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_numa_benchmark_state
391     *pnbs = NULL;
392
393   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_overall_benchmark_state
394     *obs;
395
396   struct libbenchmark_threadset_per_thread_state
397     *pts;
398
399   LFDS710_MISC_BARRIER_LOAD;
400
401   LFDS710_PAL_ASSERT( libbenchmark_threadset_per_thread_state != NULL );
402
403   pts = (struct libbenchmark_threadset_per_thread_state *) libbenchmark_threadset_per_thread_state;
404
405   ptbs = LIBBENCHMARK_THREADSET_PER_THREAD_STATE_GET_USERS_PER_THREAD_STATE( *pts );
406   obs = LIBBENCHMARK_THREADSET_PER_THREAD_STATE_GET_USERS_OVERALL_STATE( *pts );
407   if( obs->numa_mode == LIBBENCHMARK_TOPOLOGY_NUMA_MODE_NUMA or obs->numa_mode == LIBBENCHMARK_TOPOLOGY_NUMA_MODE_NUMA_BUT_NOT_USED )
408     pnbs = LIBBENCHMARK_THREADSET_PER_THREAD_STATE_GET_USERS_PER_NUMA_STATE( *pts );
409
410   bs = obs->bs;
411
412   LIBBENCHMARK_PRNG_INIT( ps, ptbs->per_thread_prng_seed );
413
414   LIBBENCHMARK_PAL_TIME_UNITS_PER_SECOND( &time_units_per_second );
415
416   switch( obs->numa_mode )
417   {
418     case LIBBENCHMARK_TOPOLOGY_NUMA_MODE_SMP:
419       element_key_array = obs->element_key_array;
420       number_element_keys = obs->number_element_keys;
421     break;
422
423     case LIBBENCHMARK_TOPOLOGY_NUMA_MODE_NUMA:
424       element_key_array = pnbs->element_key_array;
425       number_element_keys = pnbs->number_element_keys;
426     break;
427
428     case LIBBENCHMARK_TOPOLOGY_NUMA_MODE_NUMA_BUT_NOT_USED:
429       element_key_array = pnbs->element_key_array;
430       number_element_keys = pnbs->number_element_keys;
431     break;
432   }
433
434   libbenchmark_threadset_thread_ready_and_wait( pts );
435
436   LIBBENCHMARK_PAL_GET_HIGHRES_TIME( &current_time );
437
438   end_time = current_time + time_units_per_second * libbenchmark_globals_benchmark_duration_in_seconds;
439
440   while( current_time < end_time )
441   {
442     LIBBENCHMARK_PRNG_GENERATE( ps, random_value );
443     index = random_value % number_element_keys;
444
445     // TRD : read
446     libbenchmark_datastructure_btree_au_windows_mutex_get_by_key( bs, NULL, &element_key_array[index], &existing_be );
447     // LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_GET_VALUE_FROM_ELEMENT( benchmark_state->bs, *existing_be, datum );
448
449     LIBBENCHMARK_PRNG_GENERATE( ps, random_value );
450     index = random_value % number_element_keys;
451
452     // TRD : write
453     libbenchmark_datastructure_btree_au_windows_mutex_get_by_key( bs, NULL, &element_key_array[index], &existing_be );
454     // LIBBENCHMARK_DATASTRUCTURE_BTREE_AU_WINDOWS_MUTEX_SET_VALUE_IN_ELEMENT( benchmark_state->bs, *existing_be, benchmark_state->benchmark_element_array[index].datum );
455
456     operation_count++;
457
458     if( time_loop++ == TIME_LOOP_COUNT )
459     {
460       time_loop = 0;
461       LIBBENCHMARK_PAL_GET_HIGHRES_TIME( &current_time );
462     }
463   }
464
465   ptbs->operation_count = operation_count;
466
467   LFDS710_MISC_BARRIER_STORE;
468
469   lfds710_misc_force_store();
470
471   return LIBSHARED_PAL_THREAD_RETURN_CAST(RETURN_SUCCESS);
472 }
473
474
475
476
477
478 /****************************************************************************/
479 void libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_cleanup( struct lfds710_list_aso_state *logical_processor_set,
480                                                                          enum libbenchmark_topology_numa_mode numa_mode,
481                                                                          struct libbenchmark_results_state *rs,
482                                                                          struct libbenchmark_threadset_state *tsets )
483 {
484   struct lfds710_list_asu_element
485     *lasue = NULL;
486
487   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_overall_benchmark_state
488     *obs;
489
490   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_per_thread_benchmark_state
491     *ptbs;
492
493   struct libbenchmark_threadset_per_thread_state
494     *pts;
495
496   LFDS710_PAL_ASSERT( logical_processor_set != NULL );
497   // TRD : numa_mode can be any value in its range
498   LFDS710_PAL_ASSERT( rs != NULL );
499   LFDS710_PAL_ASSERT( tsets != NULL );
500
501   while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_thread_states,lasue) )
502   {
503     pts = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
504
505     ptbs = LIBBENCHMARK_THREADSET_PER_THREAD_STATE_GET_USERS_PER_THREAD_STATE( *pts );
506
507     libbenchmark_results_put_result( rs,
508                                      LIBBENCHMARK_DATASTRUCTURE_ID_BTREE_AU,
509                                      LIBBENCHMARK_BENCHMARK_ID_READN_THEN_WRITEN,
510                                      LIBBENCHMARK_LOCK_ID_WINDOWS_MUTEX,
511                                      numa_mode,
512                                      logical_processor_set,
513                                      LIBBENCHMARK_TOPOLOGY_NODE_GET_LOGICAL_PROCESSOR_NUMBER( *pts->tns_lp ),
514                                      LIBBENCHMARK_TOPOLOGY_NODE_GET_WINDOWS_GROUP_NUMBER( *pts->tns_lp ),
515                                      ptbs->operation_count );
516   }
517
518   obs = tsets->users_threadset_state;;
519
520   libbenchmark_datastructure_btree_au_windows_mutex_cleanup( obs->bs, NULL );
521
522   return;
523 }
524
525
526
527
528
529 /****************************************************************************/
530 static int key_compare_function( void const *new_key, void const *existing_key )
531 {
532   struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element
533     *new_benchmark_element,
534     *existing_benchmark_element;
535
536   LFDS710_PAL_ASSERT( new_key != NULL );
537   LFDS710_PAL_ASSERT( existing_key != NULL );
538
539   new_benchmark_element = (struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element *) new_key;
540   existing_benchmark_element = (struct libbenchmark_benchmark_btree_au_windows_mutex_readn_writen_benchmark_element *) existing_key;
541
542   if( new_benchmark_element->datum < existing_benchmark_element->datum )
543     return -1;
544
545   if( new_benchmark_element->datum > existing_benchmark_element->datum )
546     return 1;
547
548   return 0;
549 }
550