Bug 996613 - printk_ratelimited function doesn't work always
Summary: printk_ratelimited function doesn't work always
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Bugzilla
Classification: Community
Component: Bugzilla General
Version: 4.4
Hardware: x86_64
OS: Linux
unspecified
urgent
Target Milestone: ---
Assignee: PnT DevOps Devs
QA Contact: tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-08-13 14:23 UTC by caiqiuming
Modified: 2013-08-21 04:25 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-08-21 04:25:52 UTC
Embargoed:


Attachments (Terms of Use)

Description caiqiuming 2013-08-13 14:23:31 UTC
Description of problem:
The purpose of "ratelimit for printk" doesn't work always in rhel6.2 or above release.








Version-Release number of selected component (if applicable):
[root@r64-115 linux]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@r64-115 linux]# uname -a
Linux r64-115 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

The problem existed in rhel6.2, rhel6.2... also.








How reproducible:
sure occur!





Steps to Reproduce:
1. don't need to change the following parameters, left them as default value.
/proc/sys/kernel/printk_ratelimit
/proc/sys/kernel/printk_ratelimit_burst

2.write an ordinary kernel module, using "printk_ratelimited" function to printk some messages in loop about 1000 or more times.
 
Actual results:
You can see it will print All the times your loop, the purpose of "ratelimit for printk" out of work. In my system it may lead to panic coz print too much in console.

Expected results:
The print items should be limited.



Additional info:
See the code file: linux-2.6.32-358.el6.x86_64/include/linux/kernel.h
in "Red Hat Enterprise Linux Server release 6.4" kernel source:
************************************************
 626 #define printk_ratelimited(fmt, ...)  ({                \
 627         static struct ratelimit_state _rs = {           \
 628                 .interval = DEFAULT_RATELIMIT_INTERVAL, \
 629                 .burst = DEFAULT_RATELIMIT_BURST,       \
 630         };                                              \
 631                                                         \
 632         if (!__ratelimit(&_rs))                         \
 633                 printk(fmt, ##__VA_ARGS__);             \
 634 })
************************************************

In line 632 the condition is negatived, which make the problem wrong.
Because the fact is printk will work when __ratelimit is true.
See the Suse kernel source correspondingly, which work perfect:
--------------------------------------------
#ifdef CONFIG_PRINTK
#define printk_ratelimited(fmt, ...)  ({                \
    static DEFINE_RATELIMIT_STATE(_rs,                \
                      DEFAULT_RATELIMIT_INTERVAL,    \
                      DEFAULT_RATELIMIT_BURST);        \
                                    \
    if (__ratelimit(&_rs))                        \
        printk(fmt, ##__VA_ARGS__);                \
})
-------------------------------------------------

Comment 1 Jason McDonald 2013-08-21 04:25:52 UTC
This is not a bug in the Red Hat Bugzilla product. Please file the bug under the correct product and component.


Note You need to log in before you can comment on or make changes to this bug.