From 9b1e800ef07d12adcb4a7595be2ca10bb6e9e834 Mon Sep 17 00:00:00 2001 From: Boyan Karatotev Date: Thu, 10 Oct 2024 08:11:09 +0100 Subject: [PATCH] refactor(psci): move timestamp collection to psci_pwrdown_cpu psci_pwrdown_cpu has two callers, both of which save timestamps meant to measure how much time the cache maintenance operations take. Move the timestamp collection inside to save on a bit of code duplication. Change-Id: Ia2e7168faf7773d99b696cbdb6c98db7b58e31cf Signed-off-by: Boyan Karatotev --- lib/psci/psci_common.c | 19 +++++++++++++++++++ lib/psci/psci_off.c | 19 +------------------ lib/psci/psci_suspend.c | 17 ----------------- 3 files changed, 20 insertions(+), 35 deletions(-) diff --git a/lib/psci/psci_common.c b/lib/psci/psci_common.c index 25e8c5254..5a9a01500 100644 --- a/lib/psci/psci_common.c +++ b/lib/psci/psci_common.c @@ -16,6 +16,8 @@ #include #include #include +#include +#include #include #include @@ -1159,6 +1161,17 @@ int psci_secondaries_brought_up(void) ******************************************************************************/ void psci_pwrdown_cpu(unsigned int power_level) { +#if ENABLE_RUNTIME_INSTRUMENTATION + + /* + * Flush cache line so that even if CPU power down happens + * the timestamp update is reflected in memory. + */ + PMF_CAPTURE_TIMESTAMP(rt_instr_svc, + RT_INSTR_ENTER_CFLUSH, + PMF_CACHE_MAINT); +#endif + #if HW_ASSISTED_COHERENCY /* * With hardware-assisted coherency, the CPU drivers only initiate the @@ -1178,6 +1191,12 @@ void psci_pwrdown_cpu(unsigned int power_level) */ psci_do_pwrdown_cache_maintenance(power_level); #endif + +#if ENABLE_RUNTIME_INSTRUMENTATION + PMF_CAPTURE_TIMESTAMP(rt_instr_svc, + RT_INSTR_EXIT_CFLUSH, + PMF_NO_CACHE_MAINT); +#endif } /******************************************************************************* diff --git a/lib/psci/psci_off.c b/lib/psci/psci_off.c index f83753fc9..a13ae03f4 100644 --- a/lib/psci/psci_off.c +++ b/lib/psci/psci_off.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved. * Copyright (c) 2023, NVIDIA Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -112,28 +112,11 @@ int psci_do_cpu_off(unsigned int end_pwrlvl) psci_stats_update_pwr_down(end_pwrlvl, &state_info); #endif -#if ENABLE_RUNTIME_INSTRUMENTATION - - /* - * Flush cache line so that even if CPU power down happens - * the timestamp update is reflected in memory. - */ - PMF_CAPTURE_TIMESTAMP(rt_instr_svc, - RT_INSTR_ENTER_CFLUSH, - PMF_CACHE_MAINT); -#endif - /* * Arch. management. Initiate power down sequence. */ psci_pwrdown_cpu(psci_find_max_off_lvl(&state_info)); -#if ENABLE_RUNTIME_INSTRUMENTATION - PMF_CAPTURE_TIMESTAMP(rt_instr_svc, - RT_INSTR_EXIT_CFLUSH, - PMF_NO_CACHE_MAINT); -#endif - /* * Plat. management: Perform platform specific actions to turn this * cpu off e.g. exit cpu coherency, program the power controller etc. diff --git a/lib/psci/psci_suspend.c b/lib/psci/psci_suspend.c index 83df099bc..c3d6954f6 100644 --- a/lib/psci/psci_suspend.c +++ b/lib/psci/psci_suspend.c @@ -92,29 +92,12 @@ static void psci_suspend_to_pwrdown_start(unsigned int end_pwrlvl, */ cm_init_my_context(ep); -#if ENABLE_RUNTIME_INSTRUMENTATION - - /* - * Flush cache line so that even if CPU power down happens - * the timestamp update is reflected in memory. - */ - PMF_CAPTURE_TIMESTAMP(rt_instr_svc, - RT_INSTR_ENTER_CFLUSH, - PMF_CACHE_MAINT); -#endif - /* * Arch. management. Initiate power down sequence. * TODO : Introduce a mechanism to query the cache level to flush * and the cpu-ops power down to perform from the platform. */ psci_pwrdown_cpu(max_off_lvl); - -#if ENABLE_RUNTIME_INSTRUMENTATION - PMF_CAPTURE_TIMESTAMP(rt_instr_svc, - RT_INSTR_EXIT_CFLUSH, - PMF_NO_CACHE_MAINT); -#endif } /*******************************************************************************