summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/mc_config/mss_eff_config/mss_throttle_to_power.C
blob: 05787c61e9bffa160d058c7e29c751afaffcdeda (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/mc_config/mss_eff_config/mss_throttle_to_power.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2014              */
/*                                                                        */
/* 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                                                     */
// $Id: mss_throttle_to_power.C,v 1.13 2014/03/10 16:31:27 jdsloat Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/chips/
//          centaur/working/procedures/ipl/fapi/mss_throttle_to_power.C,v $
//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2011
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//------------------------------------------------------------------------------
// *! TITLE       : mss_throttle_to_power
// *! DESCRIPTION : see additional comments below
// *! OWNER NAME  : Joab Henderson    Email: joabhend@us.ibm.com
// *! BACKUP NAME : Michael Pardeik   Email: pardeik@us.ibm.com
// *! ADDITIONAL COMMENTS :
//
// applicable CQ component memory_screen
//
// DESCRIPTION:
// The purpose of this procedure is to set the power attributes for each dimm
// and channel pair
//
//------------------------------------------------------------------------------
// Don't forget to create CVS comments when you check in your changes!
//------------------------------------------------------------------------------
// CHANGE HISTORY:
//------------------------------------------------------------------------------
// Version:|  Author: |  Date:  | Comment:
//---------|----------|---------|-----------------------------------------------
//   1.13  | jdsloat  |10-MAR-14| Edited comments
//   1.12  | pardeik  |06-JAN-14| added dimm power curve uplift from MRW
//         |          |         | use max utiliation from MRW for MAX_UTIL
//   1.11  | pardeik  |13-NOV-13| changed MAX_UTIL from 75 to 56.25
//   1.10  | bellows  |19-SEP-13| fixed possible buffer overrun found by stradale
//   1.9   | pardeik  |04-DEC-12| update lines to have a max width of 80 chars
//         |          |         | added FAPI_ERR before return code lines
//         |          |         | made trace statements for procedures FAPI_IMP
//   1.8   | pardeik  |25-OCT-12| updated FAPI_ERR sections, added CQ component
//         |          |         | comment line
//   1.7   | pardeik  |19-OCT-12| use ATTR_MSS_CHANNEL_PAIR_MAXPOWER instead of
//         |          |         | ATTR_MSS_CHANNEL_MAXPOWER
//         | pardeik  |19-OCT-12| multiple throttle N values by 4 to get dram
//         |          |         | utilization
//   1.6   | pardeik  |11-OCT-12| updated to use new throttle attributes, made
//         |          |         | function mss_throttle_to_power_calc
//   1.5   | pardeik  |10-APR-12| power calculation updates and fixes
//   1.5   | pardeik  |10-APR-12| power calculation updates and fixes
//   1.4   | pardeik  |04-APR-12| moved cdimm power calculation to end of
//         |          |         | section instead of having it in multiple
//         |          |         | places
//   1.3   | pardeik  |04-APR-12| use else if instead of if after checking
//         |          |         | throttle denominator to zero
//   1.2   | pardeik  |03-APR-12| use mba target intead of mbs, added cdimm
//         |          |         | power calculation for half of cdimm
//   1.1   | pardeik  |01-APR-11| Updated to use attributes and fapi functions
//         |          |         | to loop through ports/dimms
//         | pardeik  |01-DEC-11| First Draft.


//------------------------------------------------------------------------------
//  My Includes
//------------------------------------------------------------------------------
#include <mss_throttle_to_power.H>

//------------------------------------------------------------------------------
//  Includes
//------------------------------------------------------------------------------
#include <fapi.H>


extern "C" {

    using namespace fapi;


//------------------------------------------------------------------------------
// Funtions in this file
//------------------------------------------------------------------------------
    fapi::ReturnCode mss_throttle_to_power(const fapi::Target & i_target_mba);

    fapi::ReturnCode mss_throttle_to_power_calc
      (
       const fapi::Target &i_target_mba,
       uint32_t i_throttle_n_per_mba,
       uint32_t i_throttle_n_per_chip,
       uint32_t i_throttle_d,
       float &channel_pair_power
       );


//------------------------------------------------------------------------------
// @brief mss_throttle_to_power(): This function will get the throttle
// attributes and call another function to determine the dimm and channel pair
// power based on those throttles
//
// @param[in]	const fapi::Target &i_target_mba:  MBA Target
//
// @return fapi::ReturnCode
//------------------------------------------------------------------------------

    fapi::ReturnCode mss_throttle_to_power(const fapi::Target & i_target_mba)
    {
	fapi::ReturnCode rc = fapi::FAPI_RC_SUCCESS;

	const char* procedure_name = "mss_throttle_to_power";

	FAPI_IMP("*** Running %s ***", procedure_name);

	uint32_t throttle_n_per_mba;
	uint32_t throttle_n_per_chip;
	uint32_t throttle_d;
	float channel_pair_power;

// Get input attributes
	rc = FAPI_ATTR_GET(ATTR_MSS_MEM_THROTTLE_NUMERATOR_PER_MBA,
			   &i_target_mba, throttle_n_per_mba);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_MSS_MEM_THROTTLE_NUMERATOR_PER_MBA");
	    return rc;
	}
	rc = FAPI_ATTR_GET(ATTR_MSS_MEM_THROTTLE_NUMERATOR_PER_CHIP,
			   &i_target_mba, throttle_n_per_chip);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_MSS_MEM_THROTTLE_NUMERATOR_PER_CHIP");
	    return rc;
	}
	rc = FAPI_ATTR_GET(ATTR_MSS_MEM_THROTTLE_DENOMINATOR,
			   &i_target_mba, throttle_d);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_MSS_MEM_THROTTLE_DENOMINATOR");
	    return rc;
	}

// Call function mss_throttle_to_power_calc
	rc = mss_throttle_to_power_calc(
					i_target_mba,
					throttle_n_per_mba,
					throttle_n_per_chip,
					throttle_d,
					channel_pair_power
					);
	if (rc)
	{
	    FAPI_ERR("Error (0x%x) calling mss_throttle_to_power_calc", static_cast<uint32_t>(rc));
	    return rc;
	}

	FAPI_IMP("*** %s COMPLETE ***", procedure_name);
	return rc;

    }



//------------------------------------------------------------------------------
// @brief mss_throttle_to_power_calc(): This function will calculate the dimm
// and channel pair power and update attributes with the power values
//
// @param[in]   const fapi::Target &i_target_mba:  MBA Target
// @param[in]   uint32_t i_throttle_n_per_mba:  Throttle value for
//              cfg_nm_n_per_mba
// @param[in]   uint32_t i_throttle_n_per_chip:  Throttle value for
//              cfg_nm_n_per_chip
// @param[in]	uint32_t i_throttle_d:  Throttle value for cfg_nm_m
// @param[out]  float &o_channel_pair_power:  channel pair power at these
//              throttle settings
//
// @return fapi::ReturnCode
//------------------------------------------------------------------------------

    fapi::ReturnCode mss_throttle_to_power_calc
      (
       const fapi::Target &i_target_mba,
       uint32_t i_throttle_n_per_mba,
       uint32_t i_throttle_n_per_chip,
       uint32_t i_throttle_d,
       float &o_channel_pair_power
       )
    {
	fapi::ReturnCode rc = fapi::FAPI_RC_SUCCESS;

	const char* procedure_name = "mss_throttle_to_power_calc";

	FAPI_IMP("*** Running %s ***", procedure_name);

	const uint8_t MAX_NUM_PORTS = 2;
	const uint8_t MAX_NUM_DIMMS = 2;

	uint32_t l_power_slope_array[MAX_NUM_PORTS][MAX_NUM_DIMMS];
	uint32_t l_power_int_array[MAX_NUM_PORTS][MAX_NUM_DIMMS];
	uint8_t l_dimm_ranks_array[MAX_NUM_PORTS][MAX_NUM_DIMMS];
	uint8_t l_port;
	uint8_t l_dimm;
	float l_dimm_power_array[MAX_NUM_PORTS][MAX_NUM_DIMMS];
	uint32_t l_dimm_power_array_integer[MAX_NUM_PORTS][MAX_NUM_DIMMS];
	float l_utilization;
	float l_channel_power_array[MAX_NUM_PORTS];
	uint32_t l_channel_power_array_integer[MAX_NUM_PORTS];
	uint32_t l_channel_pair_power_integer;
	uint8_t l_num_dimms_on_port;
	uint8_t l_power_curve_percent_uplift;
	uint32_t l_max_dram_databus_util;
;

// get input attributes
	rc = FAPI_ATTR_GET(ATTR_MRW_MAX_DRAM_DATABUS_UTIL,
			   NULL, l_max_dram_databus_util);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_MRW_MAX_DRAM_DATABUS_UTIL");
	    return rc;
	}
	rc = FAPI_ATTR_GET(ATTR_MRW_DIMM_POWER_CURVE_PERCENT_UPLIFT,
			   NULL, l_power_curve_percent_uplift);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_MRW_DIMM_POWER_CURVE_PERCENT_UPLIFT");
	    return rc;
	}
	rc = FAPI_ATTR_GET(ATTR_MSS_POWER_SLOPE,
			   &i_target_mba, l_power_slope_array);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_MSS_POWER_SLOPE");
	    return rc;
	}
	rc = FAPI_ATTR_GET(ATTR_MSS_POWER_INT,
			   &i_target_mba, l_power_int_array);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_MSS_POWER_INT");
	    return rc;
	}
	rc = FAPI_ATTR_GET(ATTR_EFF_NUM_RANKS_PER_DIMM,
			   &i_target_mba, l_dimm_ranks_array);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_EFF_NUM_RANKS_PER_DIMM");
	    return rc;
	}
	rc = FAPI_ATTR_GET(ATTR_EFF_NUM_DROPS_PER_PORT,
			   &i_target_mba, l_num_dimms_on_port);
	if (rc) {
	    FAPI_ERR("Error getting attribute ATTR_EFF_NUM_DROPS_PER_PORT");
	    return rc;
	}

// Maximum theoretical data bus utilization (percent of max) (for ceiling)
// Comes from MRW value in c% - convert to %
	float MAX_UTIL = (float) l_max_dram_databus_util / 100;

// add up the power from all dimms for this MBA (across both channels) using the
// throttle values
	o_channel_pair_power = 0;
	l_channel_pair_power_integer = 0;
	for (l_port = 0; l_port < MAX_NUM_PORTS; l_port++)
	{
	    l_channel_power_array[l_port] = 0;
	    l_channel_power_array_integer[l_port] = 0;
	    for (l_dimm=0; l_dimm < MAX_NUM_DIMMS; l_dimm++)
	    {
// default dimm power is zero (used for dimms that are not physically present)
		l_dimm_power_array[l_port][l_dimm] = 0;
		l_dimm_power_array_integer[l_port][l_dimm] = 0;
		l_utilization = 0;
// See if there are any ranks present on the dimm (configured or deconfigured)
		if (l_dimm_ranks_array[l_port][l_dimm] > 0)
		{
// N/M throttling has the dimm0 and dimm1 throttles the same for DIMM level
// throttling, which we plan to use
// MBA or chip level throttling could limit the commands to a dimm (used along
// with the dimm level throttling)
// If MBA/chip throttle is less than dimm throttle, then use MBA/chip throttle
// If MBA/chip throttle is greater than dimm throttle, then use the dimm
// throttle
// If either of these are above the MAX_UTIL, then use MAX_UTIL
// Get power from each dimm here
// Note that the MAX_UTIL effectively is the percent of maximum bandwidth for
// that dimm

		    if (i_throttle_d == 0)
		    {
// throttle denominator is zero (N/M throttling disabled), set dimm power to the
// maximum
			FAPI_DBG("N/M Throttling is disabled (M=0).  Use Max DIMM Power");
			l_dimm_power_array[l_port][l_dimm] =
			  (l_power_slope_array[l_port][l_dimm] *
			   ((float)MAX_UTIL / 100) +
			   l_power_int_array[l_port][l_dimm]);
			l_utilization = (float)MAX_UTIL;
		    }
		    else if (
			     (
			      ((float)i_throttle_n_per_mba * 100 * 4) /
			      i_throttle_d *
			      l_num_dimms_on_port
			      )
			     >
			     (((float)i_throttle_n_per_chip * 100 * 4) /
			      i_throttle_d)
			     )
		    {
// limited by the mba/chip throttles (ie.  cfg_nm_n_per_chip)
			if ((((float)i_throttle_n_per_chip * 100 * 4) /
			     i_throttle_d) > MAX_UTIL)
			{
// limited by the maximum utilization
			    l_dimm_power_array[l_port][l_dimm] =
			      (l_power_slope_array[l_port][l_dimm] *
			       ((float)MAX_UTIL / 100) +
			       l_power_int_array[l_port][l_dimm]);
			    l_utilization = (float)MAX_UTIL;
			}
			else
			{
// limited by the per chip throttles
			    l_dimm_power_array[l_port][l_dimm] =
			      (l_power_slope_array[l_port][l_dimm] *
			       (((float)i_throttle_n_per_chip * 4)
				/ i_throttle_d) +
			       l_power_int_array[l_port][l_dimm]);
			    l_utilization = (((float)i_throttle_n_per_chip *
					      100 * 4) / i_throttle_d);
			}
		    }
		    else
		    {
// limited by the per mba throttles (ie.  cfg_nm_n_per_mba)
			if ((((float)i_throttle_n_per_mba * 100 * 4) /
			     i_throttle_d * l_num_dimms_on_port) > MAX_UTIL)
			{
// limited by the maximum utilization
			    l_dimm_power_array[l_port][l_dimm] =
			      (l_power_slope_array[l_port][l_dimm] *
			       ((float)MAX_UTIL / 100) +
			       l_power_int_array[l_port][l_dimm]);
			    l_utilization = (float)MAX_UTIL;
			}
			else
			{
// limited by the per mba throttles
// multiply by number of dimms on port since other dimm has same throttle value
			    l_dimm_power_array[l_port][l_dimm] =
			      (l_power_slope_array[l_port][l_dimm] *
			       (((float)i_throttle_n_per_mba * 4) /
				i_throttle_d * l_num_dimms_on_port) +
			       l_power_int_array[l_port][l_dimm]);
			    l_utilization =
			      (((float)i_throttle_n_per_mba * 100 * 4) /
			       i_throttle_d * l_num_dimms_on_port);
			}
		    }
		}
// Get dimm power in integer format (add on 1 since value will get truncated)
// Include any system uplift here too
		if (l_dimm_power_array[l_port][l_dimm] > 0)
		{
		    l_dimm_power_array[l_port][l_dimm] =
		      l_dimm_power_array[l_port][l_dimm]
		      * (1 + (float)l_power_curve_percent_uplift / 100);
		    l_dimm_power_array_integer[l_port][l_dimm] =
		      (int)l_dimm_power_array[l_port][l_dimm] + 1;
		}
// calculate channel power by adding up the power of each dimm
		l_channel_power_array[l_port] = l_channel_power_array[l_port] +
		  l_dimm_power_array[l_port][l_dimm];
		FAPI_DBG("[P%d:D%d][CH Util %4.2f/%4.2f][Slope:Int %d:%d][UpliftPercent %d][Power %4.2f cW]", l_port, l_dimm, l_utilization, MAX_UTIL, l_power_slope_array[l_port][l_dimm], l_power_int_array[l_port][l_dimm], l_power_curve_percent_uplift, l_dimm_power_array[l_port][l_dimm]);
	    }
	    FAPI_DBG("[P%d][Power %4.2f cW]", l_port, l_channel_power_array[l_port]);
	}
// get the channel pair power for this MBA (add on 1 since value will get
// truncated)
	for (l_port = 0; l_port < MAX_NUM_PORTS; l_port++)
	{
	    o_channel_pair_power = o_channel_pair_power +
	      l_channel_power_array[l_port];
	    if (l_channel_power_array_integer[l_port] > 0)
	    {
		l_channel_power_array_integer[l_port] =
		  (int)l_channel_power_array[l_port] + 1;
	    }
	}
	FAPI_DBG("Channel Pair Power %4.2f cW]", o_channel_pair_power);

	if (o_channel_pair_power > 0)
	{
	    l_channel_pair_power_integer = (int)o_channel_pair_power + 1;
	}
//------------------------------------------------------------------------------
// Update output attributes
	rc = FAPI_ATTR_SET(ATTR_MSS_DIMM_MAXPOWER,
			   &i_target_mba, l_dimm_power_array_integer);
	if (rc) {
	    FAPI_ERR("Error writing attribute ATTR_MSS_DIMM_MAXPOWER");
	    return rc;
	}
	rc = FAPI_ATTR_SET(ATTR_MSS_CHANNEL_PAIR_MAXPOWER,
			   &i_target_mba, l_channel_pair_power_integer);
	if (rc) {
	    FAPI_ERR("Error writing attribute ATTR_MSS_CHANNEL_PAIR_MAXPOWER");
	    return rc;
	}

	FAPI_IMP("*** %s COMPLETE ***", procedure_name);
	return rc;
    }


} //end extern C
OpenPOWER on IntegriCloud