免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2464 | 回复: 2
打印 上一主题 下一主题

诡异的ubuntu和centos [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-12 18:26 |只看该作者 |倒序浏览
内核里加了一个补丁,统计TCP连接建立的时间,然后可以通过/proc/net/tcp看到,比如
qxl@qxl-desktop:~$ cat /proc/net/tcp
  sl  local_address rem_address   st tx_queue rx_queue tr tm->when retrnsmt   uid  timeout inode   time_spent                                       
   0: 00000000:0015 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 4565 0.0 1 dd52c500 300 0 0 2 -1                          
   1: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 3496 0.0 1 dd52c000 300 0 0 2 -1                          
   2: 0100007F:0277 00000000:0000 0A 00000000:00000000 00:00000000 00000000     0        0 4342 0.0 1 df324000 300 0 0 2 -1                          
   3: 16000001:0016 FE000001:0514 01 00000034:00000000 01:0000001F 00000000     0        0 10522 0.669 4 dd52ca00 32 4 5 5 -1  
最后一条是1.0.0.22 到1.0.0.254的ssh连接建立的/proc记录项,我在内核的代码里也加了打印,时间也一样。
qxl@qxl-desktop:~$ dmesg

[  218.942497] [-------------------------------------------Start---------------------------------------]
[  218.942522] syn_requesting, req_ip = 010000fe,req_port = 1300,reply_ip = 01000016,reply_port = 22
[  218.942622] tcp_v4_hnd_req,port = 1300,src = 010000fe,daddr = 01000016
[  218.942695] include/net/sock.h,sk->sk_ack_backlog = 0,                       sk->sk_max_ack_backog = 128
[  218.943194] Total time 0.669,Sock = dd52ca00
[  218.943204] [--------------------------------------------End----------------------------------------]
两个时间都是0.669(ms),奇怪的问题是在centos操作系统下,编译的也是同样的内核代码(2.6.32),改动都一样。centos下dmesg能查看打印出的时间,但是在/proc/net/tcp里,没有建立的ssh连接的记录项,我查看了/proc/net/tcp的帮助文档,里面也是说先打印出监听态的socket,然后打印出已经建立连接的相关信息,但是在centos下全是监听态的,没有连接态的,
有哪位高手,能帮看看这个问题。另外,请问下,tcp4_seq_show(strcut seq_file *seq,void *v)里的两个参数,是从什么地方传递进去的

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
2 [报告]
发表于 2010-08-12 19:36 |只看该作者
另外,请问下,tcp4_seq_show(strcut seq_file *seq,void *v)里的两个参数,是从什么地方传递进去的?

该函数应该是你读tcp这个proc文件的时候,会调用到该函数。你可以看一下调用该函数的程序

论坛徽章:
0
3 [报告]
发表于 2010-08-12 20:19 |只看该作者
ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
{
        struct seq_file *m = (struct seq_file *)file->private_data;
        size_t copied = 0;
        loff_t pos;
        size_t n;
        void *p;
        int err = 0;

        mutex_lock(&m->lock);

        /* Don't assume *ppos is where we left it */
        if (unlikely(*ppos != m->read_pos)) {
                m->read_pos = *ppos;
                while ((err = traverse(m, *ppos)) == -EAGAIN)
                        ;
                if (err) {
                        /* With prejudice... */
                        m->read_pos = 0;
                        m->version = 0;
                        m->index = 0;
                        m->count = 0;
                        goto Done;
                }
        }

        /*
         * seq_file->op->..m_start/m_stop/m_next may do special actions
         * or optimisations based on the file->f_version, so we want to
         * pass the file->f_version to those methods.
         *
         * seq_file->version is just copy of f_version, and seq_file
         * methods can treat it simply as file version.
         * It is copied in first and copied out after all operations.
         * It is convenient to have it as  part of structure to avoid the
         * need of passing another argument to all the seq_file methods.
         */
        m->version = file->f_version;
        /* grab buffer if we didn't have one */
        if (!m->buf) {
                m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
                if (!m->buf)
                        goto Enomem;
        }
        /* if not empty - flush it first */
        if (m->count) {
                n = min(m->count, size);
                err = copy_to_user(buf, m->buf + m->from, n);
                if (err)
                        goto Efault;
                m->count -= n;
                m->from += n;
                size -= n;
                buf += n;
                copied += n;
                if (!m->count)
                        m->index++;
                if (!size)
                        goto Done;
        }
        /* we need at least one record in buffer */
        pos = m->index;
        p = m->op->start(m, &pos);
        while (1) {
                err = PTR_ERR(p);
                if (!p || IS_ERR(p))
                        break;
                err = m->op->show(m, p);


seq_read()最终会调用 show函数,但是对于ubuntu和centos,同一个内核版本,而且是同一套自己修改的内核源码,代码没有任何差别,两者的/proc/net/tcp输出却不一样,这点非常不理解啊。请大家帮下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP