-
Notifications
You must be signed in to change notification settings - Fork 502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add newline to last pr_info to force dmesg to flush #235
Conversation
dmesg only flushes when it encounter a newline. Without a newline, the line is held in memory pending another printk. In this particular example (example_atomic.c), the last pr_info in atomic_bitwise() prints when another printk happens (either by another module, or __exit for this module. This can be confusing to new learner. This patch adds a newline to the last pr_info forcing dmesg to print to the screen when the module is loaded.
I am not sure if adding a newline to each pr_info() call is better or not. I defer to @linD026 . |
I ran the
It's actually the same as this PR version. |
On running
Note the missing Bits 5 line in the dmesg output, even though that Bits 5 printk() has been called. Then further on running To be honest, its not actually a code problem as you said above. The code is correct from a module point of view. At some point some other printk will occur and flush out the Bits 5 line. The problem is when a learner (like me) tries the code, runs the insmod and wonders why the Bits 5 line did not output in dmesg. That is exactly what happened to me and frankly made me learn a few more things. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.
Now, I know what is this PR targeting.
It makes sense to me.
Some amateur research (which might be incorrect). In printk.c prb_final_commit() or prb_commit() is called depending on the presence of a newline. prb_*_commit functions are defined in printk_ringbuffer.c From comments above the prb_*_commit functions, here are the relevant quotes.
So it might seem, that it is a printk behavior, and not a dmesg behavior as my commit message says. printk also seems to remove newlines, and then adds its own. |
@mechanicalamit, Please create a new issue, so that we can track later. |
@jserv, the above was an attempt to understand and explain why this behavior was occurring. I don't think its an issue. |
dmesg only flushes when it encounter a newline. Without a newline, the line is held in memory pending another printk. In this particular example (example_atomic.c), the last pr_info in atomic_bitwise() prints when another printk happens (either by another module, or __exit for this module.
This can be confusing to new learner. This patch adds a newline to the last pr_info forcing dmesg to print to the screen when the module is loaded.
--------------- Alternate solution ---------------
Alternate solutions could be adding a newline to BYTE_TO_BINARY_PATTERN
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c\n"
... or adding a newline to each pr_info() call.