Anonymous Coward (1001664) has uploaded this change for review.

View Change

riscv: temporarily block multiple-threads

Sometime needs to temporarily block multiple-threads.
So add this code.

Change-Id: Ia0eeed51e0952c66a9a9f25a90105fe471ffa70e
Signed-off-by: Xiang Wang <wxjstz@126.com>
---
M src/arch/riscv/include/arch/smp/smp.h
1 file changed, 30 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/58/27358/1
diff --git a/src/arch/riscv/include/arch/smp/smp.h b/src/arch/riscv/include/arch/smp/smp.h
index bdf8ec4..2672595 100644
--- a/src/arch/riscv/include/arch/smp/smp.h
+++ b/src/arch/riscv/include/arch/smp/smp.h
@@ -1,6 +1,8 @@
/*
* This file is part of the coreboot project.
*
+ * Copyright (C) 2018 HardenedLinux.
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
@@ -10,3 +12,31 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
+#ifndef _SMP_H
+#define _SMP_H
+
+#include <arch/smp/atomic.h>
+#include <arch/smp/spinlock.h>
+
+ /*
+ * If your code needs to temporarily block multiple-threads, do this:
+ * if(RUNNING_ON_HART(active)) // `active` is hartid of working thread
+ * {
+ * ... single-threaded work ...
+ * }
+ * SMP_SYNC();
+ * //`SMP_SYNC` is not required, if other hart not need to wait for
+ * //the single-threaded work to complete.
+ * ... multi-threaded work ...
+ */
+
+
+#define RUNNING_ON_HART(active) ((active) == read_csr(mhartid))
+
+#define SMP_SYNC() do {\
+static int counter;\
+atomic_add(&counter, 1);\
+do { barrier(); } while (counter < CONFIG_HART_NUM);\
+} while (0)
+
+ #endif //_SMP_H

To view, visit change 27358. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia0eeed51e0952c66a9a9f25a90105fe471ffa70e
Gerrit-Change-Number: 27358
Gerrit-PatchSet: 1
Gerrit-Owner: Anonymous Coward (1001664)