2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief OS abstraction from time measurement
23 * @author Sebastian Hack, Michael Beck, Matthias Braun
28 #include "stat_timing.h"
38 /* define GNU macro for processor affinity stuff if on linux */
39 #if defined __linux__ && !defined __USE_GNU
44 /* we can only use the scheduling stuff, if that macro is defined in unistd.h */
45 #if defined(_XOPEN_REALTIME) && _XOPEN_REALTIME != -1
49 static int in_max_prio = 0;
50 static cpu_set_t affinity;
52 static struct sched_param sched_params;
54 void timing_enter_max_prio(void)
57 int new_scheduler = SCHED_FIFO;
58 struct sched_param new_sched_params;
59 cpu_set_t new_affinity;
64 /* remember old scheduler settings */
65 res = sched_getaffinity(0, sizeof(affinity), &affinity);
68 scheduler = sched_getscheduler(0);
71 res = sched_getparam(0, &sched_params);
76 CPU_ZERO(&new_affinity);
77 CPU_SET(0, &new_affinity);
78 res = sched_setaffinity(0, sizeof(new_affinity), &new_affinity);
81 new_scheduler = SCHED_FIFO;
82 new_sched_params = sched_params;
83 new_sched_params.sched_priority = sched_get_priority_max(new_scheduler);
84 sched_setscheduler(0, new_scheduler, &new_sched_params);
91 void timing_leave_max_prio(void)
98 /* restore old settings */
99 res = sched_setaffinity(0, sizeof(affinity), &affinity);
103 sched_setscheduler(0, scheduler, &sched_params);
116 /* dummy implementation */
118 void timing_enter_max_prio(void)
122 void timing_leave_max_prio(void)