From: Mr NeilBrown Date: Sat, 20 Jun 2020 02:47:19 +0000 (-0400) Subject: LU-9859 libcfs: fold cfs_tracefile_*_arch into their only callers. X-Git-Tag: 2.13.55~75 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=068cf5c7cd29cc1c27effb71ff9b511d14207147;hp=d6bbba7da72e7d9d4046a8c26be51c7535b26eb5 LU-9859 libcfs: fold cfs_tracefile_*_arch into their only callers. There is no need to separate "arch" init/fini from the rest, so fold it all in. This requires some slightly subtle changes to clean-up to make sure we don't walk lists before they are initialized. Test-Parameters: trivial Change-Id: Id78385cfc29ab3d5162a5fb84283e7a6ce6bf91a Signed-off-by: Mr NeilBrown Reviewed-on: https://review.whamcloud.com/39117 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 3f9ca12..2d0ec57 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -140,82 +140,6 @@ static inline void cfs_trace_put_tcd(struct cfs_trace_cpu_data *tcd) put_cpu(); } -/* percents to share the total debug memory for each type */ -static unsigned int pages_factor[CFS_TCD_TYPE_MAX] = { - 80, /* 80% pages for CFS_TCD_TYPE_PROC */ - 10, /* 10% pages for CFS_TCD_TYPE_SOFTIRQ */ - 10 /* 10% pages for CFS_TCD_TYPE_IRQ */ -}; - -int cfs_tracefile_init_arch(void) -{ - struct cfs_trace_cpu_data *tcd; - int i; - int j; - - /* initialize trace_data */ - memset(cfs_trace_data, 0, sizeof(cfs_trace_data)); - for (i = 0; i < CFS_TCD_TYPE_MAX; i++) { - cfs_trace_data[i] = - kmalloc_array(num_possible_cpus(), - sizeof(union cfs_trace_data_union), - GFP_KERNEL); - if (!cfs_trace_data[i]) - goto out_trace_data; - } - - /* arch related info initialized */ - cfs_tcd_for_each(tcd, i, j) { - spin_lock_init(&tcd->tcd_lock); - tcd->tcd_pages_factor = pages_factor[i]; - tcd->tcd_type = i; - tcd->tcd_cpu = j; - } - - for (i = 0; i < num_possible_cpus(); i++) - for (j = 0; j < 3; j++) { - cfs_trace_console_buffers[i][j] = - kmalloc(CFS_TRACE_CONSOLE_BUFFER_SIZE, - GFP_KERNEL); - - if (!cfs_trace_console_buffers[i][j]) - goto out_buffers; - } - - return 0; - -out_buffers: - for (i = 0; i < num_possible_cpus(); i++) - for (j = 0; j < 3; j++) { - kfree(cfs_trace_console_buffers[i][j]); - cfs_trace_console_buffers[i][j] = NULL; - } -out_trace_data: - for (i = 0; cfs_trace_data[i]; i++) { - kfree(cfs_trace_data[i]); - cfs_trace_data[i] = NULL; - } - pr_err("lnet: Not enough memory\n"); - return -ENOMEM; -} - -void cfs_tracefile_fini_arch(void) -{ - int i; - int j; - - for (i = 0; i < num_possible_cpus(); i++) - for (j = 0; j < 3; j++) { - kfree(cfs_trace_console_buffers[i][j]); - cfs_trace_console_buffers[i][j] = NULL; - } - - for (i = 0; cfs_trace_data[i]; i++) { - kfree(cfs_trace_data[i]); - cfs_trace_data[i] = NULL; - } -} - static inline struct cfs_trace_page * cfs_tage_from_list(struct list_head *list) { @@ -1277,21 +1201,39 @@ void cfs_trace_stop_thread(void) mutex_unlock(&cfs_trace_thread_mutex); } +/* percents to share the total debug memory for each type */ +static unsigned int pages_factor[CFS_TCD_TYPE_MAX] = { + 80, /* 80% pages for CFS_TCD_TYPE_PROC */ + 10, /* 10% pages for CFS_TCD_TYPE_SOFTIRQ */ + 10 /* 10% pages for CFS_TCD_TYPE_IRQ */ +}; + int cfs_tracefile_init(int max_pages) { struct cfs_trace_cpu_data *tcd; - int i; - int j; - int rc; - int factor; + int i; + int j; - rc = cfs_tracefile_init_arch(); - if (rc != 0) - return rc; + /* initialize trace_data */ + memset(cfs_trace_data, 0, sizeof(cfs_trace_data)); + for (i = 0; i < CFS_TCD_TYPE_MAX; i++) { + cfs_trace_data[i] = + kmalloc_array(num_possible_cpus(), + sizeof(union cfs_trace_data_union), + GFP_KERNEL); + if (!cfs_trace_data[i]) + goto out_trace_data; + } + /* arch related info initialized */ cfs_tcd_for_each(tcd, i, j) { - /* tcd_pages_factor is initialized int tracefile_init_arch. */ - factor = tcd->tcd_pages_factor; + int factor = pages_factor[i]; + + spin_lock_init(&tcd->tcd_lock); + tcd->tcd_pages_factor = factor; + tcd->tcd_type = i; + tcd->tcd_cpu = j; + INIT_LIST_HEAD(&tcd->tcd_pages); INIT_LIST_HEAD(&tcd->tcd_stock_pages); INIT_LIST_HEAD(&tcd->tcd_daemon_pages); @@ -1302,7 +1244,31 @@ int cfs_tracefile_init(int max_pages) LASSERT(tcd->tcd_max_pages > 0); tcd->tcd_shutting_down = 0; } + + for (i = 0; i < num_possible_cpus(); i++) + for (j = 0; j < 3; j++) { + cfs_trace_console_buffers[i][j] = + kmalloc(CFS_TRACE_CONSOLE_BUFFER_SIZE, + GFP_KERNEL); + if (!cfs_trace_console_buffers[i][j]) + goto out_buffers; + } + return 0; + +out_buffers: + for (i = 0; i < num_possible_cpus(); i++) + for (j = 0; j < 3; j++) { + kfree(cfs_trace_console_buffers[i][j]); + cfs_trace_console_buffers[i][j] = NULL; + } +out_trace_data: + for (i = 0; cfs_trace_data[i]; i++) { + kfree(cfs_trace_data[i]); + cfs_trace_data[i] = NULL; + } + pr_err("lnet: Not enough memory\n"); + return -ENOMEM; } static void trace_cleanup_on_all_cpus(void) @@ -1314,6 +1280,9 @@ static void trace_cleanup_on_all_cpus(void) for_each_possible_cpu(cpu) { cfs_tcd_for_each_type_lock(tcd, i, cpu) { + if (!tcd->tcd_pages_factor) + /* Not initialised */ + continue; tcd->tcd_shutting_down = 1; list_for_each_entry_safe(tage, tmp, &tcd->tcd_pages, linkage) { @@ -1330,12 +1299,23 @@ static void trace_cleanup_on_all_cpus(void) static void cfs_trace_cleanup(void) { struct page_collection pc; + int i; + int j; INIT_LIST_HEAD(&pc.pc_pages); trace_cleanup_on_all_cpus(); - cfs_tracefile_fini_arch(); + for (i = 0; i < num_possible_cpus(); i++) + for (j = 0; j < 3; j++) { + kfree(cfs_trace_console_buffers[i][j]); + cfs_trace_console_buffers[i][j] = NULL; + } + + for (i = 0; cfs_trace_data[i]; i++) { + kfree(cfs_trace_data[i]); + cfs_trace_data[i] = NULL; + } } void cfs_tracefile_exit(void) diff --git a/libcfs/libcfs/tracefile.h b/libcfs/libcfs/tracefile.h index 924e163..2a7b47f 100644 --- a/libcfs/libcfs/tracefile.h +++ b/libcfs/libcfs/tracefile.h @@ -53,9 +53,6 @@ extern char lnet_debug_log_upcall[1024]; extern void libcfs_run_debug_log_upcall(char *file); -int cfs_tracefile_init_arch(void); -void cfs_tracefile_fini_arch(void); - int cfs_tracefile_dump_all_pages(char *filename); void cfs_trace_debug_print(void); void cfs_trace_flush_pages(void);