2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief OS abstraction from time measurement
9 * @author Sebastian Hack, Michael Beck, Matthias Braun
13 #include "stat_timing.h"
23 /* define GNU macro for processor affinity stuff if on linux */
24 #if defined __linux__ && !defined __USE_GNU
29 /* we can only use the scheduling stuff, if that macro is defined in unistd.h */
30 #if defined(_XOPEN_REALTIME) && _XOPEN_REALTIME != -1
34 static int in_max_prio = 0;
35 static cpu_set_t affinity;
37 static struct sched_param sched_params;
39 void timing_enter_max_prio(void)
42 int new_scheduler = SCHED_FIFO;
43 struct sched_param new_sched_params;
44 cpu_set_t new_affinity;
49 /* remember old scheduler settings */
50 res = sched_getaffinity(0, sizeof(affinity), &affinity);
53 scheduler = sched_getscheduler(0);
56 res = sched_getparam(0, &sched_params);
61 CPU_ZERO(&new_affinity);
62 CPU_SET(0, &new_affinity);
63 res = sched_setaffinity(0, sizeof(new_affinity), &new_affinity);
66 new_scheduler = SCHED_FIFO;
67 new_sched_params = sched_params;
68 new_sched_params.sched_priority = sched_get_priority_max(new_scheduler);
69 sched_setscheduler(0, new_scheduler, &new_sched_params);
76 void timing_leave_max_prio(void)
83 /* restore old settings */
84 res = sched_setaffinity(0, sizeof(affinity), &affinity);
88 sched_setscheduler(0, scheduler, &sched_params);
101 /* dummy implementation */
103 void timing_enter_max_prio(void)
107 void timing_leave_max_prio(void)