summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/plat/prdfLineDelete.C
blob: 6ea383fec18a591a394e854ae96ab0b86b48fd20 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/plat/prdfLineDelete.C $              */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2005,2014              */
/*                                                                        */
/* 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                                                     */

/** @file prdfLineDelete.C
 * Contains the definitions needed for the line delete algorithms and the CE
 * table.
 */


#include <prdfLineDelete.H>
#include <iipServiceDataCollector.h>
#include <prdfBitString.H>

namespace PRDF
{

// See prdfLineDelete.H for full function documentation.
namespace LineDelete
{

    /* PrdfCacheCETable::addAddress
     * Insert address into CE table.
     */
    bool PrdfCacheCETable::addAddress( PrdfCacheAddress i_addr,
                                       STEP_CODE_DATA_STRUCT & i_sdc )
    {
        // Get the time of the current error.
        Timer timeOfError = i_sdc.service_data->GetTOE();

        // Check if time interval has elapsed. If so, flush the table.
        if ( (timeOfError > cv_flushTimer) || !cv_flushTimerInited )
        {
            this->flushTable();
            cv_flushTimer = timeOfError + iv_thPolicy.interval;
            cv_flushTimerInited = true;
        }

        // Increment address hit count and total table count.
        uint32_t count = ++cv_ceTable[i_addr];
        cv_total++;

        // Return whether the address threshold has been reached or not.
        return ( iv_thPolicy.threshold <= count );
    }

    bool PrdfCacheCETable::addrThReached( PrdfCacheAddress i_addr,
                                          STEP_CODE_DATA_STRUCT & i_sdc )
    {
        bool o_reached = false;

        if ( cv_flushTimerInited && !isIntervalElapsed(i_sdc) )
        {
            uint32_t * count = cv_ceTable.find( i_addr );
            if ( NULL  != count )
            {
                o_reached = ( iv_thPolicy.threshold <= *count );
            }
        }

        return o_reached;
    }

    /* PrdfCacheCETable::isIntervalElapsed()
     */
    bool PrdfCacheCETable::isIntervalElapsed( STEP_CODE_DATA_STRUCT & i_sdc )
    {
        bool o_rc = false;
        if ( cv_flushTimerInited )
            o_rc = ( i_sdc.service_data->GetTOE() > cv_flushTimer );
        return o_rc;
    }

    /* PrdfCacheCETable::flushTable()
     * Clear all entries from CE table.
     */
    void PrdfCacheCETable::flushTable()
    {
        // wipe interval timer and clear all hits.
        cv_flushTimerInited = false;
        cv_ceTable.clear();
        cv_total = 0;
    }

    /* PrdfCacheCETable::getTotalCount()
     * Clear all CE hits from the table and reset timer to 0.
     */
    uint32_t PrdfCacheCETable::getTotalCount() // zs01
    {
        return cv_total;
    }

    /* PrdfCacheCETable::addToCaptureData()
     * Will add CE table to the capture data.
     */
    void PrdfCacheCETable::addToCaptureData(TARGETING::TargetHandle_t i_pchipHandle, int32_t i_scomId,
                                            CaptureData & io_cd)  // zs02
    {
        const uint32_t l_maxEntries
                        = CaptureData::MAX_ENTRY_SIZE / (2 * sizeof(uint32_t));

        uint32_t l_entryTable[l_maxEntries * 2];
        uint32_t l_entryIndex = 0;

        // Loop on all entries in CE table.
        for (PrdfCacheAddressTable::iterator i = cv_ceTable.begin();
            i != cv_ceTable.end(); ++i)
        {
            // Add entry to table.
            l_entryTable[2 * l_entryIndex] = i.first();
            l_entryTable[2 * l_entryIndex + 1] = i.second();

            // Check if entry chunk is filled, or reached the end of entries.
            if ( ( l_maxEntries == (l_entryIndex + 1) ) ||
                 ( (i + 1) == cv_ceTable.end() ) )
            {
                // Add chunk to capture data.
                BIT_STRING_ADDRESS_CLASS l_entryChunk( 0,
                        ( ( (l_entryIndex + 1) * (2 * sizeof(uint32_t)) ) * 8 ),
                                  (CPU_WORD*) l_entryTable );
                io_cd.Add(i_pchipHandle, i_scomId, l_entryChunk);
            }

            // Increment entry ID.
            l_entryIndex = (l_entryIndex + 1) % l_maxEntries;
        }
    }

    /* PrdfCacheCETable::getLargestEntry
     * Will search the PrdfCacheCETable for the address with the largest count
     */
    PrdfCacheAddress PrdfCacheCETable::getLargestEntry( uint32_t * o_count )
    {
        PrdfCacheAddress largestEntry = 0;
        uint32_t highestCount = 0;

        // Loop on all entries in CE table.
        for (PrdfCacheAddressTable::iterator i = cv_ceTable.begin();
             i != cv_ceTable.end(); ++i)
        {
            if ( i.second() > highestCount )
            {
                largestEntry = i.first();
                highestCount = i.second();

                if (o_count != NULL)
                    (*o_count) = highestCount;
            }
        }

        return largestEntry;
    }

    /* PrdfCacheCETable::getTableSize
     */
    uint32_t PrdfCacheCETable::getTableSize() //zs04
    {
        return cv_ceTable.size();
    }

 //mp26 a
    /* PrdfCacheCETable::getCRCAnalysisEntries
     * Will search the PrdfCacheCETable for the address with the largest count
     * Also returns highest, second highest, and lowest count values
     */

    //NOTE: need to make sure table size is not zero before calling this function.
    PrdfCacheAddress PrdfCacheCETable::getCRCAnalysisEntries(
                                                             uint32_t & o_countHigh,
                                                             uint32_t & o_count2ndHigh,
                                                             uint32_t & o_countLow)
    {
        PrdfCacheAddress largestEntry = 0;

        do
        {

            PrdfCacheAddressTable::iterator i = cv_ceTable.begin();

            // Initialize the counts to the value of the first entry.
            largestEntry = i.first();
            o_countHigh = i.second();
            o_count2ndHigh = 0;
            o_countLow = 0;

            if ( 1 == getTableSize() ) break; // only one entry

              ++i; // There are at least two entries, start at the second.

              // Initialize 2nd highest count and low count.
              if ( i.second() > o_countHigh )
              {
                  o_count2ndHigh = o_countHigh;
                  o_countLow = o_countHigh;

                  largestEntry = i.first();
                  o_countHigh = i.second();
              }
              else
              {
                  o_count2ndHigh = i.second();
                  o_countLow = i.second();
              }

              // Loop on all entries in CE table.
                ++i; // Start at third entry.
                  // Note: loop will exit immediately if the table count is 2.
                      for ( ; i != cv_ceTable.end(); ++i )
                      {
                          // Get highest count.
                            if ( i.second() > o_countHigh )
                            {
                                o_count2ndHigh = o_countHigh;

                                largestEntry = i.first();
                                o_countHigh = i.second();
                            }
                          // Get second highest count.
                            else if ( (i.second() > o_count2ndHigh) &&
                                      (i.second() <= o_countHigh) )
                            {
                                o_count2ndHigh = i.second();
                            }
                          // Get lowest count.
                            else if ( i.second() < o_countLow )
                            {
                                o_countLow = i.second();
                            }
                      }

        } while (0);

        return largestEntry;
    }
};

} // end namespace PRDF

OpenPOWER on IntegriCloud