console loglevel

Personal Computer/Linux 2007. 8. 22. 20:16 posted by tolkien
kernel내 pr_debug()라는 함수가 있다.
include/linux/kernel.h에 다음과 같이 정의되어 있는 함수이다.
#define pr_debug(fmt,arg...) \
	printk(KERN_DEBUG fmt,##arg)
kernel 몇몇 code의 debug print문은 저걸로 되어 있는 것을 볼 수 있는데,
저 msg를 보려면 해당 source 상단에 #define DEBUG 로 해주는 것만으로는
안된다. console에서
echo "8" > /proc/sys/kernel/printk
와 같이 해주어야 하는데, 이건 booting이 끝난다음에나 가능한 방법이다.

결국 kernel/printk.c를 손대야 한다.
어느 건 손대야 하는지 알고자 한다면
위 echo 8 ... 하는 것부터 쫓아가는 것이 무난.
kernel/sysctl.c:root_table[]
	{
		.ctl_name	= KERN_PRINTK,
		.procname	= "printk",
		.data		= &console_loglevel,
		.maxlen		= 4*sizeof(int),
		.mode		= 0644,
		.proc_handler	= &proc_dointvec,
	},
proc_dointvec()이므로 단순한 integer 변수 값만 바꾸는 것외 나머지는 다른 곳에서 처리한다는 것.
console_loglevel은 include/linux/kernel.h 안에 정의되어 있다.
extern int console_printk[];

#define console_loglevel (console_printk[0])
console_printk[]는 kernel/printk.c에 다음과 같이 정의되어 있습니다.
/* printk's without a loglevel use this.. */
#define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */

/* We show everything that is MORE important than this.. */
#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
#define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */

int console_printk[4] = {
	DEFAULT_CONSOLE_LOGLEVEL,	/* console_loglevel */
	DEFAULT_MESSAGE_LOGLEVEL,	/* default_message_loglevel */
	MINIMUM_CONSOLE_LOGLEVEL,	/* minimum_console_loglevel */
	DEFAULT_CONSOLE_LOGLEVEL,	/* default_console_loglevel */
};

따라서, console_print[0] = 8로 바꾸어주면 debug msg가 주루룩.