summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/plat/pegasus/prdfCenMbaTdRankData_rt.H
blob: 2c593fec819194a780cc932f356a717124afa37f (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/plat/pegasus/prdfCenMbaTdRankData_rt.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016                             */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* 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                                                     */

#ifndef __prdfCenMbaTdRankData_rt_H
#define __prdfCenMbaTdRankData_rt_H

/** @file prdfCenMbaTdRankData_rt.H */

// Framework includes
#include <prdfPlatServices.H>

// Pegasus includes
#include <prdfCenAddress.H>
#include <prdfThresholdUtils.H>

// Other includes
#include <vector>
#include <algorithm>

namespace PRDF
{

/**
 * @brief A sorted list of all master ranks behind an MBA.
 *
 * The list will be sorted by the order in which hardware will scrub memory.
 * Each time a rank is targeted for diagnostics, the rank should be marked as
 * bad. This is intended to assist in the design in which PRD will do a fast
 * scrub on the next 'good' rank between targeted diagnostics procedures. The
 * hope is that even though we may skip around in memory targeting ranks that
 * are reporting errors, we are still able to continue scrubbing the rest of
 * the good memory at least one every 24 hours.
 *
 * @note  This list is only intended to be used by the runtime TD controller.
 */
class TdRankList
{
  public: // structs, typedefs

    /** @brief Structure to represent a rank list entry. */
    struct Entry
    {
        CenRank rank;   ///< The rank in which this event occurred.
        bool    isGood; ///< False if currently being targeted by diagnotics

        /** @brief Default constructor */
        Entry() : isGood(true) {}

        /** @brief Constructor */
        explicit Entry( const CenRank & i_rank ) :
            rank(i_rank), isGood(true)
        {}
    };

    typedef std::vector<Entry>           List;
    typedef std::vector<Entry>::iterator ListItr;

  public: // functions

    /** @brief Default constructor */
    TdRankList() : iv_list(), iv_curRank(iv_list.end()) {}

    /**
     * @brief  Populates and sorts the list.
     * @param  i_mbaTrgt The target MBA.
     * @note   Should be called in the TD controller's initialize() function.
     * @note   Will fail if unable to find any configured ranks behind the given
     *         MBA. This is to guarantee the list is not empty.
     * @return Non-SUCCESS if an internal function fails, SUCCESS otherwise.
     */
    int32_t initialize( TARGETING::TargetHandle_t i_mbaTrgt );

    /**
     * @return A contant reference to the master rank list.
     * @note   This is useful if someone needs to iterate over the list of
     *         ranks.
     */
    const List & getList() const { return iv_list; }

    /**
     * @brief  Will find the next rank in the list that is marked as 'good'.
     *
     * Will start with the entry that iv_curRank is pointing to and increment
     * the iterator until it points to a rank that is marked as good. If the
     * search reaches the end of the list, this function will wrap around to the
     * beginning the list.
     *
     * @note   If the returned entry's isGood field is false, it means all ranks
     *         in the list are set to bad.
     *
     * @return The next 'good' list entry.
     */
    Entry findNextGoodRank();

    /**
     * @brief  Marks the given rank as 'good'.
     * @param  i_rank A rank that has completed Targeted diagnostics.
     * @note   Should be called when all entries for a rank are removed from
     *         the TD queue.
     * @return Non-SUCCESS if an internal function fails, SUCCESS otherwise.
     */
    int32_t setGood( const CenRank & i_rank )
    { return setRankStatus( i_rank, true ); }

    /**
     * @brief  Marks the given rank as 'bad'.
     * @param  i_rank A rank that is currently targeted for diagnostics.
     * @note   Should be called when an entry is added to the TD queue.
     * @return Non-SUCCESS if an internal function fails, SUCCESS otherwise.
     */
    int32_t setBad( const CenRank & i_rank )
    { return setRankStatus( i_rank, false ); }

    /**
     * @brief  Will initialize iv_curRank so that background  scrubbing (or the
     *         fast rank scrub) can resume on the next good rank after the rank
     *         that was interrupted.
     * @param  i_rank The rank that was interrupted.
     * @note   Should be called when background scrubbing is interrupted by an
     *         error.
     * @return Non-SUCCESS if an internal function fails, SUCCESS otherwise.
     */
    int32_t setInterruptedRank( const CenRank & i_rank );

  private: // functions

    /**
     * @brief  Sets a rank's status to good or bad depending on inputs.
     * @param  i_rank   The target rank.
     * @param  i_isGood True to set good, false to set bad.
     * @return Non-SUCCESS if an internal function fails, SUCCESS otherwise.
     */
    int32_t setRankStatus( const CenRank & i_rank, bool i_isGood );

    /**
     * @param i_rank The target rank.
     * @return An iterator pointing the rank in the list. Will return
     *         iv_list.end() if the rank is not found.
     */
    ListItr findRank( const CenRank & i_rank )
    { return std::find_if(iv_list.begin(), iv_list.end(), MatchRank(i_rank)); }

  private: // instance variables

    List    iv_list;    ///< The master list
    ListItr iv_curRank; ///< Will point to the next rank that is considered good

  private: // functors

    /**
     * @brief Functor to find a rank in this list.
     * @note  This functor will only match master rank.
     */
    class MatchRank
    {
      public:
        explicit MatchRank( const CenRank & i_rank ) : iv_rank(i_rank) {}

        bool operator() ( const Entry & i_e ) const
        { return ( iv_rank.getMaster() == i_e.rank.getMaster() ); }

      private:
        CenRank iv_rank; ///< Rank to match.
    };

};

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

/**
 * @brief A map containing VCM data for affected ranks.
 *
 * Keeps track of VCM false alarm thresholds.
 *
 * @note  This data is only intended to be used by the runtime TD controller.
 */
class VcmRankData
{
  private: // structs, typedefs

    /** @brief Structure to represent a data entry. */
    struct Entry
    {
        /** Time based false alarm counter. */
        TimeBasedThreshold falseAlarms;

        /** @brief Default constructor */
        Entry() :
            falseAlarms( 4, 7 * ThresholdResolution::ONE_DAY )
        {}
    };

  public: // functions

    /** @brief Default constructor */
    VcmRankData() : iv_map() {}

    /**
     * @brief  Increments the time based counter for false alarms.
     * @param  i_rank        Target master rank.
     * @param  i_sc          The step code data struct.
     * @return TRUE if false alarm threshold is exceeded, FALSE otherwise.
     */
    bool incFalseAlarm( const CenRank & i_rank, STEP_CODE_DATA_STRUCT & i_sc )
    {
        return (iv_map[getKey(i_rank)].falseAlarms).inc( i_sc );
    }

    /**
     * @param  Target master rank.
     * @return Current false alarm threshold count.
     */
    uint8_t getFalseAlarmCount( const CenRank & i_rank );

  private: // functions

    /**
     * @brief  VCM procedures operate on master ranks only.
     * @return Master rank key value.
     */
    uint8_t getKey( const CenRank & i_rank )
    {
        return i_rank.getMaster();
    }

  private: // instance variables

    std::map<uint8_t, Entry> iv_map; ///< The VCM data map

};

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

/**
 * @brief A map containing TPS data for affected ranks.
 *
 * Keeps track of TPS false alarm thresholds and whether a rank has been banned
 * from further TPS request because TPS is no longer useful for that rank.
 *
 * @note  This data is only intended to be used by the runtime TD controller.
 */
class TpsRankData
{
  private: // structs, typedefs

    /** @brief Structure to represent a data entry. */
    struct Entry
    {
        bool isBanned; ///< True if TPS is no longer allowed on this rank.

        /** Time based false alarm counter. */
        TimeBasedThreshold falseAlarms;

        /** @brief Default constructor */
        Entry() :
            isBanned(false),
            falseAlarms( 3, 7 * ThresholdResolution::ONE_DAY )
        {}
    };

  public: // functions

    /** @brief Default constructor */
    TpsRankData() : iv_map() {}

    /**
     * @brief  Increments the time based counter for false alarms.
     * @param  i_rank        Target slave rank.
     * @param  i_sc          The step code data struct.
     * @return TRUE if false alarm threshold is exceeded, FALSE otherwise.
     */
    bool incFalseAlarm( const CenRank & i_rank, STEP_CODE_DATA_STRUCT & i_sc )
    {
        return (iv_map[i_rank].falseAlarms).inc( i_sc );
    }

    /**
     * @param  Target slave rank.
     * @return Current false alarm threshold count.
     */
    uint8_t getFalseAlarmCount( const CenRank & i_rank );

    /**
     * @brief  Initially TPS only counts hard CEs. After serveral false alarms
     *         TPS needs to switch to counting all CEs.
     * @param  i_rank Target slave rank.
     * @return True if this threshold has been reached and TPS needs to count
     *         all CEs, false otherwise.
     */
    bool checkCeTypeTh( const CenRank & i_rank );

    /**
     * @brief  Ban all future TPS requests on this rank.
     * @param  i_rank  Target slave rank.
     */
    void ban( const CenRank & i_rank ) { iv_map[i_rank].isBanned = true; }

    /**
     * @brief  Check if TPS requests are banned on this rank.
     *
     * There are two ways a rank can be banned:
     *  - If ban() was called on this rank. This is a permanent ban. It should
     *    only be called if there was a predictive error log calling out this
     *    rank.
     *  - If there was a TPS false alarm threshold. This is a temporary ban. All
     *    subsequent TPS requests for this rank will be suppressed until the
     *    threshold time period has expired.
     *
     * @param  i_rank  Target slave rank.
     * @param  i_sc    The step code data struct.
     * @return True if TPS is not allowed on this rank, false otherwise.
     */
    bool isBanned( const CenRank & i_rank, STEP_CODE_DATA_STRUCT & i_sc );

  private: // instance variables

    std::map<CenRank, Entry> iv_map; ///< The TPS data map

};

} // end namespace PRDF

#endif // __prdfCenMbaTdRankData_rt_H

OpenPOWER on IntegriCloud