最近,正在参与一个mmc io 性能测试工具的编写,我的部分是进行一个log filter的工作,菜鸟入门,边学边写边记录。
要实现mmc io的性能测试功能,需要实现主要的两个模块:
mmc block 的读写操作,包括顺序读写,随机读写,大数据读写等等
获取kernel log,并筛选出坏块信息,并判断出是否出现坏块
先从第二个模块开始:
1.关于kernel log
Quoting from kernel/printk.c:
/*
* Commands to sys_syslog:
*
* 0 -- Close the log. Currently a NOP.
* 1 -- Open the log. Currently a NOP.
* 2 -- Read from the log.
* 3 -- Read all messages remaining in the ring buffer.
* 4 -- Read and clear all messages remaining in the ring buffer
* 5 -- Clear ring buffer.
* 6 -- Disable printk to console
* 7 -- Enable printk to console
* 8 -- Set level of messages printed to console
* 9 -- Return number of unread characters in the log buffer
* 10 -- Return size of the log buffer
*/
Kernel has a cyclic buffer of length LOG_BUF_LEN in which messages given as arguments to the kernel function printk() are stored (regard‐less of their loglevel). In early kernels, LOG_BUF_LEN had the value 4096; from kernel 1.3.54, it was 8192; from kernel 2.1.113 it was 16384; since 2.4.23/2.6 the value is a kernel configuration option. In recent kernels the size can be queried with command type.
要获取内核日志,可以通过 klogctl 调用来控制和读取内核环形缓冲区。在用户空间中,Klogctl 的原型函数定义为:
int klogctl( int typ