xref: /haiku/src/system/libroot/os/scheduler.c (revision bec80c1ced7ed0da911c4de650ac86d6b71d5ea0)
15af32e75SAxel Dörfler /*
2ee0d2be9SAxel Dörfler  * Copyright 2004-2010, Haiku. All rights reserved.
3fc069a2aSMichael Pfeiffer  * Distributed under the terms of the MIT License.
4fc069a2aSMichael Pfeiffer  *
5fc069a2aSMichael Pfeiffer  * Authors:
6*bec80c1cSJérôme Duval  *		Jérôme Duval, jerome.duval@gmail.com
7fc069a2aSMichael Pfeiffer  *		Michael Pfeiffer, laplace@users.sourceforge.net
85af32e75SAxel Dörfler  */
95af32e75SAxel Dörfler 
105af32e75SAxel Dörfler 
115af32e75SAxel Dörfler #include <scheduler.h>
125af32e75SAxel Dörfler 
13ee0d2be9SAxel Dörfler #include <syscalls.h>
14ee0d2be9SAxel Dörfler 
15fc069a2aSMichael Pfeiffer 
16fc069a2aSMichael Pfeiffer static struct {
17fc069a2aSMichael Pfeiffer 	uint32 what;
18fc069a2aSMichael Pfeiffer 	int32 priority;
19c569fd76SAxel Dörfler } sWhatPriorityArray[] = {
20fc069a2aSMichael Pfeiffer 	// highest priority first
21fc069a2aSMichael Pfeiffer 	{B_MIDI_PROCESSING, 0x78},
22fc069a2aSMichael Pfeiffer 	{B_AUDIO_RECORDING | B_AUDIO_PLAYBACK, 0x73},
23fc069a2aSMichael Pfeiffer 	{B_LIVE_AUDIO_MANIPULATION, 0x6e},
24fc069a2aSMichael Pfeiffer 	{B_VIDEO_RECORDING, 0x19},
25fc069a2aSMichael Pfeiffer 	{B_VIDEO_PLAYBACK, 0x14},
26fc069a2aSMichael Pfeiffer 	{B_USER_INPUT_HANDLING, 0x0f},
27fc069a2aSMichael Pfeiffer 	{B_LIVE_VIDEO_MANIPULATION, 0x0e},
28fc069a2aSMichael Pfeiffer 	{B_LIVE_3D_RENDERING, 0x0c},
29fc069a2aSMichael Pfeiffer 	{B_STATUS_RENDERING, 0xa},
30fc069a2aSMichael Pfeiffer 	{B_OFFLINE_PROCESSING, 0x06},
31fc069a2aSMichael Pfeiffer 	{B_NUMBER_CRUNCHING, 0x05},
32fc069a2aSMichael Pfeiffer 	{(uint32)-1, -1}
33fc069a2aSMichael Pfeiffer };
34fc069a2aSMichael Pfeiffer 
3553aac05eSPawel Dziepak status_t __set_scheduler_mode(int32 mode);
3653aac05eSPawel Dziepak int32 __get_scheduler_mode(void);
3753aac05eSPawel Dziepak 
38c569fd76SAxel Dörfler 
395af32e75SAxel Dörfler int32
suggest_thread_priority(uint32 what,int32 period,bigtime_t jitter,bigtime_t length)40c569fd76SAxel Dörfler suggest_thread_priority(uint32 what, int32 period, bigtime_t jitter,
41c569fd76SAxel Dörfler 	bigtime_t length)
425af32e75SAxel Dörfler {
431384a3a8SMichael Pfeiffer 	int i;
44fc069a2aSMichael Pfeiffer 	int32 priority = what == B_DEFAULT_MEDIA_PRIORITY ? 0x0a : 0;
45fc069a2aSMichael Pfeiffer 		// default priority
46fc069a2aSMichael Pfeiffer 
47ee0d2be9SAxel Dörfler 	// TODO: this needs kernel support, and is a pretty simplistic solution
48ee0d2be9SAxel Dörfler 
49c569fd76SAxel Dörfler 	for (i = 0; sWhatPriorityArray[i].what != (uint32)-1; i ++) {
50c569fd76SAxel Dörfler 		if ((what & sWhatPriorityArray[i].what) != 0) {
51c569fd76SAxel Dörfler 			priority = sWhatPriorityArray[i].priority;
52fc069a2aSMichael Pfeiffer 			break;
53fc069a2aSMichael Pfeiffer 		}
54fc069a2aSMichael Pfeiffer 	}
55fc069a2aSMichael Pfeiffer 
56fc069a2aSMichael Pfeiffer 	return priority;
575af32e75SAxel Dörfler }
585af32e75SAxel Dörfler 
59c569fd76SAxel Dörfler 
605af32e75SAxel Dörfler bigtime_t
estimate_max_scheduling_latency(thread_id thread)61c569fd76SAxel Dörfler estimate_max_scheduling_latency(thread_id thread)
625af32e75SAxel Dörfler {
63ee0d2be9SAxel Dörfler 	return _kern_estimate_max_scheduling_latency(thread);
645af32e75SAxel Dörfler }
655af32e75SAxel Dörfler 
66308f594eSPawel Dziepak 
67308f594eSPawel Dziepak status_t
__set_scheduler_mode(int32 mode)684ec76fd8SPawel Dziepak __set_scheduler_mode(int32 mode)
69308f594eSPawel Dziepak {
70308f594eSPawel Dziepak 	return _kern_set_scheduler_mode(mode);
71308f594eSPawel Dziepak }
72308f594eSPawel Dziepak 
73308f594eSPawel Dziepak 
74308f594eSPawel Dziepak int32
__get_scheduler_mode(void)754ec76fd8SPawel Dziepak __get_scheduler_mode(void)
76308f594eSPawel Dziepak {
77308f594eSPawel Dziepak 	return _kern_get_scheduler_mode();
78308f594eSPawel Dziepak }
79308f594eSPawel Dziepak 
804ec76fd8SPawel Dziepak 
814ec76fd8SPawel Dziepak B_DEFINE_WEAK_ALIAS(__set_scheduler_mode, set_scheduler_mode);
824ec76fd8SPawel Dziepak B_DEFINE_WEAK_ALIAS(__get_scheduler_mode, get_scheduler_mode);
834ec76fd8SPawel Dziepak 
84