summaryrefslogtreecommitdiff
path: root/mali_kbase/ipa/mali_kbase_ipa_simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'mali_kbase/ipa/mali_kbase_ipa_simple.c')
-rw-r--r--mali_kbase/ipa/mali_kbase_ipa_simple.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/mali_kbase/ipa/mali_kbase_ipa_simple.c b/mali_kbase/ipa/mali_kbase_ipa_simple.c
index 0fd2136..afbac80 100644
--- a/mali_kbase/ipa/mali_kbase_ipa_simple.c
+++ b/mali_kbase/ipa/mali_kbase_ipa_simple.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
/*
*
- * (C) COPYRIGHT 2016-2018, 2020-2022 ARM Limited. All rights reserved.
+ * (C) COPYRIGHT 2016-2023 ARM Limited. All rights reserved.
*
* This program is free software and is provided to you under the terms of the
* GNU General Public License version 2 as published by the Free Software
@@ -51,10 +51,10 @@
static int dummy_temp;
-static int kbase_simple_power_model_get_dummy_temp(
- struct thermal_zone_device *tz,
- int *temp)
+static int kbase_simple_power_model_get_dummy_temp(struct thermal_zone_device *tz, int *temp)
{
+ CSTD_UNUSED(tz);
+
*temp = READ_ONCE(dummy_temp);
return 0;
}
@@ -63,8 +63,7 @@ static int kbase_simple_power_model_get_dummy_temp(
#ifdef thermal_zone_get_temp
#undef thermal_zone_get_temp
#endif
-#define thermal_zone_get_temp(tz, temp) \
- kbase_simple_power_model_get_dummy_temp(tz, temp)
+#define thermal_zone_get_temp(tz, temp) kbase_simple_power_model_get_dummy_temp(tz, temp)
void kbase_simple_power_model_set_dummy_temp(int temp)
{
@@ -129,16 +128,16 @@ static u32 calculate_temp_scaling_factor(s32 ts[4], s64 t)
* Deg^-N, so we need to multiply the last coefficient by 1000.
* Range: -2^63 < res_big < 2^63
*/
- const s64 res_big = ts[3] * t3 /* +/- 2^62 */
- + ts[2] * t2 /* +/- 2^55 */
- + ts[1] * t /* +/- 2^48 */
- + ts[0] * (s64)1000; /* +/- 2^41 */
+ const s64 res_big = ts[3] * t3 /* +/- 2^62 */
+ + ts[2] * t2 /* +/- 2^55 */
+ + ts[1] * t /* +/- 2^48 */
+ + ts[0] * (s64)1000; /* +/- 2^41 */
/* Range: -2^60 < res_unclamped < 2^60 */
s64 res_unclamped = div_s64(res_big, 1000);
/* Clamp to range of 0x to 10x the static power */
- return clamp(res_unclamped, (s64) 0, (s64) 10000000);
+ return clamp(res_unclamped, (s64)0, (s64)10000000);
}
/* We can't call thermal_zone_get_temp() directly in model_static_coeff(),
@@ -147,8 +146,7 @@ static u32 calculate_temp_scaling_factor(s32 ts[4], s64 t)
*/
static int poll_temperature(void *data)
{
- struct kbase_ipa_model_simple_data *model_data =
- (struct kbase_ipa_model_simple_data *) data;
+ struct kbase_ipa_model_simple_data *model_data = (struct kbase_ipa_model_simple_data *)data;
int temp;
while (!kthread_should_stop()) {
@@ -159,8 +157,9 @@ static int poll_temperature(void *data)
ret = thermal_zone_get_temp(tz, &temp);
if (ret) {
- pr_warn_ratelimited("Error reading temperature for gpu thermal zone: %d\n",
- ret);
+ pr_warn_ratelimited(
+ "Error reading temperature for gpu thermal zone: %d\n",
+ ret);
temp = FALLBACK_STATIC_TEMPERATURE;
}
} else {
@@ -179,22 +178,21 @@ static int model_static_coeff(struct kbase_ipa_model *model, u32 *coeffp)
{
u32 temp_scaling_factor;
struct kbase_ipa_model_simple_data *model_data =
- (struct kbase_ipa_model_simple_data *) model->model_data;
+ (struct kbase_ipa_model_simple_data *)model->model_data;
u64 coeff_big;
int temp;
temp = READ_ONCE(model_data->current_temperature);
/* Range: 0 <= temp_scaling_factor < 2^24 */
- temp_scaling_factor = calculate_temp_scaling_factor(model_data->ts,
- temp);
+ temp_scaling_factor = calculate_temp_scaling_factor(model_data->ts, temp);
/*
* Range: 0 <= coeff_big < 2^52 to avoid overflowing *coeffp. This
* means static_coefficient must be in range
* 0 <= static_coefficient < 2^28.
*/
- coeff_big = (u64) model_data->static_coefficient * (u64) temp_scaling_factor;
+ coeff_big = (u64)model_data->static_coefficient * (u64)temp_scaling_factor;
*coeffp = div_u64(coeff_big, 1000000);
return 0;
@@ -203,7 +201,7 @@ static int model_static_coeff(struct kbase_ipa_model *model, u32 *coeffp)
static int model_dynamic_coeff(struct kbase_ipa_model *model, u32 *coeffp)
{
struct kbase_ipa_model_simple_data *model_data =
- (struct kbase_ipa_model_simple_data *) model->model_data;
+ (struct kbase_ipa_model_simple_data *)model->model_data;
#if MALI_USE_CSF
/* On CSF GPUs, the dynamic power for top-level and shader cores is
@@ -215,8 +213,7 @@ static int model_dynamic_coeff(struct kbase_ipa_model *model, u32 *coeffp)
*/
coeffp[KBASE_IPA_BLOCK_TYPE_TOP_LEVEL] =
model_data->dynamic_coefficient / TOP_LEVEL_DYN_COEFF_SCALER;
- coeffp[KBASE_IPA_BLOCK_TYPE_SHADER_CORES] =
- model_data->dynamic_coefficient;
+ coeffp[KBASE_IPA_BLOCK_TYPE_SHADER_CORES] = model_data->dynamic_coefficient;
#else
*coeffp = model_data->dynamic_coefficient;
#endif
@@ -228,7 +225,7 @@ static int add_params(struct kbase_ipa_model *model)
{
int err = 0;
struct kbase_ipa_model_simple_data *model_data =
- (struct kbase_ipa_model_simple_data *)model->model_data;
+ (struct kbase_ipa_model_simple_data *)model->model_data;
err = kbase_ipa_model_add_param_s32(model, "static-coefficient",
(s32 *)&model_data->static_coefficient, 1, true);
@@ -240,21 +237,18 @@ static int add_params(struct kbase_ipa_model *model)
if (err)
goto end;
- err = kbase_ipa_model_add_param_s32(model, "ts",
- model_data->ts, 4, true);
+ err = kbase_ipa_model_add_param_s32(model, "ts", model_data->ts, 4, true);
if (err)
goto end;
- err = kbase_ipa_model_add_param_string(model, "thermal-zone",
- model_data->tz_name,
+ err = kbase_ipa_model_add_param_string(model, "thermal-zone", model_data->tz_name,
sizeof(model_data->tz_name), true);
if (err)
goto end;
model_data->temperature_poll_interval_ms = 200;
err = kbase_ipa_model_add_param_s32(model, "temp-poll-interval-ms",
- &model_data->temperature_poll_interval_ms,
- 1, false);
+ &model_data->temperature_poll_interval_ms, 1, false);
end:
return err;
@@ -265,16 +259,14 @@ static int kbase_simple_power_model_init(struct kbase_ipa_model *model)
int err;
struct kbase_ipa_model_simple_data *model_data;
- model_data = kzalloc(sizeof(struct kbase_ipa_model_simple_data),
- GFP_KERNEL);
+ model_data = kzalloc(sizeof(struct kbase_ipa_model_simple_data), GFP_KERNEL);
if (!model_data)
return -ENOMEM;
- model->model_data = (void *) model_data;
+ model->model_data = (void *)model_data;
model_data->current_temperature = FALLBACK_STATIC_TEMPERATURE;
- model_data->poll_temperature_thread = kthread_run(poll_temperature,
- (void *) model_data,
+ model_data->poll_temperature_thread = kthread_run(poll_temperature, (void *)model_data,
"mali-simple-power-model-temp-poll");
if (IS_ERR(model_data->poll_temperature_thread)) {
err = PTR_ERR(model_data->poll_temperature_thread);
@@ -295,13 +287,16 @@ static int kbase_simple_power_model_init(struct kbase_ipa_model *model)
static int kbase_simple_power_model_recalculate(struct kbase_ipa_model *model)
{
struct kbase_ipa_model_simple_data *model_data =
- (struct kbase_ipa_model_simple_data *)model->model_data;
+ (struct kbase_ipa_model_simple_data *)model->model_data;
struct thermal_zone_device *tz;
lockdep_assert_held(&model->kbdev->ipa.lock);
if (!strnlen(model_data->tz_name, sizeof(model_data->tz_name))) {
model_data->gpu_tz = NULL;
+ dev_warn(model->kbdev->dev,
+ "No thermal zone specified, will use the default temperature value of %u",
+ FALLBACK_STATIC_TEMPERATURE);
} else {
char tz_name[THERMAL_NAME_LENGTH];
u32 string_len = strscpy(tz_name, model_data->tz_name, sizeof(tz_name));
@@ -347,7 +342,7 @@ static int kbase_simple_power_model_recalculate(struct kbase_ipa_model *model)
static void kbase_simple_power_model_term(struct kbase_ipa_model *model)
{
struct kbase_ipa_model_simple_data *model_data =
- (struct kbase_ipa_model_simple_data *)model->model_data;
+ (struct kbase_ipa_model_simple_data *)model->model_data;
kthread_stop(model_data->poll_temperature_thread);
@@ -355,11 +350,11 @@ static void kbase_simple_power_model_term(struct kbase_ipa_model *model)
}
struct kbase_ipa_model_ops kbase_simple_ipa_model_ops = {
- .name = "mali-simple-power-model",
- .init = &kbase_simple_power_model_init,
- .recalculate = &kbase_simple_power_model_recalculate,
- .term = &kbase_simple_power_model_term,
- .get_dynamic_coeff = &model_dynamic_coeff,
- .get_static_coeff = &model_static_coeff,
+ .name = "mali-simple-power-model",
+ .init = &kbase_simple_power_model_init,
+ .recalculate = &kbase_simple_power_model_recalculate,
+ .term = &kbase_simple_power_model_term,
+ .get_dynamic_coeff = &model_dynamic_coeff,
+ .get_static_coeff = &model_static_coeff,
};
KBASE_EXPORT_TEST_API(kbase_simple_ipa_model_ops);