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.
19 #include "handle_aggregator.h"
20 #include "stats_prio_task.h"
22 #include "prox_globals.h"
25 struct lcore_task_stats {
26 struct task_stats task_stats[MAX_TASKS_PER_CORE];
29 struct lcore_prio_task_stats {
30 struct prio_task_stats prio_task_stats[MAX_TASKS_PER_CORE];
34 static struct prio_task_stats prio_task_stats_set[RTE_MAX_LCORE * MAX_TASKS_PER_CORE];
35 static uint8_t nb_prio_tasks_tot;
37 int stats_get_n_prio_tasks_tot(void)
39 return nb_prio_tasks_tot;
42 struct prio_task_stats_sample *stats_get_prio_task_stats_sample(uint32_t prio_task_id, int l)
44 return &prio_task_stats_set[prio_task_id].sample[l == last_stat];
47 struct prio_task_stats_sample *stats_get_prio_task_stats_sample_by_core_task(uint32_t lcore_id, uint32_t prio_task_id, int l)
49 for (uint8_t task_id = 0; task_id < nb_prio_tasks_tot; ++task_id) {
50 if ((prio_task_stats_set[task_id].lcore_id == lcore_id) && (prio_task_stats_set[task_id].task_id == task_id))
51 return &prio_task_stats_set[prio_task_id].sample[l == last_stat];
56 void stats_prio_task_reset(void)
58 struct prio_task_stats *cur_task_stats;
60 for (uint8_t task_id = 0; task_id < nb_prio_tasks_tot; ++task_id) {
61 cur_task_stats = &prio_task_stats_set[task_id];
62 for (int i = 0; i < 8; i++) {
63 cur_task_stats->tot_drop_tx_fail_prio[i] = 0;
64 cur_task_stats->tot_rx_prio[i] = 0;
69 uint64_t stats_core_task_tot_drop_tx_fail_prio(uint8_t prio_task_id, uint8_t prio)
71 return prio_task_stats_set[prio_task_id].tot_drop_tx_fail_prio[prio];
74 uint64_t stats_core_task_tot_rx_prio(uint8_t prio_task_id, uint8_t prio)
76 return prio_task_stats_set[prio_task_id].tot_rx_prio[prio];
79 void stats_prio_task_post_proc(void)
81 for (uint8_t task_id = 0; task_id < nb_prio_tasks_tot; ++task_id) {
82 struct prio_task_stats *cur_task_stats = &prio_task_stats_set[task_id];
83 const struct prio_task_stats_sample *last = &cur_task_stats->sample[last_stat];
84 const struct prio_task_stats_sample *prev = &cur_task_stats->sample[!last_stat];
86 for (int i=0; i<8; i++) {
87 cur_task_stats->tot_rx_prio[i] += last->rx_prio[i] - prev->rx_prio[i];
88 cur_task_stats->tot_drop_tx_fail_prio[i] += last->drop_tx_fail_prio[i] - prev->drop_tx_fail_prio[i];
93 void stats_prio_task_update(void)
95 uint64_t before, after;
97 for (uint8_t task_id = 0; task_id < nb_prio_tasks_tot; ++task_id) {
98 struct prio_task_stats *cur_task_stats = &prio_task_stats_set[task_id];
99 struct prio_task_rt_stats *stats = cur_task_stats->stats;
100 struct prio_task_stats_sample *last = &cur_task_stats->sample[last_stat];
102 before = rte_rdtsc();
103 for (int i=0; i<8; i++) {
104 last->drop_tx_fail_prio[i] = stats->drop_tx_fail_prio[i];
105 last->rx_prio[i] = stats->rx_prio[i];
108 last->tsc = (before >> 1) + (after >> 1);
112 void stats_prio_task_init(void)
114 struct lcore_cfg *lconf;
117 /* add cores that are receiving from and sending to physical ports first */
119 while(prox_core_next(&lcore_id, 0) == 0) {
120 lconf = &lcore_cfg[lcore_id];
121 for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
122 struct task_args *targ = &lconf->targs[task_id];
123 if (strcmp(targ->task_init->mode_str, "aggreg") == 0) {
124 struct prio_task_rt_stats *stats = &((struct task_aggregator *)(lconf->tasks_all[task_id]))->stats;
125 prio_task_stats_set[nb_prio_tasks_tot].stats = stats;
126 prio_task_stats_set[nb_prio_tasks_tot].lcore_id = lcore_id;
127 prio_task_stats_set[nb_prio_tasks_tot++].task_id = task_id;