summaryrefslogtreecommitdiffstats
path: root/src/occ_405/amec/amec_oversub.c
blob: 26d86b96f0706d6b68d465e6ab3cbe87e70830d0 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/amec/amec_oversub.c $                             */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2017                        */
/* [+] 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                                                     */

//*************************************************************************/
// Includes
//*************************************************************************/
#include "ssx.h"
#include <occ_common.h>
#include <trac.h>
#include <amec_sys.h>
#include <proc_pstate.h>
#include <dcom.h>
#include <occ_sys_config.h>
#include <amec_service_codes.h>
#include <pgpe_interface.h>
#include <amec_freq.h>

//*************************************************************************/
// Externs
//*************************************************************************/

//*************************************************************************/
// Macros
//*************************************************************************/

//*************************************************************************/
// Defines/Enums
//*************************************************************************/
#define OVERSUB_REASON_DELAY_4MS     16  // 4ms (unit is 250us)
#define OVERSUB_REASON_COUNT_TIMEOUT 2
#define OVERSUB_REASON_DETERMINED    1

//*************************************************************************/
// Structures
//*************************************************************************/

//*************************************************************************/
// Globals
//*************************************************************************/

//*************************************************************************/
// Function Prototypes
//*************************************************************************/

//*************************************************************************/
// Functions
//*************************************************************************/

// Function Specification
//
// Name: amec_oversub_isr
//
// Description: Oversubscription ISR
//
// Task Flags:
//
// Note: This function is only ever called from Critical interrupt context
//
// End Function Specification
void amec_oversub_isr(void)
{
    static uint32_t L_isr_count = 0;
    static uint8_t L_polarity = SSX_IRQ_POLARITY_ACTIVE_HIGH; // Default is high
    uint8_t l_cur_polarity = L_polarity;

    L_isr_count++;

    // SSX_IRQ_POLARITY_ACTIVE_HIGH means over-subscription is active
    if(L_polarity == SSX_IRQ_POLARITY_ACTIVE_HIGH)
    {
        // oversub only switches pcap in amec_pcap_calc
        // throttling only done if actually needed due to reaching power cap
        g_amec->oversub_status.oversubReasonLatchCount = OVERSUB_REASON_DELAY_4MS;

        // Set oversubPinLive and oversubActiveTime
        g_amec->oversub_status.oversubPinLive = 1;
        g_amec->oversub_status.oversubActiveTime = ssx_timebase_get();

        // Setup the IRQ
        ssx_irq_setup(OCCHW_IRQ_EXTERNAL_TRAP,
                      SSX_IRQ_POLARITY_ACTIVE_LOW,
                      SSX_IRQ_TRIGGER_LEVEL_SENSITIVE);
        L_polarity = SSX_IRQ_POLARITY_ACTIVE_LOW;

    }
    else  // over-subscription is inactive
    {
        // Clear oversubPinLive
        g_amec->oversub_status.oversubPinLive = 0;

        // Set oversubInActiveTime
        g_amec->oversub_status.oversubInactiveTime = ssx_timebase_get();

        // Setup the IRQ
        ssx_irq_setup(OCCHW_IRQ_EXTERNAL_TRAP,
                      SSX_IRQ_POLARITY_ACTIVE_HIGH,
                      SSX_IRQ_TRIGGER_LEVEL_SENSITIVE);

        L_polarity = SSX_IRQ_POLARITY_ACTIVE_HIGH;
    }

    // Trace Oversub Event, Polarity and ISR count
    TRAC_INFO("Oversub IRQ - Polarity (high active):%d, oversubPinLive: %d, count: %d)", l_cur_polarity, g_amec->oversub_status.oversubPinLive, L_isr_count);

}


// Function Specification
//
// Name: amec_oversub_check
//
// Description: Oversubscription check called in amec_slv_common_tasks_pre()
//
// Task Flags:
//
// End Function Specification
void amec_oversub_check(void)
{
    errlHndl_t l_errl = NULL;
    static BOOLEAN              L_prev_ovs_state = FALSE;  // oversub happened

    // oversubscription condition happened?
    if ( AMEC_INTF_GET_OVERSUBSCRIPTION() == TRUE )
    {
        if ( L_prev_ovs_state != TRUE)
        {
            L_prev_ovs_state = TRUE;

            TRAC_ERR("Oversubscription condition happened");

            /* @
             * @errortype
             * @moduleid    AMEC_SLAVE_CHECK_PERFORMANCE
             * @reasoncode  OVERSUB_ALERT
             * @userdata1   Previous OVS State
             * @userdata4   ERC_AMEC_SLAVE_OVS_STATE
             * @devdesc     Oversubscription condition happened
             */
            l_errl = createErrl(AMEC_SLAVE_CHECK_PERFORMANCE,//modId
                                OVERSUB_ALERT,                //reasoncode
                                ERC_AMEC_SLAVE_OVS_STATE,     //Extended reason code
                                ERRL_SEV_INFORMATIONAL,       //Severity
                                NULL,                         //Trace Buf
                                DEFAULT_TRACE_SIZE,           //Trace Size
                                L_prev_ovs_state,             //userdata1
                                0);                           //userdata2

            // set the mfg action flag (allows callout to be added to info error)
            setErrlActions(l_errl, ERRL_ACTIONS_MANUFACTURING_ERROR);

            // add the oversubscription symbolic callout
            addCalloutToErrl(l_errl,
                             ERRL_CALLOUT_TYPE_COMPONENT_ID,
                             ERRL_COMPONENT_ID_OVERSUBSCRIPTION,
                             ERRL_CALLOUT_PRIORITY_HIGH);

            // Commit Error
            commitErrl(&l_errl);
        }
    }
    else
    {
        if(L_prev_ovs_state)
        {
            L_prev_ovs_state = FALSE;
            TRAC_IMP("Oversubscription condition cleared");
        }
    }

    // Figure out the over-subscription reason
    if(g_amec->oversub_status.oversubReasonLatchCount > 1)
    {
        if( g_amec->oversub_status.oversubReasonLatchCount == OVERSUB_REASON_COUNT_TIMEOUT)
        {
            g_amec->oversub_status.oversubReason = INDETERMINATE;
            g_amec->oversub_status.oversubReasonLatchCount = OVERSUB_REASON_DETERMINED;

            TRAC_INFO("Oversub (oversubReason: %d)", g_amec->oversub_status.oversubReason );
        }
        else
        {
            // If we can figure out why oversub happened, set oversubReason to valide enum value
            // then set oversubReasonLatchCount = 1

            // If we can't figure it out, decrease oversubReasonLatchCount and we will try again in 250us
            g_amec->oversub_status.oversubReasonLatchCount--; // The unit of oversubReasonLatchCount is 250us
        }
    }
}

/*----------------------------------------------------------------------------*/
/* End                                                                        */
/*----------------------------------------------------------------------------*/
OpenPOWER on IntegriCloud