diff --git a/repos/dde_uos-intel-gpgpu/src/virt/rpc.cc b/repos/dde_uos-intel-gpgpu/src/virt/rpc.cc index 852bef3ece..fcffc82525 100644 --- a/repos/dde_uos-intel-gpgpu/src/virt/rpc.cc +++ b/repos/dde_uos-intel-gpgpu/src/virt/rpc.cc @@ -73,11 +73,8 @@ void Session_component::start_task(unsigned long kconf) _global_sched->update_vgpu(&vgpu); } - // trigger sched if its idle - if(_global_sched->is_idle()) - { - _global_sched->handle_gpu_event(); - } + // trigger sched + _global_sched->trigger(); /*static int id = 0; Genode::log("Kernel ", id); diff --git a/repos/dde_uos-intel-gpgpu/src/virt/scheduler.h b/repos/dde_uos-intel-gpgpu/src/virt/scheduler.h index 2a2be72aac..b5474dbd40 100644 --- a/repos/dde_uos-intel-gpgpu/src/virt/scheduler.h +++ b/repos/dde_uos-intel-gpgpu/src/virt/scheduler.h @@ -35,9 +35,6 @@ namespace gpgpu_virt { Scheduler& operator=(const Scheduler&) = delete; Scheduler& operator=(Scheduler&&) = delete; - public: - Scheduler() : strat(), _curr_vgpu(nullptr), idle(true) { } - /** * @brief Switch to new vGPU's context * @@ -49,6 +46,9 @@ namespace gpgpu_virt { (void)vgpu; } + public: + Scheduler() : strat(), _curr_vgpu(nullptr), idle(true) { } + /** * @brief Implmentation for the handling of events from the GPU * @details The handler is especially important for scheduling the next vGPU and for @@ -89,6 +89,18 @@ namespace gpgpu_virt { _global_gpgpu_genode->free(next); } + /** + * @brief + * + */ + void trigger() + { + const bool b = __sync_lock_test_and_set(&idle, false); + if(b) + { + handle_gpu_event(); + } + } /** * @brief diff --git a/repos/dde_uos-intel-gpgpu/src/virt/strategies/cfs.h b/repos/dde_uos-intel-gpgpu/src/virt/strategies/cfs.h index 6c37ca39b8..b359203eb7 100644 --- a/repos/dde_uos-intel-gpgpu/src/virt/strategies/cfs.h +++ b/repos/dde_uos-intel-gpgpu/src/virt/strategies/cfs.h @@ -2,7 +2,7 @@ #define CFS_H #include "cfs_entry.h" -#include "util/rbtree.h" +#include "util/guarded_rbtree.h" #include "../strategie.h" namespace gpgpu_virt { @@ -19,8 +19,8 @@ namespace gpgpu_virt { return (int)(&a - &b); } - util::RBTree rbt_ready; - util::RBTree rbt_idle; + util::Guarded_RBTree rbt_ready; + util::Guarded_RBTree rbt_idle; cfs_entry* _curr; CompletlyFair(const CompletlyFair ©) = delete; diff --git a/repos/dde_uos-intel-gpgpu/src/virt/strategies/util/guarded_rbtree.h b/repos/dde_uos-intel-gpgpu/src/virt/strategies/util/guarded_rbtree.h new file mode 100644 index 0000000000..737b096620 --- /dev/null +++ b/repos/dde_uos-intel-gpgpu/src/virt/strategies/util/guarded_rbtree.h @@ -0,0 +1,55 @@ +#ifndef GUARDED_RB_TREE_H +#define GUARDED_RB_TREE_H + +#include "rbtree.h" +#include + +namespace gpgpu_virt::util { + + /** + * @brief + * + * @tparam T must inherit from RBTree::RBNode class + */ + template + class Guarded_RBTree : public RBTree + { + /// @brief Mutex to secure tree operations + Genode::Mutex mtx; + + public: + /** + * @brief Construct a new Guarded_RBTree + * + * @param comp_func function to compare two elements + */ + Guarded_RBTree(int (*comp_func)(const T&, const T&)) : RBTree(comp_func), mtx() { } + + /** + * @brief Inserts an element into the tree + * + * @param data the element to be inserted + */ + void insert(T& data) + { + mtx.acquire(); + RBTree::insert(data); + mtx.release(); + } + + /** + * @brief Deletes an element from the tree + * + * @param data the element to be deleted + */ + void remove(T& data) + { + mtx.acquire(); + RBTree::remove(data); + mtx.release(); + } + + }; +} + +#endif // GUARDED_RB_TREE_H