printk function rate limits

If you're not careful, you may find yourself with printk generated thousands of news overwhelmed the console and, possibly, the system log file overflow. When using a slow console device (for example, a serial port), excess message rates can slow down the system or just that it does not respond. very difficult place to begin system failure, when the console keep output data. Therefore, you should be very attention to what you print, especially in the version of the product and drive particularly after initialization is completed normally, the product code should not be anything in the normal printing operation; printed output is an indication of abnormality should be noted.

 

On the other hand, you might want to send a log message, if you drive the device to stop working but you should be careful not to be too far a failure will always continue to face the process of trying to fool thousands of times per second to produce;.. If your driver every time print "my device is broken", it may produce a lot of output, if it is possible to slow the console device occupy CPU - without interruption used to drive the console, even a serial port or a line printer.

 

In many cases, the best approach is to set up a sign saying, "I have complained about this," and does not print any subsequent messages as long as the flag is set. However, there are several reasons occasionally issued a "Device or bad . the "prompt kernel already provides a function to help this situation:

 

int printk_ratelimit(void);

 

This function should be called before printing a message you think might be often repeated If this function returns a non-zero value, continue printing your messages, otherwise skip it this way, the typical calls such as this..:

 

if (printk_ratelimit())

printk(KERN_NOTICE "The printer is still on fire\n");

 

printk_ratelimit by tracking how many messages are sent to the console to work. When the output level exceeds a limit, printk_ratelimit began to return to 0 and the message is discarded.

 

printk_ratelimit behavior by modifying / proc / sys / kern / printk_ratelimit (message before re-enabling the number of seconds) and / proc / sys / kernel / printk_ratelimit_burst (pre speed may receive the message number) to customize.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11106361.html