xref: /haiku/src/system/kernel/scheduler/scheduler.cpp (revision 91054f1d38dd7827c0f0ba9490c213775ec7b471)
1 /*
2  * Copyright 2008-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <kscheduler.h>
7 #include <smp.h>
8 
9 #include "scheduler_affine.h"
10 #include "scheduler_simple.h"
11 
12 // Defines which scheduler(s) to use. Possible values:
13 // 0 - Auto-select scheduler based on detected core count
14 // 1 - Always use the simple scheduler
15 // 2 - Always use the affine scheduler
16 #define SCHEDULER_TYPE 1
17 
18 struct scheduler_ops* gScheduler;
19 SchedulerListenerList gSchedulerListeners;
20 
21 
22 SchedulerListener::~SchedulerListener()
23 {
24 }
25 
26 
27 /*!	Add the given scheduler listener. Thread lock must be held.
28 */
29 void
30 scheduler_add_listener(struct SchedulerListener* listener)
31 {
32 	gSchedulerListeners.Add(listener);
33 }
34 
35 
36 /*!	Remove the given scheduler listener. Thread lock must be held.
37 */
38 void
39 scheduler_remove_listener(struct SchedulerListener* listener)
40 {
41 	gSchedulerListeners.Remove(listener);
42 }
43 
44 
45 void
46 scheduler_init(void)
47 {
48 	int32 cpu_count = smp_get_num_cpus();
49 	dprintf("scheduler_init: found %ld logical cpus\n", cpu_count);
50 #if SCHEDULER_TYPE == 0
51 	if (cpu_count > 1) {
52 		dprintf("scheduler_init: using affine scheduler\n");
53 		scheduler_affine_init();
54 	} else {
55 		dprintf("scheduler_init: using simple scheduler\n");
56 		scheduler_simple_init();
57 	}
58 #elif SCHEDULER_TYPE == 1
59 	scheduler_simple_init();
60 #elif SCHEDULER_TYPE == 2
61 	scheduler_affine_init();
62 #endif
63 
64 #if SCHEDULER_TRACING
65 	add_debugger_command_etc("scheduler", &cmd_scheduler,
66 		"Analyze scheduler tracing information",
67 		"<thread>\n"
68 		"Analyzes scheduler tracing information for a given thread.\n"
69 		"  <thread>  - ID of the thread.\n", 0);
70 #endif
71 }
72