{"id":114,"date":"2015-07-31T09:24:00","date_gmt":"2015-07-31T09:24:00","guid":{"rendered":"http:\/\/fila-lab.de\/?page_id=114"},"modified":"2023-11-26T19:12:04","modified_gmt":"2023-11-26T18:12:04","slug":"high-performance-library","status":"publish","type":"page","link":"https:\/\/fila-lab.de\/index.php\/our-work\/high-performance-library\/","title":{"rendered":"HighPerTimer"},"content":{"rendered":"\n<p><strong><em>finished<\/em><\/strong><\/p>\n\n\n<h2 style=\"text-align: center;\"><span class=\"our-work-title\"><span class=\"our-work-data\"><span lang=\"en-GB\">High Performance Timer<\/span><\/span> \u2013 High precision time keeping on Linux systems<\/span><\/h2>\n<p style=\"text-align: justify;\"><strong>Motivation.<\/strong>&nbsp;<span class=\"our-work-data\"><span lang=\"en-GB\">In contemporary high-speed communication systems, by modelling autonomous mobile robots or in industrial control environments, acquisition of the system time can occur hundred thousand times a second and even more frequently. So the time of this system time acquisition as well as the CPU costs for this must be kept as low as possible. However, during the implementation of any kind of time critical applications, a number of pitfalls on the level of OS can appear soon. Though the Linux OS has already proved itself suitable for embedding into many sizes of projects and offers the ideal development platform, in some applications Linux still shows itself not enough effective. <b>This project aims to solve those problems and improve accuracy of system calls for timing measurements along with reduced CPU <\/b><b>resources<\/b><b>. <\/b>While the time acquisition via Unix system interfaces costs up to 2 microseconds, the suggested solution provides time acquisition means with CPU costs of about 100 nsec and less on a standard PC platform and about 200 ns on ARM Cortex A series. The approach for precise timing is available on user-space beyond the standard C++ library. Additionally, the library possesses <span style=\"color: #353535;\">microsecond-precise process suspension and resuming <\/span><span style=\"color: #353535;\">functions. <\/span>This feature extends the horizon of time-critical applications in the industrial communications and automation, which can be implemented in high-level programming languages on Linux OS.<br \/>\n<\/span><\/span><\/p>\n<p><span class=\"our-work-data\"><span lang=\"en-GB\"><strong>Library desciptin.<\/strong> The <b>HPTimer<\/b> (High Performance Timer) and the corresponding library <b><i>HighPerTimer<\/i><\/b>&nbsp;present a simple interface for gathering time values from Linux user space. During the initialization stage HPTimer is assigned to the fastest and the most reliable time source available on the given platform. The pitfall here is different architectures use different timer hardware and the given library takes upon itself the identification of the platform and the timer source. Consequently, the further interaction by HPTimer occurs directly with time registers avoiding standard Linux system calls (e.g. <i>clock_gettime <\/i>or <i>gettimeofday<\/i>). On ARM Cortex A8\/A9\/A5 processors, for accessing time hardware, the library needs an additional device driver to be installed and loaded as a module beforehand, as the appropriate time registers are mapped into the protected kernel space. For PC platforms no special drivers are required.<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">The library provides the following features:<\/span><\/span><\/p>\n<ul style=\"padding-left: 1em; text-indent: -1em;\">\n<li style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">automatic detection of the reliable time hardware and ability to change the default time source inside the main routine;<\/span><\/span><\/li>\n<li style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">manipulation with time accuracy up to nanoseconds;<\/span><\/span><\/li>\n<li style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">precise sleep functions with reduced CPU usage and appropriate interrupt handlers of the sleeping thread;<\/span><\/span><\/li>\n<li style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">a set of mathematical and comparison operators of an HPTimer C++ object;<\/span><\/span><\/li>\n<li style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">support of Intel, AMD, VIA, ARM Cortex A8\/A9\/A5 processors.<\/span><\/span><\/li>\n<\/ul>\n<p><span class=\"our-work-data\"><b>Perfomance information.&nbsp;<\/b><\/span><span class=\"our-work-data\">Below the performance information of some processors is presented. In the table mean values of the cost of setting a timer are shown. Tests have been performed in a loop of 100 million values and possible peaks due to hardware interrupts have not been filtered.<\/span><\/p>\n<table class=\"our-work-data\" style=\"border: 1px solid; border-collapse: collapse; font-size: small;\">\n<tbody>\n<tr>\n<th style=\"border: 1px solid;\"><span style=\"font-size: small;\">Processor (CPU)<\/span><\/th>\n<th style=\"border: 1px solid;\">Software clock Frequency<\/th>\n<th style=\"border: 1px solid;\">Cost of system call, \u00b5sec<\/th>\n<th style=\"border: 1px solid;\">Cost of setting HPTimer, \u00b5sec<\/th>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">Intel\u00ae Core\u2122 i7-2600<\/td>\n<td style=\"border: 1px solid;\">1600 MHz<\/td>\n<td style=\"border: 1px solid;\">0.031<\/td>\n<td style=\"border: 1px solid;\">0.017<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">Intel\u00ae Core\u2122 i5-3337U<\/td>\n<td style=\"border: 1px solid;\">1800 MHz<\/td>\n<td style=\"border: 1px solid;\">0.044<\/td>\n<td style=\"border: 1px solid;\">0.019<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">AMD Opteron\u2122 4238<\/td>\n<td style=\"border: 1px solid;\">3300 MHz<\/td>\n<td style=\"border: 1px solid;\">0.061<\/td>\n<td style=\"border: 1px solid;\">0.031<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">AMD Athlon\u2122 X2 BE-2350<\/td>\n<td style=\"border: 1px solid;\">1000 MHz<\/td>\n<td style=\"border: 1px solid;\">1.117<\/td>\n<td style=\"border: 1px solid;\">1.063<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">VIA Nano X2 U4025<\/td>\n<td style=\"border: 1px solid;\">1067 MHz<\/td>\n<td style=\"border: 1px solid;\">0.102<\/td>\n<td style=\"border: 1px solid;\">0.038<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">ARM Cortex A8<\/td>\n<td style=\"border: 1px solid;\">24 MHz<\/td>\n<td style=\"border: 1px solid;\">1.262<\/td>\n<td style=\"border: 1px solid;\">0.391<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">ARM Cortex A9<\/td>\n<td style=\"border: 1px solid;\">32.768 KHz<sup>1<\/sup><\/td>\n<td style=\"border: 1px solid;\">&#8211;<sup>2<\/sup><\/td>\n<td style=\"border: 1px solid;\">0.508<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\">ARM Cortex A5<\/td>\n<td style=\"border: 1px solid;\">12 MHz<\/td>\n<td style=\"border: 1px solid;\">2.069<\/td>\n<td style=\"border: 1px solid;\">0.636<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">Table 1: Examples of costs of setting timer on different processors<\/span><\/span><\/p>\n<p style=\"text-align: justify; font-size: 10px;\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p style=\"text-align: justify; font-size: 10px;\"><span class=\"our-work-data\"><span lang=\"en-GB\"><sup>1<\/sup>HPTimer uses a 19 MHz clock instead<\/span><\/span><\/p>\n<p style=\"text-align: justify; font-size: 10px;\"><span class=\"our-work-data\"><span lang=\"en-GB\"><sup>2<\/sup>In the case of the ARM Cortex A9 processor, the system timer has 32.768 K?z frequency with 30.518 usec resolution respectively. In fact, it means that with the standard system call only intervals of more than 30 \u00b5sec can be tracked, even with the monotonic time source and CLOCK_MONOTONIC flag<\/span><\/span><\/p>\n<p style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">The important advantage of <i>HighPerTimer<\/i> is a significantly improved precision of sleep functions. In the context of this paper, the term \u201emiss\u201c of sleep times refers to a delayed wake up from the synchronous sleep call, whereby the quantity of this miss is the time difference between the real return time of sleep against the target wake-up time. Though in the&nbsp;version 2.6 of the Linux kernel, a redesign of timers took place, even in the 3.x kernel versions, this miss is still in the range of 50 \u00b5sec (for PC platform) and 100-400 \u00b5sec (for ARM processors). So often CPU-costly busy-waits are inserted into communication and control programs to assure precise protocol timings. At this point, the <i>HighPerTimer<\/i> can provide precise sleep functions, where the CPU overhead during the sleep keeps at 1-1.89&nbsp;% in contrary to 100 % of busy waits. At the same time the benefits of very accurate process resuming times on long waits are maintained. <\/span>Below the table of the comparison miss values is shown. It should be considered that for all methods the miss value depends on the sleep interval, so the Table 2 consists of two part, where sleep time is more then 1 msec and where is less. The measurements were performed on the Intel\u00ae Core\u2122 i7-2600 processor, for the calculating the mean value it was used a loop of 10000 steps and total performance time of measurements is equal about 830 minutes.<\/span><\/p>\n<table class=\"our-work-data\" style=\"border: 1px solid; border-collapse: collapse; font-size: small;\">\n<tbody>\n<tr>\n<th style=\"border: 1px solid;\" rowspan=\"2\"><\/th>\n<th style=\"border: 1px solid;\">Sleep time &gt;= 1 msec<\/th>\n<th style=\"border: 1px solid;\">Sleep time &lt; 1 msec<\/th>\n<th style=\"border: 1px solid;\" rowspan=\"2\">CPU usage<\/th>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\"><strong>Mean miss, \u00b5sec<\/strong><\/td>\n<td style=\"border: 1px solid;\"><strong>Mean miss, \u00b5sec<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\"><strong>System sleep<\/strong><\/td>\n<td style=\"border: 1px solid;\">61.985<\/td>\n<td style=\"border: 1px solid;\">50.879<\/td>\n<td style=\"border: 1px solid;\">0.016 %<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\"><strong>Busy-waiting loop<\/strong><\/td>\n<td style=\"border: 1px solid;\">0.160<\/td>\n<td style=\"border: 1px solid;\">0.070<\/td>\n<td style=\"border: 1px solid;\">99.681 %<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid;\"><strong>HPTimer sleep<\/strong><\/td>\n<td style=\"border: 1px solid;\">0.258<\/td>\n<td style=\"border: 1px solid;\">0.095<\/td>\n<td style=\"border: 1px solid;\">1.892 %<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: justify;\"><span class=\"our-work-data\"><span lang=\"en-GB\">Table 2: The comparison of miss values of different sleep methods<\/span><\/span><\/p>\n<p><span class=\"our-work-data\"><span lang=\"en-GB\"> <strong>Project manager \u2013 <\/strong><\/span><\/span><\/p>","protected":false},"excerpt":{"rendered":"<p>finished High Performance Timer \u2013 High precision time keeping on Linux systems Motivation.&nbsp;In contemporary high-speed communication systems, by modelling autonomous mobile robots or in industrial control environments, acquisition of the system time can occur hundred thousand times a second and even more frequently. So the time of this system time acquisition as well as the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":9,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/pages\/114"}],"collection":[{"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/comments?post=114"}],"version-history":[{"count":29,"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/pages\/114\/revisions"}],"predecessor-version":[{"id":1104,"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/pages\/114\/revisions\/1104"}],"up":[{"embeddable":true,"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/pages\/9"}],"wp:attachment":[{"href":"https:\/\/fila-lab.de\/index.php\/wp-json\/wp\/v2\/media?parent=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}