[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/libs/libksysguard
From:       John Tapsell <john.tapsell () kdemail ! net>
Date:       2007-11-01 1:57:25
Message-ID: 1193882245.722147.19604.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 731579 by johnflux:

Show the scheduler priority


 M  +11 -0     processcore/process.cpp  
 M  +4 -1      processcore/process.h  
 M  +4 -0      processcore/processes.cpp  
 M  +10 -0     processcore/processes.h  
 M  +14 -2     processcore/processes_base_p.h  
 M  +32 -4     processcore/processes_linux_p.cpp  
 M  +1 -0      processcore/processes_local_p.h  
 M  +4 -0      processcore/processes_remote_p.cpp  
 M  +1 -0      processcore/processes_remote_p.h  
 M  +14 -1     processui/ProcessModel.cc  


--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/process.cpp \
#731578:731579 @@ -72,6 +72,16 @@
 		default: return i18nc("process status", "unknown");
 	}
 }
+
+QString KSysGuard::Process::schedulerAsString() const { 
+	switch( scheduler ) { 
+		case Fifo: return i18nc("Scheduler", "FIFO");
+		case RoundRobin: return i18nc("Scheduler", "Round Robin");
+		case Batch: return i18nc("Scheduler", "Batch");
+		default: return QString();
+	}
+}
+
 void KSysGuard::Process::clear() {
 	pid = 0; 
 	parent_pid = 0; 
@@ -95,5 +105,6 @@
 	parent = NULL;
 	ioPriorityClass = None;
 	ioniceLevel = -1;
+	scheduler = Other;
 }
 
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/process.h \
#731578:731579 @@ -34,6 +34,7 @@
     public:
 	enum ProcessStatus { Running, Sleeping, DiskSleep, Zombie, Stopped, Paging, \
OtherStatus };  enum IoPriorityClass { None, RealTime, BestEffort, Idle };
+	enum Scheduler { Other = 0, Fifo, RoundRobin, Batch };
         Process();
         Process(long long _pid, long long _ppid, Process *_parent);
 
@@ -67,7 +68,8 @@
         int totalUserUsage; ///Percentage (0 to 100) from the sum of itself and all \
its children recursively.  If there's no children, it's equal to userUsage.  It might \
be more than 100% on multiple cpu core systems  int totalSysUsage; ///Percentage (0 \
to 100) from the sum of itself and all its children recursively. If there's no \
children, it's equal to sysUsage. It might be more than 100% on multiple cpu core \
                systems
         unsigned long numChildren; ///Number of children recursively that this \
                process has.  From 0+
-        int niceLevel;      ///Niceness (-20 to 20) of this process.  A lower number \
means a higher priority. +        int niceLevel;      ///If Scheduler = Other, \
niceLevel is the niceness (-20 to 20) of this process.  A lower number means a higher \
priority.  Otherwise sched priority (1 to 99) +	Scheduler scheduler; ///The scheduler \
                this process is running in.  See man sched_getscheduler for more info
         IoPriorityClass ioPriorityClass; /// The IO priority class.  See man ionice \
for detailed information.  int ioniceLevel;    ///IO Niceless (0 to 7) of this \
process.  A lower number means a higher io priority.  -1 if not known or not \
                applicable because ioPriorityClass is Idle or None
         long vmSize;   ///Virtual memory size in KiloBytes, including memory used, \
mmap'ed files, graphics memory etc, @@ -83,6 +85,7 @@
 	QString niceLevelAsString() const; /// Returns a simple translated string of the \
nice priority.  e.g. "Normal", "High", etc  QString ioniceLevelAsString() const; /// \
Returns a simple translated string of the io nice priority.  e.g. "Normal", "High", \
etc  QString ioPriorityClassAsString() const; /// Returns a translated string of the \
io nice class.  i.e. "None", "Real Time", "Best Effort", "Idle" +	QString \
schedulerAsString() const; /// Returns a translated string of the scheduler class.  \
e.g. "FIFO", "Round Robin", "Batch"  
 	int index;  /// Each process has a parent process.  Each sibling has a unique \
number to identify it under that parent.  This is that number.  
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/processes.cpp \
#731578:731579 @@ -320,6 +320,10 @@
     return d->mAbstractProcesses->setNiceness(pid, priority);
 }
 
+bool Processes::setScheduler(long pid, KSysGuard::Process::Scheduler priorityClass, \
int priority) { +    return d->mAbstractProcesses->setScheduler(pid, priorityClass, \
priority); +}
+
 bool Processes::setIoNiceness(long pid, KSysGuard::Process::IoPriorityClass \
                priorityClass, int priority) {
     return d->mAbstractProcesses->setIoNiceness(pid, priorityClass, priority);
 }
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/processes.h \
#731578:731579 @@ -113,6 +113,16 @@
 	bool setNiceness(long pid, int priority);
 
 	/**
+	 *  Set the scheduler for a process.  This is defined according to POSIX.1-2001 
+	 *  See "man sched_setscheduler" for more information.
+	 *
+	 *  @p priorityClass One of SCHED_FIFO, SCHED_RR, SCHED_OTHER, and SCHED_BATCH
+	 *  @p priority Set to 0 for SCHED_OTHER and SCHED_BATCH.  Between 1 and 99 for \
SCHED_FIFO and SCHED_RR +	 *  @return false if you do not have permission to set the \
priority +	 */
+	bool setScheduler(long pid, KSysGuard::Process::Scheduler priorityClass, int \
priority); +
+	/**
 	 *  Set the io priority for a process.  This is from 7 (very nice, lowest io \
                priority) to
 	 *  0 (highest priority).  The default value is determined as: io_nice = (cpu_nice \
                + 20) / 5.
 	 *
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/processes_base_p.h \
#731578:731579 @@ -73,14 +73,26 @@
 	virtual bool sendSignal(long pid, int sig) = 0;
 
 	/**
-	 *  Set the priority for a process.  This is from 19 (very nice, lowest priority) \
                to 
-	 *    -20 (highest priority).  The default value for a process is 0.
+	 *  Set the priority for a process.  For the normal scheduler, this is usually from \
19  +	 *  (very nice, lowest priority) to -20 (highest priority).  The default value \
for a process is 0. +	 *
+	 *  This has no effect if the scheduler is not the normal one (SCHED_OTHER)
 	 *  
 	 *  @return false if you do not have permission to set the priority
 	 */
 	virtual bool setNiceness(long pid, int priority) = 0;
 
 	/**
+	 *  Set the scheduler for a process.  This is defined according to POSIX.1-2001 
+	 *  See "man sched_setscheduler" for more information.
+	 *
+	 *  @p priorityClass One of SCHED_FIFO, SCHED_RR, SCHED_OTHER, and SCHED_BATCH
+	 *  @p priority Set to 0 for SCHED_OTHER and SCHED_BATCH.  Between 1 and 99 for \
SCHED_FIFO and SCHED_RR +	 *  @return false if you do not have permission to set the \
priority +	 */
+	virtual bool setScheduler(long pid, int priorityClass, int priority) = 0;
+	
+	/**
 	 *  Return the total amount of physical memory in KB.  This is fast (just a system \
                call)
 	 *  Returns 0 on error
 	 */
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/processes_linux_p.cpp \
#731578:731579 @@ -39,6 +39,8 @@
 //for ionice
 #include <sys/ptrace.h>
 #include <asm/unistd.h>
+//for getsched
+#include <sched.h>
 
 #define PROCESS_BUFFER_SIZE 1000
 
@@ -107,7 +109,7 @@
       inline bool readProcStat(long pid, Process *process);
       inline bool readProcStatm(long pid, Process *process);
       inline bool readProcCmdline(long pid, Process *process);
-      inline bool getIoNice(long pid, Process *process);
+      inline bool getNiceness(long pid, Process *process);
       QFile mFile;
       char mBuffer[PROCESS_BUFFER_SIZE+1]; //used as a buffer to read data into      \
  DIR* mProcDir;
@@ -248,7 +250,7 @@
 			      ps->sysTime = atoll(word+1);
 			      break;
 			    case 18: //niceLevel
-			      ps->niceLevel = atoi(word+1);
+			      ps->niceLevel = atoi(word+1);  /*Or should we use getPriority instead? */
 			      break;
 			    case 22: //vmSize
 			      ps->vmSize = atol(word+1);
@@ -347,7 +349,17 @@
     return true;
 }
 
-bool ProcessesLocal::Private::getIoNice(long pid, Process *process) {
+bool ProcessesLocal::Private::getNiceness(long pid, Process *process) {
+  int sched = sched_getscheduler(pid);
+  process->scheduler = (KSysGuard::Process::Scheduler) sched;  //Sets it to -1 if we \
can't get the scheduler +  if(sched == SCHED_FIFO || sched == SCHED_RR) {
+    struct sched_param param;
+    if(sched_getparam(pid, &param) == 0)
+      process->niceLevel = param.sched_priority;
+    else
+      process->niceLevel = 0;  //Error getting scheduler parameters. 
+  }
+
 #ifdef HAVE_IONICE
   int ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);  /* Returns from 0 to 7 for the \
iopriority, and -1 if there's an error */  if(ioprio == -1) {
@@ -369,7 +381,7 @@
     if(!d->readProcStatus(pid, process)) return false;
     if(!d->readProcStatm(pid, process)) return false;
     if(!d->readProcCmdline(pid, process)) return false;
-    if(!d->getIoNice(pid, process)) return false;
+    if(!d->getNiceness(pid, process)) return false;
 
     return true;
 }
@@ -393,6 +405,7 @@
     }
     return true;
 }
+
 bool ProcessesLocal::setNiceness(long pid, int priority) {
     if(pid <= 0) return false; // check the parameters
     if ( setpriority( PRIO_PROCESS, pid, priority ) ) {
@@ -401,6 +414,21 @@
     }
     return true;
 }
+
+bool ProcessesLocal::setScheduler(long pid, int priorityClass, int priority) {
+    if(priorityClass == SCHED_OTHER || priorityClass == SCHED_BATCH)
+	    priority = 0;
+    if(pid <= 0) return false; // check the parameters
+    struct sched_param params;
+    params.sched_priority = priority;
+    if ( sched_setscheduler( pid, priorityClass, &params ) ) {
+	    //set scheduler failed
+	    return false;
+    }
+    return true;
+}
+
+
 bool ProcessesLocal::setIoNiceness(long pid, int priorityClass, int priority) {
 #ifdef HAVE_IONICE
     if (ioprio_set(IOPRIO_WHO_PROCESS, pid, priority | priorityClass << \
                IOPRIO_CLASS_SHIFT) == -1) {
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/processes_local_p.h \
#731578:731579 @@ -41,6 +41,7 @@
 	virtual bool updateProcessInfo(long pid, Process *process);
 	virtual bool sendSignal(long pid, int sig);
         virtual bool setNiceness(long pid, int priority);
+	virtual bool setScheduler(long pid, int priorityClass, int priority);
 	virtual long long totalPhysicalMemory();
 	virtual bool setIoNiceness(long pid, int priorityClass, int priority);
 	virtual bool supportsIoNiceness();
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/processes_remote_p.cpp \
#731578:731579 @@ -67,6 +67,10 @@
     return false; //Not yet supported
 }
 
+bool ProcessesRemote::setScheduler(long pid, int priorityClass, int priority) {
+    return false;
+}
+
 bool ProcessesRemote::supportsIoNiceness() {
     return false;
 }
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processcore/processes_remote_p.h \
#731578:731579 @@ -36,6 +36,7 @@
 	virtual bool updateProcessInfo(long pid, Process *process);
 	virtual bool sendSignal(long pid, int sig);
         virtual bool setNiceness(long pid, int priority);
+	virtual bool setScheduler(long pid, int priorityClass, int priority);
 	virtual long long totalPhysicalMemory();
 	virtual bool setIoNiceness(long pid, int priorityClass, int priority);
 	virtual bool supportsIoNiceness();
--- trunk/KDE/kdebase/workspace/libs/libksysguard/processui/ProcessModel.cc \
#731578:731579 @@ -777,7 +777,20 @@
 			return d->getTooltipForUser(process);
 		}
 		case HeadingNiceness: {
-		        QString tooltip = i18n("<qt>Nice level: %1 (%2)", process->niceLevel, \
process->niceLevelAsString() ); +		        QString tooltip;
+			switch(process->scheduler) {
+			  case KSysGuard::Process::Other:
+			  case KSysGuard::Process::Batch:
+				  tooltip = i18n("<qt>Nice level: %1 (%2)", process->niceLevel, \
process->niceLevelAsString() ); +				  break;
+			  case KSysGuard::Process::RoundRobin:
+			  case KSysGuard::Process::Fifo:
+				  tooltip = i18n("<qt>Scheduler priority: %1", process->niceLevel);
+				  break;
+			}
+			if(process->scheduler != KSysGuard::Process::Other)
+				tooltip += i18n("<br/>Scheduler: %1", process->schedulerAsString());
+
 			if(process->ioPriorityClass != KSysGuard::Process::None) {
 				if((process->ioPriorityClass == KSysGuard::Process::RealTime || \
process->ioPriorityClass == KSysGuard::Process::BestEffort) && process->ioniceLevel \
                != -1)
 					tooltip += i18n("<br/>I/O Nice level: %1 (%2)", process->ioniceLevel, \
process->ioniceLevelAsString() );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic