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 "prox_malloc.h"
21 #include "stats_l4gen.h"
22 #include "task_init.h"
24 struct task_l4gen_stats {
25 struct task_base base;
26 struct l4_stats l4_stats;
29 struct stats_l4gen_manager {
31 struct task_l4_stats task_l4_stats[0];
35 static struct stats_l4gen_manager *sl4m;
37 int stats_get_n_l4gen(void)
42 struct task_l4_stats *stats_get_l4_stats(uint32_t i)
44 return &sl4m->task_l4_stats[i];
47 struct l4_stats_sample *stats_get_l4_stats_sample(uint32_t i, int l)
49 return &sl4m->task_l4_stats[i].sample[l == last_stat];
52 static struct stats_l4gen_manager *alloc_stats_l4gen_manager(void)
54 struct lcore_cfg *lconf;
55 uint32_t lcore_id = -1;
58 const int socket_id = rte_lcore_to_socket_id(rte_lcore_id());
61 while (prox_core_next(&lcore_id, 0) == 0) {
62 lconf = &lcore_cfg[lcore_id];
63 for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
64 struct task_args *targ = &lconf->targs[task_id];
66 if (!strcmp(targ->task_init->mode_str, "genl4"))
71 mem_size = sizeof(struct stats_l4gen_manager) + sizeof(struct task_l4_stats) * n_l4gen;
72 return prox_zmalloc(mem_size, socket_id);
75 void stats_l4gen_init(void)
77 struct lcore_cfg *lconf;
78 uint32_t lcore_id = -1;
80 sl4m = alloc_stats_l4gen_manager();
82 while(prox_core_next(&lcore_id, 0) == 0) {
83 lconf = &lcore_cfg[lcore_id];
84 for (uint8_t task_id = 0; task_id < lconf->n_tasks_all; ++task_id) {
85 struct task_args *targ = &lconf->targs[task_id];
87 if (!strcmp(targ->task_init->mode_str, "genl4")) {
88 sl4m->task_l4_stats[sl4m->n_l4gen].task = (struct task_l4gen_stats *)lconf->tasks_all[task_id];
89 sl4m->task_l4_stats[sl4m->n_l4gen].lcore_id = lcore_id;
90 sl4m->task_l4_stats[sl4m->n_l4gen].task_id = task_id;
97 void stats_l4gen_update(void)
99 uint64_t before, after;
101 for (uint16_t i = 0; i < sl4m->n_l4gen; ++i) {
102 struct task_l4gen_stats *task_l4gen = sl4m->task_l4_stats[i].task;
104 before = rte_rdtsc();
105 sl4m->task_l4_stats[i].sample[last_stat].stats = task_l4gen->l4_stats;
108 sl4m->task_l4_stats[i].sample[last_stat].tsc = (before >> 1) + (after >> 1);