]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.1.0/test_and_benchmark/libbenchmark/src/libbenchmark_topology/libbenchmark_topology_query.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_query.c
1 /***** includes *****/
2 #include "libbenchmark_topology_internal.h"
3
4
5
6
7
8 /****************************************************************************/
9 void libbenchmark_topology_query( struct libbenchmark_topology_state *ts, enum libbenchmark_topology_query query_type, void *query_input, void *query_output )
10 {
11   LFDS710_PAL_ASSERT( ts != NULL );
12
13   // TRD : query type can be any value in its range
14   // TRD : query_input can be NULL in some cases
15   // TRD : query_outputput can be NULL in some cases
16
17   switch( query_type )
18   {
19     case LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMBER_OF_NODE_TYPE:
20     {
21       enum libbenchmark_topology_node_type
22         type;
23
24       lfds710_pal_uint_t
25         *count;
26
27       struct lfds710_btree_au_element
28         *baue = NULL;
29
30       struct libbenchmark_topology_node_state
31         *tns;
32
33       // TRD : query_input is an enum and so can be 0
34       LFDS710_PAL_ASSERT( query_output != NULL );
35
36       type = (enum libbenchmark_topology_node_type) (lfds710_pal_uint_t) query_input;
37       count = (lfds710_pal_uint_t *) query_output;
38
39       *count = 0;
40
41       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) )
42       {
43         tns = LFDS710_BTREE_AU_GET_VALUE_FROM_ELEMENT( *baue );
44
45         if( tns->type == type )
46           (*count)++;
47       }
48     }
49     break;
50
51     case LIBBENCHMARK_TOPOLOGY_QUERY_GET_NUMA_NODE_FOR_LOGICAL_PROCESSOR:
52     {
53       struct lfds710_btree_au_element
54         *baue;
55
56       struct libbenchmark_topology_node_state
57         *tns_lp,
58         *tns = NULL;
59
60       LFDS710_PAL_ASSERT( query_input != NULL );
61       LFDS710_PAL_ASSERT( query_output != NULL );
62
63       *(struct libbenchmark_topology_node_state **) query_output = NULL;
64
65       tns_lp = (struct libbenchmark_topology_node_state *) query_input;
66
67       // TRD : find the LP, the climb the tree to the first larger NUMA node
68
69       lfds710_btree_au_get_by_key( &ts->topology_tree, NULL, tns_lp, &baue );
70
71       while( lfds710_btree_au_get_by_relative_position(&baue,LFDS710_BTREE_AU_RELATIVE_POSITION_NEXT_LARGER_ELEMENT_IN_ENTIRE_TREE) )
72       {
73         tns = LFDS710_BTREE_AU_GET_VALUE_FROM_ELEMENT( *baue );
74
75         if( tns->type == LIBBENCHMARK_TOPOLOGY_NODE_TYPE_NUMA )
76           break;
77       }
78
79       if( tns->type == LIBBENCHMARK_TOPOLOGY_NODE_TYPE_NUMA )
80         *(struct libbenchmark_topology_node_state **) query_output = tns;
81     }
82     break;
83   }
84
85   return;
86 }
87