From ef2d30328fbb1b85c3e2aaaa37b39e4cbf2fb7e2 Mon Sep 17 00:00:00 2001 From: Philip Elcan Date: Thu, 26 Sep 2019 14:16:38 -0400 Subject: [PATCH] gpu: nvgpu: ecc: improve CCM for nvgpu_ecc_free This reduces the code complexity for nvgpu_ecc_free() by creating a helper function free_ecc_stat_count_array(). The TCC metric is reduced from 27 to 5. JIRA NVGPU-4094 Change-Id: I80c85fe56d253616817682278f4bef241c346d57 Signed-off-by: Philip Elcan Reviewed-on: https://git-master.nvidia.com/r/2206518 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/ecc.c | 166 ++++++++++++--------------------- 1 file changed, 60 insertions(+), 106 deletions(-) diff --git a/drivers/gpu/nvgpu/common/ecc.c b/drivers/gpu/nvgpu/common/ecc.c index 3b4c09947..444f1df97 100644 --- a/drivers/gpu/nvgpu/common/ecc.c +++ b/drivers/gpu/nvgpu/common/ecc.c @@ -210,6 +210,21 @@ int nvgpu_ecc_counter_init_per_fbpa(struct gk20a *g, return 0; } +/* helper function that frees the count array if non-NULL. */ +static void free_ecc_stat_count_array(struct gk20a *g, + struct nvgpu_ecc_stat **stat, + u32 gpc_count) +{ + u32 i; + + if (stat != NULL) { + for (i = 0; i < gpc_count; i++) { + nvgpu_kfree(g, stat[i]); + } + nvgpu_kfree(g, stat); + } +} + /* release all ecc_stat */ void nvgpu_ecc_free(struct gk20a *g) { @@ -224,112 +239,51 @@ void nvgpu_ecc_free(struct gk20a *g) gpc_count = nvgpu_gr_config_get_gpc_count(gr_config); - for (i = 0; i < gpc_count; i++) { - if (ecc->gr.sm_lrf_ecc_single_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_lrf_ecc_single_err_count[i]); - } - - if (ecc->gr.sm_lrf_ecc_double_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_lrf_ecc_double_err_count[i]); - } - - if (ecc->gr.sm_shm_ecc_sec_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_shm_ecc_sec_count[i]); - } - - if (ecc->gr.sm_shm_ecc_sed_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_shm_ecc_sed_count[i]); - } - - if (ecc->gr.sm_shm_ecc_ded_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_shm_ecc_ded_count[i]); - } - - if (ecc->gr.tex_ecc_total_sec_pipe0_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_ecc_total_sec_pipe0_count[i]); - } - - if (ecc->gr.tex_ecc_total_ded_pipe0_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_ecc_total_ded_pipe0_count[i]); - } - - if (ecc->gr.tex_unique_ecc_sec_pipe0_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_sec_pipe0_count[i]); - } - - if (ecc->gr.tex_unique_ecc_ded_pipe0_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_ded_pipe0_count[i]); - } - - if (ecc->gr.tex_ecc_total_sec_pipe1_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_ecc_total_sec_pipe1_count[i]); - } - - if (ecc->gr.tex_ecc_total_ded_pipe1_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_ecc_total_ded_pipe1_count[i]); - } - - if (ecc->gr.tex_unique_ecc_sec_pipe1_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_sec_pipe1_count[i]); - } - - if (ecc->gr.tex_unique_ecc_ded_pipe1_count != NULL) { - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_ded_pipe1_count[i]); - } - - if (ecc->gr.sm_l1_tag_ecc_corrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_l1_tag_ecc_corrected_err_count[i]); - } - - if (ecc->gr.sm_l1_tag_ecc_uncorrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_l1_tag_ecc_uncorrected_err_count[i]); - } - - if (ecc->gr.sm_cbu_ecc_corrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_cbu_ecc_corrected_err_count[i]); - } - - if (ecc->gr.sm_cbu_ecc_uncorrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_cbu_ecc_uncorrected_err_count[i]); - } - - if (ecc->gr.sm_l1_data_ecc_corrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_l1_data_ecc_corrected_err_count[i]); - } - - if (ecc->gr.sm_l1_data_ecc_uncorrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_l1_data_ecc_uncorrected_err_count[i]); - } - - if (ecc->gr.sm_icache_ecc_corrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_icache_ecc_corrected_err_count[i]); - } - - if (ecc->gr.sm_icache_ecc_uncorrected_err_count != NULL) { - nvgpu_kfree(g, ecc->gr.sm_icache_ecc_uncorrected_err_count[i]); - } - } - nvgpu_kfree(g, ecc->gr.sm_lrf_ecc_single_err_count); - nvgpu_kfree(g, ecc->gr.sm_lrf_ecc_double_err_count); - nvgpu_kfree(g, ecc->gr.sm_shm_ecc_sec_count); - nvgpu_kfree(g, ecc->gr.sm_shm_ecc_sed_count); - nvgpu_kfree(g, ecc->gr.sm_shm_ecc_ded_count); - nvgpu_kfree(g, ecc->gr.tex_ecc_total_sec_pipe0_count); - nvgpu_kfree(g, ecc->gr.tex_ecc_total_ded_pipe0_count); - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_sec_pipe0_count); - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_ded_pipe0_count); - nvgpu_kfree(g, ecc->gr.tex_ecc_total_sec_pipe1_count); - nvgpu_kfree(g, ecc->gr.tex_ecc_total_ded_pipe1_count); - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_sec_pipe1_count); - nvgpu_kfree(g, ecc->gr.tex_unique_ecc_ded_pipe1_count); - nvgpu_kfree(g, ecc->gr.sm_l1_tag_ecc_corrected_err_count); - nvgpu_kfree(g, ecc->gr.sm_l1_tag_ecc_uncorrected_err_count); - nvgpu_kfree(g, ecc->gr.sm_cbu_ecc_corrected_err_count); - nvgpu_kfree(g, ecc->gr.sm_cbu_ecc_uncorrected_err_count); - nvgpu_kfree(g, ecc->gr.sm_l1_data_ecc_corrected_err_count); - nvgpu_kfree(g, ecc->gr.sm_l1_data_ecc_uncorrected_err_count); - nvgpu_kfree(g, ecc->gr.sm_icache_ecc_corrected_err_count); - nvgpu_kfree(g, ecc->gr.sm_icache_ecc_uncorrected_err_count); + free_ecc_stat_count_array(g, ecc->gr.sm_lrf_ecc_single_err_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_lrf_ecc_double_err_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_shm_ecc_sec_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_shm_ecc_sed_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_shm_ecc_ded_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_ecc_total_sec_pipe0_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_ecc_total_ded_pipe0_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_unique_ecc_sec_pipe0_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_unique_ecc_ded_pipe0_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_ecc_total_sec_pipe1_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_ecc_total_ded_pipe1_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_unique_ecc_sec_pipe1_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.tex_unique_ecc_ded_pipe1_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_l1_tag_ecc_corrected_err_count, + gpc_count); + free_ecc_stat_count_array(g, + ecc->gr.sm_l1_tag_ecc_uncorrected_err_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_cbu_ecc_corrected_err_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_cbu_ecc_uncorrected_err_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_l1_data_ecc_corrected_err_count, + gpc_count); + free_ecc_stat_count_array(g, + ecc->gr.sm_l1_data_ecc_uncorrected_err_count, + gpc_count); + free_ecc_stat_count_array(g, ecc->gr.sm_icache_ecc_corrected_err_count, + gpc_count); + free_ecc_stat_count_array(g, + ecc->gr.sm_icache_ecc_uncorrected_err_count, + gpc_count); nvgpu_kfree(g, ecc->gr.gcc_l15_ecc_corrected_err_count); nvgpu_kfree(g, ecc->gr.gcc_l15_ecc_uncorrected_err_count);