<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>Worst-Case Time Disparity Analysis of Message Synchronization in ROS</title></titleStmt>
			<publicationStmt>
				<publisher>IEEE</publisher>
				<date>12/01/2022</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10512397</idno>
					<idno type="doi">10.1109/RTSS55097.2022.00014</idno>
					<title level='j'>2022 IEEE Real-Time Systems Symposium (RTSS)</title>
<idno></idno>
<biblScope unit="volume"></biblScope>
<biblScope unit="issue"></biblScope>					

					<author>Ruoxiang Li</author><author>Nan Guan</author><author>Xu Jiang</author><author>Zhishan Guo</author><author>Zheng Dong</author><author>Mingsong Lv</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[The selected set is the one with the smallest time disparity among all regular message sets including the pivot.]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><p>Definition 3 (Selected Set). Let &#923; be the set of all regular message sets consisting of messages currently in queues (either arrived or predicted) and including the pivot. The selected set has the smallest time disparity among all elements in &#923;.</p><p>If multiple elements in &#923; all have the smallest time disparity, the selected set S = {m 1 , ..., m N } must satisfy the following condition: there does not exist another element S &#8242; = {m &#8242; 1 , ..., m &#8242; N } in &#923; s.t. (i) &#8710;(S &#8242; ) = &#8710;(S) and (ii) &#8707;m i &#8712; S : t(m &#8242; i ) &lt; t(m i ). If only one regular message set in &#923; has the smallest time disparity, it is clearly the selected set. If multiple regular message sets in &#923; all have the smallest time disparity, according to the second half of Definition 3, the one with as-early-aspossible messages is the selected set. For example, in Fig. <ref type="figure">3</ref>, among all regular message sets including the pivot m 1  4 , the two sets S = {m 2  1 , m 2 2 , m 3 3 , m<ref type="foot">foot_0</ref> 4 } and S &#8242; = {m 2 1 , m 2 2 , m 4 3 , m 1 4 } both have the smallest time disparity 6. According to the second half of Definition 3, S &#8242; is not the selected set because there exists S containing m 3  3 which is earlier than its correspondence m 4  3 in S &#8242; . S is the selected set, because there is no other regular message set containing the pivot has the same time disparity as S and satisfies &#8707;m i &#8712; S : t(m &#8242; i ) &lt; t(m i ). Although the selected set is defined as selecting among all regular message sets including the pivot, which could be exponentially many, it is found by a polynomial-time procedure in its implementation in the ROS Message Synchronizer. As we aim to provide a high-level model focusing on what is the result generated by the policy, but not how the results are obtained, we will not further discuss details of its polynomialtime implementation in ROS.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>D. The ApproximateTime Policy</head><p>Algorithm 1 shows the pseudo-code for the Approximate-Time policy to select and publish the output message set when a new message arrives. Suppose at the current moment Q i originally has k messages {m 1 i , ..., m k i }, where m k i is a predicted message (recall that the last message in a queue must be a predicted message). The algorithm first updates Q i with the newly arrived message m i (Line 1 to 3), by discarding the original predicted message m k i , putting the newly arrived message to the end of Q i as m k i , and finally generating a new predicted message</p><p>Next, the algorithm repeatedly checks whether each queue currently contains at least one arrived message or not. If not, i.e., some queue only has a predicted message, it is impossible to publish an output message set anyway, so the algorithm simply stops without any further checking. If yes, it first sets the current pivot according to Definition 2 (Line 5). Then it checks whether all predicted messages' timestamps are no earlier than t(m P ) (Line 6). If not, the algorithm returns without publishing any output message set (Line 15), the intuition behind which is explained as follows. If a predicted message m k in some queue Q k has t(m k ) &lt; t(m P ), then the timestamps of the arrived messages (if any) in this queue are even smaller, so this predicted message has the closest timestamp to the pivot m P . Therefore, the next message to arrive in this queue has a chance to make a better output message set than the existing arrived messages in Q k , so it makes sense to wait until the next message of Q k arrives (and its actual timestamp is revealed) to make the decision 1 . If all predicted messages' timestamps are no earlier than t(m P ), the algorithm will find the selected set S according to Definition 3 (Line 7), and checks whether all messages in S are arrived messages (Line 8). If not, i.e., S contains at least one predicted message, S cannot be published and the algorithm stops (Line 13). If yes, S is published as an output message set (Line 9). After that, for each queue Q j , the corresponding message m j in S and all messages in Q j before m j are discarded.</p><p>From Algorithm 1, we can see that under the Approximate-Time policy, the output message sets are decided based on the messages' timestamps, but not their arrival times. The arrival Lemma 7. Let S PUB = {m 1 , ..., m N } be an output message set published at time t. The required size of</p><p>Proof. If a message is in Q i at time t, its timestamp is no later than t -D B i . On the other hand, the timestamp of m i is no earlier than a(m 1 i ) -D W i . Therefore, the total length of the time interval to generate messages that are after m 1 i and have arrived at</p><p>Lemma 8. Let S PUB = {m 1 , ..., m N } be an output message set published at time t and m P &#8712; S PUB is the pivot. Then for each m i &#8712; S PUB and m 1 i is the corresponding earliest message in Q i , we have</p><p>where &#8710; denotes the RHS of <ref type="bibr">(12)</ref>.</p><p>Proof. By Theorem 1, for each m j &#8712; S PUB , we know</p><p>On the other hand, we also have</p><p>Since m P &#8712; S PUB , the lemma is proved.</p><p>Lemma 9. Let S PUB = {m 1 , ..., m N } be an output message set published at time t and m P is the pivot in S PUB , then</p><p>Proof. Let t &#8242; denote the earliest time point at which each nonpivot contains at least one arrived message with timestamp larger than t(m P ). By the definition of t &#8242; , some message arrives at t &#8242; and thus Algorithm 1 is executed at t &#8242; . We will first prove S PUB is published no later than t &#8242; . We prove this by contradiction, assuming S PUB is published after t &#8242; . By the definition of t &#8242; , the while-condition in Line 4 and the if-condition in Line 6 in Algorithm 1 are both true, so the selected set at t &#8242; must not be S PUB (otherwise S PUB is published at t &#8242; ). Let S be the selected set at t &#8242; . First, S does not contain any predicted message, since for each Q i there exists an arrived message with timestamp later than t(m P ) (so the predicted message is "further away" from the m P than this arrived message). Therefore, the selected set S must be published, so the pivot m P must not be in S (since the same message cannot be included in two published output message sets). Therefore, for the queue of m P , S includes a message after m P . After S is published, all messages before the published message in S are discarded, and in particular, m P is discarded, which contradicts that m P is in S PUB which is published after t &#8242; . Therefore, our assumption is false, so S PUB is published no later than t &#8242; , i.e., t &#8804; t &#8242; . We assume message m &#8242; i of Q i arrived at t &#8242; and triggers the execution of Algorithm 1, so m &#8242; i is the first message in</p><p>, and since t &#8804; t &#8242; , the lemma is proved. Theorem 2. The required size of Q i for any published output message set is upper bounded by</p><p>where &#8710; denotes the RHS of <ref type="bibr">(12)</ref>.</p><p>Proof. The theorem is proved by combining Lemma 7, Lemma 9 and Lemma 8.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>VI. EXPERIMENTS</head><p>We conduct experiments to both validate our high-level model of the ApproximateTime policy and evaluate the analysis precision of the time disparity bound in Theorem 1. The source codes of all experiments are anonymously available online at <ref type="url">https:// github.com/</ref> ruoxianglee/ synchronizer.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>A. Model Validation</head><p>We implement Algorithm 1 (called our implementation) in the Message Filter package of ROS2 (the Dashing version) and let it run in parallel with the original implementation of the Ap-proximateTime policy in ROS2. We implement Algorithm 1 in a straightforward way, without any performance optimization, to reduce the chance of introducing implementation errors. When a new message arrives at the Message Synchronizer, our implementation and the original implementation will update their own queues, select and publish the output message set independently. We compare all the output message sets published in the two implementations to see if they are the same. We run the experiments on an Intel i7 desktop computer with ROS2 Dashing installed on Ubuntu 18.04, using artificial input messages generated using timers with different settings, including different number of input channels (from 2 to 9, as currently the ROS Message Filter supports up to 9 input channels), different timestamp separation of each channel (T B i chosen between 10ms and 100ms, and the ratio between T B i and T W i chosen between 1 and 1.8). For the experiments in each setting, the delay experienced by the messages randomly varies between 1ms and 40ms. We in total conduct experiments with 700 different settings, and run the system for 0.5 hours in each setting. In all these experiments, the output message sets produced by our implementation and the original implementation are exactly the same. Besides artificial input messages, we also conduct experiments with sensor data inputs generated by the SVL simulator <ref type="bibr">[13]</ref> (including camera, LiDAR and IMU sensors in SVL, with different frequency settings), where the outputs of the two implementations are also the same. These experiments justify the correctness of our model with high confidence. software development, <ref type="bibr">[21]</ref> proposes a multipurpose lowoverhead framework for tracing ROS application. Some work aimed to improve the real-time capability of ROS from the system architecture perspective. <ref type="bibr">[22]</ref> presented a real-time ROS architecture for separately executing real-time and non-real-time tasks on a integrated OS environment with multi-core processors. <ref type="bibr">[23]</ref> proposed an offline scheduling framework for ROS considering both ROS scheduling restrictions and CPU/GPU coordination mechanism. <ref type="bibr">[24]</ref> presented a priority-based message transmission mechanism to reduce the worst-case execution time for node processing and inserting a sync node to harmonize the frequencies of different sensor data to improve the time disparity. In <ref type="bibr">[25]</ref>, a fixed-priority based DAG scheduling framework was proposed with endto-end latency guarantees. The authors also introduced a synchronization mechanism to reduce the time disparity, but their work is based on measurement for the specific case but does not provide any formal analysis.</p><p>Some recent work has been done on formal real-time performance analysis of ROS2. <ref type="bibr">[26]</ref>, <ref type="bibr">[27]</ref> modeled the singlethread Executor in ROS2 and studied response time analysis of processing chains executing on it. <ref type="bibr">[28]</ref> redesigns the ROS2 executor with a fixed priority assignment policy to overcome the limitations of the default scheduling strategy of ROS2, and analyze the end-to-end latency based on the proposed scheduling policy. <ref type="bibr">[29]</ref> proposes an automatic latency manager and apply existing real-time scheduling theory to latency control of the critical callback chains in ROS2 applications, which adaptively estimates and adjusts the scheduling parameters without the user's involvement. In <ref type="bibr">[30]</ref>, the authors take both the starvation freedom and execution-time variance of the default ROS2 scheduler into consideration, and propose a more accurate response time analysis for processing chains. <ref type="bibr">[31]</ref> presents two new executors based on the thread dispatch model and producer-consumer model and developed corresponding response time analysis techniques. The above work all focus on the executor component in ROS, while in this paper we consider another important component: the Message Synchronizer.</p><p>Past work on real-time scheduling and analysis studied different real-time performance metrics, such as response time <ref type="bibr">[32]</ref>, <ref type="bibr">[33]</ref>, tardiness <ref type="bibr">[34]</ref> and data freshness <ref type="bibr">[35]</ref>. However, existing analysis and design techniques developed oriented to these constraints do not apply to the analysis of time disparity studied in this paper.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>VIII. CONCLUSION</head><p>In this paper, we model the ApproximateTime message synchronization policy in ROS and formally analyze the worst-case time disparity of their output message sets. We conduct experiments to evaluate the precision of the developed time disparity upper bound against the maximal observed time disparity in real execution, and compare them with the synchronization policy in Apollo CyberRT. Experiment results show that our analysis has good precision and the synchronization policy in ROS greatly outperforms Apollo CyberRT in terms of both observed worst-case time disparity and the theoretical bound. This is the first step towards the analytical study of the data synchronization in multi-sensor data fusion regarding the worst-case time disparity metrics, and many problems along this direction are still open. For example, the required queue size bound derived in this paper is only to show that our time disparity analysis is applicable without assuming infinite queue sizes, but it is unclear whether we could develop tighter bound than that, which will be a topic for our future work. We will also study how to improve the design and implementation of the ROS Message Synchronizer for average-case time disparity performance while maintaining the same (or even better) worst-case time disparity bound. For an arbitrary slave queue Q i (2 &#8804; i &#8804; N ), let m &#8242; i be the next message after m i . We have</p><p>Combing ( <ref type="formula">14</ref>)-( <ref type="formula">17</ref>), we have</p><p>&#8226; If t(m 1 ) &gt; t(m i ), by <ref type="bibr">(18)</ref>, we have</p><p>&#8226; If t(m 1 ) &#8804; t(m i ), by <ref type="bibr">(18)</ref>, we have</p><p>The theorem can be proved by combining these two cases.</p></div><note xmlns="http://www.tei-c.org/ns/1.0" place="foot" n="1" xml:id="foot_0"><p>If the checking of Line 6 is removed, the selected set includes a predicted message and thus cannot be published anyway. Therefore, removing this checking (i.e., removing Line 6, 14 and 15) actually does not change the result of Algorithm 1. However, the checking in Line 6 guarantees the existence of m Y i when finding the selected set as will be discussed in the Section IV, so we keep it in our abstract model.</p></note>
		</body>
		</text>
</TEI>
