summaryrefslogtreecommitdiffstats
path: root/src/occ_405/thread/chom.c
blob: 025a174faa3e4332461bb30f1e1aadb026d9820c (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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/thread/chom.c $                                   */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2018                        */
/* [+] 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                                                     */

#include <occ_common.h>
#include <comp_ids.h>
#include <sensor.h>
#include <trac.h>
#include <chom.h>
#include <mode.h>
#include <dcom.h>
#include <amec_sys.h>
#include <occ_service_codes.h>
#include <thread_service_codes.h>

extern amec_sys_t g_amec_sys;

#define CHOM_SENSOR_DATA(index,data) [index] = data

// chom timer
uint32_t g_chom_gen_periodic_log_timer;

// track which power mode has been during the polling period
uint8_t  g_chom_pwr_modes[OCC_INTERNAL_MODE_MAX_NUM]; // Nominal, SPS, DPS, DPS-MP, FFO

// force immediate chom log flag
uint8_t  g_chom_force;

// indicates that chom data has been reset
bool    g_chom_reset = FALSE;

// chom data log
ChomLogData_t   g_chom_log;
ChomLogData_t * g_chom = &g_chom_log;

// Make sure that the size of chom log is less than 3kB
// otherwise cause error on the compile.
STATIC_ASSERT( sizeof(ChomLogData_t) > CHOM_LOG_DATA_MAX );

// Chom Sensors Table
//   Some of the chom sensors need multiple mini-sensor to calculate
//   the max, summation of temperature or bandwidth
//   mark those mini-sensor "NULL" and will be updated
//   from "chom_update_sensors()"

const uint16_t * g_chom_sensor_table[CHOM_NUM_OF_SENSORS] =
{   // Node total power (DC)
    &g_amec_sys.sys.pwrsys.sample,
    // APSS sensors 1 per channel (16 total)
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    // Processor frequency
    &G_dcom_slv_outbox_rx[0].freqa,
    &G_dcom_slv_outbox_rx[1].freqa,
    &G_dcom_slv_outbox_rx[2].freqa,
    &G_dcom_slv_outbox_rx[3].freqa,
    // Processor utilization sensor
    &G_dcom_slv_outbox_rx[0].util,
    &G_dcom_slv_outbox_rx[1].util,
    &G_dcom_slv_outbox_rx[2].util,
    &G_dcom_slv_outbox_rx[3].util,
    // Processor temperature sensors
    &G_dcom_slv_outbox_rx[0].tempprocthermal,
    &G_dcom_slv_outbox_rx[1].tempprocthermal,
    &G_dcom_slv_outbox_rx[2].tempprocthermal,
    &G_dcom_slv_outbox_rx[3].tempprocthermal,
    // Centaur temperature sensors
    &G_dcom_slv_outbox_rx[0].temp2mscent,
    &G_dcom_slv_outbox_rx[1].temp2mscent,
    &G_dcom_slv_outbox_rx[2].temp2mscent,
    &G_dcom_slv_outbox_rx[3].temp2mscent,
    // DIMM temperature sensors
    &G_dcom_slv_outbox_rx[0].tempdimmthrm,
    &G_dcom_slv_outbox_rx[1].tempdimmthrm,
    &G_dcom_slv_outbox_rx[2].tempdimmthrm,
    &G_dcom_slv_outbox_rx[3].tempdimmthrm,
    // VRM VDD temperatures
    // TEMPVDDP0 ~ TEMPVDDP7
    &G_dcom_slv_outbox_rx[0].tempvdd,
    &G_dcom_slv_outbox_rx[1].tempvdd,
    &G_dcom_slv_outbox_rx[2].tempvdd,
    &G_dcom_slv_outbox_rx[3].tempvdd,
    // Instructions per second sensor
    NULL,
    // Memory bandwidth for process memory controller
    // P0M0 ~ P0M7
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    // P1M0 ~ P1M7
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    // P2M0 ~ P2M7
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    // P3M0 ~ P3M7
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
};


// Function Specification
//
// Name: chom_data_init
//
// Description: Init chom data
//
// End Function Specification
void chom_data_init()
{
    // chom data reset
    chom_data_reset();
    // update eyecatcher
    memcpy(&g_chom->nodeData.eyecatcher, "CHOM", 0x04);
    // update chom version
    g_chom->nodeData.version = CHOM_VERSION;
    // update num of sensors
    g_chom->nodeData.numSensors = CHOM_NUM_OF_SENSORS;
}


// Function Specification
//
// Name: chom_data_reset
//
// Description: Reset chom data
//
// End Function Specification
void chom_data_reset()
{
    // reset chom data log
    memset(g_chom, 0x00, sizeof(*g_chom));
    // reset chom modes in log
    memset(g_chom_pwr_modes, 0x00, sizeof(g_chom_pwr_modes));
    // reset chom timer
    g_chom_gen_periodic_log_timer = 0;
    // reset flag
    g_chom_force = FALSE;
    // reset static data
    g_chom_reset = TRUE;
}


// Function Specification
//
// Name: chom_update_sensors
//
// Description: Update chom sensor data
//
// End Function Specification
void chom_update_sensors()
{
    uint32_t l_mips = 0;
    uint16_t l_mem_rw = 0;
    uint16_t l_sample = 0;

    static uint32_t L_memBWNumSamples[NUM_CHOM_MODES][MAX_NUM_MEM_CONTROLLERS] = {{0}};

    // Use FMF as default
    static uint32_t * L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_FMF];

    if(TRUE == g_chom_reset)
    {
        memset(L_memBWNumSamples, 0, sizeof(L_memBWNumSamples));
        g_chom_reset = FALSE;
    }

    uint16_t i = 0, j = 0;

    // Is the current mode different than previous poll
    if (g_chom->nodeData.curPwrMode != CURRENT_MODE())
    {
        // update current power mode
        g_chom->nodeData.curPwrMode = CURRENT_MODE();
        // copy the current mode data to previous mode
        memcpy(&g_chom->sensorData[1], &g_chom->sensorData[0], sizeof(ChomSensorData_t));
        // reset all fields in the current chom sensors
        memset(&g_chom->sensorData[0], 0x00, sizeof(ChomSensorData_t));
        // update power saving mode of sensor data
        g_chom->sensorData[0].pwrMode.mode = g_chom->nodeData.curPwrMode;

        // initial min value of chom sensors
        for (i=0 ; i<CHOM_NUM_OF_SENSORS ; i++)
        {
            g_chom->sensorData[0].sensor[i].sampleMin = 0xffff;
        }

        // update the number of power modes during the polling period
        switch (g_chom->nodeData.curPwrMode)
        {
            case OCC_MODE_NOMINAL:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_NOM] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_NOMINAL];
                break;

            case OCC_MODE_PWRSAVE:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_SPS] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_SPS];
                break;

            case OCC_MODE_DYN_POWER_SAVE:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_DPS] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_DPS];
                break;

            case OCC_MODE_DYN_POWER_SAVE_FP:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_DPS_MP] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_DPS_MP];
                break;

            case OCC_MODE_FFO:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_FFO] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_FFO];
                break;

            case OCC_MODE_NOM_PERFORMANCE:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_NOM_PERF] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_NOM_PERF];
                break;

            case OCC_MODE_MAX_PERFORMANCE:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_MAX_PERF] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_MAX_PERF];
                break;

            case OCC_MODE_FMF:
                g_chom_pwr_modes[OCC_INTERNAL_MODE_FMF] = 1;
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_FMF];
                break;

            default:
                TRAC_INFO("chom_update_sensors: Cannot record chom data for mode 0x%02X",
                          g_chom->sensorData[0].pwrMode.mode);
                L_curNumSamplePtr = L_memBWNumSamples[CHOM_MODE_FMF];
                break;
        }
    }

    // update number of samples
    g_chom->sensorData[0].pwrMode.numOfSamples++;

    // update APSS
    uint16_t l_apss_idx = CHOMPWRAPSSCH0;
    uint16_t l_current_channel = 0;
    for( i = 0; i < MAX_APSS_ADC_CHANNELS; i++ )
    {
        // Transfer data from AMEC sensor to CHOM sensor
        l_current_channel = AMECSENSOR_ARRAY_PTR( PWRAPSSCH0, i )->sample;
       // TRAC_INFO("channel %d reading: %d", i, l_current_channel);
        g_chom->sensorData[0].sensor[l_apss_idx].sample = l_current_channel;

        // Send the corresponding function ID in the node data
        g_chom->nodeData.channelFuncIds[i] =
                         G_apss_ch_to_function[i];
        l_apss_idx++;
    }


    // update MIPS
    uint16_t l_mips_count = 0;
    uint16_t l_mem_idx = CHOMBWP0M0;

    // Loop through OCCs updating chom sensors
    for ( i = 0; i < CHOM_MAX_OCCS; i++ )
    {
        // count MIPS
        if ( 0 != G_dcom_slv_outbox_rx[i].ips4msp0 )
        {
            l_mips += G_dcom_slv_outbox_rx[i].ips4msp0;
            l_mips_count++;
        }

        // update memory bandwidth
        for ( j = 0; j < MAX_NUM_MEM_CONTROLLERS; j++)
        {
            l_mem_rw = G_dcom_slv_outbox_rx[i].mrd[j] +
                       G_dcom_slv_outbox_rx[i].mwr[j];

            // If l_mem_rw == 0, do not add to sensor
            if(l_mem_rw != 0)
            {
                g_chom->sensorData[0].sensor[l_mem_idx].sample = l_mem_rw;
                L_curNumSamplePtr[j]++;

                // Calculate the averages/min/max for the memory bandwidth sensors
                l_sample = g_chom->sensorData[0].sensor[l_mem_idx].sample;

                if (g_chom->sensorData[0].sensor[l_mem_idx].sampleMin > l_sample)
                {
                    g_chom->sensorData[0].sensor[l_mem_idx].sampleMin = l_sample;
                }
                if (g_chom->sensorData[0].sensor[l_mem_idx].sampleMax < l_sample)
                {
                    g_chom->sensorData[0].sensor[l_mem_idx].sampleMax = l_sample;
                }

                g_chom->sensorData[0].sensor[l_mem_idx].accumulator += l_sample;
                g_chom->sensorData[0].sensor[l_mem_idx].average =
                                 (g_chom->sensorData[0].sensor[l_mem_idx].accumulator /
                                  L_curNumSamplePtr[j]);
            }
            l_mem_idx++;
        }
    }

    // Update MIPS
    if (l_mips_count != 0)
    {
        g_chom->sensorData[0].sensor[CHOMIPS].sample = (l_mips/l_mips_count);
    }

    // loop through all sensors and update data from mini-sensors
    for (i = 0 ; i<CHOM_NUM_OF_SENSORS ; i++)
    {
        // Skip memory bandwidth controllers since handled above
        if( i == CHOMBWP0M0 )
        {
            i += (MAX_NUM_MEMORY_SENSORS-1);
            continue;
        }

        // update sample, min, max, average sensor data
        if (NULL != g_chom_sensor_table[i])
        {
            // directly mapping to mini-sensor
            g_chom->sensorData[0].sensor[i].sample = *g_chom_sensor_table[i];
        }

        l_sample = g_chom->sensorData[0].sensor[i].sample;

        if (g_chom->sensorData[0].sensor[i].sampleMin > l_sample)
        {
            g_chom->sensorData[0].sensor[i].sampleMin = l_sample;
        }
        if (g_chom->sensorData[0].sensor[i].sampleMax < l_sample)
        {
            g_chom->sensorData[0].sensor[i].sampleMax = l_sample;
        }
        g_chom->sensorData[0].sensor[i].accumulator += l_sample;
        g_chom->sensorData[0].sensor[i].average = (g_chom->sensorData[0].sensor[i].accumulator/
                                                   g_chom->sensorData[0].pwrMode.numOfSamples);
    }

    // Collect the error history data and fclip history
    int proc_idx = 0, errh_idx = 0, slv_idx = 0, entry_idx = 0, clip_idx = 0;

    // get the master proc index
    uint8_t master_id = G_pbax_id.chip_id;

    // Iterate through procs
    for( proc_idx = 0; proc_idx < CHOM_MAX_OCCS; proc_idx++ )
    {
        // If we are on the master proc, skip it since it is already
        // present in the call home log
        if( proc_idx == master_id )
        {
            continue;
        }
        else
        {
            // Add Fclip history
            g_chom->nodeData.fClipHist[clip_idx] =
                G_dcom_slv_outbox_rx[proc_idx].fClipHist;
            clip_idx++;

            // Iterate through each proc's error history counts
            for( errh_idx = 0; errh_idx < DCOM_MAX_ERRH_ENTRIES; errh_idx++)
            {
                // If the entry id is 0, we have reached the end of error history
                // counts for this proc
                // If entry_idx is 4, we have reached our limit of entries to collect
                if((G_dcom_slv_outbox_rx[proc_idx].errhCount[errh_idx].error_id == 0) ||
                   (entry_idx >= CHOM_MAX_ERRH_ENTRIES))
                {
                    break;
                }
                else
                {
                    // Add the error history to the chom data
                    g_chom->nodeData.errhCounts[slv_idx][entry_idx] =
                        G_dcom_slv_outbox_rx[proc_idx].errhCount[errh_idx];
                    slv_idx++;
                    entry_idx++;
                }
            }
        }
    }
}



// Function Specification
//
// Name: chom_gen_periodic_log
//
// Description: Create call home data logs
//
// End Function Specification
void chom_gen_periodic_log()
{
    uint8_t        i                = 0;
    errlHndl_t     l_errlHndl       = NULL;

    TRAC_INFO("Enter chom_gen_periodic_log");
    TRAC_INFO("chom size = %d", sizeof(*g_chom));
    // update total time
    g_chom->nodeData.totalTime = g_chom_gen_periodic_log_timer;

    // update the number of different power modes
    for (i=0 ; i<OCC_INTERNAL_MODE_MAX_NUM ; i++)
    {
        if (g_chom_pwr_modes[i] == 1)
        {
            g_chom->nodeData.modeInLog++;
        }
    }

    /* @
     * @errortype
     * @moduleid    THRD_MID_GEN_CALLHOME_LOG
     * @reasoncode  GEN_CALLHOME_LOG
     * @userdata1   0
     * @userdata2   0
     * @userdata4   OCC_NO_EXTENDED_RC
     * @devdesc     Generating periodic call-home log, which contains critical power/thermal/performance data since the last log was generated (or the last OCC reset)
     */
    l_errlHndl = createErrl(
            THRD_MID_GEN_CALLHOME_LOG,    // modId
            GEN_CALLHOME_LOG,             // reasoncode
            OCC_NO_EXTENDED_RC,           // Extended reason code
            ERRL_SEV_CALLHOME_DATA,       // Severity; will be changed to informational in errl.c
            NULL,                         // Trace Buf
            0,                            // Trace Size
            0,                            // userdata1
            0                             // userdata2
            );

    // add chom data
    addUsrDtlsToErrl(l_errlHndl,
                     (uint8_t*)g_chom,
                     sizeof(*g_chom),
                     ERRL_STRUCT_VERSION_1,
                     ERRL_USR_DTL_CALLHOME_DATA);

    // commit error log
    if (l_errlHndl != NULL)
    {
        commitErrl(&l_errlHndl);
    }
}


// Function Specification
//
// Name: chom_force_gen_log()
//
// Description: immediate chom log
//
// End Function Specification
void chom_force_gen_log()
{
    g_chom_force = TRUE;
}


// Function Specification
//
// Name: chom_main
//
// Description: Call home data routine
//
// End Function Specification
void chom_main()
{
    MAIN_DBG("CHOM routine processing...");

    // check if this is the first time we run
    if (memcmp(&g_chom->nodeData.eyecatcher, "CHOM", 0x04) != 0)
    {
        chom_data_init();
    }

    // only update chom sensors on active, observing, or characterizing OCCs
    if (IS_OCC_STATE_ACTIVE()           ||
        IS_OCC_STATE_OBSERVATION()      ||
        IS_OCC_STATE_CHARACTERIZATION())
    {
        chom_update_sensors();
    }

    // increase chom timer
    g_chom_gen_periodic_log_timer++;

    // check if the timer expired
    if ((g_chom_gen_periodic_log_timer >= CHOM_GEN_LOG_PERIODIC_TIME) ||
        (TRUE == g_chom_force))
    {
        chom_gen_periodic_log();
        chom_data_reset();
    }
}
OpenPOWER on IntegriCloud