mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
thread safe scheduling
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<cfs_entry> rbt_ready;
|
||||
util::RBTree<cfs_entry> rbt_idle;
|
||||
util::Guarded_RBTree<cfs_entry> rbt_ready;
|
||||
util::Guarded_RBTree<cfs_entry> rbt_idle;
|
||||
cfs_entry* _curr;
|
||||
|
||||
CompletlyFair(const CompletlyFair ©) = delete;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef GUARDED_RB_TREE_H
|
||||
#define GUARDED_RB_TREE_H
|
||||
|
||||
#include "rbtree.h"
|
||||
#include <base/mutex.h>
|
||||
|
||||
namespace gpgpu_virt::util {
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @tparam T must inherit from RBTree::RBNode class
|
||||
*/
|
||||
template <typename T>
|
||||
class Guarded_RBTree : public RBTree<T>
|
||||
{
|
||||
/// @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<T>(comp_func), mtx() { }
|
||||
|
||||
/**
|
||||
* @brief Inserts an element into the tree
|
||||
*
|
||||
* @param data the element to be inserted
|
||||
*/
|
||||
void insert(T& data)
|
||||
{
|
||||
mtx.acquire();
|
||||
RBTree<T>::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<T>::remove(data);
|
||||
mtx.release();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif // GUARDED_RB_TREE_H
|
||||
Reference in New Issue
Block a user