change process priority based on scheduling priority
authorChristian Grothoff <christian@grothoff.org>
Sat, 17 Apr 2010 17:45:48 +0000 (17:45 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 17 Apr 2010 17:45:48 +0000 (17:45 +0000)
TODO
src/util/os_priority.c
src/util/scheduler.c
src/util/test_os_start_process.c

diff --git a/TODO b/TODO
index 6c9e18429ffad3247a84f8f2a2fb955545773f49..25e3ea0dd4ef2d9716ea6b8f821b54cfe786f0b4 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,27 +1,13 @@
 0.9.0pre1:
 * PEERINFO:
   - trust: need *fast* way to check/update trust in peers
-           (async peerinfo would not be right; certainly not with the
-            current API)
+           (async peerinfo would not be right; certainly not with the current API)
+* STATISTICS:
+  - does not seem to work with timeouts (especially if service is not running)
 * UTIL:
-  - scheduler should change OS process priority based on task priority;   
-    should make better use of task priorities in general
   - only connect() sockets that are ready (select()) [Nils]
     [On W32, we need to select after calling socket before
      doing connect etc.]
-* SETUP:
-  - design & implement new setup tool
-* TBENCH: [MW]
-  - good to have for transport/DV evaluation! 
-* DV: [Nate]
-  - write DV API (need to move declarations from dv_api.c to gnunet_dv_service.h!)
-  - implement DV service 
-  - implement DV library (looks done)
-  - implement DV transport plugin
-  - implement testcases 
-  - implement performance tests
-* STATISTICS:
-  - does not seem to work with timeouts (especially if service is not running)
 * TOPOLOGY:
   - needs more testing (especially F2F topology)
   - needs to re-try connecting after disconnect (currently, it
@@ -52,6 +38,9 @@
     more balanced load)
   - check if new HELLO learned is different from old HELLO
     before resetting entire state!
+* DATASTORE:
+  - API lacks cancellation methods (needed? or is disconnect enough?); 
+    may also want to integrate request queuing here instead of gnunet-service-fs_drq.c 
 * FS: [CG]
   - support recursive download even if filename is NULL and we hence
     do not generate files on disk (use temp_filename)
   - [gnunet-service-fs.c:700]: member 'ConnectedPeer::last_client_replies_woff' is never used
   - GAP improvements:
     + active reply route caching design & implementation of service; gap extension!
-* DATASTORE:
-  - API lacks cancellation methods (needed? or is disconnect enough?); 
-    may also want to integrate request queuing here instead of gnunet-service-fs_drq.c 
+* TBENCH: [MW]
+  - good to have for transport/DV evaluation! 
+* DV: [Nate]
+  - write DV API (need to move declarations from dv_api.c to gnunet_dv_service.h!)
+  - implement DV service 
+  - implement DV library (looks done)
+  - implement DV transport plugin
+  - implement testcases 
+  - implement performance tests
 * GNUNET-GTK:
   - use g_main_context_set_poll_func to integrate GTK with GNUnet Scheduler!? (YUCK!)
   - OR: add scheduler API to enable integration with GTK main loop instead of doing our own select
   - use g_main_context_pending, g_main_context_query / g_main_context_check / g_main_context_dispatch
     and NEVER g_main_loop_run (can this be done? might be the clean way to do this! But how
-    to integrate this with "tak_main"?  Docu says:
+    to integrate this with "gtk_main"?  Docu says:
     "It's OK to use the GLib main loop directly instead of gtk_main(), though it involves 
      slightly more typing. See GMainLoop in the GLib documentation."
     => so maybe it "just works"?
+* SETUP:
+  - design & implement new setup tool
 
 0.9.0pre2:
 * TRACEKIT: [MW]
index 14aab8ce1c86c5b6f44e79036f57f300b0338587..e57d11d63f4a985cab664c5aeb72617163b18172 100644 (file)
@@ -62,6 +62,8 @@ GNUNET_OS_set_process_priority (pid_t proc,
                                 enum GNUNET_SCHEDULER_Priority prio)
 {
   int rprio = 0;
+  int have;
+  int delta;
 
   GNUNET_assert (prio < GNUNET_SCHEDULER_PRIORITY_COUNT);
   if (prio == GNUNET_SCHEDULER_PRIORITY_KEEP)
@@ -69,35 +71,39 @@ GNUNET_OS_set_process_priority (pid_t proc,
   /* convert to MINGW/Unix values */
   switch (prio)
     {
-    case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
+    case GNUNET_SCHEDULER_PRIORITY_UI:
+    case GNUNET_SCHEDULER_PRIORITY_URGENT:
 #ifdef MINGW
-      rprio = NORMAL_PRIORITY_CLASS;
+      rprio = HIGH_PRIORITY_CLASS;
 #else
       rprio = 0;
 #endif
       break;
+
     case GNUNET_SCHEDULER_PRIORITY_HIGH:
 #ifdef MINGW
       rprio = ABOVE_NORMAL_PRIORITY_CLASS;
 #else
-      rprio = -5;
+      rprio = 5;
 #endif
       break;
-    case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
+
+    case GNUNET_SCHEDULER_PRIORITY_DEFAULT:
 #ifdef MINGW
-      rprio = BELOW_NORMAL_PRIORITY_CLASS;
+      rprio = NORMAL_PRIORITY_CLASS;
 #else
-      rprio = 10;
+      rprio = 7;
 #endif
       break;
-    case GNUNET_SCHEDULER_PRIORITY_UI:
-    case GNUNET_SCHEDULER_PRIORITY_URGENT:
+
+    case GNUNET_SCHEDULER_PRIORITY_BACKGROUND:
 #ifdef MINGW
-      rprio = HIGH_PRIORITY_CLASS;
+      rprio = BELOW_NORMAL_PRIORITY_CLASS;
 #else
-      rprio = -10;
+      rprio = 10;
 #endif
       break;
+
     case GNUNET_SCHEDULER_PRIORITY_IDLE:
 #ifdef MINGW
       rprio = IDLE_PRIORITY_CLASS;
@@ -113,10 +119,15 @@ GNUNET_OS_set_process_priority (pid_t proc,
 #ifdef MINGW
   SetPriorityClass (GetCurrentProcess (), rprio);
 #else
-  if (proc == getpid ())
+  if ( (0 == proc) ||
+       (proc == getpid () ) )
     {
+      have = nice (0);
+      delta = rprio - have;
       errno = 0;
-      if ((-1 == nice (rprio)) && (errno != 0))
+      if ( (rprio != 0) &&
+          (-1 == nice (delta)) && 
+          (errno != 0) )
         {
           GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING |
                                GNUNET_ERROR_TYPE_BULK, "nice");
index b5d998ef598c35fb6a8c224125de39b6c9f2f530..0e40d184da4316c5fc1bd7e65ff344d361fd5546 100644 (file)
@@ -25,6 +25,7 @@
  */
 #include "platform.h"
 #include "gnunet_common.h"
+#include "gnunet_os_lib.h"
 #include "gnunet_scheduler_lib.h"
 #include "gnunet_signal_lib.h"
 #include "gnunet_time_lib.h"
@@ -167,6 +168,11 @@ struct GNUNET_SCHEDULER_Handle
    */
   enum GNUNET_SCHEDULER_Priority current_priority;
 
+  /**
+   * How 'nice' are we right now?
+   */
+  int nice_level;
+
 };
 
 
@@ -495,7 +501,11 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched)
       GNUNET_assert (pos != NULL);      /* ready_count wrong? */
       sched->ready[p] = pos->next;
       sched->ready_count--;
-      sched->current_priority = pos->priority;
+      if (sched->current_priority != pos->priority)
+       {
+         sched->current_priority = pos->priority;
+         GNUNET_OS_set_process_priority (0, pos->priority);
+       }
       sched->active_task = pos;
       tc.sched = sched;
       tc.reason = pos->reason;
index 3b34beedf3f6fe544dc53f17370f7dc1ec44db4a..d6cd623d26ef3effbe960f40cb252b2d606ae275 100644 (file)
@@ -103,7 +103,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   char *fn;
   const struct GNUNET_DISK_FileHandle *stdout_read_handle;
-  struct GNUNET_DISK_FileHandle *wh;
+  const struct GNUNET_DISK_FileHandle *wh;
 
   GNUNET_asprintf(&fn, "cat");