2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #ifndef _STATS_TASK_H_
18 #define _STATS_TASK_H_
24 /* The struct task_stats is read/write from the task itself and
25 read-only from the core that collects the stats. Since only the
26 task executing the actual work ever modifies the stats, no locking
27 is required. Both a read and a write are atomic (assuming the
28 correct alignment). From this, it followed that the statistics can
29 be incremented directly by the task itself. In cases where these
30 assumptions do not hold, a possible solution (although slightly
31 less accurate) would be to keep accumulate statistics temporarily
32 in a separate structure and periodically copying the statistics to
33 the statistics core through atomic primitives, for example through
34 rte_atomic32_set(). The accuracy would be determined by the
35 frequency at which the statistics are transferred to the statistics
38 struct task_rt_stats {
39 uint32_t rx_pkt_count;
40 uint32_t tx_pkt_count;
41 uint32_t drop_tx_fail;
42 uint32_t drop_discard;
43 uint32_t drop_handled;
48 } __attribute__((packed)) __rte_cache_aligned;
51 #define TASK_STATS_ADD_IDLE(stats, cycles) do { \
52 (stats)->idle_cycles += (cycles) + rdtsc_overhead_stats; \
55 #define TASK_STATS_ADD_TX(stats, ntx) do { \
56 (stats)->tx_pkt_count += ntx; \
59 #define TASK_STATS_ADD_DROP_TX_FAIL(stats, ntx) do { \
60 (stats)->drop_tx_fail += ntx; \
63 #define TASK_STATS_ADD_DROP_HANDLED(stats, ntx) do { \
64 (stats)->drop_handled += ntx; \
67 #define TASK_STATS_ADD_DROP_DISCARD(stats, ntx) do { \
68 (stats)->drop_discard += ntx; \
71 #define TASK_STATS_ADD_RX(stats, ntx) do { \
72 (stats)->rx_pkt_count += ntx; \
75 #define TASK_STATS_ADD_RX_BYTES(stats, bytes) do { \
76 (stats)->rx_bytes += bytes; \
79 #define TASK_STATS_ADD_TX_BYTES(stats, bytes) do { \
80 (stats)->tx_bytes += bytes; \
83 #define TASK_STATS_ADD_DROP_BYTES(stats, bytes) do { \
84 (stats)->drop_bytes += bytes; \
87 #define START_EMPTY_MEASSURE() uint64_t cur_tsc = rte_rdtsc();
89 #define TASK_STATS_ADD_IDLE(stats, cycles) do {} while(0)
90 #define TASK_STATS_ADD_TX(stats, ntx) do {} while(0)
91 #define TASK_STATS_ADD_DROP_TX_FAIL(stats, ntx) do {} while(0)
92 #define TASK_STATS_ADD_DROP_HANDLED(stats, ntx) do {} while(0)
93 #define TASK_STATS_ADD_DROP_DISCARD(stats, ntx) do {} while(0)
94 #define TASK_STATS_ADD_RX(stats, ntx) do {} while(0)
95 #define TASK_STATS_ADD_RX_BYTES(stats, bytes) do {} while(0)
96 #define TASK_STATS_ADD_TX_BYTES(stats, bytes) do {} while(0)
97 #define TASK_STATS_ADD_DROP_BYTES(stats, bytes) do {} while(0)
98 #define START_EMPTY_MEASSURE() do {} while(0)
101 struct task_stats_sample {
103 uint32_t tx_pkt_count;
104 uint32_t drop_tx_fail;
105 uint32_t drop_discard;
106 uint32_t drop_handled;
107 uint32_t rx_pkt_count;
108 uint32_t empty_cycles;
115 uint64_t tot_tx_pkt_count;
116 uint64_t tot_drop_tx_fail;
117 uint64_t tot_drop_discard;
118 uint64_t tot_drop_handled;
119 uint64_t tot_rx_pkt_count;
121 struct task_stats_sample sample[2];
123 struct task_rt_stats *stats;
124 /* flags set if total RX/TX values need to be reported set at
125 initialization time, only need to access stats values in port */
129 void stats_task_reset(void);
130 void stats_task_post_proc(void);
131 void stats_task_update(void);
132 void stats_task_init(void);
134 int stats_get_n_tasks_tot(void);
136 struct task_stats *stats_get_task_stats(uint32_t lcore_id, uint32_t task_id);
137 struct task_stats_sample *stats_get_task_stats_sample(uint32_t lcore_id, uint32_t task_id, int last);
138 void stats_task_get_host_rx_tx_packets(uint64_t *rx, uint64_t *tx, uint64_t *tsc);
140 uint64_t stats_core_task_tot_rx(uint8_t lcore_id, uint8_t task_id);
141 uint64_t stats_core_task_tot_tx(uint8_t lcore_id, uint8_t task_id);
142 uint64_t stats_core_task_tot_drop(uint8_t lcore_id, uint8_t task_id);
143 uint64_t stats_core_task_last_tsc(uint8_t lcore_id, uint8_t task_id);
145 #endif /* _STATS_TASK_H_ */