summaryrefslogtreecommitdiffstats
path: root/src/usr/targeting/common/utilFilter.C
blob: d981b6051a79a085717b920d69586768acd064ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/targeting/common/utilFilter.C $                       */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
//******************************************************************************
// Includes
//******************************************************************************
#include <targeting/common/commontargeting.H>
#include <targeting/common/entitypath.H>
#include <targeting/common/trace.H>
#include <attributeenums.H>
#include <targeting/common/iterators/rangefilter.H>
#include <targeting/common/predicates/predicateisfunctional.H>
#include <targeting/common/predicates/predicatepostfixexpr.H>
#include <targeting/common/predicates/predicateattrval.H>

/**
 * Miscellaneous Filter Utility Functions
 */

namespace TARGETING
{

/**
 * @brief Populate the o_vector with target object pointers based on the
 *        requested class, type, and functional state.
 *
 * @parm[out] o_vector, reference of vector of target pointers.
 * @parm[in]  i_class, the class of the targets to be obtained
 * @parm[in]  i_type, the type of the targets to be obtained
 * @parm[in]  i_functional, set to true to return only functional targets
 *
 * @return N/A
 */
void _getAllChipsOrChiplets( TARGETING::TargetHandleList & o_vector,
                     CLASS i_class, TYPE  i_type, bool i_functional = true )
{
    // Get all chip/chiplet targets
    //  Use PredicateIsFunctional to filter only functional chips/chiplets
    TARGETING::PredicateIsFunctional l_isFunctional;
    //  filter for functional Chips/Chiplets
    TARGETING::PredicateCTM l_Filter(i_class, i_type);
    // declare a postfix expression widget
    TARGETING::PredicatePostfixExpr l_goodFilter;
    //  is-a--chip  is-functional   AND
    l_goodFilter.push(&l_Filter).push(&l_isFunctional).And();
    // apply the filter through all targets.
    TARGETING::TargetRangeFilter l_filter( TARGETING::targetService().begin(),
                            TARGETING::targetService().end(), &l_goodFilter );
    if (!i_functional)
    {
        l_filter.setPredicate(&l_Filter);
    }

    o_vector.clear();
    for ( ; l_filter; ++l_filter)
    {
        o_vector.push_back( *l_filter );
    }
}


void getAllChips( TARGETING::TargetHandleList & o_vector,
                  TYPE i_chipType, bool i_functional = true )
{
    _getAllChipsOrChiplets(o_vector, CLASS_CHIP, i_chipType, i_functional);
}


void getAllLogicalCards( TARGETING::TargetHandleList & o_vector,
                         TYPE i_cardType,
                         bool i_functional = true )
{
    _getAllChipsOrChiplets( o_vector,
                            CLASS_LOGICAL_CARD,
                            i_cardType,
                            i_functional );
}


void getAllCards( TARGETING::TargetHandleList & o_vector,
                  TYPE i_cardType,
                  bool i_functional = true )
{
    _getAllChipsOrChiplets( o_vector,
                            CLASS_CARD,
                            i_cardType,
                            i_functional );
}


void getAllChiplets( TARGETING::TargetHandleList & o_vector,
                     TYPE i_chipletType, bool i_functional = true )
{
    _getAllChipsOrChiplets(o_vector, CLASS_UNIT, i_chipletType, i_functional);
}


void getChildChiplets( TARGETING::TargetHandleList& o_vector,
                 const Target * i_chip, TYPE i_type, bool i_functional )
{
    //  get the chiplets associated with this cpu
    TARGETING::PredicateCTM l_chipletFilter(CLASS_UNIT, i_type);

    o_vector.clear();
    if (i_functional)
    {
        //  Use PredicateIsFunctional to filter only functional chiplets
        TARGETING::PredicateIsFunctional l_functional;
        TARGETING::PredicatePostfixExpr l_functionalChiplets;
        l_functionalChiplets.push(&l_chipletFilter).push(&l_functional).And();
        TARGETING::targetService().getAssociated(
                o_vector,
                i_chip,
                TARGETING::TargetService::CHILD,
                TARGETING::TargetService::ALL,
                &l_functionalChiplets );
    }
    else
    {
        TARGETING::targetService().getAssociated(
                o_vector,
                i_chip,
                TARGETING::TargetService::CHILD,
                TARGETING::TargetService::ALL,
                &l_chipletFilter );
    }

}

void getAffinityTargets ( TARGETING::TargetHandleList& o_vector,
                 const Target * i_target, CLASS i_class, TYPE i_type,
                 TARGETING::TargetService::ASSOCIATION_TYPE i_association,
                  bool i_functional )
{
    //  find all the targets that are affinity-associated with i_target
    TARGETING::PredicateCTM l_targetFilter(i_class, i_type);

    o_vector.clear();
    if (i_functional)
    {
        //  Use PredicateIsFunctional to filter only functional chips
        TARGETING::PredicateIsFunctional l_functional;
        TARGETING::PredicatePostfixExpr l_functionalTargets;
        l_functionalTargets.push(&l_targetFilter).push(&l_functional).And();
        TARGETING::targetService().getAssociated(
                o_vector,
                i_target,
                i_association,
                TARGETING::TargetService::ALL,
                &l_functionalTargets );
    }
    else
    {
        TARGETING::targetService().getAssociated(
                o_vector,
                i_target,
                i_association,
                TARGETING::TargetService::ALL,
                &l_targetFilter );
    }

}

void getChildAffinityTargets(
          TARGETING::TargetHandleList& o_vector,
    const Target*                      i_target, 
          CLASS                        i_class, 
          TYPE                         i_type, 
          bool                         i_functional)
{
    getAffinityTargets (o_vector, i_target, i_class, i_type,
        TARGETING::TargetService::CHILD_BY_AFFINITY, 
        i_functional); 
}


void getParentAffinityTargets(
          TARGETING::TargetHandleList& o_vector,
    const Target*                      i_target, 
          CLASS                        i_class, 
          TYPE                         i_type,
          bool                         i_functional )
{

    getAffinityTargets (o_vector, i_target, i_class, i_type,
        TARGETING::TargetService::PARENT_BY_AFFINITY,
        i_functional); 
}

const Target * getParentChip( const Target * i_pChiplet )
{

    const Target * l_pChip = NULL;

    // Create a Class/Type/Model predicate to look for chips
    TARGETING::PredicateCTM l_predicate(TARGETING::CLASS_CHIP);

    // Create a vector of TARGETING::Target pointers
    TARGETING::TargetHandleList l_chipList;

    // Get parent
    TARGETING::targetService().getAssociated(l_chipList, i_pChiplet,
                          TARGETING::TargetService::PARENT,
                          TARGETING::TargetService::ALL, &l_predicate);

    if (l_chipList.size() == 1)
    {
        l_pChip = l_chipList[0];
    }
    else
    {
        TARG_ERR("Number of Parent chip is not 1, but %d",l_chipList.size());
    }

    return l_pChip;
}

void getPeerTargets(
          TARGETING::TargetHandleList& o_peerTargetList,
    const Target*                      i_pSrcTarget,
    const PredicateBase*               i_pPeerFilter,
    const PredicateBase*               i_pResultFilter)
{
    #define TARG_FN "getPeerTargets"
    TARG_ENTER();
    Target* l_pPeerTarget = NULL;
    
    if(i_pSrcTarget == NULL)
    {
        TARG_ASSERT("User tried to call getPeerTargets using NULL Target"
                " Handle");
    }
    
    // Clear the list
    o_peerTargetList.clear();
    do
    {
        // List to maintain all child targets which are found by get associated
        // from the Src target with i_pPeerFilter predicate 
        TARGETING::TargetHandleList l_pSrcTarget_list;

        // Create input master predicate here by taking in the i_pPeerFilter
        TARGETING::PredicatePostfixExpr l_superPredicate;
        TARGETING::PredicateAttrVal<TARGETING::ATTR_PEER_TARGET>
            l_notNullPeerExist(NULL, true);
        l_superPredicate.push(&l_notNullPeerExist);
        if(i_pPeerFilter)
        {
            l_superPredicate.push(i_pPeerFilter).And();
        }

        // Check if the i_srcTarget is the leaf node
        if(i_pSrcTarget->tryGetAttr<TARGETING::ATTR_PEER_TARGET>(l_pPeerTarget))
        {
            if(l_superPredicate(i_pSrcTarget))
            {
                // Exactly one Peer Target to Cross
                // Put this to input target list
                l_pSrcTarget_list.push_back(
                        const_cast<TARGETING::Target*>(i_pSrcTarget));
            }
            else
            {
                TARG_INF("Input Target provided doesn't have a valid Peer "
                    "Target Attribute, Returning Empty List");
                break;
            }
        }
        // Not a leaf node, find out all leaf node with valid PEER Target
        else
        {
            (void) TARGETING::targetService().getAssociated(
                    l_pSrcTarget_list,
                    i_pSrcTarget,
                    TARGETING::TargetService::CHILD,
                    TARGETING::TargetService::ALL,
                    &l_superPredicate);
        }

        // Now we have a list of input targets on which we have to find the peer
        // Check if we have a result predicate filter to apply
        if(i_pResultFilter == NULL)
        {
            // Simply get the Peer Target for all Src target in the list and
            // return
            for(TARGETING::TargetHandleList::const_iterator pTargetIt 
                    = l_pSrcTarget_list.begin(); 
                pTargetIt != l_pSrcTarget_list.end();
                ++pTargetIt)
            {
                TARGETING::Target* l_pPeerTgt = 
                    (*pTargetIt)->getAttr<TARGETING::ATTR_PEER_TARGET>();
                o_peerTargetList.push_back(l_pPeerTgt);
            }
            break;
        }
        // Result predicate filter is not NULL, we need to apply this predicate
        // on each of the PEER Target found on the input target list
        else
        {
            for(TARGETING::TargetHandleList::const_iterator pTargetIt 
                    = l_pSrcTarget_list.begin(); 
                pTargetIt != l_pSrcTarget_list.end();
                ++pTargetIt)
            {
                TARGETING::TargetHandleList l_peerTarget_list;
                TARGETING::Target* l_pPeerTgt = 
                    (*pTargetIt)->getAttr<TARGETING::ATTR_PEER_TARGET>();

                // Check whether this target matches the filter criteria
                // or we have to look for ALL Parents matching the criteria.
                if((*i_pResultFilter)(l_pPeerTgt))
                {
                    o_peerTargetList.push_back(l_pPeerTgt);
                }
                else
                {
                    (void) TARGETING::targetService().getAssociated(
                            l_peerTarget_list,
                            l_pPeerTgt,
                            TARGETING::TargetService::PARENT,
                            TARGETING::TargetService::ALL,
                            i_pResultFilter);
                    if(!l_peerTarget_list.empty())
                    {
                        // Insert the first one only.
                        o_peerTargetList.push_back(
                                l_peerTarget_list.front());
                    }
                }
            }
        }
    } while(0);

    TARG_EXIT();
    #undef TARG_FN
}

};  // end namespace
OpenPOWER on IntegriCloud