xref: /haiku/src/system/libroot/os/scheduler.c (revision 4ec76fd89d90e02bb4fc3d8d567234ab949ae9ed)
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:
6fc069a2aSMichael Pfeiffer  *      Jérôme Duval, korli@users.sourceforge.net.
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 
35c569fd76SAxel Dörfler 
365af32e75SAxel Dörfler int32
37c569fd76SAxel Dörfler suggest_thread_priority(uint32 what, int32 period, bigtime_t jitter,
38c569fd76SAxel Dörfler 	bigtime_t length)
395af32e75SAxel Dörfler {
401384a3a8SMichael Pfeiffer 	int i;
41fc069a2aSMichael Pfeiffer 	int32 priority = what == B_DEFAULT_MEDIA_PRIORITY ? 0x0a : 0;
42fc069a2aSMichael Pfeiffer 		// default priority
43fc069a2aSMichael Pfeiffer 
44ee0d2be9SAxel Dörfler 	// TODO: this needs kernel support, and is a pretty simplistic solution
45ee0d2be9SAxel Dörfler 
46c569fd76SAxel Dörfler 	for (i = 0; sWhatPriorityArray[i].what != (uint32)-1; i ++) {
47c569fd76SAxel Dörfler 		if ((what & sWhatPriorityArray[i].what) != 0) {
48c569fd76SAxel Dörfler 			priority = sWhatPriorityArray[i].priority;
49fc069a2aSMichael Pfeiffer 			break;
50fc069a2aSMichael Pfeiffer 		}
51fc069a2aSMichael Pfeiffer 	}
52fc069a2aSMichael Pfeiffer 
53fc069a2aSMichael Pfeiffer 	return priority;
545af32e75SAxel Dörfler }
555af32e75SAxel Dörfler 
56c569fd76SAxel Dörfler 
575af32e75SAxel Dörfler bigtime_t
58c569fd76SAxel Dörfler estimate_max_scheduling_latency(thread_id thread)
595af32e75SAxel Dörfler {
60ee0d2be9SAxel Dörfler 	return _kern_estimate_max_scheduling_latency(thread);
615af32e75SAxel Dörfler }
625af32e75SAxel Dörfler 
63308f594eSPawel Dziepak 
64308f594eSPawel Dziepak status_t
65*4ec76fd8SPawel Dziepak __set_scheduler_mode(int32 mode)
66308f594eSPawel Dziepak {
67308f594eSPawel Dziepak 	return _kern_set_scheduler_mode(mode);
68308f594eSPawel Dziepak }
69308f594eSPawel Dziepak 
70308f594eSPawel Dziepak 
71308f594eSPawel Dziepak int32
72*4ec76fd8SPawel Dziepak __get_scheduler_mode(void)
73308f594eSPawel Dziepak {
74308f594eSPawel Dziepak 	return _kern_get_scheduler_mode();
75308f594eSPawel Dziepak }
76308f594eSPawel Dziepak 
77*4ec76fd8SPawel Dziepak 
78*4ec76fd8SPawel Dziepak B_DEFINE_WEAK_ALIAS(__set_scheduler_mode, set_scheduler_mode);
79*4ec76fd8SPawel Dziepak B_DEFINE_WEAK_ALIAS(__get_scheduler_mode, get_scheduler_mode);
80*4ec76fd8SPawel Dziepak 
81