summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/config/iipSystem.C
blob: 1e79437d3b75bcd0bb049100a9fdfe2a417cd049 (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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/config/iipSystem.C $       */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1996,2014              */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

// Module Description **************************************************
//
// Description: This module provides the implementation for the PRD
//              System class.
//
// End Module Description **********************************************

/*--------------------------------------------------------------------*/
/* Emit the virtual function tables and inline function defintions in
 this translation unit.                                             */
/*--------------------------------------------------------------------*/
#ifdef __GNUC__
#endif

//----------------------------------------------------------------------
//  Includes
//----------------------------------------------------------------------

#include <prdfMain.H>
#include <iipSystem.h>
#include <iipResolution.h>
#include <iipsdbug.h>
#include <iipchip.h>
#include <iipDomain.h>
#include <iipServiceDataCollector.h>
#include <iipResolutionFactory.h>
#include <prdfPlatServices.H>
#include <prdfGlobal.H>
#include <prdfRuleMetaData.H>
#include <prdfMfgThresholdMgr.H>

namespace PRDF
{

//----------------------------------------------------------------------
//  User Types
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Constants
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Macros
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Internal Function Prototypes
//----------------------------------------------------------------------

//----------------------------------------------------------------------
//  Global Variables
//----------------------------------------------------------------------

//---------------------------------------------------------------------
// Member Function Specifications
//---------------------------------------------------------------------

System::System( Resolution & noSystemAttentions ) :
    chips(),
    prioritizedDomains(),
    noAttnResolution(noSystemAttentions)
{}

System::~System(void)
{
    for(ChipMapType::iterator chipIterator = chips.begin();
        chipIterator != chips.end();chipIterator++)
    {
        delete (*chipIterator);
    }

    // change to delete prioritiezed Domains instead of domains dg04
    for(DomainContainerType::iterator domainIterator = prioritizedDomains.begin();
        domainIterator != prioritizedDomains.end();domainIterator++)
    {
        delete (*domainIterator);
    }
    // clear the Resolution factory
    ResolutionFactory::Access().Reset();

    // clear the MfgThresholdMgr
    MfgThresholdMgr::getInstance()->reset();

    // clear the threshold policies
    ThresholdResolution::reset();
    //clears list of all the RuleMetaData instances
    for( RuleMetaDataList::iterator l_itMetaData = iv_listRuleData.begin();
            l_itMetaData != iv_listRuleData.end(); l_itMetaData++ )
    {
        delete( l_itMetaData->second );
    }
    iv_listRuleData.clear();

}

CHIP_CLASS * System::GetChip(TARGETING::TargetHandle_t i_pchipHandle )
{
    CHIP_CLASS * chipPtr = NULL;

    //  chips.LookUp(chipPtr, chipId);
    for(uint32_t i = 0; i < chips.size(); ++i)
    {
        if(chips[i]->GetChipHandle() == i_pchipHandle)
        {
            chipPtr = chips[i];
            break;
        }
    }

    return(chipPtr);
}

Domain * System::GetDomain(DOMAIN_ID domainId)
{
    Domain * domainPtr = NULL;

    //  domains.LookUp(domainPtr, domainId);
    for(uint32_t i = 0; i < prioritizedDomains.size(); ++i)
    {
        if(prioritizedDomains[i]->GetId() == domainId)
        {
            domainPtr = prioritizedDomains[i];
            break;
        }
    }

    return(domainPtr);
}

void System::AddChips(ChipContainerIterator begin,
                      ChipContainerIterator end)
{
    size_t l_size = 0;
    if(begin < end) l_size = end-begin;
    else l_size = begin-end;
    chips.reserve(chips.size()+l_size);
    while(begin != end)
    {
        chips.push_back(*begin);
        begin++;
    }
}

void System::AddDomains(DomainContainerIterator begin,
                        DomainContainerIterator end)
{
    size_t l_size = 0;
    if(begin < end) l_size = end-begin;
    else l_size = begin-end;
    prioritizedDomains.reserve(prioritizedDomains.size()+l_size);
    // The Configurator owns determining the priority of the domains.
    while(begin != end)
    {
        prioritizedDomains.push_back(*begin);        // dg01 - add: Keep order given
        begin++;
    }
}

void System::RemoveStoppedChips(TARGETING::TargetHandle_t i_pchipHandle)
{
    PRDF_TRAC("System::RemoveStoppedChips chip: 0x%08x",
                  PlatServices::getHuid(i_pchipHandle));
    for(DomainContainerType::iterator domainIterator = prioritizedDomains.begin();
        domainIterator != prioritizedDomains.end(); domainIterator++)
    {
        (*domainIterator)->Remove(i_pchipHandle);
    }
}

// --------------------------------------------------------------------

void System::RemoveNonFunctionalChips()
{
    ChipMapType l_chips;

    for(ChipMapType::iterator chipIterator = chips.begin();
        chipIterator != chips.end();
        chipIterator++)
    {
        if(!PlatServices::isFunctional((*chipIterator)->GetChipHandle()))
        {
            l_chips.push_back(*chipIterator);
        }
    }

    // The reason for l_chips is because we can't remove elements from a vector
    // as we are iterating on it. Otherwise, it will foul up the iterators.
    // Now, this is not the most efficient way to remove the chips, because this
    // implementation will remove (put at the end of the vector) the chip then
    // erase it and repeat for each element. Instead, it should remove all chips
    // then erase all removed chips. However, for the scope of this code, the
    // efficiency increase is nominal so it can be left for future improvements.
    for(ChipMapType::iterator chipIterator = l_chips.begin();
        chipIterator != l_chips.end();
        chipIterator++)
    {
        RemoveStoppedChips((*chipIterator)->GetChipHandle());
    }
}

// --------------------------------------------------------------------

void System::Initialize(void)
{
    uint32_t rc = SUCCESS;
    //SYSTEM_DEBUG_CLASS sysdebug; dg08d

    for(ChipMapType::iterator chipIterator = chips.begin();
        (chipIterator != chips.end()) && (rc == SUCCESS);chipIterator++)
    {
        rc = (*chipIterator)->Initialize();
        // if rc then an error log was (will be) committed
        if(rc != SUCCESS)
        {
            PRDF_ERR( "System::Initialize of chips failed. rc = %x", rc );
        }
    }

    // change domains to priortizedDomains  dg04
    for(DomainContainerType::iterator domainIterator = prioritizedDomains.begin();
        (domainIterator != prioritizedDomains.end()) && (rc == SUCCESS);
        domainIterator++)
    {
        rc = (*domainIterator)->Initialize();

        if(rc != SUCCESS)
        {
            PRDF_ERR( "System::Initialize of chips failed. rc = %x", rc );
        }
    }
}

// -------------------------------------------------------------------

int32_t System::Analyze(STEP_CODE_DATA_STRUCT & serviceData,
                    ATTENTION_TYPE attentionType)
{
    #define PRDF_FUNC "[System::Analyze] "
    SYSTEM_DEBUG_CLASS sysdebug;
    Domain * domainAtAttentionPtr = NULL;
    ServiceDataCollector * l_saved_sdc = NULL;
    ServiceDataCollector * l_temp_sdc = NULL;

    int32_t rc = (prioritizedDomains.empty() ? NO_DOMAINS_IN_SYSTEM : SUCCESS);
    int32_t l_saved_rc = 0;
    int32_t l_primaryRc = 0;
    if(rc == SUCCESS)
    {
        // IF machine check then check for recoverable errors first
        // otherwise just check for the given type of attention
        ATTENTION_TYPE startAttention = attentionType;
        if((attentionType == MACHINE_CHECK) || (attentionType == UNIT_CS))
            startAttention = RECOVERABLE;

        ATTENTION_TYPE atnType = startAttention;
        for(atnType = startAttention;
            domainAtAttentionPtr == NULL && atnType >= attentionType ;
            --atnType)
        {
            for(DomainContainerType::iterator domainIterator = prioritizedDomains.begin();
                domainIterator != prioritizedDomains.end() && domainAtAttentionPtr == NULL;
                domainIterator++)
            {
                domainAtAttentionPtr = ((*domainIterator)->Query(atnType)) ? (*domainIterator) : NULL;
                if(domainAtAttentionPtr != NULL)
                {
                    serviceData.service_data->SetCauseAttentionType(atnType);
                    rc = domainAtAttentionPtr->Analyze(serviceData, atnType);
                    if((rc == PRD_SCAN_COMM_REGISTER_ZERO) ||
                        (rc == PRD_POWER_FAULT))
                    {
                        // save sdc, and continue
                        if(l_saved_sdc == NULL)
                        {
                            l_saved_sdc = new ServiceDataCollector(
                                                *serviceData.service_data);
                            l_saved_rc = rc;
                        }
                        // TODO clear serviceData ?
                        domainAtAttentionPtr = NULL;

                        if(rc == PRD_POWER_FAULT)
                        {
                            PRDF_ERR( PRDF_FUNC"Power Fault detected!" );
                            break;
                        }
                    }
                    else if ( ( attentionType == MACHINE_CHECK )
                             && ( atnType != MACHINE_CHECK ) )
                    {
                        // We were asked to analyze MACHINE XTOP, but we found
                        // another attention and did analyze that. In this case
                        // we want to add additional signature of MACHINE XSTOP
                        // attention to error log.

                        // l_temp_sdc is not NULL. It is a code bug. Do not do
                        // anything for error isolation pass.
                        if ( NULL != l_temp_sdc )
                        {
                            PRDF_ERR( PRDF_FUNC"l_temp_sdc is not NULL" );
                            continue;
                        }

                        // Do a setup for error isolation pass for MACHINE
                        // XTOP. In this pass, we are only interested in
                        // error signature.
                        domainAtAttentionPtr = NULL;
                        l_temp_sdc = new ServiceDataCollector (
                                                    *serviceData.service_data );
                        // Set up Error Isolation Pass Flag.
                        serviceData.service_data->setIsolationOnlyPass();
                        // Set the outer for loop iteration variable atnType so
                        // that we analyze MACHINE XSTOP in next iteration.
                        atnType = MACHINE_CHECK + 1;
                        // save primary rc.
                        l_primaryRc = rc;
                        break;
                    }

                } // end domainAtAttentionPtr != NULL
            } // end inner for loop
        } // end outer for loop

        // if ptr is NULL && we don't have a saved SDC than we have noAttns
        // if ptr is NULL && we have a saved SDC then we have an attn with no-bits-on
        // otherwise we are done - aready did the analysis
        if ( domainAtAttentionPtr == NULL)
        {
            if(l_saved_sdc == NULL)
            {
                rc = noAttnResolution.Resolve(serviceData);
            }
            else
            {
                *serviceData.service_data = *l_saved_sdc;
                sysdebug.CalloutThoseAtAttention(serviceData);
                rc = l_saved_rc;
            }
        }

        // l_temp_sdc will not be NULL if we go to ERROR ISOLATION ONLY PASS.
        // In that case get the secondary signature and update this.
        if ( NULL != l_temp_sdc )
        {
            // Merge SUE flag
            if( serviceData.service_data->IsSUE() )
            {
                l_temp_sdc->SetSUE();
            }

            // We are having only one secondary signature. Secondary signature
            // here is mainly used for XSTOP error. XSTOP error can only happen
            // on Fabric domain. For fabric domain, we use Fabric sorting which
            // will give us first chip which is root cause for the XSTOP error.
            // So signature we get after fabric sorting is enough for FFDC
            // perspective.

            l_temp_sdc->AddSignatureList(
                           *( serviceData.service_data->GetErrorSignature() ));

            // merge debug scom data from the two analysis
            l_temp_sdc->GetCaptureData().mergeData(
                            serviceData.service_data->GetCaptureData());

            *serviceData.service_data = *l_temp_sdc;
            delete l_temp_sdc;

            // We will discard any error we get in ERROR ISOLATION ONLY PASS,
            // and restore rc found in primary pass.
            rc = l_primaryRc;
        }

        if(l_saved_sdc != NULL) delete l_saved_sdc; //dg05a

    }
    #undef PRDF_FUNC
    return(rc);
}

RuleMetaData* System::getChipMetaData( TARGETING::TYPE i_type,
                                        const char *i_fileName,
                                        ScanFacility & i_scanFactory,
                                        ResolutionFactory & i_reslFactory,
                                        errlHndl_t & o_errl )
{
    if( NULL == iv_listRuleData[i_type] )
    {
        iv_listRuleData[i_type] = new RuleMetaData( i_fileName,i_scanFactory,
                                                    i_reslFactory,i_type,
                                                    o_errl );
    }
    return iv_listRuleData[i_type];

}

} // end namespace PRDF

OpenPOWER on IntegriCloud