xref: /haiku/src/system/libroot/os/scheduler.c (revision c569fd76b48e5eef4df5cabdaf1d6b01ddedf61d)
15af32e75SAxel Dörfler /*
2*c569fd76SAxel Dörfler  * Copyright 2004-2008, 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 
13fc069a2aSMichael Pfeiffer 
14fc069a2aSMichael Pfeiffer static struct {
15fc069a2aSMichael Pfeiffer 	uint32 what;
16fc069a2aSMichael Pfeiffer 	int32 priority;
17*c569fd76SAxel Dörfler } sWhatPriorityArray[] = {
18fc069a2aSMichael Pfeiffer 	// highest priority first
19fc069a2aSMichael Pfeiffer 	{B_MIDI_PROCESSING, 0x78},
20fc069a2aSMichael Pfeiffer 	{B_AUDIO_RECORDING | B_AUDIO_PLAYBACK, 0x73},
21fc069a2aSMichael Pfeiffer 	{B_LIVE_AUDIO_MANIPULATION, 0x6e},
22fc069a2aSMichael Pfeiffer 	{B_VIDEO_RECORDING, 0x19},
23fc069a2aSMichael Pfeiffer 	{B_VIDEO_PLAYBACK, 0x14},
24fc069a2aSMichael Pfeiffer 	{B_USER_INPUT_HANDLING, 0x0f},
25fc069a2aSMichael Pfeiffer 	{B_LIVE_VIDEO_MANIPULATION, 0x0e},
26fc069a2aSMichael Pfeiffer 	{B_LIVE_3D_RENDERING, 0x0c},
27fc069a2aSMichael Pfeiffer 	{B_STATUS_RENDERING, 0xa},
28fc069a2aSMichael Pfeiffer 	{B_OFFLINE_PROCESSING, 0x06},
29fc069a2aSMichael Pfeiffer 	{B_NUMBER_CRUNCHING, 0x05},
30fc069a2aSMichael Pfeiffer 	{(uint32)-1, -1}
31fc069a2aSMichael Pfeiffer };
32fc069a2aSMichael Pfeiffer 
33*c569fd76SAxel Dörfler 
345af32e75SAxel Dörfler int32
35*c569fd76SAxel Dörfler suggest_thread_priority(uint32 what, int32 period, bigtime_t jitter,
36*c569fd76SAxel Dörfler 	bigtime_t length)
375af32e75SAxel Dörfler {
381384a3a8SMichael Pfeiffer 	int i;
39fc069a2aSMichael Pfeiffer 	int32 priority = what == B_DEFAULT_MEDIA_PRIORITY ? 0x0a : 0;
40fc069a2aSMichael Pfeiffer 		// default priority
41fc069a2aSMichael Pfeiffer 
42*c569fd76SAxel Dörfler 	for (i = 0; sWhatPriorityArray[i].what != (uint32)-1; i ++) {
43*c569fd76SAxel Dörfler 		if ((what & sWhatPriorityArray[i].what) != 0) {
44*c569fd76SAxel Dörfler 			priority = sWhatPriorityArray[i].priority;
45fc069a2aSMichael Pfeiffer 			break;
46fc069a2aSMichael Pfeiffer 		}
47fc069a2aSMichael Pfeiffer 	}
48fc069a2aSMichael Pfeiffer 
49fc069a2aSMichael Pfeiffer 	return priority;
505af32e75SAxel Dörfler }
515af32e75SAxel Dörfler 
52*c569fd76SAxel Dörfler 
535af32e75SAxel Dörfler bigtime_t
54*c569fd76SAxel Dörfler estimate_max_scheduling_latency(thread_id thread)
555af32e75SAxel Dörfler {
56*c569fd76SAxel Dörfler 	if (thread == -1)
57*c569fd76SAxel Dörfler 		thread = find_thread(NULL);
585af32e75SAxel Dörfler 
595af32e75SAxel Dörfler 	return 0;
605af32e75SAxel Dörfler }
615af32e75SAxel Dörfler 
62