<p>Anonymous Coward (1001664) has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/27358">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: Ia0eeed51e0952c66a9a9f25a90105fe471ffa70e<br>Signed-off-by: Xiang Wang <wxjstz@126.com><br>---<br>M src/arch/riscv/include/arch/smp/smp.h<br>1 file changed, 30 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/58/27358/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/arch/riscv/include/arch/smp/smp.h b/src/arch/riscv/include/arch/smp/smp.h</span><br><span>index bdf8ec4..2672595 100644</span><br><span>--- a/src/arch/riscv/include/arch/smp/smp.h</span><br><span>+++ b/src/arch/riscv/include/arch/smp/smp.h</span><br><span>@@ -1,6 +1,8 @@</span><br><span> /*</span><br><span>  * This file is part of the coreboot project.</span><br><span>  *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2018 HardenedLinux.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span>  * This program is free software; you can redistribute it and/or modify</span><br><span>  * it under the terms of the GNU General Public License as published by</span><br><span>  * the Free Software Foundation; version 2 of the License.</span><br><span>@@ -10,3 +12,31 @@</span><br><span>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span>  * GNU General Public License for more details.</span><br><span>  */</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 <arch/smp/atomic.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/smp/spinlock.h></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 not required, if other hart not need to wait for</span><br><span style="color: hsl(120, 100%, 40%);">+  *      //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/27358">change 27358</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/27358"/><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: Ia0eeed51e0952c66a9a9f25a90105fe471ffa70e </div>
<div style="display:none"> Gerrit-Change-Number: 27358 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Anonymous Coward (1001664) </div>