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 #include <rte_cycles.h>
20 #include "task_base.h"
21 #include "task_init.h"
22 #include "handle_irq.h"
27 #define MAX_INDEX 65535 * 16
36 struct irq_info info[MAX_INDEX];
40 struct task_base base;
46 volatile uint16_t stats_use_lt; /* which lt to use, */
47 volatile uint16_t task_use_lt; /* 0 or 1 depending on which of the 2 result records are used */
48 struct irq_bucket buffer[2];
51 #define MAX_INTERRUPT_LENGTH 500000 /* Maximum length of an interrupt is (1 / MAX_INTERRUPT_LENGTH) seconds */
54 * This module is not handling any packets.
55 * It loops on rdtsc() and checks whether it has been interrupted
56 * for more than (1 / MAX_INTERRUPT_LENGTH) sec.
57 * This is a debugging only task, useful to check if the system h
58 * as been properly configured.
61 void task_irq_show_stats(struct task_irq *task_irq, struct input *input)
63 struct irq_bucket *bucket = &task_irq->buffer[!task_irq->task_use_lt];
66 if (bucket->index == 0) {
68 input->reply(input, buf, strlen(buf));
71 for (uint64_t i = 0; i < bucket->index; i++) {
72 sprintf(buf + strlen(buf), "%d; %"PRIu64"""; %ld; %ld; %ld; %ld ;",
76 bucket->info[i].lat * 1000000 / rte_get_tsc_hz(),
77 bucket->info[i].tsc - task_irq->start_tsc,
78 (bucket->info[i].tsc - task_irq->start_tsc) * 1000 / rte_get_tsc_hz());
79 sprintf(buf+strlen(buf), "\n");
80 input->reply(input, buf, strlen(buf));
84 for (uint64_t i = 0; i < bucket->index; i++)
85 if (bucket->info[i].lat)
86 plog_info("[%d]; Interrupt %"PRIu64": %ld cycles (%ld micro-sec) at %ld cycles (%ld msec)\n",
90 bucket->info[i].lat * 1000000 / rte_get_tsc_hz(),
91 bucket->info[i].tsc - task_irq->start_tsc,
92 (bucket->info[i].tsc - task_irq->start_tsc) * 1000 / rte_get_tsc_hz());
94 task_irq->stats_use_lt = !task_irq->task_use_lt;
98 static void irq_stop(struct task_base *tbase)
100 struct task_irq *task = (struct task_irq *)tbase;
102 uint32_t lcore_id = rte_lcore_id();
103 uint64_t lat, max_lat = 0, tot_lat = 0;
107 plog_info("Stopping core %u\n", lcore_id);
108 sleep(2); // Make sure all cores are stopped before starting to write
109 plog_info("Core ID; Interrupt (nanosec); Time (msec)\n");
110 for (int j = 0; j < 2; j++) {
111 // Start dumping the oldest bucket first
112 if (task->buffer[0].info[0].tsc < task->buffer[1].info[0].tsc)
116 struct irq_bucket *bucket = &task->buffer[bucket_id];
117 for (i=0; i< bucket->index;i++) {
118 if (bucket->info[i].lat != 0) {
119 lat = bucket->info[i].lat * 1000000000 / rte_get_tsc_hz();
124 plog_info("%d; %ld; %ld\n", lcore_id, lat,
125 (bucket->info[i].tsc - task->start_tsc) * 1000 / rte_get_tsc_hz());
130 tot_lat = tot_lat / n_lat;
131 plog_info("Core %u stopped. max lat is %ld and average is %ld\n", lcore_id, max_lat, tot_lat);
134 static inline int handle_irq_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts)
136 struct task_irq *task = (struct task_irq *)tbase;
140 if (task->stats_use_lt != task->task_use_lt)
141 task->task_use_lt = task->stats_use_lt;
142 struct irq_bucket *bucket = &task->buffer[task->task_use_lt];
145 if ((tsc1 > task->first_tsc) && (task->tsc != 0) && ((tsc1 - task->tsc) > task->max_irq) && (bucket->index < MAX_INDEX)) {
146 bucket->info[bucket->index].tsc = tsc1;
147 bucket->info[bucket->index++].lat = tsc1 - task->tsc;
153 static void init_task_irq(struct task_base *tbase,
154 __attribute__((unused)) struct task_args *targ)
156 struct task_irq *task = (struct task_irq *)tbase;
157 // max_irq expressed in cycles
158 task->max_irq = rte_get_tsc_hz() / MAX_INTERRUPT_LENGTH;
159 task->start_tsc = rte_rdtsc();
160 task->first_tsc = task->start_tsc + 2 * rte_get_tsc_hz();
161 task->lcore_id = targ->lconf->id;
162 plog_info("\tusing irq mode with max irq set to %ld cycles\n", task->max_irq);
165 static struct task_init task_init_irq = {
167 .init = init_task_irq,
168 .handle = handle_irq_bulk,
170 .flag_features = TASK_FEATURE_NO_RX,
171 .size = sizeof(struct task_irq)
174 static struct task_init task_init_none;
176 __attribute__((constructor)) static void reg_task_irq(void)
178 reg_task(&task_init_irq);