NepomukDaemons
priority.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "priority.h"
00023
00024 #ifndef _GNU_SOURCE
00025 #define _GNU_SOURCE
00026 #endif
00027
00028 #include <QtCore/QDebug>
00029
00030 #include <sys/time.h>
00031 #include <sys/resource.h>
00032
00033 #include <unistd.h>
00034 #include <sys/syscall.h>
00035 #include <errno.h>
00036
00037 #include <sched.h>
00038
00039
00040 #ifdef SYS_ioprio_set
00041 namespace {
00042 #ifndef IOPRIO_CLASS_IDLE
00043 enum {
00044 IOPRIO_CLASS_NONE,
00045 IOPRIO_CLASS_RT,
00046 IOPRIO_CLASS_BE,
00047 IOPRIO_CLASS_IDLE
00048 };
00049 #endif
00050
00051 #ifndef IOPRIO_WHO_PROCESS
00052 enum {
00053 IOPRIO_WHO_PROCESS = 1,
00054 IOPRIO_WHO_PGRP,
00055 IOPRIO_WHO_USER
00056 };
00057 #endif
00058
00059 #ifndef IOPRIO_CLASS_SHIFT
00060 const int IOPRIO_CLASS_SHIFT = 13;
00061 #endif
00062 }
00063 #endif
00064
00065
00066 bool lowerIOPriority()
00067 {
00068 #ifdef SYS_ioprio_set
00069 if ( syscall( SYS_ioprio_set, IOPRIO_WHO_PROCESS, 0, IOPRIO_CLASS_IDLE<<IOPRIO_CLASS_SHIFT ) < 0 ) {
00070 qDebug( "cannot set io scheduling to idle (%s). Trying best effort.\n", strerror( errno ));
00071 if ( syscall( SYS_ioprio_set, IOPRIO_WHO_PROCESS, 0, 7|IOPRIO_CLASS_BE<<IOPRIO_CLASS_SHIFT ) < 0 ) {
00072 qDebug( "cannot set io scheduling to best effort.\n");
00073 return false;
00074 }
00075 }
00076 return true;
00077 #else
00078 return false;
00079 #endif
00080 }
00081
00082
00083 bool lowerPriority()
00084 {
00085 return !setpriority( PRIO_PROCESS, 0, 19 );
00086 }
00087
00088
00089
00090 bool lowerSchedulingPriority()
00091 {
00092 #ifdef SCHED_BATCH
00093 struct sched_param param;
00094 memset( ¶m, 0, sizeof(param) );
00095 param.sched_priority = 0;
00096 return !sched_setscheduler( 0, SCHED_BATCH, ¶m );
00097 #else
00098 return false;
00099 #endif
00100 }