summaryrefslogtreecommitdiffstats
path: root/src/occ_405/amec/amec_perfcount.c
blob: 8924172fb07470ca37641ea51c75f0aaba48e57d (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/amec/amec_perfcount.c $                           */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,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                                                     */

/*----------------------------------------------------------------------------*/
/* Includes                                                                   */
/*----------------------------------------------------------------------------*/
#include <string.h>
#include <common_types.h>
#include <sensor.h>
#include <amec_sys.h>
#include <amec_part.h>
#include <amec_perfcount.h>

/*----------------------------------------------------------------------------*/
/* Constants                                                                  */
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
/* Globals                                                                    */
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
/* Typedef / Enum                                                             */
/*----------------------------------------------------------------------------*/

/*----------------------------------------------------------------------------*/
/* Code                                                                       */
/*----------------------------------------------------------------------------*/

// Function Specification
//
// Name: amec_calc_dps_util_counters
//
// Description: Calculate the performance counter for a core.
//
// End Function Specification
void amec_calc_dps_util_counters(const uint8_t i_core_id)
{
    /*------------------------------------------------------------------------*/
    /*  Local Variables                                                       */
    /*------------------------------------------------------------------------*/
    amec_part_t                 *l_part = NULL;
    amec_core_perf_counter_t    *l_perf = NULL;
    sensor_ptr_t                l_sensor = NULL;
    uint16_t                    l_utilization = 0;

    /*------------------------------------------------------------------------*/
    /*  Code                                                                  */
    /*------------------------------------------------------------------------*/
    l_perf = &g_amec->proc[0].core[i_core_id].core_perf;
    // Read sensor for this core
    l_sensor = AMECSENSOR_ARRAY_PTR(UTILC0, i_core_id);
    l_utilization = l_sensor->sample;
    l_part = amec_part_find_by_core(&g_amec->part_config, i_core_id);

    // Type 41 input: Check if core's utilization is within
    // epsilon of the slack threshold: if yes declare the core
    // active
    if (l_part != NULL)
    {
        if (l_utilization > (l_part->dpsalg.tlutil - l_part->dpsalg.epsilon_perc))
        {
            // indicate core is active
            l_perf->util_active_core_counter++;

            if (l_utilization < l_part->dpsalg.tlutil)
            {
                // indicate core has some slack
                l_perf->util_slack_core_counter++;
            }
        }
    }
}

// Function Specification
//
// Name: amec_core_perf_counter_ctor
//
// Description: Build the performance counter for a core.
//
// End Function Specification
amec_core_perf_counter_t* amec_core_perf_counter_ctor(amec_core_perf_counter_t* i_this_ptr,
                                                      const uint8_t i_proc_id,
                                                      const uint8_t i_core_id)
{
    /*------------------------------------------------------------------------*/
    /*  Local Variables                                                       */
    /*------------------------------------------------------------------------*/

    /*------------------------------------------------------------------------*/
    /*  Code                                                                  */
    /*------------------------------------------------------------------------*/

    //zero everything out, regardless of when we were called
    memset(i_this_ptr, 0x00, sizeof(amec_core_perf_counter_t));

    // Create space for per-core active and slack counts (for DPS #41 algorithm)
    memset(i_this_ptr->ptr_util_slack_avg_buffer, 0,
           (uint32_t)(2*MAX_UTIL_SLACK_AVG_LEN));
    memset(i_this_ptr->ptr_util_active_avg_buffer, 0,
           (uint32_t)(2*MAX_UTIL_SLACK_AVG_LEN));

    // DPS frequency request. Choose highest performance by default.
    i_this_ptr->dps_freq_request = UINT16_MAX; // input to core freq voting box

    //pass out i_this_ptr in case we're allocating this dynamically
    return i_this_ptr;
}

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