LocalSocket查看收发队列情况

这么打印是因为做项目呀,进程间通信用LocalSocket,发现通信有延迟?于是想打印收到队列的情况。

diff --git a/kernel/net/unix/af_unix.c b/kernel/net/unix/af_unix.c
old mode 100644
new mode 100755
index e05ec54ac5..156587805a
--- a/kernel/net/unix/af_unix.c
+++ b/kernel/net/unix/af_unix.c
@@ -124,6 +124,18 @@ DEFINE_SPINLOCK(unix_table_lock);
 EXPORT_SYMBOL_GPL(unix_table_lock);
 static atomic_long_t unix_nr_socks;
 
+#include <linux/timer.h>
+#include <linux/timex.h>
+#include <linux/rtc.h>
+ // 打印时间
+static void zib_get_timestr(char *buff)
+{
+    struct timex txc;
+    struct rtc_time tm;
+    do_gettimeofday(&(txc.time));
+    rtc_time_to_tm(txc.time.tv_sec, &tm);
+    sprintf(buff, "%d-%d-%d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 8, tm.tm_min, tm.tm_sec);
+}
 
 static struct hlist_head *unix_sockets_unbound(void *addr)
 {
@@ -1857,13 +1869,26 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
     bool fds_sent = false;
     int max_level;
     int data_len;
+    struct task_struct *task = NULL;
+    struct file *fp;
+    loff_t pos;
+    char buf[10], temp[1024];
+    mm_segment_t fs;
+    struct sk_buff_head *skbh = NULL;
+    int in_need_dump = 1;
 
     wait_for_unix_gc();
     err = scm_send(sock, msg, &scm, false);
     if (err < 0)
         return err;
 
-    err = -EOPNOTSUPP;
+    if (!strcmp(current->comm, "adbd"))         // 不知道为啥adb特么频繁发送,果断屏蔽掉
+        in_need_dump = 0;
+
+    zib_get_timestr(temp);
+    if (in_need_dump)
+        printk("hxw, %s, %s, pid: %d, tgid: %d, comm: %s, len: %d\n", temp, __func__, current->pid, current->tgid, current->comm, len);
+    err = -EOPNOTSUPP;
     if (msg->msg_flags&MSG_OOB)
         goto out_err;
 
@@ -1924,13 +1949,20 @@ static int unix_stream_sendmsg(struct socket *sock, struct msghdr *msg,
             goto pipe_err_free;
 
         maybe_add_creds(skb, sock, other);
+        zib_get_timestr(temp);
+        skbh = &sk->sk_write_queue;
         skb_queue_tail(&other->sk_receive_queue, skb);
         if (max_level > unix_sk(other)->recursion_level)
             unix_sk(other)->recursion_level = max_level;

+        // skbh->qlen表示发送的队列
+        if (in_need_dump)
+            printk("hxw, %s, %s %d, w_qlen: %d, data: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", temp, __func__, __LINE__, skbh->qlen, skb->data[0], skb->data[1], skb->data[2], skb->data[3]);
         unix_state_unlock(other);
         other->sk_data_ready(other);
         sent += size;
     }
+    zib_get_timestr(temp);
+    if (in_need_dump)
+        printk("hxw, %s, ~~~_~~~\n", temp);
 
     scm_destroy(&scm);
 
@@ -2276,6 +2308,9 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
     int skip;
     size_t size = state->size;
     unsigned int last_len;
+    char temp[1024];
+    struct sk_buff_head *skbh = NULL;
+    int in_need_dump = 1;
 
     if (unlikely(sk->sk_state != TCP_ESTABLISHED)) {
         err = -EINVAL;
@@ -2296,6 +2331,11 @@ static int unix_stream_read_generic(struct unix_stream_read_state *state,
      * while sleeps in memcpy_tomsg
      */
     mutex_lock(&u->iolock);
+    if (!strcmp(current->comm, "adbd"))
+        in_need_dump = 0;
+    zib_get_timestr(temp);
+    if (in_need_dump)
+        printk("hxw, %s, %s, <<enter>>\n", temp, __func__);
 
     if (flags & MSG_PEEK)
         skip = sk_peek_offset(sk, flags);
@@ -2383,8 +2423,17 @@ unlock:
             unix_copy_addr(state->msg, skb->sk);
             sunaddr = NULL;
         }
-
-        chunk = min_t(unsigned int, unix_skb_len(skb) - skip, size);
+       zib_get_timestr(temp);

+        // current->pid, current->tgid打印当前的进程号;current->comm表示进程的名字
+        if (in_need_dump)
+            printk("hxw, %s, %s, pid: %d, tgid: %d, comm: %s\n", temp, __func__, current->pid, current->tgid, current->comm);
+        skbh = &sk->sk_receive_queue;
+        zib_get_timestr(temp);

+        // skbh->qlen表示接收的队列的个数,skb->data[0]表示发送的数据
+        if (in_need_dump)
+            printk("hxw, %s, %s, r_qlen: %d, len: %d, data: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
+                temp, __func__,
+                skbh->qlen, skb->len, skb->data[0], skb->data[1], skb->data[2], skb->data[3]);
+
+        chunk = min_t(unsigned int, unix_skb_len(skb) - skip, size);
         skb_get(skb);
         chunk = state->recv_actor(skb, skip, chunk, state);
         drop_skb = !unix_skb_len(skb);
@@ -2455,6 +2504,10 @@ unlock:
         scm_recv(sock, state->msg, &scm, flags);
     else
         scm_destroy(&scm);
+
+    if (in_need_dump)
+        printk("hxw, %s, %s, <<exit>>, ~~~@_@~~~, copied: %d\n", temp, __func__, copied);
+
 out:
     return copied ? : err;
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值