-
Notifications
You must be signed in to change notification settings - Fork 82
/
packetmemstats.hh
149 lines (99 loc) · 3.78 KB
/
packetmemstats.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// -*- c-basic-offset: 4 -*-
#ifndef CLICK_PACKETMEMSTATS_HH
#define CLICK_PACKETMEMSTATS_HH
#include <click/batchelement.hh>
#include <click/multithread.hh>
#define DEF_ALIGN 64
CLICK_DECLS
/*
=c
PacketMemStats([ALIGN_STRIDE])
=s counters
keep statistics about packet memory
=d
Expects Ethernet packets as input. Checks whether input packets are aligned
with respect to the ALIGN_STRIDE argument and counts aligned and total packets.
Reports the ratio of aligned/total and unaligned/total packets.
Keyword arguments are:
=over 1
=item ALIGN_STRIDE
Unsigned integer. Defines the stride of the alignment. Defaults to 64 (usual cache line length).
=e
FromDevice(eth0) -> PacketMemStats() -> ...
=h align_stride read-only
Returns the stride of the alignment.
=h aligned_pkts read-only
Returns the number of aligned packets with respect to the stride.
=h unaligned_pkts read-only
Returns the number of unaligned packets with respect to the stride.
=h total_pkts read-only
Returns the total number of packets seen so far.
=h align_stride write-only
Updates the alignment stride.
=a BatchStats */
class PacketMemStats : public BatchElement {
public:
PacketMemStats() CLICK_COLD;
PacketMemStats(unsigned align) CLICK_COLD;
~PacketMemStats() CLICK_COLD;
const char *class_name() const override { return "PacketMemStats"; }
const char *port_count() const override { return PORTS_1_1; }
int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
int initialize(ErrorHandler *) CLICK_COLD;
void cleanup(CleanupStage) CLICK_COLD;
Packet *simple_action(Packet *) override;
#if HAVE_BATCH
PacketBatch *simple_action_batch(PacketBatch *) override;
#endif
inline unsigned get_align() {
return _align;
}
inline void set_align(unsigned align) {
if (align != _align)
click_chatter("[%s] Updating alignment from %u to: %u", class_name(), _align, align);
_align = align;
}
void get_counter_status(uint64_t &tot_aligned, uint64_t &tot_unaligned, uint64_t &total);
void add_handlers();
private:
struct MemStats {
uint64_t aligned_pkt_count;
uint64_t total_pkt_count;
MemStats() : aligned_pkt_count(0), total_pkt_count(0) {
}
inline uint64_t get_aligned_pkts() {
return aligned_pkt_count;
}
inline uint64_t get_unaligned_pkts() {
assert(total_pkt_count >= aligned_pkt_count);
return (total_pkt_count - aligned_pkt_count);
}
inline uint64_t get_total_pkts() {
return total_pkt_count;
}
void update_aligned_pkts(uint64_t ap = (uint64_t)1) {
aligned_pkt_count += ap;
}
void update_total_pkts(uint64_t tp = (uint64_t)1) {
total_pkt_count += tp;
}
void report_stats(unsigned thread_id) {
click_chatter(
"[Thread %u] Aligned: %" PRIu64 ", Unaligned: %" PRIu64 ", Total: %" PRIu64,
thread_id, get_aligned_pkts(), get_unaligned_pkts(), get_total_pkts()
);
}
};
unsigned _align;
per_thread<PacketMemStats::MemStats *> _stats;
enum{
h_aligned = 0, h_unaligned, h_total, h_align_stride, h_aligned_ratio, h_unaligned_ratio
};
inline bool mem_is_aligned(void *p, unsigned k = DEF_ALIGN) {
return ((uintptr_t)p % k == 0);
}
static String read_handler(Element *e, void *thunk);
static int write_handler(const String &, Element *, void *, ErrorHandler *) CLICK_COLD;
};
CLICK_ENDDECLS
#endif