简体   繁体   English

tcp_retransmit_skb 的 kprobe。 而不是 tcp_retransmit_skb @tcp_states,我想 kprobe __napi_schedule

[英]kprobe of tcp_retransmit_skb. instead of tcp_retransmit_skb @tcp_states, I want to kprobe __napi_schedule

In the book BPF Performance Tools there is a implementation of kprobe of tcp_retransmit_skb.在 BPF Performance Tools 一书中,有一个 tcp_retransmit_skb 的 kprobe 的实现。 I want to do the same thing but instead of tcp_retransmit_skb @tcp_states, I want to kprobe _ napi_schedule and incompocate the enum NAPI_STATE * of 'include/linux/netdevice.h'.我想做同样的事情,但不是 tcp_retransmit_skb @tcp_states,我想 kprobe _ napi_schedule 和 incompocate 'include/linux/netdevice.h'的枚举 NAPI_STATE *。 There is my implementation of the above:以上是我的实现:

 1 #!/usr/local/bin/bpftrace
  2
  3 #include <linux/netdevice.h>
  4
  5 kprobe:__napi_schedule
  6 {
  7         $ns = (struct napi_struct *)arg0;
  8
  9         // Poll is scheduled
 10         @napi[1] = "NAPI_STATE_SCHED";
 11         @napi[2] = "NAPI_STATE_DISABLE";
 12         @napi[3] = "NAPI_STATE_NPSVC";
 13         @napi[4] = "NAPI_STATE_HASHED";
 14         @napi[5] = "NAPI_STATE_NO_BUSY_POLL";
 15
 16
 17         printf("-------------------\n");
 18         printf("\n");
 19         printf("__napi_schedule: %s pid: %d\n", comm, pid);
 20         printf("\n");
 21         $state = $ns->state;
 22         printf("$ns->state: %d\n", $state);
 23         $statestr = @napi[$state];
 24         printf("state is: %s\n", $statestr);
 25         clear(@napi);
 26         printf("--------------------\n");
 27 }

When I tried to run it, it shows nothing in my printf of the 'state is'.当我尝试运行它时,它在我的“状态是”的 printf 中没有显示任何内容。

The output is:输出是:

...
__napi_schedule: tmux: server pid: 9003

$ns->state: 17
state is:
--------------------
-------------------

__napi_schedule: tmux: server pid: 9003

$ns->state: 17
state is:
--------------------
-------------------

__napi_schedule: tmux: server pid: 9003

$ns->state: 17
state is:
--------------------
...

$ns->state is a bit array, so value 17 is actually (1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED) $ns->state是一个位数组,所以值 17 实际上是(1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED) (1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED) . (1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED)

You will need to walk the bits to parse the value and display an equivalent string.您需要遍历这些位来解析值并显示等效的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM