All of lore.kernel.org
 help / color / mirror / Atom feed
* [Question] bpf map value increase unexpectedly with tracepoint qdisc/qdisc_dequeue
@ 2022-04-13 14:06 Wu Zongyong
  2022-04-13 19:30 ` Andrii Nakryiko
  0 siblings, 1 reply; 6+ messages in thread
From: Wu Zongyong @ 2022-04-13 14:06 UTC (permalink / raw)
  To: bpf

Hi,

I tried to count when tracepoint qdisc/qdisc_dequeue hit each time, then read
the count value from userspace by bpf_map_lookup_elem().
With bpftrace, I can see this tracepoint is hit about 700 times, but the count
I get from the bpf map is below 20. It's weird. Then I tried to add a bpf_printk()
to the program, and the count I get is normal which is about 700.

The bpf program codes like that:

	struct qdisc_dequeue_ctx {
	        __u64           __pad;
	        __u64           qdisc;
	        __u64           txq;
	        int             packets;
	        __u64           skbaddr;
	        int             ifindex;
	        __u32           handle;
	        __u32           parent;
	        unsigned long   txq_state;
	};
	
	struct {
	        __uint(type, BPF_MAP_TYPE_HASH);
	        __type(key, int);
	        __type(value, __u32);
	        __uint(max_entries, 1);
	        __uint(pinning, LIBBPF_PIN_BY_NAME);
	} count_map SEC(".maps");
	
	SEC("tracepoint/qdisc/qdisc_dequeue")
	int trace_dequeue(struct qdisc_dequeue_ctx *ctx)
	{
	        int key = 0;
	        __u32 *value;
	        __u32 init = 0;
	
	        value = bpf_map_lookup_elem(&count_map, &key);
	        if (value) {
	                *value += 1;
	        } else {
	                bpf_printk("value reset");
	                bpf_map_update_elem(&count_map, &key, &init, 0);
	        }
	        return 0;
	}

Any suggestion is appreciated!

Thanks,
Wu Zongyong

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-04-14 21:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 14:06 [Question] bpf map value increase unexpectedly with tracepoint qdisc/qdisc_dequeue Wu Zongyong
2022-04-13 19:30 ` Andrii Nakryiko
2022-04-14  1:50   ` Yafang Shao
2022-04-14  2:07   ` Wu Zongyong
2022-04-14  3:45     ` Wu Zongyong
2022-04-14 21:34       ` Andrii Nakryiko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.