Proc file system read function을 제작 시에 kmsg 처럼 끝나지 않는 function 제작.
글쓴이: wangmir / 작성시간: 금, 2012/12/28 - 8:57오후
proc file system을 이용해서 kernel tracing을 하는 툴을 제작 중에 있는데요..
tracing 하고 싶은 부분에 buffer를 두고 거기에 tracing log를 저장한 다음에 proc file system read function이 call 될 시에 buffer에 있는 내용을 간단하게 sprintf로 옮기는 방식으로 구현해봤습니다.
이렇게 하니까 buffer에 저장된 내용을 한번 print 해주고 더이상 해줄 것이 없으면 나가버리더라구요.
현재까지 구현한 간단한 코드입니다. kmsg처럼 계속해서 보고 있으면서 buffer에 새로운 내용이 들어올 때 출력하게 하려면 어떻게 해야 할까요?
kmsg 소스를 훑어봤는데, read를 계속 유지하면서 기다리는 코드를 찾지 못했는데(부족한 저로는 도대체 어떤 코드를 통해서 계속 출력을 해주는지 알수가 없더라구요...)
도움 주시면 감사하겠습니다.
#include "mmc_io_trace.h" int mmc_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data); struct file *trace = NULL; char *buff = NULL; char *bufp, *bufp2; int init_flag = 0; int print_counter = 0; static struct proc_dir_entry *proc_entry; int mmc_print_init(void){ if(trace != NULL){ printk(KERN_DEBUG"Already initialized:: Current state is\n"); if(buff != NULL) printk(KERN_DEBUG"buff is on\n"); if(trace != NULL) printk(KERN_DEBUG"trace file is on, \n"); return 0; } else{ buff = kmalloc(32*PAGE_SIZE, GFP_ATOMIC); if(buff == NULL){ printk(KERN_DEBUG "ERROR:: eMMC Logging Error::Kmalloc fail.\n"); return 1; } bufp = buff; proc_entry = create_proc_entry("mmc_io_trace", 0644, NULL); if(proc_entry ==NULL) return 1; else{ bufp2 = buff; proc_entry->read_proc = mmc_proc_read; } init_flag = 1; return 0; } } int mmc_printk(const char *fmt, ...){ va_list list; char tbuf[50], *tp; unsigned tlen; unsigned long long t; unsigned long nanosec_rem; print_counter++; /* Add the current time stamp */ t = cpu_clock(~0U); nanosec_rem = do_div(t, 1000000000); tlen = sprintf(tbuf, "[%5lu.%06lu] ", (unsigned long) t, nanosec_rem / 1000); if(init_flag == 0){ printk(KERN_DEBUG "ERROR: MMC_IO_TRACE initializing was failed. Cannot print IO log"); return 1; } sprintf(bufp, "%s", tbuf); bufp = buff + strlen(buff); va_start(list, fmt); vsprintf(bufp, fmt, list); va_end(list); bufp = buff + strlen(buff); if(print_counter >= 32){ memset(buff, 0x00, sizeof(buff)); bufp = buff; print_counter = 0; } return 0; } int mmc_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data){ int len; if(bufp2 >= bufp) bufp2 = buff; len = sprintf(page, "%s", bufp2); bufp2 += len; return len; }
Forums:
댓글 달기