In the book BPF Performance Tools there is a implementation of kprobe of tcp_retransmit_skb. 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'. 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'.
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)
(1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED)
.
You will need to walk the bits to parse the value and display an equivalent string.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.