<p>Anonymous Coward (1001664) has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/27348">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">riscv: temporarily block multiple-threads<br><br>Sometime needs to temporarily block multiple-threads.<br>So add this code.<br><br>Change-Id: Iedf58db6cddd44cfc17f5dfb3a5ccc0e12a49536<br>Signed-off-by: Xiang Wang <wxjstz@126.com><br>---<br>A src/arch/riscv/include/smp.h<br>1 file changed, 56 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/48/27348/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/arch/riscv/include/smp.h b/src/arch/riscv/include/smp.h</span><br><span>new file mode 100644</span><br><span>index 0000000..6253768</span><br><span>--- /dev/null</span><br><span>+++ b/src/arch/riscv/include/smp.h</span><br><span>@@ -0,0 +1,56 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (c) 2013, The Regents of the University of California (Regents).</span><br><span style="color: hsl(120, 100%, 40%);">+ * All Rights Reserved.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Redistribution and use in source and binary forms, with or without</span><br><span style="color: hsl(120, 100%, 40%);">+ * modification, are permitted provided that the following conditions are met:</span><br><span style="color: hsl(120, 100%, 40%);">+ * 1. Redistributions of source code must retain the above copyright</span><br><span style="color: hsl(120, 100%, 40%);">+ *    notice, this list of conditions and the following disclaimer.</span><br><span style="color: hsl(120, 100%, 40%);">+ * 2. Redistributions in binary form must reproduce the above copyright</span><br><span style="color: hsl(120, 100%, 40%);">+ *    notice, this list of conditions and the following disclaimer in the</span><br><span style="color: hsl(120, 100%, 40%);">+ *    documentation and/or other materials provided with the distribution.</span><br><span style="color: hsl(120, 100%, 40%);">+ * 3. Neither the name of the Regents nor the</span><br><span style="color: hsl(120, 100%, 40%);">+ *    names of its contributors may be used to endorse or promote products</span><br><span style="color: hsl(120, 100%, 40%);">+ *    derived from this software without specific prior written permission.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,</span><br><span style="color: hsl(120, 100%, 40%);">+ * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,</span><br><span style="color: hsl(120, 100%, 40%);">+ * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF</span><br><span style="color: hsl(120, 100%, 40%);">+ * REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,</span><br><span style="color: hsl(120, 100%, 40%);">+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR</span><br><span style="color: hsl(120, 100%, 40%);">+ * PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED</span><br><span style="color: hsl(120, 100%, 40%);">+ * HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE</span><br><span style="color: hsl(120, 100%, 40%);">+ * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef _SMP_H</span><br><span style="color: hsl(120, 100%, 40%);">+#define _SMP_H</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <atomic.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define barrier() {asm volatile ("fence" ::: "memory"); }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * If your code needs to temporarily block multiple-threads, do this:</span><br><span style="color: hsl(120, 100%, 40%);">+ *      if(RUNNING_ON_HART(active)) // `active` is hartid of working thread</span><br><span style="color: hsl(120, 100%, 40%);">+ *      {</span><br><span style="color: hsl(120, 100%, 40%);">+ *          ... single-threaded work ...</span><br><span style="color: hsl(120, 100%, 40%);">+ *      }</span><br><span style="color: hsl(120, 100%, 40%);">+ *      SMP_SYNC();</span><br><span style="color: hsl(120, 100%, 40%);">+ *      //`SMP_SYNC` is optional.</span><br><span style="color: hsl(120, 100%, 40%);">+ *      // if other hart need to wait for the single-threaded work to complete.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  ... multi-threaded work ...</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define RUNNING_ON_HART(active) ((active) == read_csr(mhartid))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define SMP_SYNC()  do {\</span><br><span style="color: hsl(120, 100%, 40%);">+static int counter;\</span><br><span style="color: hsl(120, 100%, 40%);">+atomic_add(&counter, 1);\</span><br><span style="color: hsl(120, 100%, 40%);">+do { barrier(); } while (counter < CONFIG_HART_NUM);\</span><br><span style="color: hsl(120, 100%, 40%);">+} while (0)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif //_SMP_H</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/27348">change 27348</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/27348"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Iedf58db6cddd44cfc17f5dfb3a5ccc0e12a49536 </div>
<div style="display:none"> Gerrit-Change-Number: 27348 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Anonymous Coward (1001664) </div>