xref: /haiku/src/system/libroot/os/scheduler.c (revision efafab643ce980e3f3c916795ed302599f6b4f66)
1 /*
2  * Copyright 2004-2010, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Jérôme Duval, jerome.duval@gmail.com
7  *		Michael Pfeiffer, laplace@users.sourceforge.net
8  */
9 
10 
11 #include <scheduler.h>
12 
13 #include <syscalls.h>
14 
15 
16 static struct {
17 	uint32 what;
18 	int32 priority;
19 } sWhatPriorityArray[] = {
20 	// highest priority first
21 	{B_MIDI_PROCESSING, 0x78},
22 	{B_AUDIO_RECORDING | B_AUDIO_PLAYBACK, 0x73},
23 	{B_LIVE_AUDIO_MANIPULATION, 0x6e},
24 	{B_VIDEO_RECORDING, 0x19},
25 	{B_VIDEO_PLAYBACK, 0x14},
26 	{B_USER_INPUT_HANDLING, 0x0f},
27 	{B_LIVE_VIDEO_MANIPULATION, 0x0e},
28 	{B_LIVE_3D_RENDERING, 0x0c},
29 	{B_STATUS_RENDERING, 0xa},
30 	{B_OFFLINE_PROCESSING, 0x06},
31 	{B_NUMBER_CRUNCHING, 0x05},
32 	{(uint32)-1, -1}
33 };
34 
35 status_t __set_scheduler_mode(int32 mode);
36 int32 __get_scheduler_mode(void);
37 
38 
39 int32
40 suggest_thread_priority(uint32 what, int32 period, bigtime_t jitter,
41 	bigtime_t length)
42 {
43 	int i;
44 	int32 priority = what == B_DEFAULT_MEDIA_PRIORITY ? 0x0a : 0;
45 		// default priority
46 
47 	// TODO: this needs kernel support, and is a pretty simplistic solution
48 
49 	for (i = 0; sWhatPriorityArray[i].what != (uint32)-1; i ++) {
50 		if ((what & sWhatPriorityArray[i].what) != 0) {
51 			priority = sWhatPriorityArray[i].priority;
52 			break;
53 		}
54 	}
55 
56 	return priority;
57 }
58 
59 
60 bigtime_t
61 estimate_max_scheduling_latency(thread_id thread)
62 {
63 	return _kern_estimate_max_scheduling_latency(thread);
64 }
65 
66 
67 status_t
68 __set_scheduler_mode(int32 mode)
69 {
70 	return _kern_set_scheduler_mode(mode);
71 }
72 
73 
74 int32
75 __get_scheduler_mode(void)
76 {
77 	return _kern_get_scheduler_mode();
78 }
79 
80 
81 B_DEFINE_WEAK_ALIAS(__set_scheduler_mode, set_scheduler_mode);
82 B_DEFINE_WEAK_ALIAS(__get_scheduler_mode, get_scheduler_mode);
83 
84