lustre: libcfs: tracefile cleanups
v3 cover lustre: libcfs: tracefile cleanups
The first three patches in this series are a repost of Neil's patches. I updated the 4th patch but it contained to many changes so I broke it into 6 smaller patches for easier review. It address all the brokeness of cfs_print_to_console() which shows up in my testing. Besides the fixing more cleanups of tracefile.h was done in the new patches. The rest of the patches are Neil's work rebased due the changes I introduced.
James Simmons (6):
lustre: libcfs: fix cfs_print_to_console()
lustre: libcfs: properly handle failure paths in cfs_tracefile_init_arch()
lustre: libcfs: remove cfs_trace_refill_stack()
lustre: libcfs: move cfs_trace_data data to tracefile.c
lustre: libcfs: cleanup tracefile.h
lustre: libcfs: format macros in tracefile.h
NeilBrown (7):
lustre: libcfs: move tracefile locking from linux-tracefile.c to tracefile.c
lustre: libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb()
lustre: libcfs: move tcd locking across to tracefile.c
lustre: libcfs: merge linux-tracefile.c into tracefile.c
lustre: libcfs: fold cfs_tracefile_*_arch into their only callers.
lustre: libcfs: renamed CFS_TCD_TYPE_MAX to CFS_TCD_TYPE_CNT
lustre: libcfs: discard TCD_MAX_TYPES
-------------
Changelog
1) Initial patches from Neil Brown
2) Neil's patches pushed with the 4th patch heavly updated.
3) Broke up the 4th patch I pushed into smaller patches for easier review.
drivers/staging/lustre/lnet/libcfs/Makefile | 2 +- drivers/staging/lustre/lnet/libcfs/debug.c | 6 +- .../staging/lustre/lnet/libcfs/linux-tracefile.c | 258 -------------------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 267 +++++++++++++++++---- drivers/staging/lustre/lnet/libcfs/tracefile.h | 117 +-------- 5 files changed, 237 insertions(+), 413 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux-tracefile.c
Signature · 1 line
1.8.3.1
PATCH v3 1/13 lustre: libcfs: move tracefile locking from linux-tracefile.c to tracefile.c
From: NeilBrown <[email protected]>
There is no value in keeping it separate.
--- .../staging/lustre/lnet/libcfs/linux-tracefile.c | 22 ------------------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 25 +++++++++++----------- drivers/staging/lustre/lnet/libcfs/tracefile.h | 5 ----- 3 files changed, 13 insertions(+), 39 deletions(-)
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0 -22
@@ -47,8 +47,6 @@char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ]; -static DECLARE_RWSEM (cfs_tracefile_sem); -int cfs_tracefile_init_arch (void ) {int i;
@@ -109,26 +107,6 @@ void cfs_tracefile_fini_arch(void) } } -void cfs_tracefile_read_lock (void ) -{ -down_read (&cfs_tracefile_sem); -} - -void cfs_tracefile_read_unlock (void ) -{ -up_read (&cfs_tracefile_sem); -} - -void cfs_tracefile_write_lock (void ) -{ -down_write (&cfs_tracefile_sem); -} - -void cfs_tracefile_write_unlock (void ) -{ -up_write (&cfs_tracefile_sem); -} -enum cfs_trace_buf_type cfs_trace_buf_idx_get (void ) {if (in_irq ())
drivers/staging/lustre/lnet/libcfs/tracefile.c +13 -12
@@ -59,6 +59,7 @@static int thread_running;static atomic_t cfs_tage_allocated =ATOMIC_INIT (0 ); +static DECLARE_RWSEM (cfs_tracefile_sem);struct page_collection {struct list_head pc_pages;
@@ -711,7 +712,7 @@ int cfs_tracefile_dump_all_pages(char *filename)mm_segment_t __oldfs;int rc; -cfs_tracefile_write_lock (); +down_write (&cfs_tracefile_sem); filp =filp_open (filename,O_CREAT |O_EXCL |O_WRONLY |O_LARGEFILE ,0600 );
@@ -759,7 +760,7 @@ int cfs_tracefile_dump_all_pages(char *filename) close:filp_close (filp,NULL ); out: -cfs_tracefile_write_unlock (); +up_write (&cfs_tracefile_sem);return rc; }
@@ -873,12 +874,12 @@ int cfs_trace_daemon_command(char *str) {int rc =0 ; -cfs_tracefile_write_lock (); +down_write (&cfs_tracefile_sem);if (!strcmp (str,"stop" )) { -cfs_tracefile_write_unlock (); +up_write (&cfs_tracefile_sem);cfs_trace_stop_thread (); -cfs_tracefile_write_lock (); +down_write (&cfs_tracefile_sem);memset (cfs_tracefile,0 ,sizeof (cfs_tracefile)); }else if (!strncmp (str,"size=" ,5 )) {
@@ -905,7 +906,7 @@ int cfs_trace_daemon_command(char *str)cfs_trace_start_thread (); } -cfs_tracefile_write_unlock (); +up_write (&cfs_tracefile_sem);return rc; }
@@ -950,12 +951,12 @@ int cfs_trace_set_debug_mb(int mb) mb /=num_possible_cpus (); pages = mb << (20 -PAGE_SHIFT ); -cfs_tracefile_write_lock (); +down_write (&cfs_tracefile_sem);cfs_tcd_for_each (tcd, i, j) tcd->tcd_max_pages = (pages * tcd->tcd_pages_factor) /100 ; -cfs_tracefile_write_unlock (); +up_write (&cfs_tracefile_sem);return 0 ; }
@@ -967,12 +968,12 @@ int cfs_trace_get_debug_mb(void)struct cfs_trace_cpu_data *tcd;int total_pages =0 ; -cfs_tracefile_read_lock (); +down_read (&cfs_tracefile_sem);cfs_tcd_for_each (tcd, i, j) total_pages += tcd->tcd_max_pages; -cfs_tracefile_read_unlock (); +up_read (&cfs_tracefile_sem);return (total_pages >> (20 -PAGE_SHIFT )) +1 ; }
@@ -1002,7 +1003,7 @@ static int tracefiled(void *arg) goto end_loop; filp =NULL ; -cfs_tracefile_read_lock (); +down_read (&cfs_tracefile_sem);if (cfs_tracefile[0 ]) { filp = filp_open(cfs_tracefile, O_CREAT | O_RDWR | O_LARGEFILE,
@@ -1014,7 +1015,7 @@ static int tracefiled(void *arg) rc); } } -cfs_tracefile_read_unlock (); +up_read (&cfs_tracefile_sem);if (!filp) {put_pages_on_daemon_list (&pc);__LASSERT (list_empty (&pc.pc_pages));
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -5
@@ -65,11 +65,6 @@ enum cfs_trace_buf_type {int cfs_tracefile_init_arch (void );void cfs_tracefile_fini_arch (void ); -void cfs_tracefile_read_lock (void ); -void cfs_tracefile_read_unlock (void ); -void cfs_tracefile_write_lock (void ); -void cfs_tracefile_write_unlock (void ); -int cfs_tracefile_dump_all_pages (char *filename);void cfs_trace_debug_print (void );void cfs_trace_flush_pages (void );
Signature · 1 line
1.8.3.1
PATCH v3 2/13 lustre: libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb()
In reply to James SimmonsFrom: NeilBrown <[email protected]>
This function in used twice.
In libcfs_debug_init() the usage is pointless as the only place that set libcfs_debug_mb ensures that it does not exceed the maximum. So checking again can never help.
So open-code the small function into the only other place that it is used - in cfs_trace_set_debug_mb(), which is used to set libcfs_debug_mb.
--- drivers/staging/lustre/lnet/libcfs/debug.c | 6 +++--- drivers/staging/lustre/lnet/libcfs/linux-tracefile.c | 7 ------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 3 ++- drivers/staging/lustre/lnet/libcfs/tracefile.h | 1 - 4 files changed, 5 insertions(+), 12 deletions(-)
drivers/staging/lustre/lnet/libcfs/debug.c +3 -3
@@ -411,10 +411,10 @@ int libcfs_debug_init(unsigned long bufsize) sizeof(libcfs_debug_file_path_arr)); } -/* If libcfs_debug_mb is set to an invalid value or uninitialized -* then just make the total buffers smp_num_cpus * TCD_MAX_PAGES +/* If libcfs_debug_mb is uninitialized then just make the +* total buffers smp_num_cpus * TCD_MAX_PAGES */ -if (max >cfs_trace_max_debug_mb () || max <num_possible_cpus ()) { +if (max <num_possible_cpus ()) { max =TCD_MAX_PAGES ; }else { max = max /num_possible_cpus ();
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0 -7
@@ -227,10 +227,3 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, hdr->ph_line_num, fn, len, buf); } } - -int cfs_trace_max_debug_mb (void ) -{ -int total_mb = (totalram_pages >> (20 -PAGE_SHIFT )); - -return max (512 , (total_mb *80 ) /100 ); -}
drivers/staging/lustre/lnet/libcfs/tracefile.c +2 -1
@@ -933,7 +933,8 @@ int cfs_trace_set_debug_mb(int mb)int i;int j;int pages; -int limit =cfs_trace_max_debug_mb (); +int total_mb = (totalram_pages >> (20 -PAGE_SHIFT )); +int limit =max (512 , (total_mb *80 ) /100 );struct cfs_trace_cpu_data *tcd;if (mb <num_possible_cpus ()) {
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -1
@@ -88,7 +88,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,void libcfs_register_panic_notifier (void );void libcfs_unregister_panic_notifier (void );extern int libcfs_panic_in_progress; -int cfs_trace_max_debug_mb (void );#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))#define TCD_STOCK_PAGES (TCD_MAX_PAGES)
Signature · 1 line
1.8.3.1
PATCH v3 2/13 lustre: libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb()
Quoted 26 lines · James Simmons
From: NeilBrown <[email protected]>
This function in used twice.
Inlibcfs_debug_init()the usage is pointless as the only place that setlibcfs_debug_mbensures that it does not exceed the maximum. So checking again can never help.So open-code the small function into the only other place that it is used - in
cfs_trace_set_debug_mb(), which is used to setlibcfs_debug_mb.Signed-off-by NeilBrown <[email protected]>---
drivers/staging/lustre/lnet/libcfs/debug.c | 6 +++--- drivers/staging/lustre/lnet/libcfs/linux-tracefile.c | 7 ------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 3 ++- drivers/staging/lustre/lnet/libcfs/tracefile.h | 1 - 4 files changed, 5 insertions(+), 12 deletions(-)drivers/staging/lustre/lnet/libcfs/debug.c +0
-0
drivers/staging/lustre/lnet/libcfs/debug.c int libcfs_debug_init(unsigned long bufsize) · line 417
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/debug.c +3
-3@@ -411,10 +411,10 @@ int libcfs_debug_init(unsigned long bufsize) sizeof(libcfs_debug_file_path_arr)); } -/* If libcfs_debug_mb is set to an invalid value or uninitialized -* then just make the total buffers smp_num_cpus * TCD_MAX_PAGES +/* If libcfs_debug_mb is uninitialized then just make the +* total buffers smp_num_cpus * TCD_MAX_PAGES */ -if (max >cfs_trace_max_debug_mb () || max <num_possible_cpus ()) { +if (max <num_possible_cpus ()) {
The libcfs_debug_mb value may be set as a module option, so that the debug buffer can be sized before any debugging messages are logged (in case of problems early on in module loading and such). This code validates that the value set via module parameter is sane.
It may be that there is a mechanism to limit the value set by module option in newer kernels, but that wasn't the case in the past.
Cheers, Andreas
Quoted 45 lines
drivers/staging/lustre/lnet/libcfs/debug.c +0
-0max =TCD_MAX_PAGES ; }else { max = max /num_possible_cpus ();drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-7@@ -227,10 +227,3 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, hdr->ph_line_num, fn, len, buf); } } - -int cfs_trace_max_debug_mb (void ) -{ -int total_mb = (totalram_pages >> (20 -PAGE_SHIFT )); - -return max (512 , (total_mb *80 ) /100 ); -}drivers/staging/lustre/lnet/libcfs/tracefile.c +2
-1@@ -933,7 +933,8 @@ int cfs_trace_set_debug_mb(int mb)int i;int j;int pages; -int limit =cfs_trace_max_debug_mb (); +int total_mb = (totalram_pages >> (20 -PAGE_SHIFT )); +int limit =max (512 , (total_mb *80 ) /100 );struct cfs_trace_cpu_data *tcd;if (mb <num_possible_cpus ()) {drivers/staging/lustre/lnet/libcfs/tracefile.h +0
-2@@ -88,7 +88,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,void libcfs_register_panic_notifier (void );void libcfs_unregister_panic_notifier (void );extern int libcfs_panic_in_progress; -int cfs_trace_max_debug_mb (void );#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))#define TCD_STOCK_PAGES (TCD_MAX_PAGES) --
Quoted 2 lines
1.8.3.1
Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180628/70844d26/attachment.sig>
PATCH v3 2/13 lustre: libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb()
Quoted 43 lines · Andreas Dilger
Quoted 26 lines · James Simmons
From: NeilBrown <[email protected]>
This function in used twice.
Inlibcfs_debug_init()the usage is pointless as the only place that setlibcfs_debug_mbensures that it does not exceed the maximum. So checking again can never help.So open-code the small function into the only other place that it is used - in
cfs_trace_set_debug_mb(), which is used to setlibcfs_debug_mb.Signed-off-by NeilBrown <[email protected]>---
drivers/staging/lustre/lnet/libcfs/debug.c | 6 +++--- drivers/staging/lustre/lnet/libcfs/linux-tracefile.c | 7 ------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 3 ++- drivers/staging/lustre/lnet/libcfs/tracefile.h | 1 - 4 files changed, 5 insertions(+), 12 deletions(-)drivers/staging/lustre/lnet/libcfs/debug.c +0
-0drivers/staging/lustre/lnet/libcfs/debug.c int libcfs_debug_init(unsigned long bufsize) · line 417
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/debug.c +3
-3@@ -411,10 +411,10 @@ int libcfs_debug_init(unsigned long bufsize) sizeof(libcfs_debug_file_path_arr)); } -/* If libcfs_debug_mb is set to an invalid value or uninitialized -* then just make the total buffers smp_num_cpus * TCD_MAX_PAGES +/* If libcfs_debug_mb is uninitialized then just make the +* total buffers smp_num_cpus * TCD_MAX_PAGES */ -if (max >cfs_trace_max_debug_mb () || max <num_possible_cpus ()) { +if (max <num_possible_cpus ()) {The
libcfs_debug_mbvalue may be set as a module option, so that the debug buffer can be sized before any debugging messages are logged (in case of problems early on in module loading and such). This code validates that the value set via module parameter is sane.
Quoted 2 lines
It may be that there is a mechanism to limit the value set by module option in newer kernels, but that wasn't the case in the past.
There is such a mechanism now.
When the libcfs_debug_mb module parameter is detected, libcfs_param_debug_mb_set() is called to parse it.
This function uses kstrtouint() to convert the string
to unsigned int, and then...... oh, that's odd.
If the current value of libcfs_debug_mb is zero, then then the number is used without further checking. I hadn't noticed that.
If that current value is non-zero, then the parsed number is passed to cfs_trace_set_debug_mb(). I had assumed that always happens, and that function imposes the required limit.
I'll fix that up - make sure it always imposes the appropriate limit.
Thanks for the review!
NeilBrown
Quoted 45 lines
Cheers, Andreas
Quoted 42 lines
drivers/staging/lustre/lnet/libcfs/debug.c +0
-0max =TCD_MAX_PAGES ; }else { max = max /num_possible_cpus ();drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-7@@ -227,10 +227,3 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, hdr->ph_line_num, fn, len, buf); } } - -int cfs_trace_max_debug_mb (void ) -{ -int total_mb = (totalram_pages >> (20 -PAGE_SHIFT )); - -return max (512 , (total_mb *80 ) /100 ); -}drivers/staging/lustre/lnet/libcfs/tracefile.c +2
-1@@ -933,7 +933,8 @@ int cfs_trace_set_debug_mb(int mb)int i;int j;int pages; -int limit =cfs_trace_max_debug_mb (); +int total_mb = (totalram_pages >> (20 -PAGE_SHIFT )); +int limit =max (512 , (total_mb *80 ) /100 );struct cfs_trace_cpu_data *tcd;if (mb <num_possible_cpus ()) {drivers/staging/lustre/lnet/libcfs/tracefile.h +0
-1@@ -88,7 +88,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,void libcfs_register_panic_notifier (void );void libcfs_unregister_panic_notifier (void );extern int libcfs_panic_in_progress; -int cfs_trace_max_debug_mb (void );
Quoted 11 lines
Quoted 5 lines
drivers/staging/lustre/lnet/libcfs/tracefile.h +0
-1#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT))#define TCD_STOCK_PAGES (TCD_MAX_PAGES) --1.8.3.1
Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180629/dad555dd/attachment.sig>
PATCH v3 2/13 lustre: libcfs: open code cfs_trace_max_debug_mb() into cfs_trace_set_debug_mb()
Quoted 15 lines · NeilBrown
Quoted 2 lines
It may be that there is a mechanism to limit the value set by module option in newer kernels, but that wasn't the case in the past.
There is such a mechanism now.
When thelibcfs_debug_mbmodule parameter is detected,libcfs_param_debug_mb_set()is called to parse it.
This function useskstrtouint()to convert the string
to unsigned int, and then...... oh, that's odd.
If the current value oflibcfs_debug_mbis zero, then then the number is used without further checking. I hadn't noticed that.
If that current value is non-zero, then the parsed number is passed tocfs_trace_set_debug_mb(). I had assumed that always happens, and that function imposes the required limit.
Quoted 2 lines
I'll fix that up - make sure it always imposes the appropriate limit.
I've inserted the following patch before this one. That makes it correct :-)
Thanks,
NeilBrown
From: NeilBrown <[email protected]>
Date: Mon, 2 Jul 2018 12:14:15 +1000
Subject: [PATCH] lustre: always range-check libcfs_debug_mb setting.
When the libcfs_debug_mb module parameter is set at module-load time it isn't range-checked. When it is set via sysfs it is. This inconsistency makes the code harder to follow.
It is quite safe to call cfs_trace_set_debug_mb() and cfs_trace_get_debug_mb() before the module
is initialized as cfs_tcd_for_each() does nothing before initializtion.
So change cfs_trace_set_debug_mb() - which does
range checking - to returned the ranged checked number (it currently always returns zero) and use that as the new value, unless cfs_trace_get_debug_mb() now returns a non-zero value.
--- drivers/staging/lustre/lnet/libcfs/debug.c | 16 +++++++--------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-)
drivers/staging/lustre/lnet/libcfs/debug.c +7 -9
@@ -67,17 +67,15 @@ static int libcfs_param_debug_mb_set(const char *val,if (rc <0 )return rc; -if (!*((unsigned int *)kp->arg)) { - *((unsigned int *)kp->arg) = num; -return 0 ; - } - - rc =cfs_trace_set_debug_mb (num); + num =cfs_trace_set_debug_mb (num); -if (!rc) - *((unsigned int *)kp->arg) =cfs_trace_get_debug_mb (); + *((unsigned int *)kp->arg) = num; + num =cfs_trace_get_debug_mb (); +if (num) +/* This value is more precise */ + *((unsigned int *)kp->arg) = num; -return rc; +return 0 ; }/* While debug_mb setting look like unsigned int, in fact
drivers/staging/lustre/lnet/libcfs/tracefile.c +1 -1
@@ -958,7 +958,7 @@ int cfs_trace_set_debug_mb(int mb)up_write (&cfs_tracefile_sem); -return 0 ; +return mb; }int cfs_trace_get_debug_mb (void )
Signature · 9 lines
2.14.0.rc0.dirty -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 832 bytes Desc: not available URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180702/dc2265db/attachment.sig>
PATCH v3 3/13 lustre: libcfs: move tcd locking across to tracefile.c
In reply to James SimmonsFrom: NeilBrown <[email protected]>
No need to have this in linux-tracefile.c
--- .../staging/lustre/lnet/libcfs/linux-tracefile.c | 35 ------------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 59 ++++++++++++++++++++++ drivers/staging/lustre/lnet/libcfs/tracefile.h | 28 ---------- 3 files changed, 59 insertions(+), 63 deletions(-)
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0 -35
@@ -116,41 +116,6 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)return CFS_TCD_TYPE_PROC ; } -/* -* The walking argument indicates the locking comes from all tcd types -* iterator and we must lock it and dissable local irqs to avoid deadlocks -* with other interrupt locks that might be happening. See LU-1311 -* for details. -*/ -int cfs_trace_lock_tcd (struct cfs_trace_cpu_data *tcd,int walking) - __acquires(&tcd->tc_lock) -{ -__LASSERT (tcd->tcd_type <CFS_TCD_TYPE_MAX ); -if (tcd->tcd_type ==CFS_TCD_TYPE_IRQ ) -spin_lock_irqsave (&tcd->tcd_lock, tcd->tcd_lock_flags); -else if (tcd->tcd_type ==CFS_TCD_TYPE_SOFTIRQ ) -spin_lock_bh (&tcd->tcd_lock); -else if (unlikely (walking)) -spin_lock_irq (&tcd->tcd_lock); -else -spin_lock (&tcd->tcd_lock); -return 1 ; -} - -void cfs_trace_unlock_tcd (struct cfs_trace_cpu_data *tcd,int walking) - __releases(&tcd->tcd_lock) -{ -__LASSERT (tcd->tcd_type <CFS_TCD_TYPE_MAX ); -if (tcd->tcd_type ==CFS_TCD_TYPE_IRQ ) -spin_unlock_irqrestore (&tcd->tcd_lock, tcd->tcd_lock_flags); -else if (tcd->tcd_type ==CFS_TCD_TYPE_SOFTIRQ ) -spin_unlock_bh (&tcd->tcd_lock); -else if (unlikely (walking)) -spin_unlock_irq (&tcd->tcd_lock); -else -spin_unlock (&tcd->tcd_lock); -} - void cfs_set_ptldebug_header(struct ptldebug_header *header, struct libcfs_debug_msg_data *msgdata,
drivers/staging/lustre/lnet/libcfs/tracefile.c +59 -0
65 lines not on this page · raw message
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -28
@@ -49,8 +49,6 @@ enum cfs_trace_buf_type { CFS_TCD_TYPE_MAX }; -/* trace file lock routines */ -#define TRACEFILE_NAME_SIZE 1024extern char cfs_tracefile[TRACEFILE_NAME_SIZE ];extern long long cfs_tracefile_size;
@@ -194,11 +192,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob, j <num_possible_cpus (); \ j++, (tcd) = &(*cfs_trace_data[i])[j].tcd) -#define cfs_tcd_for_each_type_lock (tcd, i, cpu) \ - for (i = 0; cfs_trace_data[i] && \ - (tcd = &(*cfs_trace_data[i])[cpu].tcd) && \ - cfs_trace_lock_tcd(tcd, 1); cfs_trace_unlock_tcd(tcd, 1), i++) -void cfs_set_ptldebug_header (struct ptldebug_header *header,struct libcfs_debug_msg_data *m,unsigned long stack);
@@ -206,9 +199,6 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask, const char *buf, int len, const char *file, const char *fn); -int cfs_trace_lock_tcd (struct cfs_trace_cpu_data *tcd,int walking); -void cfs_trace_unlock_tcd (struct cfs_trace_cpu_data *tcd,int walking); -extern char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ];enum cfs_trace_buf_type cfs_trace_buf_idx_get (void );
@@ -221,24 +211,6 @@ void cfs_print_to_console(struct ptldebug_header *hdr, int mask,return cfs_trace_console_buffers[i][j]; } -static inline struct cfs_trace_cpu_data * -cfs_trace_get_tcd (void ) -{ -struct cfs_trace_cpu_data *tcd = - &(*cfs_trace_data[cfs_trace_buf_idx_get ()])[get_cpu ()].tcd; - -cfs_trace_lock_tcd (tcd,0 ); - -return tcd; -} - -static inline void cfs_trace_put_tcd (struct cfs_trace_cpu_data *tcd) -{ -cfs_trace_unlock_tcd (tcd,0 ); - -put_cpu (); -} -int cfs_trace_refill_stock (struct cfs_trace_cpu_data *tcd,gfp_t gfp,struct list_head *stock);
Signature · 1 line
1.8.3.1
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
In reply to James SimmonsThe original code for cfs_print_to_console() used printk() and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly to pr_info which is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold both dbghdr_to_err_string() and the function dbghdr_to_info_string() into cfs_print_to_console().
--- .../staging/lustre/lnet/libcfs/linux-tracefile.c | 55 ++++++---------------- 1 file changed, 14 insertions(+), 41 deletions(-)
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +14 -41
@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) header->ph_extern_pid =0 ; } -static char * -dbghdr_to_err_string (struct ptldebug_header *hdr) -{ -switch (hdr->ph_subsys) { -case S_LND : -case S_LNET : -return "LNetError" ; -default : -return "LustreError" ; - } -} - -static char * -dbghdr_to_info_string (struct ptldebug_header *hdr) -{ -switch (hdr->ph_subsys) { -case S_LND : -case S_LNET : -return "LNet" ; -default : -return "Lustre" ; - } -} -void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn) { -char *prefix ="Lustre" , *ptype =NULL ; +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) { +pr_info ("%s: %.*s" , prefix, len, buf); + }else if (mask &D_EMERG ) { +pr_emerg ("%sError: %d:%d:(%s:%d:%s()) %.*s" , prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); }else if (mask &D_ERROR ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_ERR ; +pr_err ("%sError: %d:%d:(%s:%d:%s()) %.*s" , prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); }else if (mask &D_WARNING ) { - prefix =dbghdr_to_info_string (hdr); - ptype =KERN_WARNING ; - }else if (mask & (D_CONSOLE | libcfs_printk)) { - prefix =dbghdr_to_info_string (hdr); - ptype =KERN_INFO ; - } - -if (mask &D_CONSOLE ) { -pr_info ("%s%s: %.*s" , ptype, prefix, len, buf); - }else { -pr_info ("%s%s: %d:%d:(%s:%d:%s()) %.*s" , ptype, prefix, +pr_warn ("%s: %d:%d:(%s:%d:%s()) %.*s" , prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); }
Signature · 1 line
1.8.3.1
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
Quoted 9 lines · James Simmons
The original code for
cfs_print_to_console()usedprintk()and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly topr_infowhich is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold bothdbghdr_to_err_string()and the functiondbghdr_to_info_string()intocfs_print_to_console().Signed-off-by James Simmons <[email protected]>
Thanks!
This code is much nicer now, and the whole series is much easier to review now that you've broken it up.
It'll all appear in my lustre-testing shortly.
Thanks,
NeilBrown
Quoted 79 lines
--- .../staging/lustre/lnet/libcfs/linux-tracefile.c | 55 ++++++---------------- 1 file changed, 14 insertions(+), 41 deletions(-)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +14
-41@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) header->ph_extern_pid =0 ; } -static char * -dbghdr_to_err_string (struct ptldebug_header *hdr) -{ -switch (hdr->ph_subsys) { -case S_LND : -case S_LNET : -return "LNetError" ; -default : -return "LustreError" ; - } -} - -static char * -dbghdr_to_info_string (struct ptldebug_header *hdr) -{ -switch (hdr->ph_subsys) { -case S_LND : -case S_LNET : -return "LNet" ; -default : -return "Lustre" ; - } -} -void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn) { -char *prefix ="Lustre" , *ptype =NULL ; +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) { +pr_info ("%s: %.*s" , prefix, len, buf); + }else if (mask &D_EMERG ) { +pr_emerg ("%sError: %d:%d:(%s:%d:%s()) %.*s" , prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); }else if (mask &D_ERROR ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_ERR ; +pr_err ("%sError: %d:%d:(%s:%d:%s()) %.*s" , prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); }else if (mask &D_WARNING ) { - prefix =dbghdr_to_info_string (hdr); - ptype =KERN_WARNING ; - }else if (mask & (D_CONSOLE | libcfs_printk)) { - prefix =dbghdr_to_info_string (hdr); - ptype =KERN_INFO ; - } - -if (mask &D_CONSOLE ) { -pr_info ("%s%s: %.*s" , ptype, prefix, len, buf); - }else { -pr_info ("%s%s: %d:%d:(%s:%d:%s()) %.*s" , ptype, prefix, +pr_warn ("%s: %d:%d:(%s:%d:%s()) %.*s" , prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); }Signature · 1 line
1.8.3.1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180628/510b8380/attachment.sig>
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
In reply to James SimmonsQuoted 22 lines · James Simmons
The original code for
cfs_print_to_console()usedprintk()and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly topr_infowhich is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold bothdbghdr_to_err_string()and the functiondbghdr_to_info_string()intocfs_print_to_console().Signed-off-by James Simmons <[email protected]>---
.../staging/lustre/lnet/libcfs/linux-tracefile.c| 55 ++++++----------------1 file changed, 14 insertions(+), 41 deletions(-)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-0@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn)
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) · line 149
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +5
-3{ +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) {
This check is broken. The default value of libcfs_printk (the mask that controls which messages should be printed to the console, and which ones should only be logged into the internal buffer) is:
#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)
so that means virtually every console message will be printed with pr_info() because this is matched first, instead of pr_emerg() or pr_err() below.
That is why the previous code was matching D_EMERG and D_ERROR first, then D_WARNING, and (D_CONSOLE | libcfs_printk) at the end.
Cheers, Andreas
Quoted 28 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +9
-14+pr_info ("%s: %.*s" , prefix, len, buf); + }else if (mask &D_EMERG ) { +pr_emerg ("%sError: %d:%d:(%s:%d:%s()) %.*s" , prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); }else if (mask &D_ERROR ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_ERR ; +pr_err ("%sError: %d:%d:(%s:%d:%s()) %.*s" , prefix, + hdr->ph_pid, hdr->ph_extern_pid, file, + hdr->ph_line_num, fn, len, buf); }else if (mask &D_WARNING ) { - prefix =dbghdr_to_info_string (hdr); - ptype =KERN_WARNING ; - }else if (mask & (D_CONSOLE | libcfs_printk)) { - prefix =dbghdr_to_info_string (hdr); - ptype =KERN_INFO ; - } - -if (mask &D_CONSOLE ) { -pr_info ("%s%s: %.*s" , ptype, prefix, len, buf); - }else { -pr_info ("%s%s: %d:%d:(%s:%d:%s()) %.*s" , ptype, prefix, +pr_warn ("%s: %d:%d:(%s:%d:%s()) %.*s" , prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } --
Quoted 2 lines
1.8.3.1
Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180628/b49c7062/attachment.sig>
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
Quoted 37 lines
Quoted 22 lines
The original code for
cfs_print_to_console()usedprintk()and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly topr_infowhich is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold bothdbghdr_to_err_string()and the functiondbghdr_to_info_string()intocfs_print_to_console().Signed-off-by James Simmons <[email protected]>---
.../staging/lustre/lnet/libcfs/linux-tracefile.c| 55 ++++++----------------1 file changed, 14 insertions(+), 41 deletions(-)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-0@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) · line 149
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +5
-3{ +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) {This check is broken. The default value of
libcfs_printk(the mask that controls which messages should be printed to the console, and which ones should only be logged into the internal buffer) is:
Quoted 8 lines
#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)so that means virtually every console message will be printed with
pr_info()because this is matched first, instead ofpr_emerg()orpr_err()below.That is why the previous code was matching
D_EMERGandD_ERRORfirst, thenD_WARNING, and (D_CONSOLE|libcfs_printk) at the end.
So to do this right we need:
static void cfs_print_to_console(struct ptldebug_header *hdr, int mask,
const char *buf, int len, const char
*file,
const char *fn)
{
char *prefix = "Lustre";
if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET)
prefix = "LNet";
if (mask & D_CONSOLE) {
if (mask & D_EMERG) {
pr_emerg("%sError: %.*s", prefix, len, buf);
} else if (mask & D_ERROR) {
pr_err("%sError: %.*s", prefix, len, buf);
} else if (mask & D_WARNING) {
pr_warn("%s: %.*s", prefix, len, buf);
} else if (mask & libcfs_printk) {
pr_info("%s: %.*s", prefix, len, buf);
}
} else {
if (mask & D_EMERG) {
pr_emerg("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix,
hdr->ph_pid, hdr->ph_extern_pid, file,
hdr->ph_line_num, fn, len, buf);
} else if (mask & D_ERROR) {
pr_err("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix,
hdr->ph_pid, hdr->ph_extern_pid, file,
hdr->ph_line_num, fn, len, buf);
} else if (mask & D_WARNING) {
pr_warn("%s: %d:%d:(%s:%d:%s()) %.*s", prefix,
hdr->ph_pid, hdr->ph_extern_pid, file,
hdr->ph_line_num, fn, len, buf);
} else if (mask & libcfs_printk) {
pr_info("%s: %.*s", prefix, len, buf);
}
}
}PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
Quoted 77 lines · James Simmons
Quoted 36 lines
Quoted 21 lines
The original code for
cfs_print_to_console()usedprintk()and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly topr_infowhich is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold bothdbghdr_to_err_string()and the functiondbghdr_to_info_string()intocfs_print_to_console().Signed-off-by James Simmons <[email protected]>---
.../staging/lustre/lnet/libcfs/linux-tracefile.c| 55 ++++++----------------1 file changed, 14 insertions(+), 41 deletions(-)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-0@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) · line 149
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +5
-3{ +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) {This check is broken. The default value of
libcfs_printk(the mask that controls which messages should be printed to the console, and which ones should only be logged into the internal buffer) is:Quoted 8 lines
#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)so that means virtually every console message will be printed with
pr_info()because this is matched first, instead ofpr_emerg()orpr_err()below.That is why the previous code was matching
D_EMERGandD_ERRORfirst, thenD_WARNING, and (D_CONSOLE|libcfs_printk) at the end.So to do this right we need:
static void cfs_print_to_console(struct
ptldebug_header*hdr, int mask,
const char *buf, int len, const char
*file,
const char *fn){ char *prefix = "Lustre"; if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET) prefix = "LNet"; if (mask & D_CONSOLE) { if (mask & D_EMERG) { pr_emerg("%sError: %.*s", prefix, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %.*s", prefix, len, buf); } else if (mask & D_WARNING) { pr_warn("%s: %.*s", prefix, len, buf); } else if (mask & libcfs_printk) { pr_info("%s: %.*s", prefix, len, buf); } } else { if (mask & D_EMERG) { pr_emerg("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_WARNING) {
Quoted 8 lines
pr_warn("%s: %d:%d:(%s:%d:%s()) %.*s", prefix,
hdr->ph_pid, hdr->ph_extern_pid, file,
hdr->ph_line_num, fn, len, buf);
} else if (mask & libcfs_printk) {
pr_info("%s: %.*s", prefix, len, buf);
}
}
}That doesn't look right either.
The original code would *always* print something. This code looks like it might not (e.g. for mask == 0).
What is "D_CONSOLE" suppose to mean? It seems to me "make the messages less verbose" and it isn't clear to me that what is called "D_CONSOLE".
Thanks,
NeilBrown
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180702/de30cd2c/attachment.sig>
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
Quoted 87 lines
Quoted 78 lines
Quoted 37 lines
Quoted 22 lines
The original code for
cfs_print_to_console()usedprintk()and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly topr_infowhich is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold bothdbghdr_to_err_string()and the functiondbghdr_to_info_string()intocfs_print_to_console().Signed-off-by James Simmons <[email protected]>---
.../staging/lustre/lnet/libcfs/linux-tracefile.c| 55 ++++++----------------1 file changed, 14 insertions(+), 41 deletions(-)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-0@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) · line 149
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +5
-3{ +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) {This check is broken. The default value of
libcfs_printk(the mask that controls which messages should be printed to the console, and which ones should only be logged into the internal buffer) is:Quoted 8 lines
#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)so that means virtually every console message will be printed with
pr_info()because this is matched first, instead ofpr_emerg()orpr_err()below.That is why the previous code was matching
D_EMERGandD_ERRORfirst, thenD_WARNING, and (D_CONSOLE|libcfs_printk) at the end.So to do this right we need:
static void cfs_print_to_console(struct
ptldebug_header*hdr, int mask,
const char *buf, int len, const char
*file,
const char *fn){ char *prefix = "Lustre"; if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET) prefix = "LNet"; if (mask & D_CONSOLE) { if (mask & D_EMERG) { pr_emerg("%sError: %.*s", prefix, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %.*s", prefix, len, buf); } else if (mask & D_WARNING) { pr_warn("%s: %.*s", prefix, len, buf); } else if (mask & libcfs_printk) { pr_info("%s: %.*s", prefix, len, buf); } } else { if (mask & D_EMERG) { pr_emerg("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_WARNING) {Quoted 8 lines
pr_warn("%s: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & libcfs_printk) { pr_info("%s: %.*s", prefix, len, buf); } } }
Quoted 3 lines
That doesn't look right either.
The original code would *always* print something. This code looks like it might not (e.g. for mask == 0).
Is that correct behavior? A mask of zero means don't do anything. Also if you look at the original in the OpenSFS branch you can see if mask was to be 0 then ptype would be NULl :-(
Note a D_CANT_MASK prevents some fields in the mask from being disabled.
Quoted 2 lines
What is "
D_CONSOLE" suppose to mean? It seems to me "make the messages less verbose" and it isn't clear to me that what is called "D_CONSOLE".
It means two things. If by itself then it means use pr_info. If it is one field in the mask then it means less detail. Confusing no :-( That is my understanding of it. Maybe someone else can clarify if I'm wrong.
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
In reply to NeilBrownQuoted 87 lines
Quoted 78 lines
Quoted 37 lines
Quoted 22 lines
The original code for
cfs_print_to_console()usedprintk()and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly topr_infowhich is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold bothdbghdr_to_err_string()and the functiondbghdr_to_info_string()intocfs_print_to_console().Signed-off-by James Simmons <[email protected]>---
.../staging/lustre/lnet/libcfs/linux-tracefile.c| 55 ++++++----------------1 file changed, 14 insertions(+), 41 deletions(-)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-0@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) · line 149
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +5
-3{ +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) {This check is broken. The default value of
libcfs_printk(the mask that controls which messages should be printed to the console, and which ones should only be logged into the internal buffer) is:Quoted 8 lines
#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)so that means virtually every console message will be printed with
pr_info()because this is matched first, instead ofpr_emerg()orpr_err()below.That is why the previous code was matching
D_EMERGandD_ERRORfirst, thenD_WARNING, and (D_CONSOLE|libcfs_printk) at the end.So to do this right we need:
static void cfs_print_to_console(struct
ptldebug_header*hdr, int mask,
const char *buf, int len, const char
*file,
const char *fn){ char *prefix = "Lustre"; if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET) prefix = "LNet"; if (mask & D_CONSOLE) { if (mask & D_EMERG) { pr_emerg("%sError: %.*s", prefix, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %.*s", prefix, len, buf); } else if (mask & D_WARNING) { pr_warn("%s: %.*s", prefix, len, buf); } else if (mask & libcfs_printk) { pr_info("%s: %.*s", prefix, len, buf); } } else { if (mask & D_EMERG) { pr_emerg("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_WARNING) {Quoted 8 lines
pr_warn("%s: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & libcfs_printk) { pr_info("%s: %.*s", prefix, len, buf); } } }
Quoted 3 lines
That doesn't look right either.
The original code would *always* print something. This code looks like it might not (e.g. for mask == 0).
Is that correct behavior? A mask of zero means don't do anything. Also if you look at the original in the OpenSFS branch you can see if mask was to be 0 then ptype would be NULl :-(
Note a D_CANT_MASK prevents some fields in the mask from being disabled.
Quoted 2 lines
What is "
D_CONSOLE" suppose to mean? It seems to me "make the messages less verbose" and it isn't clear to me that what is called "D_CONSOLE".
It means two things. If by itself then it means use pr_info. If it is one field in the mask then it means less detail. Confusing no :-( That is my understanding of it. Maybe someone else can clarify if I'm wrong.
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
Quoted 86 lines · James Simmons
Quoted 86 lines
Quoted 85 lines
Quoted 36 lines
Quoted 21 lines
The original code for
cfs_print_to_console()usedprintk()and used tricks to select which printk level to use. Later a cleanup patch landed the just converted printk directly topr_infowhich is not exactly correct. Instead of converting back to printk lets move everything to pr_* type functions which simplify the code. This allows us to fold bothdbghdr_to_err_string()and the functiondbghdr_to_info_string()intocfs_print_to_console().Signed-off-by James Simmons <[email protected]>---
.../staging/lustre/lnet/libcfs/linux-tracefile.c| 55 ++++++----------------1 file changed, 14 insertions(+), 41 deletions(-)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +0
-0@@ -140,54 +140,27 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)void cfs_print_to_console (struct ptldebug_header *hdr,int mask,const char *buf,int len,const char *file,const char *fn)drivers/staging/lustre/lnet/libcfs/linux-tracefile.c enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) · line 149
Quoted 10 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +5
-3{ +char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) {This check is broken. The default value of
libcfs_printk(the mask that controls which messages should be printed to the console, and which ones should only be logged into the internal buffer) is:Quoted 8 lines
#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)so that means virtually every console message will be printed with
pr_info()because this is matched first, instead ofpr_emerg()orpr_err()below.That is why the previous code was matching
D_EMERGandD_ERRORfirst, thenD_WARNING, and (D_CONSOLE|libcfs_printk) at the end.So to do this right we need:
static void cfs_print_to_console(struct
ptldebug_header*hdr, int mask,
const char *buf, int len, const char
*file,
const char *fn){ char *prefix = "Lustre"; if (hdr->ph_subsys == S_LND || hdr->ph_subsys == S_LNET) prefix = "LNet"; if (mask & D_CONSOLE) { if (mask & D_EMERG) { pr_emerg("%sError: %.*s", prefix, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %.*s", prefix, len, buf); } else if (mask & D_WARNING) { pr_warn("%s: %.*s", prefix, len, buf); } else if (mask & libcfs_printk) { pr_info("%s: %.*s", prefix, len, buf); } } else { if (mask & D_EMERG) { pr_emerg("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_ERROR) { pr_err("%sError: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & D_WARNING) { pr_warn("%s: %d:%d:(%s:%d:%s()) %.*s", prefix, hdr->ph_pid, hdr->ph_extern_pid, file, hdr->ph_line_num, fn, len, buf); } else if (mask & libcfs_printk) { pr_info("%s: %.*s", prefix, len, buf); } } }
Quoted 7 lines
Quoted 3 lines
That doesn't look right either.
The original code would *always* print something. This code looks like it might not (e.g. for mask == 0).Is that correct behavior? A mask of zero means don't do anything. Also if you look at the original in the OpenSFS branch you can see if mask was to be 0 then ptype would be NULl :-(
True... so it would print something, but the something would have (null) in it. So it probably never happens.
Quoted 9 lines
Note a
D_CANT_MASKprevents some fields in the mask from being disabled.Quoted 2 lines
What is "
D_CONSOLE" suppose to mean? It seems to me "make the messages less verbose" and it isn't clear to me that what is called "D_CONSOLE".It means two things. If by itself then it means use
pr_info. If it is one field in the mask then it means less detail. Confusing no :-( That is my understanding of it. Maybe someone else can clarify if I'm wrong.
Yes, "confusing" seems an accurate description. But if that is what it is, then that is what it is.
If you send you new version as a patch, either against the original or against the buggy version, I'll apply it.
Thanks,
NeilBrown
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180706/2cadd2aa/attachment-0001.sig>
PATCH v3 4/13 lustre: libcfs: fix cfs_print_to_console()
In reply to James SimmonsQuoted 30 lines · James Simmons
Quoted 30 lines
Quoted 29 lines
Quoted 27 lines
Quoted 5 lines
void cfs_print_to_console(struct
ptldebug_header*hdr, int mask,
const char *buf, int len, const char *file, const char *fn)
{drivers/staging/lustre/lnet/libcfs/linux-tracefile.c enum cfs_trace_buf_type cfs_trace_buf_idx_get(void) · line 152
Quoted 9 lines
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +5
-3+char *prefix ="Lustre" ; + +if (hdr->ph_subsys ==S_LND || hdr->ph_subsys ==S_LNET ) + prefix ="LNet" ; -if (mask &D_EMERG ) { - prefix =dbghdr_to_err_string (hdr); - ptype =KERN_EMERG ; +if (mask & (D_CONSOLE | libcfs_printk)) {This check is broken. The default value of
libcfs_printk(the mask that controls which messages should be printed to the console, and which ones should only be logged into the internal buffer) is:#define D_CANTMASK (D_ERROR | D_EMERG | D_WARNING | D_CONSOLE)so that means virtually every console message will be printed with
pr_info()because this is matched first, instead ofpr_emerg()orpr_err()below.That is why the previous code was matching
D_EMERGandD_ERRORfirst, thenD_WARNING, and (D_CONSOLE|libcfs_printk) at the end.
Quoted 8 lines
Quoted 2 lines
The original code would *always* print something. This code looks like it might not (e.g. for mask == 0).
Is that correct behavior? A mask of zero means don't do anything. Also if you look at the original in the OpenSFS branch you can see if mask was to be 0 then ptype would be NULl :-(
Note a
D_CANT_MASKprevents some fields in the mask from being disabled.
Typically, users will set "lctl set_param debug=0" to disable debugging messages for performance, but we still want critical error messages to be printed to the console, so D_CANT_MASK is always checked for messages to be printed to the console.
Quoted 6 lines
Quoted 2 lines
What is "
D_CONSOLE" suppose to mean? It seems to me "make the messages less verbose" and it isn't clear to me that what is called "D_CONSOLE".It means two things. If by itself then it means use
pr_info. If it is one field in the mask then it means less detail. Confusing no :-( That is my understanding of it. Maybe someone else can clarify if I'm wrong.
The D_CONSOLE mask is used for "pretty" messages on the console, that will not print out the file/function/line/timestamp and other debugging fields. The D_CONSOLE flag doesn't necessarily mean "more" or "less" information, but is intended more for "ease of understanding".
Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180706/7b8454f0/attachment.sig>
PATCH v3 5/13 lustre: libcfs: properly handle failure paths in cfs_tracefile_init_arch()
In reply to James SimmonsIt is considered poor coding style in the linux kernel to call a catch all for cleanup in the initialization function. Also their is no reason to cleanup cfs_trace_console_buffers if they never been allocated. Lets unroll the error handling.
--- drivers/staging/lustre/lnet/libcfs/linux-tracefile.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c +14 -5
@@ -49,9 +49,9 @@int cfs_tracefile_init_arch (void ) { +struct cfs_trace_cpu_data *tcd;int i;int j; -struct cfs_trace_cpu_data *tcd;/* initialize trace_data */ memset (cfs_trace_data,0 ,sizeof (cfs_trace_data));
@@ -61,7 +61,7 @@ int cfs_tracefile_init_arch(void)sizeof (union cfs_trace_data_union ), GFP_KERNEL);if (!cfs_trace_data[i]) - goto out; + goto out_trace_data; }/* arch related info initialized */
@@ -79,13 +79,22 @@ int cfs_tracefile_init_arch(void) GFP_KERNEL);if (!cfs_trace_console_buffers[i][j]) - goto out; + goto out_buffers; }return 0 ; -out: -cfs_tracefile_fini_arch (); +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 ; }
Signature · 1 line
1.8.3.1
PATCH v3 6/13 lustre: libcfs: merge linux-tracefile.c into tracefile.c
In reply to James SimmonsFrom: NeilBrown <[email protected]>
It's good to keep related code together. The merger exposed the flaws of cfs_print_to_console() so rework it to behavior properly.
--- drivers/staging/lustre/lnet/libcfs/Makefile | 2 +- .../staging/lustre/lnet/libcfs/linux-tracefile.c | 176 --------------------- drivers/staging/lustre/lnet/libcfs/tracefile.c | 135 ++++++++++++++++ drivers/staging/lustre/lnet/libcfs/tracefile.h | 7 - 4 files changed, 136 insertions(+), 184 deletions(-) delete mode 100644 drivers/staging/lustre/lnet/libcfs/linux-tracefile.c
drivers/staging/lustre/lnet/libcfs/Makefile +1 -1
@@ -4,7 +4,7 @@ ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include obj-$(CONFIG_LNET) += libcfs.o -libcfs-obj-y += linux-tracefile.o linux-debug.o +libcfs-obj-y += linux-debug.o libcfs-obj-y += linux-crypto.o libcfs-obj-y += linux-crypto-adler.o
drivers/staging/lustre/lnet/libcfs/linux-tracefile.c deleted +0 -176
176 lines not on this page · raw message
drivers/staging/lustre/lnet/libcfs/tracefile.c +135 -0
159 lines not on this page · raw message
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -7
@@ -192,13 +192,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob, j <num_possible_cpus (); \ j++, (tcd) = &(*cfs_trace_data[i])[j].tcd) -void cfs_set_ptldebug_header (struct ptldebug_header *header, -struct libcfs_debug_msg_data *m, -unsigned long stack); -void cfs_print_to_console (struct ptldebug_header *hdr,int mask, -const char *buf,int len,const char *file, -const char *fn); -extern char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ];enum cfs_trace_buf_type cfs_trace_buf_idx_get (void );
Signature · 1 line
1.8.3.1
PATCH v3 7/13 lustre: libcfs: remove cfs_trace_refill_stack()
In reply to James SimmonsThe function cfs_trace_refill_stack() is not used anywhere so remove it.
--- drivers/staging/lustre/lnet/libcfs/tracefile.c | 21 --------------------- drivers/staging/lustre/lnet/libcfs/tracefile.h | 3 --- 2 files changed, 24 deletions(-)
drivers/staging/lustre/lnet/libcfs/tracefile.c +0 -21
@@ -302,27 +302,6 @@ static void cfs_tage_to_tail(struct cfs_trace_page *tage,list_move_tail (&tage->linkage, queue); } -int cfs_trace_refill_stock (struct cfs_trace_cpu_data *tcd,gfp_t gfp, -struct list_head *stock) -{ -int i; - -/* -* XXX nikita: do NOT call portals_debug_msg() (CDEBUG/ENTRY/EXIT) -* from here: this will lead to infinite recursion. -*/ - -for (i =0 ; i + tcd->tcd_cur_stock_pages <TCD_STOCK_PAGES ; ++i) { -struct cfs_trace_page *tage; - - tage =cfs_tage_alloc (gfp); -if (!tage) -break ; -list_add_tail (&tage->linkage, stock); - } -return i; -} -/* return a page that has 'len' bytes left at the end */ static struct cfs_trace_page *cfs_trace_get_tage_try (struct cfs_trace_cpu_data *tcd,unsigned long len)
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -3
@@ -204,9 +204,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,return cfs_trace_console_buffers[i][j]; } -int cfs_trace_refill_stock (struct cfs_trace_cpu_data *tcd,gfp_t gfp, -struct list_head *stock); -void cfs_trace_assertion_failed (const char *str,struct libcfs_debug_msg_data *m);
Signature · 1 line
1.8.3.1
PATCH v3 8/13 lustre: libcfs: move cfs_trace_data data to tracefile.c
In reply to James SimmonsThe macro cfs_tcd_for_each() is only used in tracefile.c so move it from the header tracefile.h along with related material in the header file.
--- drivers/staging/lustre/lnet/libcfs/tracefile.c | 12 ++++++++++-- drivers/staging/lustre/lnet/libcfs/tracefile.h | 9 --------- 2 files changed, 10 insertions(+), 11 deletions(-)
drivers/staging/lustre/lnet/libcfs/tracefile.c +10 -2
@@ -49,7 +49,8 @@#include <linux/uaccess.h> #include "tracefile.h" -/* XXX move things up to the top, comment */ +#define TCD_MAX_TYPES 8 + union cfs_trace_data_union (*cfs_trace_data[TCD_MAX_TYPES])[NR_CPUS] __cacheline_aligned;char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ];
@@ -146,7 +147,14 @@ void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking)spin_unlock (&tcd->tcd_lock); } -#define cfs_tcd_for_each_type_lock (tcd, i, cpu) \ +#define cfs_tcd_for_each (tcd, i, j) \ + for (i = 0; cfs_trace_data[i]; i++) \ + for (j = 0, ((tcd) = &(*cfs_trace_data[i])[j].tcd); \ + j < num_possible_cpus(); \ + j++, (tcd) = &(*cfs_trace_data[i])[j].tcd) + + +#define cfs_tcd_for_each_type_lock (tcd, i, cpu) \ for (i = 0; cfs_trace_data[i] && \ (tcd = &(*cfs_trace_data[i])[cpu].tcd) && \ cfs_trace_lock_tcd(tcd, 1); cfs_trace_unlock_tcd(tcd, 1), i++)
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -9
@@ -183,15 +183,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,char __pad[L1_CACHE_ALIGN (sizeof (struct cfs_trace_cpu_data ))]; }; -#define TCD_MAX_TYPES 8 -extern union cfs_trace_data_union (*cfs_trace_data[TCD_MAX_TYPES ])[NR_CPUS ]; - -#define cfs_tcd_for_each (tcd, i, j) \ - for (i = 0; cfs_trace_data[i]; i++) \ - for (j = 0, ((tcd) = &(*cfs_trace_data[i])[j].tcd); \ - j < num_possible_cpus(); \ - j++, (tcd) = &(*cfs_trace_data[i])[j].tcd) -extern char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ];enum cfs_trace_buf_type cfs_trace_buf_idx_get (void );
Signature · 1 line
1.8.3.1
PATCH v3 9/13 lustre: libcfs: cleanup tracefile.h
In reply to James SimmonsWith many things moved into tracefile.c we can cleanup a lot of things in tracefile.h. Move some items that are only used in tracefile.c from tracefile.h into tracefile.c. In tracefile.h we have the ifdef LUSTRE_TRACEFILE_PRIVATE which has several duplicate defines. We can remove those duplicates.
--- drivers/staging/lustre/lnet/libcfs/tracefile.c | 18 +++++++++++-- drivers/staging/lustre/lnet/libcfs/tracefile.h | 37 -------------------------- 2 files changed, 16 insertions(+), 39 deletions(-)
drivers/staging/lustre/lnet/libcfs/tracefile.c +16 -2
@@ -37,8 +37,6 @@*/ #define DEBUG_SUBSYSTEM S_LNET -#define LUSTRE_TRACEFILE_PRIVATE -#define pr_fmt (fmt) "Lustre: " fmt#include <linux/ratelimit.h> #include <linux/highmem.h>
@@ -49,8 +47,16 @@#include <linux/uaccess.h> #include "tracefile.h" +#define CFS_TRACE_CONSOLE_BUFFER_SIZE 1024#define TCD_MAX_TYPES 8 +enum cfs_trace_buf_type { +CFS_TCD_TYPE_PROC =0 , +CFS_TCD_TYPE_SOFTIRQ , +CFS_TCD_TYPE_IRQ , +CFS_TCD_TYPE_MAX +}; + union cfs_trace_data_union (*cfs_trace_data[TCD_MAX_TYPES])[NR_CPUS] __cacheline_aligned;char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ];
@@ -168,6 +174,14 @@ enum cfs_trace_buf_type cfs_trace_buf_idx_get(void)return CFS_TCD_TYPE_PROC ; } +static inline char *cfs_trace_get_console_buffer (void ) +{ +unsigned int i =get_cpu (); +unsigned int j =cfs_trace_buf_idx_get (); + +return cfs_trace_console_buffers[i][j]; +} +static inline struct cfs_trace_cpu_data *cfs_trace_get_tcd (void ) {
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -37
@@ -42,13 +42,6 @@#include <linux/smp.h> #include <linux/libcfs/libcfs.h> -enum cfs_trace_buf_type { -CFS_TCD_TYPE_PROC =0 , -CFS_TCD_TYPE_SOFTIRQ , -CFS_TCD_TYPE_IRQ , -CFS_TCD_TYPE_MAX -}; -#define TRACEFILE_NAME_SIZE 1024extern char cfs_tracefile[TRACEFILE_NAME_SIZE ];extern long long cfs_tracefile_size;
@@ -91,22 +84,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,#define TCD_STOCK_PAGES (TCD_MAX_PAGES)#define CFS_TRACEFILE_SIZE (500 << 20) -#ifdef LUSTRE_TRACEFILE_PRIVATE - -/* - * Private declare for tracefile - */ -#define TCD_MAX_PAGES (5 << (20 - PAGE_SHIFT)) -#define TCD_STOCK_PAGES (TCD_MAX_PAGES) - -#define CFS_TRACEFILE_SIZE (500 << 20) - -/* - * Size of a buffer for sprinting console messages if we can't get a page - * from system - */ -#define CFS_TRACE_CONSOLE_BUFFER_SIZE 1024 - union cfs_trace_data_union { struct cfs_trace_cpu_data { /*
@@ -183,18 +160,6 @@ int cfs_trace_copyout_string(char __user *usr_buffer, int usr_buffer_nob,char __pad[L1_CACHE_ALIGN (sizeof (struct cfs_trace_cpu_data ))]; }; -extern char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ]; -enum cfs_trace_buf_type cfs_trace_buf_idx_get (void ); - -static inline char * -cfs_trace_get_console_buffer (void ) -{ -unsigned int i =get_cpu (); -unsigned int j =cfs_trace_buf_idx_get (); - -return cfs_trace_console_buffers[i][j]; -} -void cfs_trace_assertion_failed (const char *str,struct libcfs_debug_msg_data *m);
@@ -216,6 +181,4 @@ void cfs_trace_assertion_failed(const char *str,__LASSERT (page_count (tage->page) >0 ); \ } while (0) -#endif /* LUSTRE_TRACEFILE_PRIVATE */ -#endif /* __LIBCFS_TRACEFILE_H__ */
Signature · 1 line
1.8.3.1
PATCH v3 10/13 lustre: libcfs: fold cfs_tracefile_*_arch into their only callers.
In reply to James SimmonsFrom: NeilBrown <[email protected]>
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.
--- drivers/staging/lustre/lnet/libcfs/tracefile.c | 147 +++++++++++-------------- drivers/staging/lustre/lnet/libcfs/tracefile.h | 3 - 2 files changed, 63 insertions(+), 87 deletions(-)
drivers/staging/lustre/lnet/libcfs/tracefile.c +63 -84
@@ -200,82 +200,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) {
@@ -1324,21 +1248,38 @@ 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; - rc =cfs_tracefile_init_arch (); -if (rc) -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);
@@ -1350,7 +1291,31 @@ int cfs_tracefile_init(int max_pages) 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 )
@@ -1362,6 +1327,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,
@@ -1380,12 +1348,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 )
drivers/staging/lustre/lnet/libcfs/tracefile.h +0 -3
@@ -53,9 +53,6 @@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 );
Signature · 1 line
1.8.3.1
PATCH v3 11/13 lustre: libcfs: renamed CFS_TCD_TYPE_MAX to CFS_TCD_TYPE_CNT
In reply to James SimmonsFrom: NeilBrown <[email protected]>
The possible TCD types are 0, 1, 2.
So the MAX is 2.
The count of the number of types is 3.
CFS_TCD_TYPE_MAX is 3 - obviously wrong.
So rename it to CFS_TCD_TYPE_CNT.
Also there are 2 places where "3" is used rather
than the macro - fix them.
--- drivers/staging/lustre/lnet/libcfs/tracefile.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/staging/lustre/lnet/libcfs/tracefile.c +8 -8
@@ -54,12 +54,12 @@ enum cfs_trace_buf_type {CFS_TCD_TYPE_PROC =0 ,CFS_TCD_TYPE_SOFTIRQ ,CFS_TCD_TYPE_IRQ , -CFS_TCD_TYPE_MAX +CFS_TCD_TYPE_CNT }; union cfs_trace_data_union (*cfs_trace_data[TCD_MAX_TYPES])[NR_CPUS] __cacheline_aligned; -char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_MAX ]; +char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_CNT ];char cfs_tracefile[TRACEFILE_NAME_SIZE ];long long cfs_tracefile_size =CFS_TRACEFILE_SIZE ;static struct tracefiled_ctl trace_tctl;
@@ -127,7 +127,7 @@ static void put_pages_on_tcd_daemon_list(struct page_collection *pc,int cfs_trace_lock_tcd (struct cfs_trace_cpu_data *tcd,int walking) __acquires(&tcd->tc_lock) { -__LASSERT (tcd->tcd_type <CFS_TCD_TYPE_MAX ); +__LASSERT (tcd->tcd_type <CFS_TCD_TYPE_CNT );if (tcd->tcd_type ==CFS_TCD_TYPE_IRQ )spin_lock_irqsave (&tcd->tcd_lock, tcd->tcd_lock_flags);else if (tcd->tcd_type ==CFS_TCD_TYPE_SOFTIRQ )
@@ -142,7 +142,7 @@ int cfs_trace_lock_tcd(struct cfs_trace_cpu_data *tcd, int walking)void cfs_trace_unlock_tcd (struct cfs_trace_cpu_data *tcd,int walking) __releases(&tcd->tcd_lock) { -__LASSERT (tcd->tcd_type <CFS_TCD_TYPE_MAX ); +__LASSERT (tcd->tcd_type <CFS_TCD_TYPE_CNT );if (tcd->tcd_type ==CFS_TCD_TYPE_IRQ )spin_unlock_irqrestore (&tcd->tcd_lock, tcd->tcd_lock_flags);else if (tcd->tcd_type ==CFS_TCD_TYPE_SOFTIRQ )
@@ -1249,7 +1249,7 @@ void cfs_trace_stop_thread(void) }/* percents to share the total debug memory for each type */ -static unsigned int pages_factor[CFS_TCD_TYPE_MAX ] = { +static unsigned int pages_factor[CFS_TCD_TYPE_CNT ] = {80 ,/* 80% pages for CFS_TCD_TYPE_PROC */ 10 ,/* 10% pages for CFS_TCD_TYPE_SOFTIRQ */ 10 /* 10% pages for CFS_TCD_TYPE_IRQ */
@@ -1263,7 +1263,7 @@ int cfs_tracefile_init(int max_pages)/* initialize trace_data */ memset (cfs_trace_data,0 ,sizeof (cfs_trace_data)); -for (i =0 ; i <CFS_TCD_TYPE_MAX ; i++) { +for (i =0 ; i <CFS_TCD_TYPE_CNT ; i++) { cfs_trace_data[i] = kmalloc_array(num_possible_cpus(), sizeof(union cfs_trace_data_union),
@@ -1292,7 +1292,7 @@ int cfs_tracefile_init(int max_pages) }for (i =0 ; i <num_possible_cpus (); i++) -for (j =0 ; j <3 ; j++) { +for (j =0 ; j <CFS_TCD_TYPE_CNT ; j++) { cfs_trace_console_buffers[i][j] =kmalloc (CFS_TRACE_CONSOLE_BUFFER_SIZE ,GFP_KERNEL );
@@ -1356,7 +1356,7 @@ static void cfs_trace_cleanup(void)trace_cleanup_on_all_cpus ();for (i =0 ; i <num_possible_cpus (); i++) -for (j =0 ; j <3 ; j++) { +for (j =0 ; j <CFS_TCD_TYPE_CNT ; j++) {kfree (cfs_trace_console_buffers[i][j]); cfs_trace_console_buffers[i][j] =NULL ; }
Signature · 1 line
1.8.3.1
PATCH v3 12/13 lustre: libcfs: discard TCD_MAX_TYPES
In reply to James SimmonsFrom: NeilBrown <[email protected]>
As well as CFS_TCD_TYPE_CNT we have TCD_MAX_TYPES which has a larger value but a similar meaning. Discard it and just use CFS_TCD_TYPE_CNT.
Two places relied on the fact that TCD_MAX_TYPES was larger and so there would be NULLs at the end of the array. Change them to check the array size properly.
--- drivers/staging/lustre/lnet/libcfs/tracefile.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/staging/lustre/lnet/libcfs/tracefile.c +4 -5
@@ -48,7 +48,6 @@#include "tracefile.h" #define CFS_TRACE_CONSOLE_BUFFER_SIZE 1024 -#define TCD_MAX_TYPES 8enum cfs_trace_buf_type {CFS_TCD_TYPE_PROC =0 ,
@@ -57,7 +56,7 @@ enum cfs_trace_buf_type {CFS_TCD_TYPE_CNT }; -union cfs_trace_data_union (*cfs_trace_data[TCD_MAX_TYPES])[NR_CPUS] __cacheline_aligned; +union cfs_trace_data_union (*cfs_trace_data[CFS_TCD_TYPE_CNT])[NR_CPUS] __cacheline_aligned;char *cfs_trace_console_buffers[NR_CPUS ][CFS_TCD_TYPE_CNT ];char cfs_tracefile[TRACEFILE_NAME_SIZE ];
@@ -154,14 +153,14 @@ void cfs_trace_unlock_tcd(struct cfs_trace_cpu_data *tcd, int walking) }#define cfs_tcd_for_each (tcd, i, j) \ - for (i = 0; cfs_trace_data[i]; i++) \ + for (i = 0; i < CFS_TCD_TYPE_CNT && cfs_trace_data[i]; i++) \ for (j = 0, ((tcd) = &(*cfs_trace_data[i])[j].tcd); \ j < num_possible_cpus(); \ j++, (tcd) = &(*cfs_trace_data[i])[j].tcd)#define cfs_tcd_for_each_type_lock (tcd, i, cpu) \ - for (i = 0; cfs_trace_data[i] && \ + for (i = 0; i < CFS_TCD_TYPE_CNT && cfs_trace_data[i] && \ (tcd = &(*cfs_trace_data[i])[cpu].tcd) && \ cfs_trace_lock_tcd(tcd, 1); cfs_trace_unlock_tcd(tcd, 1), i++)
@@ -1361,7 +1360,7 @@ static void cfs_trace_cleanup(void) cfs_trace_console_buffers[i][j] =NULL ; } -for (i =0 ; cfs_trace_data[i]; i++) { +for (i =0 ; i <CFS_TCD_TYPE_CNT && cfs_trace_data[i]; i++) {kfree (cfs_trace_data[i]); cfs_trace_data[i] =NULL ; }
Signature · 1 line
1.8.3.1
PATCH v3 13/13 lustre: libcfs: format macros in tracefile.h
In reply to James SimmonsThe __LASSERT_* macros are ugly and hard to read. This patch beautifies them.
--- drivers/staging/lustre/lnet/libcfs/tracefile.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/staging/lustre/lnet/libcfs/tracefile.h +12 -12
@@ -161,21 +161,21 @@ void cfs_trace_assertion_failed(const char *str, struct libcfs_debug_msg_data *m);/* ASSERTION that is safe to use within the debug system */ -#define __LASSERT (cond) \ -do { \ +#define __LASSERT (cond) \ +do { \ if (unlikely(!(cond))) { \ - LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_EMERG, NULL); \ - cfs_trace_assertion_failed("ASSERTION("#cond") failed", \ - &msgdata); \ - } \ + LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_EMERG, NULL); \ + cfs_trace_assertion_failed("ASSERTION("#cond") failed", \ + &msgdata); \ + } \ } while (0) -#define __LASSERT_TAGE_INVARIANT (tage) \ -do { \ - __LASSERT(tage); \ - __LASSERT(tage->page); \ - __LASSERT(tage->used <= PAGE_SIZE); \ - __LASSERT(page_count(tage->page) > 0); \ +#define __LASSERT_TAGE_INVARIANT (tage) \ +do { \ + __LASSERT(tage); \ + __LASSERT(tage->page); \ + __LASSERT(tage->used <= PAGE_SIZE); \ + __LASSERT(page_count(tage->page) > 0); \ } while (0)#endif /* __LIBCFS_TRACEFILE_H__ */
Signature · 1 line
1.8.3.1