VPP节点统计信息

节点的统计位于函数dispatch_node函数中,节点处理函数运行之后(node->function)返回值为处理的报文数量n(n_vectors),通过函数vlib_node_runtime_update_stats来更新节点的相关统计信息。

static_always_inline u64
dispatch_node (vlib_main_t * vm, vlib_node_runtime_t * node,vlib_node_type_t type, vlib_node_state_t dispatch_state,vlib_frame_t * frame, u64 last_time_stamp)
{if (PREDICT_TRUE (vm->dispatch_wrapper_fn == 0))n = node->function (vm, node, frame);elsen = vm->dispatch_wrapper_fn (vm, node, frame);t = clib_cpu_time_now ();v = vlib_node_runtime_update_stats (vm, node,/* n_calls */ 1,/* n_vectors */ n,/* n_clocks */ t - last_time_stamp);

三种统计维度:调用次数、报文数量和时间,对应以上的参数n_calls=1,n_vectors=n和n_clocks=t - last_time_stamp。将node中的三个记录统计信息的成员分别累加上对应的值。

always_inline u32
vlib_node_runtime_update_stats (vlib_main_t * vm, vlib_node_runtime_t * node,uword n_calls, uword n_vectors, uword n_clocks)
{u32 ca0, ca1, v0, v1, cl0, cl1, r;cl0 = cl1 = node->clocks_since_last_overflow;ca0 = ca1 = node->calls_since_last_overflow;v0 = v1 = node->vectors_since_last_overflow;ca1 = ca0 + n_calls;v1 = v0 + n_vectors;cl1 = cl0 + n_clocks;node->calls_since_last_overflow = ca1;node->clocks_since_last_overflow = cl1;node->vectors_since_last_overflow = v1;

max_clock和max_clock_n分别记录最大的时钟周期,和在此周期中处理的报文数量。

  node->max_clock_n = node->max_clock > n_clocks ? node->max_clock_n : n_vectors;node->max_clock = node->max_clock > n_clocks ? node->max_clock : n_clocks;

如果累加统计值之后,三者之中有某一个数值出现反转(32bit溢出overflow),调用同步函数vlib_node_runtime_sync_stats,将统计信息由节点结构vlib_node_runtime_t同步到对应的vlib_node_t中,即由运行时节点结构同步到主节点结构中,参见函数vlib_node_runtime_sync_stats。

  r = vlib_node_runtime_update_main_loop_vector_stats (vm, node, n_vectors);if (PREDICT_FALSE (ca1 < ca0 || v1 < v0 || cl1 < cl0)) {node->calls_since_last_overflow = ca0;node->clocks_since_last_overflow = cl0;node->vectors_since_last_overflow = v0;vlib_node_runtime_sync_stats (vm, node, n_calls, n_vectors, n_clocks);}return r;

统计信息同步

根据节点索引,取得主节点结构。

void
vlib_node_runtime_sync_stats (vlib_main_t *vm, vlib_node_runtime_t *r,uword n_calls, uword n_vectors, uword n_clocks)
{vlib_node_t *n = vlib_get_node (vm, r->node_index);vlib_node_runtime_sync_stats_node (n, r, n_calls, n_vectors, n_clocks);
}

将统计信息由32位的*_overflow累加到主节点的统计结构中,并且,请求运行节点结构中的统计值*_overflow。

/* Sync up runtime (32 bit counters) and main node stats (64 bit counters). */
void
vlib_node_runtime_sync_stats_node (vlib_node_t *n, vlib_node_runtime_t *r,uword n_calls, uword n_vectors, uword n_clocks)
{n->stats_total.calls += n_calls + r->calls_since_last_overflow;n->stats_total.vectors += n_vectors + r->vectors_since_last_overflow;n->stats_total.clocks += n_clocks + r->clocks_since_last_overflow;n->stats_total.max_clock = r->max_clock;n->stats_total.max_clock_n = r->max_clock_n;r->calls_since_last_overflow = 0;r->vectors_since_last_overflow = 0;r->clocks_since_last_overflow = 0;
}

主循环统计更新

每次主循环执行,都会将计数递增main_loop_count。

always_inline void
vlib_increment_main_loop_counter (vlib_main_t * vm)
{      vm->main_loop_count++;...
}static_always_inline void
vlib_main_or_worker_loop (vlib_main_t * vm, int is_main)
{vlib_increment_main_loop_counter (vm);

PROCESS节点统计

以上dispatch_node处理的是VLIB_NODE_TYPE_PRE_INPUT/INPUT/INTERNAL三种类型的节点,对于VLIB_NODE_TYPE_PROCESS类型节点,由函数vlib_process_update_stats进行统计更新。其核心为以上介绍的函数vlib_node_runtime_update_stats。

always_inline void
vlib_process_update_stats (vlib_main_t * vm,vlib_process_t * p,uword n_calls, uword n_vectors, uword n_clocks)
{vlib_node_runtime_update_stats (vm, &p->node_runtime,n_calls, n_vectors, n_clocks);
}

显示节点统计信息

注册显示节点信息命令:show runtime,可以显示指定节点的统计信息,或者显示所有节点的统计信息。

VLIB_CLI_COMMAND (show_node_runtime_command, static) = {.path = "show runtime",.short_help = "Show packet processing runtime",.function = show_node_runtime,.is_mp_safe = 1,
};

在显示节点统计信息之前,需要先收集下节点信息,如下函数vlib_node_sync_stats。首先,根据获取到节点对应的运行节点结构rt。其次由函数vlib_node_runtime_sync_stats将未同步的统计信息同步到节点主结构中。

void
vlib_node_sync_stats (vlib_main_t * vm, vlib_node_t * n)
{vlib_node_runtime_t *rt;if (n->type == VLIB_NODE_TYPE_PROCESS) {/* Nothing to do for PROCESS nodes except in main thread */if (vm != vlib_get_first_main ()) return;vlib_process_t *p = vlib_get_process_from_node (vm, n);n->stats_total.suspends += p->n_suspends;p->n_suspends = 0;rt = &p->node_runtime;} elsert = vec_elt_at_index (vm->node_main.nodes_by_type[n->type], n->runtime_index);vlib_node_runtime_sync_stats (vm, rt, 0, 0, 0);

最后,将运行时下一个frame结构中统计的vectors值,同步到主节点结构中。

  /* Sync up runtime next frame vector counters with main node structure. */{vlib_next_frame_t *nf;for (i = 0; i < rt->n_next_nodes; i++) {nf = vlib_node_runtime_get_next_frame (vm, rt, i);vec_elt (n->n_vectors_by_next_node, i) += nf->vectors_since_last_overflow;nf->vectors_since_last_overflow = 0;

格式化统计信息函数,如下format_vlib_node_stats。如果节点结构为空,仅显示标题信息。

static u8 *
format_vlib_node_stats (u8 * s, va_list * va)
{vlib_main_t *vm = va_arg (*va, vlib_main_t *);vlib_node_t *n = va_arg (*va, vlib_node_t *);int max = va_arg (*va, int);f64 v, x, maxc, maxcn;u8 *ns, *misc_info = 0;u64 c, p, l, d;if (!n) {if (max)s = format (s, "%=30s%=17s%=16s%=16s%=16s%=16s","Name", "Max Node Clocks", "Vectors at Max","Max Clocks", "Avg Clocks", "Avg Vectors/Call");elses = format (s, "%=30s%=12s%=16s%=16s%=16s%=16s%=16s","Name", "State", "Calls", "Vectors", "Suspends","Clocks", "Vectors/Call");return s;}indent = format_get_indent (s);

由节点中获得时钟周期、调用数量、报文数量和suspends数量的值。计算处理一个报文使用的最长的时钟周期maxcn。

  l = n->stats_total.clocks - n->stats_last_clear.clocks;c = n->stats_total.calls - n->stats_last_clear.calls;p = n->stats_total.vectors - n->stats_last_clear.vectors;d = n->stats_total.suspends - n->stats_last_clear.suspends;maxc = (f64) n->stats_total.max_clock;maxn = n->stats_total.max_clock_n;if (n->stats_total.max_clock_n)maxcn = (f64) n->stats_total.max_clock / (f64) maxn;elsemaxcn = 0.0;

计算每个报文、每次调用、每个suspend所花费的时钟周期,优先级依次降低。计算每次调用calls,处理的报文数量vectors,结果为v。

  /* Clocks per packet, per call or per suspend. */x = 0;if (p > 0)x = (f64) l / (f64) p;else if (c > 0)x = (f64) l / (f64) c;else if (d > 0)x = (f64) l / (f64) d;if (c > 0)v = (double) p / (double) c;elsev = 0;

输出节点的统计信息,以及以上的计算值。

  ns = n->name;if (max)s = format (s, "%-30v%=17.2e%=16d%=16.2e%=16.2e%=16.2e",ns, maxc, maxn, maxcn, x, v);elses = format (s, "%-30v%=12U%16Ld%16Ld%16Ld%16.2e%16.2f", ns,format_vlib_node_state, vm, n, c, p, d, x, v);if (ns != n->name)vec_free (ns);return s;

函数show_node_runtime处理命令show runtime。
如果在命令行指定了节点名称,如:show runtime ip4-input,调用以上介绍的统计信息收集函数和显示函数处理。

static clib_error_t *
show_node_runtime (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
{vlib_node_main_t *nm = &vm->node_main;vlib_node_t *n, ***node_dups = 0;f64 time_now, *internal_node_vector_rates = 0;u32 node_index;time_now = vlib_time_now (vm);if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) {n = vlib_get_node (vm, node_index);vlib_node_sync_stats (vm, n);vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, 0, 0);vlib_cli_output (vm, "%U\n", format_vlib_node_stats, vm, n, 0);} else {

如下显示信息:

vpp# show runtime ip4-inputName                 State         Calls          Vectors        Suspends         Clocks       Vectors/Call
ip4-input                         active          0               0               0            0.00e0            0.00

否则,对于未指定节点名称的情况,有以下处理流程。默认按照brief简洁方式显示,还可指定verbose、max或者summary方式。

      vlib_node_t **nodes;f64 dt;u64 n_input, n_output, n_drop, n_punt;u64 n_clocks, l, v, c, d;int brief = 1, summary = 0, max = 0;vlib_main_t **stat_vms = 0, *stat_vm;/* Suppress nodes with zero calls since last clear */if (unformat (input, "brief") || unformat (input, "b"))    brief = 1;if (unformat (input, "verbose") || unformat (input, "v"))  brief = 0;if (unformat (input, "max") || unformat (input, "m"))      max = 1;if (unformat (input, "summary") || unformat (input, "sum") || unformat (input, "su"))summary = 1;

遍历所有的线程,生成线程vlib_main_t结构向量。

    for (i = 0; i < vlib_get_n_threads (); i++) {stat_vm = vlib_get_main_by_index (i);if (stat_vm)vec_add1 (stat_vms, stat_vm);}/* Barrier sync across stats scraping.* Otherwise, the counts will be grossly inaccurate.*/vlib_worker_thread_barrier_sync (vm);

遍历每个线程的vlib_main结构,并遍历其中的每个节点,同步每个节点的统计信息。完成之后,将节点克隆一份,添加到node_dups向量。

    for (j = 0; j < vec_len (stat_vms); j++) {stat_vm = stat_vms[j];nm = &stat_vm->node_main;for (i = 0; i < vec_len (nm->nodes); i++) {n = nm->nodes[i];vlib_node_sync_stats (stat_vm, n);}nodes = vec_dup (nm->nodes);vec_add1 (node_dups, nodes);vec_add1 (internal_node_vector_rates, vlib_internal_node_vector_rate (stat_vm));}vlib_worker_thread_barrier_release (vm);

遍历每个线程的vlib_main结构,以及其中的每个主节点结构,计算全部节点的n_output/n_drop/n_punt/n_input的统计总量。

    for (j = 0; j < vec_len (stat_vms); j++) {stat_vm = stat_vms[j];nodes = node_dups[j];vec_sort_with_function (nodes, node_cmp);n_input = n_output = n_drop = n_punt = n_clocks = 0;for (i = 0; i < vec_len (nodes); i++) {n = nodes[i];v = n->stats_total.vectors - n->stats_last_clear.vectors;switch (n->type) {default: continue;case VLIB_NODE_TYPE_INTERNAL:n_output += (n->flags & VLIB_NODE_FLAG_IS_OUTPUT) ? v : 0;n_drop += (n->flags & VLIB_NODE_FLAG_IS_DROP) ? v : 0;n_punt += (n->flags & VLIB_NODE_FLAG_IS_PUNT) ? v : 0;if (n->flags & VLIB_NODE_FLAG_IS_HANDOFF)  n_input += v;break;case VLIB_NODE_TYPE_INPUT:n_input += v;break;}}

输出当前线程的id,线程名称和cpu索引等信息。数据线程处理的全部节点的总量信息。最后,如果没有指定summary参数,输出每个节点的统计信息。

      if (vlib_get_n_threads () > 1) {vlib_worker_thread_t *w = vlib_worker_threads + j;if (j > 0) vlib_cli_output (vm, "---------------");if (w->cpu_id > -1)vlib_cli_output (vm, "Thread %d %s (lcore %u)", j, w->name, w->cpu_id);elsevlib_cli_output (vm, "Thread %d %s", j, w->name);}dt = time_now - nm->time_last_runtime_stats_clear;vlib_cli_output (vm, "Time %.1f, %f sec internal node vector rate %.2f loops/sec %.2f\n""  vector rates in %.4e, out %.4e, drop %.4e, punt %.4e",dt, vlib_stats_get_segment_update_rate (), internal_node_vector_rates[j], stat_vm->loops_per_second,(f64) n_input / dt, (f64) n_output / dt, (f64) n_drop / dt, (f64) n_punt / dt);if (summary == 0) {vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, 0, max);for (i = 0; i < vec_len (nodes); i++) {c = nodes[i]->stats_total.calls - nodes[i]->stats_last_clear.calls;d = nodes[i]->stats_total.suspends - nodes[i]->stats_last_clear.suspends;if (c || d || !brief) {vlib_cli_output (vm, "%U", format_vlib_node_stats, stat_vm, nodes[i], max);

如下,输出线程2的统计信息:

---------------
Thread 2 vpp_wk_1 (lcore 3)
Time 13238.4, 10 sec internal node vector rate 0.00 loops/sec 14040836.44vector rates in 5.0524e5, out 5.0524e5, drop 0.0000e0, punt 0.0000e0Name                 State         Calls          Vectors        Suspends         Clocks       Vectors/Call
dpdk-input                       polling      180198867720      6688500986               0          4.59e3             .04
ethernet-input                   active          544505661      6688500986               0          4.32e1           12.28
...

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/140251.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

搭建Docker

一、概念 云服务器大家肯定不陌生了&#xff0c;相比较传统物理服务器来说他的价格&#xff0c;个性化的配置服务&#xff0c;节省了很多的运维成本&#xff0c;越来越多的企业以及个人开发者更加的青睐于云服务器。有了属于自己的服务器就可以部署搭建自己个人网站了&#xf…

mac安装brew

命令 /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"如图 选择下载源&#xff0c;进行安装 安装完成 验证

安卓常见设计模式9------外观模式(Kotlin版)

1. W1 是什么&#xff0c;什么是外观模式&#xff1f;​ 外观模式&#xff08;Facade Pattern&#xff09;是一种结构型设计模式&#xff0c;它提供了一个简单的接口&#xff0c;用于隐藏底层系统的复杂性&#xff0c;并将其封装成一个更高级别的接口供客户端使用。外观模式有…

Java基础知识第四讲:Java 基础 - 深入理解泛型机制

Java 基础 - 深入理解泛型机制 背景&#xff1a;Java泛型这个特性是从JDK 1.5才开始加入的&#xff0c;为了兼容之前的版本&#xff0c;Java泛型的实现采取了“伪泛型”的策略&#xff0c;即Java在语法上支持泛型&#xff0c;但是在编译阶段会进行所谓的“类型擦除”&#xff0…

Linux--gcc/g++

一、gcc/g是什么 gcc的全称是GNU Compiler Collection&#xff0c;它是一个能够编译多种语言的编译器。最开始gcc是作为C语言的编译器&#xff08;GNU C Compiler&#xff09;&#xff0c;现在除了c语言&#xff0c;还支持C、java、Pascal等语言。gcc支持多种硬件平台 二、gc…

C++(20):自定义类型的自定义结构化绑定

C++17引入了map,tuple等类型的结构化绑定,不过有些限制 C++(17):结构化绑定_c++17结构化绑定_风静如云的博客-CSDN博客 C++20允许定制自定义类的结构化绑定,不过需要满足几个条件: 1.在类外实现get<int>(Type)函数、或在类内实现Type::get<int>()成员函数 2…

用示波器测量高压电

示波器本身是不可以测试几千v的高压电电路的&#xff0c;一般自带的探头衰减倍数不够&#xff0c;需要使用高压差分探头或者高压探棒&#xff0c;将测试信号衰减到合适的范围再接入示波器。 普通探头能测差分电压吗&#xff1f;差分探头和普通探头有什么区别&#xff1f;全网最…

NameServer的作用及功能

NameServer是整个消息队列中的状态服务器&#xff0c;集群的各个组件通过它来了解全局的信息。同时&#xff0c;各个角色的机器都要定期向NameServer上报自己的状态&#xff0c;超时不上报的话&#xff0c;NameServer会认为某个机器出故障不可用了&#xff0c;其他的组件会把这…

同一台Linux同时安装MYSQL5.7和MYSQL8(第一篇)

在一台Linxu上面同时安装mysql5.7和mysql8.0的步骤&#xff0c;记录一下&#xff0c;方便后续回顾&#xff0c;后续文章之后会接着介绍搭建两台虚拟机一主一从的架构。 其中配置的文件名称、目录、端口号、IP地址要根据自己电脑的实际情况进行更改。 安装完成后效果 [rootzong…

精确杂草控制植物检测模型的改进推广

Improved generalization of a plant-detection model for precision weed control 摘要1、介绍2、结论摘要 植物检测模型缺乏普遍性是阻碍实现自主杂草控制系统的主要挑战之一。 本文研究了训练和测试数据集分布对植物检测模型泛化误差的影响,并使用增量训练来减小泛化误差。…

vmware workstation 与 device/credential guard 不兼容

VM虚拟机报错 vmware虚拟机启动时报错&#xff1a;vmware workstation 与 device/credential guard 不兼容&#xff1a; 系统是win10专业版&#xff0c;导致报错原因最终发现是安装了docker&#xff0c;docker自带下载虚拟机Hyper-V&#xff0c;而导致vmware workstation 与 …

web-worker 基本使用

Web Workers 是浏览器中的一项技术&#xff0c;它允许在独立的线程中运行 JavaScript 代码&#xff0c;从而避免主线程阻塞。这对于执行长时间运行的计算、处理大量数据或执行其他 CPU 密集型任务非常有用。下面是一个简单的使用 Web Workers 的示例&#xff0c;包括主线程和工…

华为L410上制作内网镜像模板01

原文链接&#xff1a;华为L410上制作离线安装软件模板01 hello&#xff0c;大家好啊&#xff0c;今天给大家带来一篇在内网搭建Apache服务器&#xff0c;用于安装完内网操作系统后&#xff0c;在第一次开机时候&#xff0c;为系统安装软件&#xff0c;今天给大家用WeChat举例&a…

Qt绘制饼状图

必须在MainWindow.h头文件开头放 #include <QtCharts> //必须这么设置 创建chart&#xff1a; void MainWindow::iniPiewChart() { //饼图初始化QChart *chart new QChart();chart->setTitle(" Piechart演示");chart->setAnimationOptions(QChar…

数据分析实战 | 贝叶斯分类算法——病例自动诊断分析

目录 一、数据及分析对象 二、目的及分析任务 三、方法及工具 四、数据读入 五、数据理解 六、数据准备 七、模型训练 八、模型评价 九、模型调参 十、模型预测 一、数据及分析对象 CSV文件——“bc_data.csv” 数据集链接&#xff1a;https://download.csdn.net/d…

【leaflet】1. 初见

▒ 目录 ▒ &#x1f6eb; 导读需求开发环境 1️⃣ 概念概念解释特点 2️⃣ 学习路线图3️⃣ html示例&#x1f6ec; 文章小结&#x1f4d6; 参考资料 &#x1f6eb; 导读 需求 要做游戏地图了&#xff0c;看到大量产品都使用的leaflet&#xff0c;所以开始学习这个。 开发环境…

QGridLayout

QGridLayout QGridLayout 是 Qt 框架中的一个布局管理器类&#xff0c;用于在窗口或其他容器中创建基于网格的布局。 QGridLayout 将窗口或容器划分为行和列的网格&#xff0c;并将小部件放置在相应的单元格中。可以通过调整行、列和单元格的大小来控制布局的样式和结构。 以…

深入理解强化学习——多臂赌博机:梯度赌博机算法的数学证明

分类目录&#xff1a;《深入理解强化学习》总目录 通过将梯度赌博机算法理解为梯度上升的随机近似&#xff0c;我们可以深人了解这一算法的本质。在精确的梯度上升算法中&#xff0c;每一个动作的偏好函数 H t ( a ) H_t(a) Ht​(a)与增量对性能的影响成正比&#xff1a; H t …

基于SSM和vue的在线购物系统

文章目录 项目介绍主要功能截图:部分代码展示设计总结项目获取方式🍅 作者主页:超级无敌暴龙战士塔塔开 🍅 简介:Java领域优质创作者🏆、 简历模板、学习资料、面试题库【关注我,都给你】 🍅文末获取源码联系🍅 项目介绍 基于SSM和vue的在线购物系统,java项目。…

FlinkSQL聚合函数(Aggregate Function)详解

使用场景&#xff1a; 聚合函数即 UDAF&#xff0c;常⽤于进多条数据&#xff0c;出⼀条数据的场景。 上图展示了⼀个 聚合函数的例⼦ 以及 聚合函数包含的重要⽅法。 案例场景&#xff1a; 关于饮料的表&#xff0c;有三个字段&#xff0c;分别是 id、name、price&#xff0…