<!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/DonutAnees">Mohammed Anees</a> created an issue: <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5512">#5512</a>
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<h2 id="user-content-summary" dir="auto" style="margin-top: 0; margin-bottom: 10px;" align="initial">Summary<a href="#summary" aria-label="Link to heading 'Summary'" data-heading-content="Summary" class="anchor" style="margin-top: 0;"></a>
</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">There was this particular FIXME which wanted to implement the cache operations specific to each I386 CPU.</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" 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="plaintext" style="margin-top: 0;">/*</span>
<span id="LC2" class="line" lang="plaintext"> * CACHE MANAGER: The following functions are CPU-specific.</span>
<span id="LC3" class="line" lang="plaintext"> * They provide the basic implementation for the rtems_* cache</span>
<span id="LC4" class="line" lang="plaintext"> * management routines. If a given function has no meaning for the CPU,</span>
<span id="LC5" class="line" lang="plaintext"> * it does nothing by default.</span>
<span id="LC6" class="line" lang="plaintext"> *</span>
<span id="LC7" class="line" lang="plaintext"> * FIXME: The routines below should be implemented per CPU,</span>
<span id="LC8" class="line" lang="plaintext"> *        to accomodate the capabilities of each.</span>
<span id="LC9" class="line" lang="plaintext"> */</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">With respect to this I am proposing the following changes;</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;">
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/bsps/i386/pc386/start/cpuModel.S?ref_type=heads#L101" style="margin-top: 0;">https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/bsps/i386/pc386/start/cpuModel.S?ref_type=heads#L101</a> the existing code here calls the CPUID instruction in the order of CPUID ( EAX = 4), (EAX = 1), (EAX = 0). im not sure if there is a technical reason for this order. CPUID(EAX=0) returns the maximum supported input value for the CPUID instruction, so maybe it would be safer to call that first and use it to check whether the leaf value we are querying is actually supported. The Intel manual mentions that if the requested leaf is larger than what the processor supports, it returns the data for the highest leaf instead of failing, so we might end up writing incorrect data into some of these fields.</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">To verify if the CPU supports the CLFLUSHOPT instruction, leaf 7 is required, this CLFLUSHOPT is used for the cache operation. Adding a global for this in cpuModel.S</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/bsps/i386/include/libcpu/cpuModel.h?ref_type=heads" style="margin-top: 0;">https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/bsps/i386/include/libcpu/cpuModel.h?ref_type=heads</a> macros for detecting CPU capabilities - x86_has_wbinvd, x86_has_clflush, x86_has_clflushopt, x86_has_sse2 ( useful to identify mfence can be used for memory barrier ), x86_get_cache_line_size ( I just am not sure if CPUID operation is not supported what should be the default cache line size be here? )</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">finally <a href="https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/bsps/i386/shared/cache/cache.c?ref_type=heads" style="margin-top: 0;">https://gitlab.rtems.org/rtems/rtos/rtems/-/blob/main/bsps/i386/shared/cache/cache.c?ref_type=heads</a>
<ol style="margin: 0; padding: 0;">
<li style="margin-top: 0; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0 0 1rem;"><strong style="font-weight: 600; margin-top: 0;"><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;">_CPU_cache_flush_line</code> -</strong> added</p>
<p style="color: #3a383f; margin: 0 0 1rem;">no fence here for this, just flushes one cache line at the address, check if CLFLUSHOPT/CLFLUSH is available and execute whatever is available, caller which verify if atleast CLFLUSH is available</p>
</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0 0 1rem;"><strong style="font-weight: 600; margin-top: 0;"><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;">_CPU_cache_flush_data_range</code> -</strong> added</p>
<p style="color: #3a383f; margin: 0 0 1rem;">for the provided range, it calls <strong style="font-weight: 600; margin-top: 0;"><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;">_CPU_cache_flush_line</code></strong> with fence, checks if atleast CLFLUSH is available, if not checks if <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;">wbinvd</code> is available, if not returns</p>
</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0 0 1rem;"><strong style="font-weight: 600; margin-top: 0;"><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;">_CPU_cache_invalidate_data_range</code> and <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;">_CPU_cache_invalidate_instruction_range</code></strong></p>
<p style="color: #3a383f; margin: 0 0 1rem;">as for these from what I read online flush, will also invalid at every level, therefore just making them call <strong style="font-weight: 600; margin-top: 0;"><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;">_CPU_cache_flush_data_range</code> (needs discussion)</strong></p>
</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">
<p style="color: #3a383f; margin: 0 0 1rem;">Removed the following since they were required before adding <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;">CPU_CACHE_SUPPORT_PROVIDES_RANGE_FUNCTIONS</code>, with them now available not needed anymore</p>
<ul style="margin: 0 0 1rem; padding: 0;">
<li style="margin-top: 0; line-height: 1.6em; margin-left: 25px; padding-left: 3px;">CPU_cache_flush_1_data_line</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">_CPU_cache_invalidate_1_data_line</li>
<li style="line-height: 1.6em; margin-left: 25px; padding-left: 3px;">_CPU_cache_invalidate_1_instruction_line</li>
</ul>
</li>
</ol>
</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/5512">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-eq0mp8755ku1yrbrcbqnala87/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/5512 at 1772738051
</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/5512"}}</script>


</p>
</div>
</body>
</html>