]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libtest/src/libtest_tests/libtest_tests_list_addonly_singlylinked_unordered_new_end.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libtest / src / libtest_tests / libtest_tests_list_addonly_singlylinked_unordered_new_end.c
1 /***** includes *****/
2 #include "libtest_tests_internal.h"
3
4 /***** structs *****/
5 struct test_element
6 {
7   struct lfds710_list_asu_element
8     lasue;
9
10   lfds710_pal_uint_t
11     element_number,
12     thread_number;
13 };
14
15 struct test_per_thread_state
16 {
17   lfds710_pal_uint_t
18     number_elements_per_thread;
19
20   struct lfds710_list_asu_state
21     *lasus;
22
23   struct test_element
24     *element_array;
25 };
26
27 /***** private prototypes *****/
28 static libshared_pal_thread_return_t LIBSHARED_PAL_THREAD_CALLING_CONVENTION new_end_thread( void *libtest_threadset_per_thread_state );
29
30
31
32
33
34 /****************************************************************************/
35 void libtest_tests_list_asu_new_end( struct lfds710_list_asu_state *list_of_logical_processors, struct libshared_memory_state *ms, enum lfds710_misc_validity *dvs )
36 {
37   lfds710_pal_uint_t
38     loop,
39     number_elements,
40     number_elements_per_thread,
41     number_logical_processors,
42     *per_thread_counters,
43     subloop;
44
45   struct lfds710_list_asu_element
46     *lasue = NULL;
47
48   struct lfds710_list_asu_state
49     lasus;
50
51   struct lfds710_misc_validation_info
52     vi;
53
54   struct libtest_logical_processor
55     *lp;
56
57   struct libtest_threadset_per_thread_state
58     *pts;
59
60   struct libtest_threadset_state
61     ts;
62
63   struct test_element
64     *element_array,
65     *element;
66
67   struct test_per_thread_state
68     *tpts;
69
70   LFDS710_PAL_ASSERT( list_of_logical_processors != NULL );
71   LFDS710_PAL_ASSERT( ms != NULL );
72   LFDS710_PAL_ASSERT( dvs != NULL );
73
74   /* TRD : run one thread per logical processor
75            run for 250k elements
76            each thread loops, calling lfds710_list_asu_new_element_by_position( LFDS710_LIST_ASU_POSITION_END )
77            data element contain a thread_number and element_number
78            verification should show element_number increasing on a per thread basis
79   */
80
81   *dvs = LFDS710_MISC_VALIDITY_VALID;
82
83   lfds710_list_asu_query( list_of_logical_processors, LFDS710_LIST_ASU_QUERY_GET_POTENTIALLY_INACCURATE_COUNT, NULL, (void **) &number_logical_processors );
84   tpts = libshared_memory_alloc_from_unknown_node( ms, sizeof(struct test_per_thread_state) * number_logical_processors, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
85   pts = libshared_memory_alloc_from_unknown_node( ms, sizeof(struct libtest_threadset_per_thread_state) * number_logical_processors, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
86   per_thread_counters = libshared_memory_alloc_from_unknown_node( ms, sizeof(lfds710_pal_uint_t) * number_logical_processors, LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
87   element_array = libshared_memory_alloc_largest_possible_array_from_unknown_node( ms, sizeof(struct test_element), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES, &number_elements );
88
89   number_elements_per_thread = number_elements / number_logical_processors;
90
91   lfds710_list_asu_init_valid_on_current_logical_core( &lasus, NULL );
92
93   for( loop = 0 ; loop < number_logical_processors ; loop++ )
94     for( subloop = 0 ; subloop < number_elements_per_thread ; subloop++ )
95     {
96       (element_array+(loop*number_elements_per_thread)+subloop)->thread_number = loop;
97       (element_array+(loop*number_elements_per_thread)+subloop)->element_number = subloop;
98     }
99
100   libtest_threadset_init( &ts, NULL );
101
102   loop = 0;
103
104   while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(*list_of_logical_processors,lasue) )
105   {
106     lp = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
107
108     (tpts+loop)->lasus = &lasus;
109     (tpts+loop)->element_array = element_array + (loop*number_elements_per_thread);
110     (tpts+loop)->number_elements_per_thread = number_elements_per_thread;
111
112     libtest_threadset_add_thread( &ts, &pts[loop], lp, new_end_thread, &tpts[loop] );
113
114     loop++;
115   }
116
117   LFDS710_MISC_BARRIER_STORE;
118
119   lfds710_misc_force_store();
120
121   // TRD : run the test
122   libtest_threadset_run( &ts );
123
124   libtest_threadset_cleanup( &ts );
125
126   /* TRD : validate the resultant list
127            iterate over each element
128            we expect to find element numbers increment on a per thread basis
129   */
130
131   LFDS710_MISC_BARRIER_LOAD;
132
133   vi.min_elements = vi.max_elements = number_elements_per_thread * number_logical_processors;
134
135   lfds710_list_asu_query( &lasus, LFDS710_LIST_ASU_QUERY_SINGLETHREADED_VALIDATE, &vi, dvs );
136
137   for( loop = 0 ; loop < number_logical_processors ; loop++ )
138     *(per_thread_counters+loop) = 0;
139
140   lasue = NULL;
141
142   while( *dvs == LFDS710_MISC_VALIDITY_VALID and LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(lasus, lasue) )
143   {
144     element = LFDS710_LIST_ASU_GET_VALUE_FROM_ELEMENT( *lasue );
145
146     if( element->thread_number >= number_logical_processors )
147     {
148       *dvs = LFDS710_MISC_VALIDITY_INVALID_TEST_DATA;
149       break;
150     }
151
152     if( element->element_number > per_thread_counters[element->thread_number] )
153       *dvs = LFDS710_MISC_VALIDITY_INVALID_MISSING_ELEMENTS;
154
155     if( element->element_number < per_thread_counters[element->thread_number] )
156       *dvs = LFDS710_MISC_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;
157
158     if( element->element_number == per_thread_counters[element->thread_number] )
159       per_thread_counters[element->thread_number]++;
160   }
161
162   lfds710_list_asu_cleanup( &lasus, NULL );
163
164   return;
165 }
166
167
168
169
170
171 /****************************************************************************/
172 static libshared_pal_thread_return_t LIBSHARED_PAL_THREAD_CALLING_CONVENTION new_end_thread( void *libtest_threadset_per_thread_state )
173 {
174   lfds710_pal_uint_t
175     loop;
176
177   struct libtest_threadset_per_thread_state
178     *pts;
179
180   struct test_per_thread_state
181     *tpts;
182
183   LFDS710_MISC_MAKE_VALID_ON_CURRENT_LOGICAL_CORE_INITS_COMPLETED_BEFORE_NOW_ON_ANY_OTHER_LOGICAL_CORE;
184
185   LFDS710_PAL_ASSERT( libtest_threadset_per_thread_state != NULL );
186
187   pts = (struct libtest_threadset_per_thread_state *) libtest_threadset_per_thread_state;
188   tpts = LIBTEST_THREADSET_GET_USER_STATE_FROM_PER_THREAD_STATE( *pts );
189
190   libtest_threadset_thread_ready_and_wait( pts );
191
192   for( loop = 0 ; loop < tpts->number_elements_per_thread ; loop++ )
193   {
194     LFDS710_LIST_ASU_SET_KEY_IN_ELEMENT( (tpts->element_array+loop)->lasue, tpts->element_array+loop );
195     LFDS710_LIST_ASU_SET_VALUE_IN_ELEMENT( (tpts->element_array+loop)->lasue, tpts->element_array+loop );
196     lfds710_list_asu_insert_at_position( tpts->lasus, &(tpts->element_array+loop)->lasue, NULL, LFDS710_LIST_ASU_POSITION_END );
197   }
198
199   LFDS710_MISC_BARRIER_STORE;
200
201   lfds710_misc_force_store();
202
203   return LIBSHARED_PAL_THREAD_RETURN_CAST(RETURN_SUCCESS);
204 }
205