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
27 #include "stat_timing.h"
37 /* define GNU macro for processor affinity stuff if on linux */
38 #if defined __linux__ && !defined __USE_GNU
43 /* we can only use the scheduling stuff, if that macro is defined in unistd.h */
44 #if defined(_XOPEN_REALTIME) && _XOPEN_REALTIME != -1
48 static int in_max_prio = 0;
49 static cpu_set_t affinity;
51 static struct sched_param sched_params;
53 void timing_enter_max_prio(void)
56 int new_scheduler = SCHED_FIFO;
57 struct sched_param new_sched_params;
58 cpu_set_t new_affinity;
63 /* remember old scheduler settings */
64 res = sched_getaffinity(0, sizeof(affinity), &affinity);
67 scheduler = sched_getscheduler(0);
70 res = sched_getparam(0, &sched_params);
75 CPU_ZERO(&new_affinity);
76 CPU_SET(0, &new_affinity);
77 res = sched_setaffinity(0, sizeof(new_affinity), &new_affinity);
80 new_scheduler = SCHED_FIFO;
81 new_sched_params = sched_params;
82 new_sched_params.sched_priority = sched_get_priority_max(new_scheduler);
83 sched_setscheduler(0, new_scheduler, &new_sched_params);
90 void timing_leave_max_prio(void)
97 /* restore old settings */
98 res = sched_setaffinity(0, sizeof(affinity), &affinity);
102 sched_setscheduler(0, scheduler, &sched_params);
115 /* dummy implementation */
117 void timing_enter_max_prio(void)
121 void timing_leave_max_prio(void)