Proc file system read function을 제작 시에 kmsg 처럼 끝나지 않는 function 제작.

wangmir의 이미지

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;
 
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.