<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style="--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>
GitLab
</title>
<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>
<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style="font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";">
<div class="content">
<p class="details" style="font-style: italic; color: #626168;">
<a href="https://gitlab.rtems.org/sebhub">Sebastian Huber</a> created an issue: <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5538">#5538</a>
</p>
<p>
Assignee: Sebastian Huber
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">It needs to be specified what the limits of <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">CLOCK_MONOTONIC</code> should be and what happens if the limit is reached if it can be reached. This clock is also known as the <em>uptime</em>.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">This issue is related to <a href="https://users.rtems.org/t/rtems-time-representation-limits-or-rtems-end-of-time/483" rel="nofollow noreferrer noopener" target="_blank" style="margin-top: 0;">https://users.rtems.org/t/rtems-time-representation-limits-or-rtems-end-of-time/483</a> which talks about <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">CLOCK_REALTIME</code>.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">The <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">CLOCK_MONOTONIC</code> is a clock provided by RTEMS which measures the time since an unspecified starting point. In contrast to <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">CLOCK_REALTIME</code>, this clock cannot be set. It may be affected by incremental adjustments for example carried out by the NTP or the use of a PPS signal. The current starting point is one second:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre data-canonical-lang="c" class="code highlight js-syntax-highlight language-c" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" lang="c" style="margin-top: 0;"><span class="k" style="margin-top: 0;">static</span> <span class="k">struct</span> <span class="n">timehands</span> <span class="n">th0</span> <span class="o">=</span> <span class="p">{</span></span>
<span id="LC2" class="line" lang="c"> <span class="cm" style="margin-top: 0;">/* ... */</span></span>
<span id="LC3" class="line" lang="c"> <span class="p" style="margin-top: 0;">.</span><span class="n">th_scale</span> <span class="o">=</span> <span class="p">(</span><span class="kt">uint64_t</span><span class="p">)</span><span class="o">-</span><span class="mi">1</span> <span class="o">/</span> <span class="mi">1000000</span><span class="p">,</span></span>
<span id="LC4" class="line" lang="c"> <span class="p" style="margin-top: 0;">.</span><span class="n">th_offset</span> <span class="o">=</span> <span class="p">{</span> <span class="p">.</span><span class="n">sec</span> <span class="o">=</span> <span class="mi">1</span> <span class="p">},</span></span>
<span id="LC5" class="line" lang="c"> <span class="cm" style="margin-top: 0;">/* ... */</span></span>
<span id="LC6" class="line" lang="c"><span class="p" style="margin-top: 0;">};</span></span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Due to performance reasons, a snapshot is also available through this object:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre data-canonical-lang="c" class="code highlight js-syntax-highlight language-c" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" lang="c" style="margin-top: 0;"><span class="cp" style="margin-top: 0;">#define time_uptime _Timecounter_Time_uptime</span></span>
<span id="LC2" class="line" lang="c"><span class="k" style="margin-top: 0;">volatile</span> <span class="kt">time_t</span> <span class="n">time_uptime</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span></span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Declared as:</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre data-canonical-lang="c" class="code highlight js-syntax-highlight language-c" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" lang="c" style="margin-top: 0;"><span class="cm" style="margin-top: 0;">/**</span></span>
<span id="LC2" class="line" lang="c"><span class="cm" style="margin-top: 0;"> * @brief The uptime in seconds.</span></span>
<span id="LC3" class="line" lang="c"><span class="cm" style="margin-top: 0;"> *</span></span>
<span id="LC4" class="line" lang="c"><span class="cm" style="margin-top: 0;"> * For compatibility with the FreeBSD network stack the initial value is one</span></span>
<span id="LC5" class="line" lang="c"><span class="cm" style="margin-top: 0;"> * second.</span></span>
<span id="LC6" class="line" lang="c"><span class="cm" style="margin-top: 0;"> */</span></span>
<span id="LC7" class="line" lang="c"><span class="k" style="margin-top: 0;">extern</span> <span class="k">volatile</span> <span class="kt">time_t</span> <span class="n">_Timecounter_Time_uptime</span><span class="p">;</span></span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">This used to be a 32-bit signed integer for performance reasons, however, it was changed to address a code analysis finding here: <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5204" title="kern_tc.c: Uses int32_t not time_t (time overflow)" class="gfm gfm-issue" data-original="#5204" data-link="false" data-link-reference="false" data-issue="28923" data-project="26" data-iid="5204" data-namespace-path="rtems/rtos/rtems" data-project-path="rtems/rtos/rtems" data-issue-type="issue" data-container="body" data-placement="top" data-reference-type="issue" style="margin-top: 0;">#5204</a>.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">It needs to be clarified what the limits of <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">CLOCK_MONOTONIC</code> should be:</p>
<ol dir="auto" style="text-align: initial; margin: 0; padding: 0;">
<li style="margin-top: 0; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">With a signed 32-bit integer, the uptime is limited to about 68 years. If the system reaches this limit, then the uptime overflows and yields a negative number. In this case, the calculations involving time values are undefined or implementation-defined in C.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">With an unsigned 32-bit integer, the uptime is limited to about 136 years. If the limit is reached, then modulo arithmetic applies. There are issues, if the time value is assigned to 32-bit singed integer. The libbsd network stack requires a signed integer for <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">time_uptime</code>.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">With a 64-bit integer there are not practical limits. 32-bit targets may have performance issues. 32-bit targets may have correctness issues in the instant the time <em style="margin-top: 0;">t</em> changes from any time which satisfies <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; white-space: pre-wrap; overflow-wrap: break-word; word-break: keep-all; padding: 0.125rem 0.25rem;">t % (UINT32MAX + 1) == UINT32MAX</code> to the next value.</li>
</ol>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5538">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/2-bfvnyrxm638f55yhz2v3ll6cq/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5538 at 1774923251
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5538"}}</script>
</p>
</div>
</body>
</html>