12 #include <ecl/config/ecl.hpp> 13 #if defined(ECL_IS_POSIX) 22 #include "../../include/ecl/threads/priority_pos.hpp" 34 using std::ostringstream;
59 #if _POSIX_PRIORITY_SCHEDULING > 0 60 int rr_min = sched_get_priority_min(SCHED_RR);
int rr_max = sched_get_priority_max(SCHED_RR);
61 if ( ( rr_min == -1 ) || (rr_max == -1) ) {
62 ecl_throw(StandardException(LOC,
NotSupportedError,
"The posix SCHED_RR policy is not available on this system [sched_get_priority_min/max]."));
67 if ( !threads::set_real_time_priority(SCHED_RR,rr_min+(priority_level -
RealTimePriority1)*(rr_max - rr_min)/10) ) {
74 ecl_throw(StandardException(LOC,
NotSupportedError,
"Your version of posix does not support real time priority scheduling for process management."));
88 switch (priority_level) {
90 return_value = setpriority(PRIO_PROCESS,0,PRIO_MIN);
94 setpriority(PRIO_PROCESS,0,PRIO_MIN + (PRIO_MAX-PRIO_MIN)/4);
98 setpriority(PRIO_PROCESS,0,PRIO_MIN + (PRIO_MAX-PRIO_MIN)/2);
102 setpriority(PRIO_PROCESS,0,PRIO_MIN + 3*(PRIO_MAX-PRIO_MIN)/4);
106 setpriority(PRIO_PROCESS,0,PRIO_MAX);
114 if ( return_value == -1 ) {
121 Priority get_priority() ecl_debug_throw_decl(StandardException)
126 #if _POSIX_PRIORITY_SCHEDULING > 0 127 int scheduler = sched_getscheduler(0);
128 switch ( scheduler ) {
134 case ( SCHED_OTHER ) : {
138 case ( SCHED_RR ) : {
143 if ( sched_getparam(0,¶m) != 0 ) {
147 int rr_min = sched_get_priority_min(SCHED_RR);
148 int rr_max = sched_get_priority_max(SCHED_RR);
149 if ( ( rr_min == -1 ) || (rr_max == -1) ) {
150 ecl_throw(StandardException(LOC,
NotSupportedError,
"The posix SCHED_RR policy is not available on this system [sched_get_priority_min/max]."));
153 if ( param.sched_priority >= rr_min + 3*(rr_max-rr_min)/10 ) {
155 }
else if ( param.sched_priority >= rr_min + 2*(rr_max-rr_min)/10 ) {
157 }
else if ( param.sched_priority >= rr_min + (rr_max-rr_min)/10 ) {
165 #if defined(SCHED_BATCH) // Didn't turn up on an old gcc3 with an arm pax270 board. 174 switch ( getpriority(PRIO_PROCESS,0) ) {
176 case (PRIO_MIN + (PRIO_MAX-PRIO_MIN)/4) : {
return HighPriority; }
177 case (PRIO_MIN + (PRIO_MAX-PRIO_MIN)/2) : {
return NormalPriority; }
178 case (PRIO_MIN + 3*(PRIO_MAX-PRIO_MIN)/4) : {
return LowPriority; }
188 std::string print_priority_diagnostics() ecl_debug_throw_decl(StandardException) {
190 ostringstream ostream;
193 ostream <<
"***********************************************************\n";
194 ostream <<
"* System Statistics\n";
195 ostream <<
"***********************************************************\n";
198 #if _POSIX_PRIORITY_SCHEDULING > 0 199 int rr_min = sched_get_priority_min(SCHED_RR);
200 int rr_max = sched_get_priority_max(SCHED_RR);
201 if ( ( rr_min == -1 ) || (rr_max == -1) ) {
202 ecl_throw(StandardException(LOC,
NotSupportedError,
"The posix SCHED_RR policy is not available on this system [sched_get_priority_min/max]."));
203 return std::string(
"The posix SCHED_RR policy is not available on this system [sched_get_priority_min/max].");
205 ostream <<
"Real Time Priorities [Low,High]............[" << rr_min <<
"," << rr_max <<
"]\n";
207 ostream <<
"Niceness [Low,High]........................[" << PRIO_MAX <<
"," << PRIO_MIN <<
"]\n";
209 ostream <<
"***********************************************************\n";
210 ostream <<
"* Priority Statistics\n";
211 ostream <<
"***********************************************************\n";
213 #if _POSIX_PRIORITY_SCHEDULING > 0 214 int scheduler = sched_getscheduler(0);
215 switch ( scheduler ) {
218 return std::string(
"Call to sched_getscheduler failed.");
220 case ( SCHED_OTHER ) : {
221 ostream <<
"Scheduler..................................SCHED_OTHER" <<
"\n";
224 case ( SCHED_RR ) : {
225 ostream <<
"Scheduler..................................SCHED_RR [RT]" <<
"\n";
228 case ( SCHED_FIFO ) : {
229 ostream <<
"Scheduler..................................SCHED_FIFO [RT]" <<
"\n";
232 #if defined(SCHED_BATCH) 233 case ( SCHED_BATCH ) : {
234 ostream <<
"Scheduler..................................SCHED_BATCH" <<
"\n";
239 ostream <<
"Scheduler..................................Unknown" <<
"\n";
244 switch ( get_priority() ) {
246 ostream <<
"Priority...................................Background\n";
250 ostream <<
"Priority...................................Low\n";
254 ostream <<
"Priority...................................Normal\n";
258 ostream <<
"Priority...................................High\n";
262 ostream <<
"Priority...................................Critical\n";
266 ostream <<
"Priority...................................RealTime4\n";
270 ostream <<
"Priority...................................RealTime3\n";
274 ostream <<
"Priority...................................RealTime2\n";
278 ostream <<
"Priority...................................RealTime1\n";
282 ostream <<
"Priority...................................Default (Inherited)\n";
286 ostream <<
"Priority...................................Unknown\n";
290 return ostream.str();
300 bool set_real_time_priority(
int policy,
int priority_level)
ecl_debug_throw_decl(StandardException) {
302 #if _POSIX_PRIORITY_SCHEDULING > 0 303 ostringstream ostream;
308 if ( priority_level < sched_get_priority_min(policy) ) {
309 ostream <<
"The realtime process priority requested was smaller than the minimum value permitted[";
310 ostream << sched_get_priority_min(policy) <<
"]\n";
313 }
else if (priority_level > sched_get_priority_max(policy) ) {
314 ostream <<
"The realtime process priority requested was greater than the maximum value permitted[";
315 ostream << sched_get_priority_max(policy) <<
"]\n";
323 sched_param schedule_parameters;
324 schedule_parameters.sched_priority = priority_level;
325 if ( sched_setscheduler(0, policy, &schedule_parameters) == -1 ) {
331 ecl_throw(StandardException(LOC,
ecl::NotSupportedError,
"Your version of posix does not support real time priority scheduling for process management."));
Embedded control libraries.
#define ecl_throw(exception)
#define ecl_debug_throw_decl(exception)
#define ecl_debug_throw(exception)
#define ecl_catch(exception)
Priority
Shared abstraction of the scheduling priorities.