Chinaunix首页 | 论坛 | 博客
  • 博客访问: 107740
  • 博文数量: 41
  • 博客积分: 2520
  • 博客等级: 少校
  • 技术积分: 440
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-22 16:25
文章分类

全部博文(41)

文章存档

2010年(41)

我的朋友

分类: LINUX

2010-01-27 12:35:22

seq file为了解决proc file需要输出内容的大小超过一个页面大小的问题。
包括总的大小,和单个记录的大小。

1. 总的大小超过的情况:

单个记录大小为2000,共100个:
May 27 10:39:56 RHEL5 kernel: mydrv_init, INFONUM = 2000
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: *pos = 0                 -----> start:
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: *pos equal to off 0
May 27 10:40:00 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(2000)
May 27 10:40:00 RHEL5 kernel: mydrv_seq_next: *pos = 1
May 27 10:40:00 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(4000)
May 27 10:40:00 RHEL5 kernel: mydrv_seq_next: *pos = 2
May 27 10:40:00 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = -1    -----> show:不可以正常输出(6000>4096)
May 27 10:40:00 RHEL5 kernel: mydrv_seq_stop                            -----> stop:
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: *pos = 2                 -----> start:从第3条记录(没有成功输出的那条),重新开始输出
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: off = 1
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: off = 2
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: *pos equal to off 2
May 27 10:40:00 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(6000)
May 27 10:40:00 RHEL5 kernel: mydrv_seq_next: *pos = 3
May 27 10:40:00 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(8000)
May 27 10:40:00 RHEL5 kernel: mydrv_seq_next: *pos = 4
May 27 10:40:00 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = -1    -----> show:不可以正常输出(10000>4096*2)
May 27 10:40:00 RHEL5 kernel: mydrv_seq_stop                            -----> stop:
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: *pos = 4
May 27 10:40:00 RHEL5 kernel: mydrv_seq_start: off = 0

再来看个例子,单个记录大小是4000,共100个:
May 27 10:47:28 RHEL5 kernel: mydrv_init, INFONUM = 4000
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: *pos = 0                 -----> start:
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: *pos equal to off 0
May 27 10:47:31 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(4000)
May 27 10:47:31 RHEL5 kernel: mydrv_seq_next: *pos = 1
May 27 10:47:31 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = -1    -----> show:不可以正常输出(8000>4096)
May 27 10:47:31 RHEL5 kernel: mydrv_seq_stop                            -----> stop:
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: *pos = 1                 -----> start:从第2条记录(没有成功输出的那条),重新开始输出
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: off = 1
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: *pos equal to off 1
May 27 10:47:31 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0
May 27 10:47:31 RHEL5 kernel: mydrv_seq_next: *pos = 2
May 27 10:47:31 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = -1
May 27 10:47:31 RHEL5 kernel: mydrv_seq_stop
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: *pos = 2
May 27 10:47:31 RHEL5 kernel: mydrv_seq_start: off = 0


可以看出,当不能成功show的时候,将重新start开始输出。
采用的输出缓冲区大小为4096。

2. 单个记录的大小超过的情况

单个记录大小为5000,共100个:
May 27 10:50:34 RHEL5 kernel: mydrv_init, INFONUM = 5000
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos = 0                 -----> start:
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos equal to off 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = -1    -----> show:不可以正常输出(5000>4096)
May 27 10:50:39 RHEL5 kernel: mydrv_seq_stop                            -----> stop:
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos = 0                 -----> start:增大了缓冲区大小,猜测4096*2=8192
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos equal to off 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(5000)
May 27 10:50:39 RHEL5 kernel: mydrv_seq_stop                            -----> stop:如果存在增大缓冲区的动作,那么正常输出一个后就stop(缓冲区采用*2的增大方式,的确不可能输出两个的)
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos = 1                 -----> start:使用已经增大的缓冲区
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 1
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos equal to off 1
May 27 10:50:39 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(10000)
May 27 10:50:39 RHEL5 kernel: mydrv_seq_stop                            -----> stop:
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos = 2
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 1
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 2
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos equal to off 2
May 27 10:50:39 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_stop
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: *pos = 3
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:50:39 RHEL5 kernel: mydrv_seq_start: off = 1

再来看个例子,单个记录大小是10000,共100个:
May 27 10:57:12 RHEL5 kernel: mydrv_init, INFONUM = 10000
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos = 0                 -----> start:
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos equal to off 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = -1    -----> show:不可以正常输出(10000>4096)
May 27 10:57:14 RHEL5 kernel: mydrv_seq_stop                            -----> stop:
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos = 0                 -----> start:增大了缓冲区大小,猜测4096*2=8192
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos equal to off 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = -1    -----> show:不可以正常输出(10000>4096*2)
May 27 10:57:14 RHEL5 kernel: mydrv_seq_stop                            -----> stop:
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos = 0                 -----> start:增大了缓冲区大小,猜测4096*2*2=16384
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos equal to off 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(10000)
May 27 10:57:14 RHEL5 kernel: mydrv_seq_stop                            -----> stop:存在增大缓冲区的动作,所以正常输出一个后就stop
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos = 1                 -----> start:使用已经增大的缓冲区
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 1
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos equal to off 1
May 27 10:57:14 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0     -----> show:可以正常输出(20000)
May 27 10:57:14 RHEL5 kernel: mydrv_seq_stop                            -----> stop:存在增大缓冲区的动作,所以正常输出一个后就stop
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos = 2                 -----> start:使用已经增大的缓冲区
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 1
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 2
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos equal to off 2
May 27 10:57:14 RHEL5 kernel: mydrv_seq_show: ret of seq_printf = 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_stop
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: *pos = 3
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 0
May 27 10:57:14 RHEL5 kernel: mydrv_seq_start: off = 1


可以看出,第一条记录就不能成功show,将增大缓冲区,增大的方式是*2。
如果增大后可以正常输出,那么输出一条记录,并且stop。然后重新start->show->stop。
如果增大后还是不可以正常输出,那么继续增大,也就是说不停的*2。直到可以正常输出。

确定了缓冲区大小后,每次只能输出一条记录。所以之后看到的过程就是start->show->stop的循环了。

采用的输出缓冲区大小为4096*2...
阅读(563) | 评论(0) | 转发(0) |
0

上一篇:mkbar by gnuplot

下一篇:netdump

给主人留下些什么吧!~~