0

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:
--------------------
...
pchaigno
  • 11,313
  • 2
  • 29
  • 54

1 Answers1

1

$ns->state is a bit array, so value 17 is actually (1 << NAPI_STATE_SCHED) | (1 << NAPI_STATE_HASHED).

You will need to walk the bits to parse the value and display an equivalent string.

pchaigno
  • 11,313
  • 2
  • 29
  • 54
  • How did you find that it is NAPI_STATE_MISSED | NAPI_STATE_NO_BUSY_POLL? I only give that the $ns->state is 17. When you said 'walk the bits', do you mean that I should use shift operation (<< or >>)? I added to the code this line '$state = $ns->state << 64;' and in the output gives these '$state is: NAPI_STATE_HASHED '. Is it right? – Panagiotis Papoulidis Aug 27 '20 at 16:09
  • Ah, sorry made a mistake. I've updated the post. Basically, 17 is 10001 in binary which maps to the above. – pchaigno Aug 27 '20 at 16:50