OSATE总线延迟的源码分析与模型修复——针对 Latency-case-study项目 端到端流延迟分析过程中空指针异常的解决

news2025/2/22 17:40:09

一、背景

 在文章AADL 端到端流延迟分析示例项目 Latency-case-study 简述的 “第八章 进行系统的端到端流延迟分析” 中,遇到了这样的一个问题:对分布式系统的端到端流延迟进行分析时,没有生成流延迟分析报告,并且错误日志提示,出现内部错误“空指针异常”。

上述文章给出的解决方案是使用旧版本的OSATE,但是这并未真正地解决问题。将OSATE项目的源代码下载,进行调试和分析,结果如下:

在涉及到总线的端到端延迟分析过程中,只将“在end to end flow中涉及的连接” 添加到指定数据结构connectionsToContributors。如果一个连接绑定到了某总线,却未在某个end to end flow中声明,那么该连接便不会添加到connectionsToContributors中,由此导致connectionsToContributors缺少关于该连接的数据,导致空指针异常。

本文在最后给出了修改后的代码,以下为详细内容:

二、问题回顾

对于Latency-case-study项目,在生成integration.software_distributed实例之后,启用流延迟分析,发现并未有任何报告被生成:

错误日志(Error Log)显示如下:

java.lang.NullPointerException: Cannot invoke "org.osate.analysis.flows.model.LatencyContributor.addSubContributor(org.osate.analysis.flows.model.LatencyContributor)" because "latencyContributor" is null

at org.osate.analysis.flows.FlowLatencyAnalysisSwitch.fillInQueuingTimes(FlowLatencyAnalysisSwitch.java:1465)

at org.osate.analysis.flows.FlowLatencyAnalysisSwitch.invokeOnSOM(FlowLatencyAnalysisSwitch.java:1052)

at org.osate.analysis.flows.handlers.CheckFlowLatency.analyzeInstanceModel(CheckFlowLatency.java:158)

at org.osate.ui.handlers.AbstractInstanceOrDeclarativeModelReadOnlyHandler.analyzeInstanceModelInMode(AbstractInstanceOrDeclarativeModelReadOnlyHandler.java:126)

at org.osate.ui.handlers.AbstractInstanceOrDeclarativeModelReadOnlyHandler.doAaxlAction(AbstractInstanceOrDeclarativeModelReadOnlyHandler.java:101)

at org.osate.ui.handlers.AbstractInstanceOrDeclarativeModelModifyHandler.processAaxlAction(AbstractInstanceOrDeclarativeModelModifyHandler.java:58)

at org.osate.ui.handlers.AbstractAaxlHandler.actionBody(AbstractAaxlHandler.java:181)

at org.osate.ui.handlers.AaxlReadOnlyHandlerAsJob$ActionAsJob.runInWorkspace(AaxlReadOnlyHandlerAsJob.java:115)

at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:43)

at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

可以看到,内部错误的主要原因是因为“ "latencyContributor" is null 

三、问题详细分析

为什么会产生空指针异常,接下来将自上而下地对问题进行分析:

在整个分析过程中,对于连接延迟的计算,涉及到了一个Map对象connectionsToContributors,其定义如下:(FlowLatencyAnalysisSwitch.java : line 111)

/*

 * Map from (bus component, connection instance) -> latency contributor. We need this because the queuing latency is computed at the end of process

 * after all the transmission times are computed. So we add the queuing latency to this latency contributor for the connection instance

 * bound to the given bus. This may contain entries that in the end are not interesting because virtual buses can be bound to

 * other virtual buses that are eventually bound to real bus. We chases down all those layers.

 */

private final Map<Pair<ComponentInstance, ConnectionInstance>, LatencyContributor> connectionsToContributors = new HashMap<>();

在流延迟分析过程中,会将端到端流中的元素按照类型依次添加到对应的Map中(其中一个Map用来存储关于连接的组件,即上面提到的connectionsToContributors),代码如下:

(FlowLatencyAnalysisSwitch.java : mapFlowElementInstance() : line 187)

public LatencyReportEntry analyzeLatency(EndToEndFlowInstance etef, SystemOperationMode som,boolean asynchronousSystem) {
		LatencyReportEntry entry = new LatencyReportEntry(etef, som, asynchronousSystem, 
			report.isMajorFrameDelay());
		for (FlowElementInstance fei : etef.getFlowElements()) {
			mapFlowElementInstance(etef, fei, entry);
		}
		// Issue 1148 moved this somewhere else
		// entry.finalizeReportEntry();
		return entry;
}

上述代码中,会遍历所有的端到端流etef(end to end flow),将每个端到端流fei(Flow Element Instance)作为参数传递给函数mapFlowElementInstance(etef, fei, entry),而该函数会间接调用processSamplingAndQueuingTimes(),从而根据端到端流的组成元素,向Map connectionsToContributors 中添加元素(只有在端到端流中声明的元素才会被添加),代码如下:(FlowLatencyAnalysisSwitch.java : processSamplingAndQueuingTimes():line 896)

	//通过下面函数获取总线的周期,对于周期性总线和非周期性总线,延迟的计算方式不同。
	double period = hasPeriod.contains(cc) ? PropertyUtils.getScaled(
	    TimingProperties::getPeriod, boundBusOrRequiredClassifier, TimeUnits.MS).orElse(0.0)    :   0.0;
	
	// 如果是周期性总线,增加采样延迟,将排队延迟设为0
	if (period > 0) {
	    // add sampling latency due to the protocol or bus being periodic
	    LatencyContributor samplingLatencyContributor = new LatencyContributorComponent(
	        boundBusOrRequiredClassifier, report.isMajorFrameDelay());
	    samplingLatencyContributor.setBestCaseMethod(LatencyContributorMethod.SAMPLED_PROTOCOL);
	    samplingLatencyContributor.setWorstCaseMethod(LatencyContributorMethod.SAMPLED_PROTOCOL);
	    samplingLatencyContributor.setSamplingPeriod(period);
	    latencyContributor.addSubContributor(samplingLatencyContributor);
	
	    // add queuing latency: always zero in this case
	    LatencyContributor queuingLatencyContributor = new LatencyContributorComponent(
	        boundBusOrRequiredClassifier, report.isMajorFrameDelay());
	    queuingLatencyContributor.setBestCaseMethod(LatencyContributorMethod.QUEUED);
	    queuingLatencyContributor.setWorstCaseMethod(LatencyContributorMethod.QUEUED);
	    queuingLatencyContributor.setMinimum(0.0);
	    queuingLatencyContributor.setMaximum(0.0);
	    latencyContributor.addSubContributor(queuingLatencyContributor);
	} 
	//如果是非周期性总线,需要在后续过程中计算排队延迟,将其存储于Map中
	else {
	    /*
		* Issue 1148
		*
		* if "boundBus" is really a bound component instance, and not a required component classifier,
		* then we remember the bus as asynchronous. Later in fillInQueuingTimes() we go through this list,
		* and then find all the connection instances bound to this bus. For each connection,
		* we compute the sum of the max transmission times of the OTHER connections bound to the bus. This
		* we set as the worse case queuing time. (Best case is 0.)
		*
		* We also remember the bus--connection pair that needs the queuing latency by storing its latency contributor.
		*/
	    if (bindingConnection != null) {
	        final ComponentInstance boundBus = (ComponentInstance) boundBusOrRequiredClassifier;
	
	        /* Set the bus order and then add it to the ordered set */
	        if (!busOrder.containsKey(boundBus)) {
	            busOrder.put(boundBus, nextBusId++);
	            asyncBuses.add(boundBus);
	        }
	        connectionsToContributors.put(new Pair<>(boundBus, bindingConnection), latencyContributor);
	}

根据上述代码:对于周期性总线和非周期性总线,其延迟的计算方式不同。

对于周期性总线,计算它的采样延迟,范围为[0, period]。

对于非周期性总线,其最小延迟为0,最大延迟按照绑定到该总线的其他连接的数据传输时间之和进行计算。

因此,对于端到端流延迟分析函数的调用代码,涉及到了一个名为 fillInQueuingTimes()的函数,其源码如下:(FlowLatencyAnalysisSwitch.java : fillInQueuingTimes():line 1412)

	private void fillInQueuingTimes(final SystemInstance system) {
		// Nothing to do if there are no asynchronous buses
		if (!asyncBuses.isEmpty()) {
			// Get all the connections bound to a bus and group them together by the bus they are bound to
			final Map<ComponentInstance, Set<ConnectionInstance>> sortedConnections = sortBoundConnections(system);
			/*
			 * Go through the list of all the asynchronous buses
			 */
			for (final NamedElement ne : asyncBuses) {
				// only proceed if it is a bus instance and not a classifier (from Required_Virtual_Bus_Class)
				if (ne instanceof ComponentInstance) {
					final ComponentInstance bus = (ComponentInstance) ne;

					// Get all the connections bound to that bus
					final Set<ConnectionInstance> boundConnections = sortedConnections.getOrDefault(bus,Collections.emptySet());
					// Get all the transmission times and compute the total
					double totalTime = 0.0;
					final Map<ConnectionInstance, Double> transmissionTimes = new HashMap<>();
					for (final ConnectionInstance ci : boundConnections) {
						final Double time = computedMaxTransmissionLatencies
								.getOrDefault(new Pair<ComponentInstance, ConnectionInstance>(bus, ci), 0.0);
						transmissionTimes.put(ci, time);
						totalTime += time;
					}

					/*
					 * Go through the list of connections again, and subtract the time associated
					 * with the current connection to find the max waiting time for each connection.
					 * (That each for each connection ci, we will have the sum of all the times
					 * for the _other_ connections bound to same bus. This gives us the max
					 * time that connection ci may have to wait to use the bus.)
					 */
					for (final ConnectionInstance ci : boundConnections) {
						final Double ciTime = transmissionTimes.get(ci);
						final double maxWaitingTime = totalTime - ciTime;

						// Finally we can stick this into the latency contributor
						final LatencyContributor latencyContributor = connectionsToContributors.get(new Pair<>(bus, ci));
						final LatencyContributor queuingLatencyContributor = new LatencyContributorComponent(bus,report.isMajorFrameDelay());
						queuingLatencyContributor.setBestCaseMethod(LatencyContributorMethod.QUEUED);
						queuingLatencyContributor.setWorstCaseMethod(LatencyContributorMethod.QUEUED);
						queuingLatencyContributor.setMinimum(0.0);
						if (report.isDisableQueuingLatency()) {
							// Hide the queuing time
							queuingLatencyContributor.setMaximum(0.0);
							queuingLatencyContributor.reportInfo("Ignoring queuing time of " + maxWaitingTime + "ms");
						} else {
							// Report the queuing time
							queuingLatencyContributor.setMaximum(maxWaitingTime);
						}
						latencyContributor.addSubContributor(queuingLatencyContributor);

						// add the sampling latency
						LatencyContributor samplingLatencyContributor = new LatencyContributorComponent(
								bus, report.isMajorFrameDelay());
						samplingLatencyContributor.setBestCaseMethod(LatencyContributorMethod.SAMPLED_PROTOCOL);
						samplingLatencyContributor.setWorstCaseMethod(LatencyContributorMethod.SAMPLED_PROTOCOL);
						samplingLatencyContributor.setSamplingPeriod(0.0);
						latencyContributor.addSubContributor(samplingLatencyContributor);
					}
				}
			}
		}
	}

在上述代码中,首先会获取一条总线上绑定的所有连接。

final Set<ConnectionInstance> boundConnections = sortedConnections.getOrDefault(bus,Collections.emptySet());

然后依次遍历每条连接,在Map connectionsToContributors中定位到这个连接并向其中添加延迟贡献。

final LatencyContributor latencyContributor = connectionsToContributors.get(new Pair<>(bus, ci));

......

latencyContributor.addSubContributor(queuingLatencyContributor);

异常出现的原因:如果一个连接没有被包含于某个端到端流,但是却被绑定到总线上,那么Map connectionsToContributors将不会添加此连接,故而在遍历绑定到总线的连接时,会出现空指针异常。

四、解决方案

修复此问题的方法有2种:

1. 完整地建模,声明系统中存在的所有端到端流,以保证不会有连接被遗漏。

2. 设定总线周期,避免排队延迟情况的出现(即绕过排队延迟计算)。

五、修复模型并测试

两种方案的代码如下:(在 integration.aadl 的 integration.software_distributed 部分)

system implementation integration.software_distributed extends integration.software_generic
	subcomponents
		s1_cpu 	: processor latency_cs::platform::generic_cpu;
		s2_cpu 	: processor latency_cs::platform::generic_cpu;
		p_cpu 	: processor latency_cs::platform::generic_cpu;
		a_cpu 	: processor latency_cs::platform::generic_cpu;
		s_p_bus: bus latency_cs::platform::generic_bus;
		p_a_bus : bus latency_cs::platform::generic_bus;
	connections
		b0 : bus access s1_cpu.net <-> s_p_bus;
		b1 : bus access s2_cpu.net <-> s_p_bus;
		b2 : bus access p_cpu.net <-> s_p_bus;
		b3 : bus access p_cpu.net <-> p_a_bus;
		b4 : bus access a_cpu.net <-> p_a_bus;
	
	-- 为解决流延迟分析过程中出现的空指针异常而增添的代码--------------
	-- 方法1.完整地建模,声明系统中存在的所有端到端流(在flows中声明)
	flows
		etef2 : end to end flow s1.sensor_source -> c0 -> p.sink0; 
		etef3 : end to end flow s2.sensor_source -> c1 -> p.sink1;
	-- ---------------------------------------------------------------
	
	properties
		-- 为解决流延迟分析过程中出现的空指针异常而增添的代码----------
		-- 方法2.设定总线周期(在properties中设定)
		--	Period => 5ms applies to s_p_bus, p_a_bus;
		-- -----------------------------------------------------------
		
		actual_processor_binding => (reference (s1_cpu)) applies to s1;
		actual_processor_binding => (reference (s2_cpu)) applies to s2;
		actual_processor_binding => (reference (p_cpu)) applies to p;
		actual_processor_binding => (reference (a_cpu)) applies to a;
		
		actual_connection_binding => (reference (s_p_bus)) applies to c0;
		actual_connection_binding => (reference (s_p_bus)) applies to c1;
		actual_connection_binding => (reference (p_a_bus)) applies to c2;
		
		-- protocol that applies to the connections
		required_virtual_bus_class => (classifier (latency_cs::platform::generic_protocol)) applies to c0, c1, c2;
end integration.software_distributed;

1. 完整地建模,声明系统中存在的所有端到端流,实例化后进行分析:

成功生成流延迟分析报告:

报告内容如下所示:

2. 设定总线周期,避免排队延迟情况的出现

成功生成流延迟分析报告:

报告内容如下所示:

六、相关链接

 OSATE 开发者文档,展示了如何部署环境并拉取OSATE源码,如下:

Setting up an OSATE development environment — OSATE 2.13.0 documentation

OSATE 项目的源码也可以直接在github下载:

osate/osate2: Open Source AADL2 Tool Environment (github.com)

latency-case-study项目的源码也可以直接在github下载:

examples/latency-case-study at master · osate/examples (github.com)

 修改后的完整的项目代码可在此处下载。

【免费】latency-case-study项目修改版(资源-CSDN文库)

如有不当或错误之处,恳请您的指正,谢谢!!!

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

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

相关文章

视频列表:点击某个视频进行播放,其余视频全部暂停(同时只播放一个视频)

目录 需求实现原理实现代码页面展示 需求 视频列表&#xff1a;点击某个视频进行播放&#xff0c;其余视频全部暂停&#xff08;同时只播放一个视频&#xff09; 实现原理 在 video 标签添加 自定义属性 id (必须唯一)给每个 video 标签 添加 play 视频播放事件播放视频时&…

Android studio进入手机调试状态

首先usb插入电脑手机打开开发者模式进入点击就会在你的页面显示了

解决方案 | 便民提效,电子签助力医疗保障服务模式创新

2023年2月&#xff0c;中共中央、国务院印发了《数字中国建设整体布局规划》&#xff0c;并发出通知&#xff0c;要求各地区各部门结合实际认真贯彻落实。《规划》指出&#xff0c;提升数字化服务水平&#xff0c;加快推进“一件事一次办”&#xff0c;推进线上线下融合&#x…

玩转硬件之Micro:bit的玩法(二) —— 秒表

秒表是一种计时器&#xff0c;用于测量时间间隔的工具。它通常具有一个数字显示屏和一个或多个按钮&#xff0c;用于开始、停止和重置计时器。秒表可以精确地测量时间&#xff0c;通常以秒为单位&#xff0c;但有些也可以测量毫秒或微秒。它们被广泛用于体育比赛、科学实验、工…

ZYNQ实验---IQ调制实现SSB PART2

一、前言 本文实验在ZYNQ实验—IQ调制实现SSB PART1的基础上进行优化完善。 下图为IQ调制实现SSB PART1中设想实现设计框图 该图设计存在的几个问题&#xff1a; PC-PS的UDP传输存在丢包中断控制发包实际不适合流数据的传输采用的BRAM模块可以存储的空间较小&#xff0c;PC…

C++ 赋值运算重载,const成员,取地址及const取地址操作符重载

C 赋值运算重载&#xff0c;const成员&#xff0c;取地址及const取地址操作符重载 1. 赋值运算符重载1.1 运算符重载1.2 赋值运算符重载1.3 前置/--和后置/--重载 2. const成员3. 取地址及const取地址操作符重载 所属专栏&#xff1a;C“嘎嘎" 系统学习❤️ &#x1f680;…

智慧灌溉平台

1.知识百科 智慧灌溉是运用物联网、云计算、大数据等新一代信息技术&#xff0c;结合农业生产的实际需求&#xff0c;通过传感器采集土壤温湿度、光照强度等信息&#xff0c;利用无线传感网络传输到中央控制系统进行智能控制。智慧灌溉系统由传感器&#xff08;水位传感器&…

解决关于“由于找不到vcruntime140.dll无法继续执行代码”的问题

今天&#xff0c;我就来谈谈关于“由于找不到vcruntime140.dll无法继续执行代码”的问题&#xff0c;为大家提供4个解决方案。希望我的经验和见解能对大家有所帮助。 首先&#xff0c;我们要明确什么是vcruntime140.dll。简单来说&#xff0c;它是一个动态链接库文件&#xff…

进口跨境商城源码:高效、安全、可扩展的电商平台解决方案

电子商务的兴起为跨境贸易提供了前所未有的机会和挑战。在这个全球化的时代&#xff0c;跨境电商平台成为许多企业进军国际市场的首选。然而&#xff0c;搭建一个高效、安全、可扩展的进口跨境商城并非易事。 1. 解决方案概述 我们推出的 "进口跨境商城源码" 提供了一…

3-性能分析-android-基于Choreographer渲染机制详解

3-性能分析-android-基于Choreographer渲染机制详解 一:主线程运行机制的本质1> 引入 Vsync 之前2> 引入 Choreographer二: Choreographer 简介1> 从 Systrace 的角度来看 Choreogrepher 的工作流程2> Choreographer 的工作流程三:Choreographer 处理一帧的逻辑…

【AI视野·今日Sound 声学论文速览 第三十二期】Tue, 24 Oct 2023

AI视野今日CS.Sound 声学论文速览 Tue, 24 Oct 2023 Totally 20 papers &#x1f449;上期速览✈更多精彩请移步主页 Interesting: &#x1f4da;nvas3d, 基于任意录音和室内3D信息合成重建不同听角&#xff08;位置&#xff09;处的新的声音。(from apple cmu) website: htt…

CMake基础【学习笔记(八)】

声明此博客为转载 CMake基础 文章目录 CMake基础一、准备知识1.1 C的编译过程1.2 静态链接库和动态链接库1.3 为什么需要CMake1.3.1 g 命令行编译1.3.2 CMake简介 二、CMake基础知识2.1 安装2.2 第一个CMake例子2.3 语法基础2.3.1 指定版本2.3.2 设置项目2.3.3 添加可执行文件…

Python画图之皮卡丘

Python-turtle画出皮卡丘&#xff08;有趣小游戏&#xff09; 一、效果图二、Python代码 一、效果图 二、Python代码 import turtledef getPosition(x, y):turtle.setx(x)turtle.sety(y)print(x, y)class Pikachu:def __init__(self):self.t turtle.Turtle()t self.tt.pensi…

小样本分割的新视角,Learning What Not to Segment【CVPR 2022】

论文地址&#xff1a;Excellent-Paper-For-Daily-Reading/image-segmentation at main 类别&#xff1a;图像分割 时间&#xff1a;2023/11/01 摘要 目前背景&#xff1a;少样本分割 &#xff08;FSS&#xff09; 得到了广泛的发展。以前的大多数工作都在努力通过分类任务衍…

Linux C语言进阶-D5~D6指针及指针的运算

指针好处&#xff1a; 使程序更加间接、紧凑、高效 有效地表示复杂的数据结构 动态分配内存 得到多于一个的函数返回值 在C语言中&#xff0c;内存单元的地址称为指针&#xff0c;专门用来存放地址的变量&#xff0c;称为指针变量 在不影响理解的情况下&#xff0c;对地址、指…

gRPC之grpcui界面工具

1、grpcui界面工具 简单的说&#xff0c;就是gRPC中的postman&#xff0c;grpcui官方地址&#xff1a;https://github.com/fullstorydev/grpcui。 1.1 安装 go get -u github.com/fullstorydev/grpcui go install github.com/fullstorydev/grpcui/cmd/grpcuiv1.2.0[rootzsx …

VueX介绍和工作原理

一、VueX的作用 VueX就是在Vue中专门集中地管理数据的一个Vue插件。 在VueX中的数据不属于任何一个组件&#xff0c;所有的组价都可以访问和修改这个数据。 因此&#xff0c;当我们的多个组件依赖同一个状态&#xff08;如用户信息&#xff09;时&#xff0c;就可以使用VueX…

【Tomcat Servlet】如何在idea上部署一个maven项目?

目录 1.创建项目 2.引入依赖 3.创建目录 4.编写代码 5.打包程序 6.部署项目 7.验证程序 什么是Tomcat和Servlet? 以idea2019为例&#xff1a; 1.创建项目 1.1 首先创建maven项目 1.2 项目名称 2.引入依赖 2.1 网址输入mvnrepository.com进入maven中央仓库->地址…

Docker 学习路线 9:运行容器

要启动一个新的容器&#xff0c;我们使用 docker run 命令&#xff0c;后跟镜像名称。基本语法如下&#xff1a; docker run [选项] 镜像 [COMMAND] [ARG...] 例如&#xff0c;要运行官方的 Nginx 镜像&#xff0c;我们可以使用&#xff1a; docker run -d -p 8080:80 nginx…

Qt5 安装 phonon

Qt5 安装 phonon Qt5 安装 phonon问题描述安装组件 Qt5 安装 phonon 开发环境&#xff1a;Qt Creator 4.6.2 Based on Qt 5.9.6 问题描述 在运行 Qt5 项目时&#xff0c;显示错误&#xff1a; error: Unknown module(s) in QT: phonon这是缺少组件的原因&#xff0c;QT: pho…