• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

NepomukDaemons

priority.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE Project
00002    Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
00003 
00004    Parts of this file are based on code from Strigi
00005    Copyright (C) 2006-2007 Jos van den Oever <jos@vandenoever.info>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License version 2 as published by the Free Software Foundation.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019    Boston, MA 02110-1301, USA.
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 // FIXME: is this really useful? Should we better use SCHED_IDLE?
00090 bool lowerSchedulingPriority()
00091 {
00092 #ifdef SCHED_BATCH
00093     struct sched_param param;
00094     memset( &param, 0, sizeof(param) );
00095     param.sched_priority = 0;
00096     return !sched_setscheduler( 0, SCHED_BATCH, &param );
00097 #else
00098     return false;
00099 #endif
00100 }

NepomukDaemons

Skip menu "NepomukDaemons"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal