2 // Copyright (c) 2010-2018 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_irq.h"
20 #include "stats_irq.h"
22 #include "prox_globals.h"
25 static struct irq_task_stats irq_task_stats_set[RTE_MAX_LCORE * MAX_TASKS_PER_CORE];
26 static uint8_t nb_irq_tasks;
28 int stats_get_n_irq_tasks(void)
33 struct irq_sample *get_irq_sample(uint32_t task_id, int l)
35 return &irq_task_stats_set[task_id].sample[last_stat == l];
38 struct irq_sample *get_irq_sample_by_core_task(uint32_t lcore_id, uint32_t irq_task_id, int l)
40 for (uint8_t task_id = 0; task_id < nb_irq_tasks; ++task_id) {
41 if ((irq_task_stats_set[task_id].lcore_id == lcore_id) && (irq_task_stats_set[task_id].task_id == irq_task_id))
42 return &irq_task_stats_set[task_id].sample[last_stat == l];
47 void stats_irq_reset(void)
49 struct irq_task_stats *cur_task_stats;
51 for (uint8_t task_id = 0; task_id < nb_irq_tasks; ++task_id) {
52 cur_task_stats = &irq_task_stats_set[task_id];
53 cur_task_stats->max_irq = 0;
54 for (uint i = 0; i < IRQ_BUCKETS_COUNT; ++i) {
55 cur_task_stats->irq[i] = 0;
60 void stats_irq_post_proc(void)
62 for (uint8_t task_id = 0; task_id < nb_irq_tasks; ++task_id) {
63 struct irq_task_stats *cur_task_stats = &irq_task_stats_set[task_id];
64 struct irq_rt_stats *stats = cur_task_stats->stats;
65 const struct irq_sample *last = &cur_task_stats->sample[last_stat];
66 const struct irq_sample *prev = &cur_task_stats->sample[!last_stat];
68 if (cur_task_stats->max_irq < last->max_irq)
69 cur_task_stats->max_irq = last->max_irq;
70 for (uint i = 0; i < IRQ_BUCKETS_COUNT; ++i) {
71 cur_task_stats->irq[i] += last->irq[i] - prev->irq[i];
77 void stats_irq_update(void)
79 for (uint8_t task_id = 0; task_id < nb_irq_tasks; ++task_id) {
80 struct irq_task_stats *cur_task_stats = &irq_task_stats_set[task_id];
81 struct irq_rt_stats *stats = cur_task_stats->stats;
82 struct irq_sample *sample = &cur_task_stats->sample[last_stat];
84 sample->max_irq = stats->max_irq;
85 for (uint i = 0; i < IRQ_BUCKETS_COUNT; ++i) {
86 sample->irq[i] = stats->irq[i];
91 void stats_irq_init(void)
93 struct lcore_cfg *lconf;
97 while(prox_core_next(&lcore_id, 0) == 0) {
98 lconf = &lcore_cfg[lcore_id];
99 for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
100 struct task_args *targ = &lconf->targs[task_id];
101 if (strcmp(targ->task_init->mode_str, "irq") == 0) {
102 struct irq_rt_stats *stats = &((struct task_irq *)(lconf->tasks_all[task_id]))->stats;
103 irq_task_stats_set[nb_irq_tasks].stats = stats;
104 irq_task_stats_set[nb_irq_tasks].lcore_id = lcore_id;
105 irq_task_stats_set[nb_irq_tasks++].task_id = task_id;
111 uint64_t get_max_irq_stats_by_core_task(uint8_t lcore_id, uint8_t irq_task_id)
113 for (uint8_t task_id = 0; task_id < nb_irq_tasks; ++task_id) {
114 if ((irq_task_stats_set[task_id].lcore_id == lcore_id) && (irq_task_stats_set[task_id].task_id == irq_task_id))
115 return (irq_task_stats_set[task_id].max_irq * 1000000) / rte_get_tsc_hz();
120 uint64_t get_irq_stats_by_core_task(uint8_t lcore_id, uint8_t irq_task_id, int id)
122 for (uint8_t task_id = 0; task_id < nb_irq_tasks; ++task_id) {
123 if ((irq_task_stats_set[task_id].lcore_id == lcore_id) && (irq_task_stats_set[task_id].task_id == irq_task_id))
124 return irq_task_stats_set[task_id].irq[id];
129 uint64_t get_max_irq_stats(uint8_t task_id)
131 return (irq_task_stats_set[task_id].max_irq * 1000000L) / rte_get_tsc_hz();
134 uint64_t get_irq_stats(uint8_t task_id, int bucket_id)
136 return irq_task_stats_set[task_id].irq[bucket_id];
138 void get_irq_buckets_by_core_task(char *buf, uint8_t lcore_id, uint8_t irq_task_id)
140 for (int i = 0; i < IRQ_BUCKETS_COUNT; i++) {
141 sprintf(buf+strlen(buf), "%ld; ", irq_bucket_maxtime_micro[i]);
143 sprintf(buf+strlen(buf), "\n");