]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libbenchmark/src/libbenchmark_topology/libbenchmark_topology_init.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.1.0 / test_and_benchmark / libbenchmark / src / libbenchmark_topology / libbenchmark_topology_init.c
1 /***** includes *****/
2 #include "libbenchmark_topology_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 int libbenchmark_topology_init( struct libbenchmark_topology_state *ts, struct libshared_memory_state *ms )
10 {
11   int
12     offset = 0,
13     rv;
14
15   lfds710_pal_uint_t
16     lp_count;
17
18   struct lfds710_btree_au_element
19     *baue;
20
21   struct libbenchmark_topology_lp_printing_offset
22     *tlpo;
23
24   struct libbenchmark_topology_node_state
25     *tns;
26
27   LFDS710_PAL_ASSERT( ts != NULL );
28   LFDS710_PAL_ASSERT( ms != NULL );
29
30   lfds710_btree_au_init_valid_on_current_logical_core( &ts->topology_tree, libbenchmark_topology_node_compare_nodes_function, LFDS710_BTREE_AU_EXISTING_KEY_FAIL, NULL );
31
32   rv = libbenchmark_porting_abstraction_layer_populate_topology( ts, ms );
33
34   lfds710_btree_au_get_by_absolute_position( &ts->topology_tree, &baue, LFDS710_BTREE_AU_ABSOLUTE_POSITION_LARGEST_IN_TREE );
35   lp_count = count_of_logical_processors_below_node( baue );
36   ts->line_width = (int) ( lp_count * 3 + lp_count - 1 );
37
38   // TRD : now form up the printing offset tree
39   lfds710_btree_au_init_valid_on_current_logical_core( &ts->lp_printing_offset_lookup_tree, libbenchmark_topology_compare_lp_printing_offsets_function, LFDS710_BTREE_AU_EXISTING_KEY_FAIL, NULL );
40
41   baue = NULL;
42
43   while( lfds710_btree_au_get_by_absolute_position_and_then_by_relative_position(&ts->topology_tree, &baue, LFDS710_BTREE_AU_ABSOLUTE_POSITION_LARGEST_IN_TREE, LFDS710_BTREE_AU_RELATIVE_POSITION_NEXT_SMALLER_ELEMENT_IN_ENTIRE_TREE) )
44   {
45     tns = LFDS710_BTREE_AU_GET_KEY_FROM_ELEMENT( *baue );
46
47     if( tns->type == LIBBENCHMARK_TOPOLOGY_NODE_TYPE_LOGICAL_PROCESSOR )
48     {
49       tlpo = libshared_memory_alloc_from_most_free_space_node( ms, sizeof(struct libbenchmark_topology_lp_printing_offset), LFDS710_PAL_ATOMIC_ISOLATION_IN_BYTES );
50
51       tlpo->tns = *tns;
52       tlpo->offset = offset;
53
54       LFDS710_BTREE_AU_SET_KEY_IN_ELEMENT( tlpo->baue, tlpo );
55       LFDS710_BTREE_AU_SET_VALUE_IN_ELEMENT( tlpo->baue, tlpo );
56
57       lfds710_btree_au_insert( &ts->lp_printing_offset_lookup_tree, &tlpo->baue, NULL );
58
59       offset += 4;
60     }
61   }
62
63   return rv;
64 }
65