2 #include "libbenchmark_threadset_internal.h"
8 /****************************************************************************/
9 void libbenchmark_threadset_init( struct libbenchmark_threadset_state *tsets,
10 struct libbenchmark_topology_state *ts,
11 struct lfds710_list_aso_state *logical_processor_set,
12 struct libshared_memory_state *ms,
13 libshared_pal_thread_return_t (LIBSHARED_PAL_THREAD_CALLING_CONVENTION *thread_function)( void *thread_user_state ),
14 void *users_threadset_state )
16 struct lfds710_list_aso_element
19 struct lfds710_list_asu_element
22 struct libbenchmark_threadset_per_numa_state
25 struct libbenchmark_threadset_per_thread_state
28 struct libbenchmark_topology_node_state
32 LFDS710_PAL_ASSERT( tsets != NULL );
33 LFDS710_PAL_ASSERT( ts != NULL );
34 LFDS710_PAL_ASSERT( logical_processor_set != NULL );
35 LFDS710_PAL_ASSERT( ms != NULL );
36 LFDS710_PAL_ASSERT( thread_function != NULL );
37 // TRD : users_threadset_state can be NULL
39 tsets->threadset_start_flag = LOWERED;
41 tsets->thread_function = thread_function;
42 tsets->users_threadset_state = users_threadset_state;
43 lfds710_list_asu_init_valid_on_current_logical_core( &tsets->list_of_per_numa_states, NULL );
44 lfds710_list_asu_init_valid_on_current_logical_core( &tsets->list_of_per_thread_states, NULL );
46 /* TRD : loop over the logical_processor_set
47 make a thread_state for each
48 and make a NUMA node state for each unique NUMA node
51 while( LFDS710_LIST_ASO_GET_START_AND_THEN_NEXT(*logical_processor_set,lasoe) )
53 tns = LFDS710_LIST_ASO_GET_VALUE_FROM_ELEMENT( *lasoe );
55 // TRD : first, make a NUMA node entry, if we need to
57 libbenchmark_topology_query( ts, LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMA_NODE_FOR_LOGICAL_PROCESSOR, tns, &tns_numa_node );
59 if( tns_numa_node != NULL )
63 while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
65 pns = LFDS710_LIST_ASO_GET_VALUE_FROM_ELEMENT( *lasue );
67 if( pns->numa_node_id == LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID(*tns_numa_node) )
73 pns = libshared_memory_alloc_from_specific_node( ms, LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID(*tns_numa_node), sizeof(struct libbenchmark_threadset_per_numa_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
75 pns->numa_node_id = LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID( *tns_numa_node );
76 pns->users_per_numa_state = NULL;
77 LFDS710_LIST_ASU_SET_VALUE_IN_ELEMENT( pns->lasue, pns );
78 lfds710_list_asu_insert_at_start( &tsets->list_of_per_numa_states, &pns->lasue );
82 // TRD : now make a thread entry (pns now points at the correct NUMA node entry)
84 pts = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_threadset_per_thread_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
86 pts = libshared_memory_alloc_from_specific_node( ms, pns->numa_node_id, sizeof(struct libbenchmark_threadset_per_thread_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
88 pts->thread_ready_flag = LOWERED;
89 pts->threadset_start_flag = &tsets->threadset_start_flag;
91 pts->numa_node_state = pns; // TRD : pns is NULL on SMP
92 pts->threadset_state = tsets;
93 pts->users_per_thread_state = NULL;
95 LFDS710_LIST_ASU_SET_VALUE_IN_ELEMENT( pts->lasue, pts );
96 lfds710_list_asu_insert_at_start( &tsets->list_of_per_thread_states, &pts->lasue );
99 LFDS710_MISC_BARRIER_STORE;
101 lfds710_misc_force_store();