Added functions to pin a thread to the current CPU (i.e. it will only be
scheduled on that CPU) and to avoid unscheduling it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27974 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -205,4 +205,32 @@ thread_interrupt(struct thread* thread, bool kill)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
thread_pin_to_current_cpu(struct thread* thread)
|
||||||
|
{
|
||||||
|
thread->pinned_to_cpu++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
thread_unpin_from_current_cpu(struct thread* thread)
|
||||||
|
{
|
||||||
|
thread->pinned_to_cpu--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
thread_disable_scheduling(struct thread* thread)
|
||||||
|
{
|
||||||
|
thread->keep_scheduled++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
thread_enable_scheduling(struct thread* thread)
|
||||||
|
{
|
||||||
|
thread->keep_scheduled--;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* _THREAD_H */
|
#endif /* _THREAD_H */
|
||||||
|
|||||||
@@ -230,6 +230,9 @@ struct thread {
|
|||||||
int32 state;
|
int32 state;
|
||||||
int32 next_state;
|
int32 next_state;
|
||||||
struct cpu_ent *cpu;
|
struct cpu_ent *cpu;
|
||||||
|
struct cpu_ent *previous_cpu;
|
||||||
|
int32 pinned_to_cpu;
|
||||||
|
int32 keep_scheduled;
|
||||||
|
|
||||||
sigset_t sig_pending;
|
sigset_t sig_pending;
|
||||||
sigset_t sig_block_mask;
|
sigset_t sig_block_mask;
|
||||||
|
|||||||
@@ -543,7 +543,7 @@ context_switch(struct thread *fromThread, struct thread *toThread)
|
|||||||
if ((fromThread->flags & THREAD_FLAGS_DEBUGGER_INSTALLED) != 0)
|
if ((fromThread->flags & THREAD_FLAGS_DEBUGGER_INSTALLED) != 0)
|
||||||
user_debug_thread_unscheduled(fromThread);
|
user_debug_thread_unscheduled(fromThread);
|
||||||
|
|
||||||
toThread->cpu = fromThread->cpu;
|
toThread->previous_cpu = toThread->cpu = fromThread->cpu;
|
||||||
fromThread->cpu = NULL;
|
fromThread->cpu = NULL;
|
||||||
|
|
||||||
arch_thread_set_current_thread(toThread);
|
arch_thread_set_current_thread(toThread);
|
||||||
@@ -560,8 +560,11 @@ context_switch(struct thread *fromThread, struct thread *toThread)
|
|||||||
static int32
|
static int32
|
||||||
reschedule_event(timer *unused)
|
reschedule_event(timer *unused)
|
||||||
{
|
{
|
||||||
// this function is called as a result of the timer event set by the scheduler
|
if (thread_get_current_thread()->keep_scheduled > 0)
|
||||||
// returning this causes a reschedule on the timer event
|
return B_HANDLED_INTERRUPT;
|
||||||
|
|
||||||
|
// this function is called as a result of the timer event set by the
|
||||||
|
// scheduler returning this causes a reschedule on the timer event
|
||||||
thread_get_current_thread()->cpu->preempted = 1;
|
thread_get_current_thread()->cpu->preempted = 1;
|
||||||
return B_INVOKE_SCHEDULER;
|
return B_INVOKE_SCHEDULER;
|
||||||
}
|
}
|
||||||
@@ -617,6 +620,14 @@ scheduler_reschedule(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// skip thread, if it doesn't want to run on this CPU
|
||||||
|
if (nextThread->pinned_to_cpu > 0
|
||||||
|
&& nextThread->previous_cpu != oldThread->cpu) {
|
||||||
|
prevThread = nextThread;
|
||||||
|
nextThread = nextThread->queue_next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// always extract real time threads
|
// always extract real time threads
|
||||||
if (nextThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
|
if (nextThread->priority >= B_FIRST_REAL_TIME_PRIORITY)
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -223,6 +223,9 @@ create_thread_struct(struct thread *inthread, const char *name,
|
|||||||
thread->id = threadID >= 0 ? threadID : allocate_thread_id();
|
thread->id = threadID >= 0 ? threadID : allocate_thread_id();
|
||||||
thread->team = NULL;
|
thread->team = NULL;
|
||||||
thread->cpu = cpu;
|
thread->cpu = cpu;
|
||||||
|
thread->previous_cpu = NULL;
|
||||||
|
thread->pinned_to_cpu = 0;
|
||||||
|
thread->keep_scheduled = 0;
|
||||||
thread->fault_handler = 0;
|
thread->fault_handler = 0;
|
||||||
thread->page_faults_allowed = 1;
|
thread->page_faults_allowed = 1;
|
||||||
thread->kernel_stack_area = -1;
|
thread->kernel_stack_area = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user