kernel: add syscalls for thread affinity

scheduler modes adapted to take into account the thread affinity mask.
when no cpu in the affinity mask is enabled, the mask is ignored.

Change-Id: I577737441ab073941a4c5e06f94f7825cffdc2c4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7674
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Jérôme Duval
2024-06-10 16:34:25 +00:00
committed by waddlesplash
parent 1dde4c4b94
commit f7a85eea15
15 changed files with 233 additions and 49 deletions
+1
View File
@@ -90,6 +90,7 @@ typedef struct CACHE_LINE_ALIGN cpu_ent {
extern cpu_ent gCPU[];
extern uint32 gCPUCacheLevelCount;
extern CPUSet gCPUEnabled;
#ifdef __cplusplus
+3
View File
@@ -160,6 +160,9 @@ thread_id _user_find_thread(const char *name);
status_t _user_get_thread_info(thread_id id, thread_info *info);
status_t _user_get_next_thread_info(team_id team, int32 *cookie, thread_info *info);
int _user_get_cpu();
status_t _user_get_thread_affinity(thread_id id, void* userMask, size_t size);
status_t _user_set_thread_affinity(thread_id id, const void* userMask, size_t size);
status_t _user_block_thread(uint32 flags, bigtime_t timeout);
status_t _user_unblock_thread(thread_id thread, status_t status);
+1
View File
@@ -449,6 +449,7 @@ struct Thread : TeamThreadIteratorEntry<thread_id>, KernelReferenceable {
int32 state; // protected by scheduler lock
struct cpu_ent *cpu; // protected by scheduler lock
struct cpu_ent *previous_cpu; // protected by scheduler lock
CPUSet cpumask;
int32 pinned_to_cpu; // only accessed by this thread or in the
// scheduler, when thread is not running
spinlock scheduler_lock;
+4 -4
View File
@@ -78,7 +78,7 @@ public:
Heap(int initialSize);
~Heap();
inline Element* PeekRoot() const;
inline Element* PeekRoot(int32 index = 0) const;
static const Key& GetKey(Element* element);
@@ -188,10 +188,10 @@ HEAP_CLASS_NAME::~Heap()
HEAP_TEMPLATE_LIST
Element*
HEAP_CLASS_NAME::PeekRoot() const
HEAP_CLASS_NAME::PeekRoot(int32 index) const
{
if (fLastElement > 0)
return fElements[0];
if (index < fLastElement)
return fElements[index];
return NULL;
}
+12 -14
View File
@@ -73,8 +73,8 @@ public:
MinMaxHeap(int initialSize);
~MinMaxHeap();
inline Element* PeekMinimum() const;
inline Element* PeekMaximum() const;
inline Element* PeekMinimum(int32 index = 0) const;
inline Element* PeekMaximum(int32 index = 0) const;
static const Key& GetKey(Element* element);
@@ -190,13 +190,12 @@ MIN_MAX_HEAP_CLASS_NAME::~MinMaxHeap()
MIN_MAX_HEAP_TEMPLATE_LIST
Element*
MIN_MAX_HEAP_CLASS_NAME::PeekMinimum() const
MIN_MAX_HEAP_CLASS_NAME::PeekMinimum(int32 index) const
{
if (fMinLastElement > 0)
return fMinElements[0];
else if (fMaxLastElement > 0) {
ASSERT(fMaxLastElement == 1);
return fMaxElements[0];
if (index < fMinLastElement)
return fMinElements[index];
else if (index - fMinLastElement < fMaxLastElement) {
return fMaxElements[fMaxLastElement - (index - fMinLastElement) - 1];
}
return NULL;
@@ -205,13 +204,12 @@ MIN_MAX_HEAP_CLASS_NAME::PeekMinimum() const
MIN_MAX_HEAP_TEMPLATE_LIST
Element*
MIN_MAX_HEAP_CLASS_NAME::PeekMaximum() const
MIN_MAX_HEAP_CLASS_NAME::PeekMaximum(int32 index) const
{
if (fMaxLastElement > 0)
return fMaxElements[0];
else if (fMinLastElement > 0) {
ASSERT(fMinLastElement == 1);
return fMinElements[0];
if (index < fMaxLastElement)
return fMaxElements[index];
else if (index - fMaxLastElement < fMinLastElement) {
return fMinElements[fMinLastElement - (index - fMaxLastElement) - 1];
}
return NULL;