]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libbenchmark/src/libbenchmark_threadset/libbenchmark_threadset_init.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libbenchmark / src / libbenchmark_threadset / libbenchmark_threadset_init.c
1 /***** includes *****/
2 #include "libbenchmark_threadset_internal.h"
3
4
5
6
7
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 )
15 {
16   struct lfds710_list_aso_element
17     *lasoe = NULL;
18
19   struct lfds710_list_asu_element
20     *lasue = NULL;
21
22   struct libbenchmark_threadset_per_numa_state
23     *pns = NULL;
24
25   struct libbenchmark_threadset_per_thread_state
26     *pts;
27
28   struct libbenchmark_topology_node_state
29     *tns,
30     *tns_numa_node;
31
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
38
39   tsets->threadset_start_flag = LOWERED;
40
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 );
45
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
49   */
50
51   while( LFDS710_LIST_ASO_GET_START_AND_THEN_NEXT(*logical_processor_set,lasoe) )
52   {
53     tns = LFDS710_LIST_ASO_GET_VALUE_FROM_ELEMENT( *lasoe );
54
55     // TRD : first, make a NUMA node entry, if we need to
56
57     libbenchmark_topology_query( ts, LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMA_NODE_FOR_LOGICAL_PROCESSOR, tns, &tns_numa_node );
58
59     if( tns_numa_node != NULL )
60     {
61       lasue = NULL;
62
63       while( LFDS710_LIST_ASU_GET_START_AND_THEN_NEXT(tsets->list_of_per_numa_states,lasue) )
64       {
65         pns = LFDS710_LIST_ASO_GET_VALUE_FROM_ELEMENT( *lasue );
66
67         if( pns->numa_node_id == LIBBENCHMARK_TOPOLOGY_NODE_GET_NUMA_ID(*tns_numa_node) )
68           break;
69       }
70
71       if( lasue == NULL )
72       {
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 );
74
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 );
79       }
80     }
81
82     // TRD : now make a thread entry (pns now points at the correct NUMA node entry)
83     if( pns == NULL )
84       pts = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_threadset_per_thread_state), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
85     else
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 );
87
88     pts->thread_ready_flag = LOWERED;
89     pts->threadset_start_flag = &tsets->threadset_start_flag;
90     pts->tns_lp = tns;
91     pts->numa_node_state = pns; // TRD : pns is NULL on SMP
92     pts->threadset_state = tsets;
93     pts->users_per_thread_state = NULL;
94
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 );
97   }
98
99   LFDS710_MISC_BARRIER_STORE;
100
101   lfds710_misc_force_store();
102
103   return;
104 }
105