mm/slub: Refactor note_cmpxchg_failure for better readability
Subsystems (2)
PATCH 1/1 mm/slub: Refactor note_cmpxchg_failure for better readability
From: Ye Liu <[email protected]>
Use IS_ENABLED() and standard if-else to make the code clearer.
--- mm/slub.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
mm/slub.c +4 -6
@@ -3064,18 +3064,16 @@ static inline void note_cmpxchg_failure(const char *n,pr_info ("%s %s: cmpxchg redo " , n, s->name); -#ifdef CONFIG_PREEMPTION -if (tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) +if (IS_ENABLED (CONFIG_PREEMPTION ) &&tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) {pr_warn ("due to cpu change %d -> %d\n" ,tid_to_cpu (tid),tid_to_cpu (actual_tid)); - else -#endif -if (tid_to_event (tid) !=tid_to_event (actual_tid)) + }else if (tid_to_event (tid) !=tid_to_event (actual_tid)) {pr_warn ("due to cpu running other code. Event %ld->%ld\n" ,tid_to_event (tid),tid_to_event (actual_tid)); -else + }else {pr_warn ("for unknown reason: actual=%lx was=%lx target=%lx\n" , actual_tid, tid,next_tid (tid)); + }#endif stat (s,CMPXCHG_DOUBLE_CPU_FAIL ); }
Signature · 1 line
2.43.0
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
IS_ENABLED()and standard if-else to make the code clearer.Signed-off-by Ye Liu <[email protected]>---
Looks good to me,
with a nit,
Quoted 8 lines
mm/slub.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)mm/slub.c +0
-0
mm/slub.c static inline void note_cmpxchg_failure(const char *n, · line 3067
Quoted 6 lines
mm/slub.c +1
-2@@ -3064,18 +3064,16 @@ static inline void note_cmpxchg_failure(const char *n,pr_info ("%s %s: cmpxchg redo " , n, s->name); -#ifdef CONFIG_PREEMPTION -if (tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) +if (IS_ENABLED (CONFIG_PREEMPTION ) &&tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) {
nit: insert newline after && as it's more than 80 columns?
Quoted 18 lines
mm/slub.c +3
-4pr_warn ("due to cpu change %d -> %d\n" , tid_to_cpu(tid), tid_to_cpu(actual_tid)); - else -#endif -if (tid_to_event (tid) !=tid_to_event (actual_tid)) + }else if (tid_to_event (tid) !=tid_to_event (actual_tid)) {pr_warn ("due to cpu running other code. Event %ld->%ld\n" ,tid_to_event (tid),tid_to_event (actual_tid)); -else + }else {pr_warn ("for unknown reason: actual=%lx was=%lx target=%lx\n" , actual_tid, tid,next_tid (tid)); + }#endif stat (s,CMPXCHG_DOUBLE_CPU_FAIL ); }Signature · 1 line
2.43.0
Quoted 22 lines · Harry Yoo
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
IS_ENABLED()and standard if-else to make the code clearer.Signed-off-by Ye Liu <[email protected]>---
Looks good to me,
Reviewed-by Harry Yoo <[email protected]>with a nit,
Quoted 9 lines
mm/slub.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)mm/slub.c +0
-0@@ -3064,18 +3064,16 @@ static inline void note_cmpxchg_failure(const char *n,
Quoted 7 lines
mm/slub.c static inline void note_cmpxchg_failure(const char *n, · line 3067
Quoted 5 lines
mm/slub.c +1
-2pr_info ("%s %s: cmpxchg redo " , n, s->name); -#ifdef CONFIG_PREEMPTION -if (tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) +if (IS_ENABLED (CONFIG_PREEMPTION ) &&tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) {nit: insert newline after && as it's more than 80 columns?
I noticed this too, but using the script ./scripts/checkpatch.pl , there were no warnings.
$ ./scripts/checkpatch.pl 0001-mm-slub-Refactor-note_cmpxchg_failure-for-better-rea.patch total: 0 errors, 0 warnings, 22 lines checked
0001-mm-slub-Refactor-note_cmpxchg_failure-for-better-rea.patch has no obvious style problems and is ready for submission.
Quoted 19 lines
Quoted 19 lines
mm/slub.c +3
-4pr_warn ("due to cpu change %d -> %d\n" , tid_to_cpu(tid), tid_to_cpu(actual_tid)); - else -#endif -if (tid_to_event (tid) !=tid_to_event (actual_tid)) + }else if (tid_to_event (tid) !=tid_to_event (actual_tid)) {pr_warn ("due to cpu running other code. Event %ld->%ld\n" ,tid_to_event (tid),tid_to_event (actual_tid)); -else + }else {pr_warn ("for unknown reason: actual=%lx was=%lx target=%lx\n" , actual_tid, tid,next_tid (tid)); + }#endif stat (s,CMPXCHG_DOUBLE_CPU_FAIL ); }Signature · 1 line
2.43.0
Signature · 2 lines
Thanks, Ye Liu
Quoted 33 lines · Ye Liu
Quoted 22 lines · Harry Yoo
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
IS_ENABLED()and standard if-else to make the code clearer.Signed-off-by Ye Liu <[email protected]>---
Looks good to me,
Reviewed-by Harry Yoo <[email protected]>with a nit,
Quoted 9 lines
mm/slub.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)mm/slub.c +0
-0@@ -3064,18 +3064,16 @@ static inline void note_cmpxchg_failure(const char *n,Quoted 7 lines
mm/slub.c static inline void note_cmpxchg_failure(const char *n, · line 3067
Quoted 5 lines
mm/slub.c +1
-2pr_info ("%s %s: cmpxchg redo " , n, s->name); -#ifdef CONFIG_PREEMPTION -if (tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) +if (IS_ENABLED (CONFIG_PREEMPTION ) &&tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) {nit: insert newline after && as it's more than 80 columns?
Quoted 6 lines
I noticed this too, but using the script
./scripts/checkpatch.pl, there were no warnings.$ ./scripts/checkpatch.pl 0001-mm-slub-Refactor-note_cmpxchg_failure-for-better-rea.patch total: 0 errors, 0 warnings, 22 lines checked0001-mm-slub-Refactor-note_cmpxchg_failure-for-better-rea.patch has no obvious style problems and is ready for submission.
IIUC the default limit is increased to 100 characters in checkpatch but 80 characters is still preferred.
Quoting Documentation/process/coding-style.rst:
2) Breaking long lines and strings
----------------------------------
Coding style is all about readability and maintainability using commonlu available tools.
The preferred limit on the length of a single line is 80 columns.
Statements longer than 80 columns should be broken into sensible chunks, unless exceeding 80 columns significantly increases readability and does not hide information.
Descendants are always substantially shorter than the parent and are placed substantially to the right. A very commonly used style is to align descendants to a function open parenthesis.
These same rules are applied to function headers with a long argument list.
However, never break user-visible strings such as printk messages because that breaks the ability to grep for them.
And also quoting a commit message:
commit bdc48fa11e46f867ea4d75fa59ee87a7f48be144
Author: Joe Perches <[email protected]> Date: Fri May 29 16:12:21 2020 -0700
checkpatch/coding-style: deprecate 80-column warning
Yes, staying withing 80 columns is certainly still _preferred_. But it's not the hard limit that the checkpatch warnings imply, and other concerns can most certainly dominate.
Increase the default limit to 100 characters. Not because 100 characters is some hard limit either, but that's certainly a "what are you doing" kind of value and less likely to be about the occasional slightly longer lines.
Miscellanea:
- to avoid unnecessary whitespace changes in files, checkpatch will no longer emit a warning about line length when scanning files unless --strict is also used
- Add a bit to coding-style about alignment to open parenthesis
Quoted 24 lines
Quoted 18 lines
Quoted 18 lines
mm/slub.c +3
-4pr_warn ("due to cpu change %d -> %d\n" , tid_to_cpu(tid), tid_to_cpu(actual_tid)); - else -#endif -if (tid_to_event (tid) !=tid_to_event (actual_tid)) + }else if (tid_to_event (tid) !=tid_to_event (actual_tid)) {pr_warn ("due to cpu running other code. Event %ld->%ld\n" ,tid_to_event (tid),tid_to_event (actual_tid)); -else + }else {pr_warn ("for unknown reason: actual=%lx was=%lx target=%lx\n" , actual_tid, tid,next_tid (tid)); + }#endif stat (s,CMPXCHG_DOUBLE_CPU_FAIL ); }Signature · 1 line
2.43.0Signature · 2 lines
Thanks, Ye Liu
Signature · 2 lines
Cheers, Harry / Hyeonggon
Quoted 36 lines · Harry Yoo
Quoted 35 lines · Ye Liu
Quoted 22 lines · Harry Yoo
Quoted 6 lines · Ye Liu
From: Ye Liu <[email protected]>
Use
IS_ENABLED()and standard if-else to make the code clearer.Signed-off-by Ye Liu <[email protected]>---
Looks good to me,
Reviewed-by Harry Yoo <[email protected]>with a nit,
Quoted 9 lines
mm/slub.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)mm/slub.c +0
-0@@ -3064,18 +3064,16 @@ static inline void note_cmpxchg_failure(const char *n,Quoted 7 lines
mm/slub.c static inline void note_cmpxchg_failure(const char *n, · line 3067
Quoted 5 lines
mm/slub.c +1
-2pr_info ("%s %s: cmpxchg redo " , n, s->name); -#ifdef CONFIG_PREEMPTION -if (tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) +if (IS_ENABLED (CONFIG_PREEMPTION ) &&tid_to_cpu (tid) !=tid_to_cpu (actual_tid)) {nit: insert newline after && as it's more than 80 columns?
I noticed this too, but using the script
./scripts/checkpatch.pl, there were no warnings.
Quoted 7 lines
Quoted 4 lines
$ ./scripts/checkpatch.pl 0001-mm-slub-Refactor-note_cmpxchg_failure-for-better-rea.patch total: 0 errors, 0 warnings, 22 lines checked0001-mm-slub-Refactor-note_cmpxchg_failure-for-better-rea.patch has no obvious style problems and is ready for submission.
IIUC the default limit is increased to 100 characters in checkpatch but 80 characters is still preferred.
Thank you for your patience.
I will update the V2 version and include your Reviewed-by: Harry Yoo <[email protected]>
Quoted 77 lines
Quoting
Documentation/process/coding-style.rst:2) Breaking long lines and strings
----------------------------------Coding style is all about readability and maintainability using commonlu available tools.
The preferred limit on the length of a single line is 80 columns.
Statements longer than 80 columns should be broken into sensible chunks, unless exceeding 80 columns significantly increases readability and does not hide information.
Descendants are always substantially shorter than the parent and are placed substantially to the right. A very commonly used style is to align descendants to a function open parenthesis.
These same rules are applied to function headers with a long argument list.
However, never break user-visible strings such as printk messages because that breaks the ability to grep for them.
And also quoting a commit message:
commit
bdc48fa11e46f867ea4d75fa59ee87a7f48be144Author: Joe Perches <[email protected]> Date: Fri May 29 16:12:21 2020 -0700checkpatch/coding-style: deprecate 80-column warning
Yes, staying withing 80 columns is certainly still _preferred_. But it's not the hard limit that the checkpatch warnings imply, and other concerns can most certainly dominate.
Increase the default limit to 100 characters. Not because 100 characters is some hard limit either, but that's certainly a "what are you doing" kind of value and less likely to be about the occasional slightly longer lines.
Miscellanea:
- to avoid unnecessary whitespace changes in files, checkpatch will no longer emit a warning about line length when scanning files unless --strict is also used
- Add a bit to coding-style about alignment to open parenthesis
Signed-off-by Joe Perches <[email protected]>Signed-off-by Linus Torvalds <[email protected]>Quoted 24 lines
Quoted 18 lines
Quoted 18 lines
mm/slub.c +3
-4pr_warn ("due to cpu change %d -> %d\n" , tid_to_cpu(tid), tid_to_cpu(actual_tid)); - else -#endif -if (tid_to_event (tid) !=tid_to_event (actual_tid)) + }else if (tid_to_event (tid) !=tid_to_event (actual_tid)) {pr_warn ("due to cpu running other code. Event %ld->%ld\n" ,tid_to_event (tid),tid_to_event (actual_tid)); -else + }else {pr_warn ("for unknown reason: actual=%lx was=%lx target=%lx\n" , actual_tid, tid,next_tid (tid)); + }#endif stat (s,CMPXCHG_DOUBLE_CPU_FAIL ); }Signature · 1 line
2.43.0Signature · 2 lines
Thanks, Ye Liu
Signature · 2 lines
Thanks, Ye Liu