common: No need to save previous scheduler priority
authorAmitay Isaacs <amitay@gmail.com>
Fri, 6 Jun 2014 02:21:25 +0000 (12:21 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Thu, 12 Jun 2014 07:33:32 +0000 (17:33 +1000)
When calling sched_setscheduler() with SCHED_OTHER, the only valid
priority is 0.  Nice value is "restored" anyway.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
(Imported from commit 19fcf6ff5206b14c481f078371f5b407d43900b7)

common/ctdb_util.c
include/ctdb_private.h

index fd0d7da1d8f05e9d5b67a24b8afde4f94cafbf40..82c4764ef8d54d22adb257d2b2e3afe597da6231 100644 (file)
@@ -342,11 +342,6 @@ void ctdb_set_scheduler(struct ctdb_context *ctdb)
                return;
        }
 
-       if (ctdb->saved_scheduler_param == NULL) {
-               ctdb->saved_scheduler_param = talloc_size(ctdb, sizeof(te));
-       }
-       *(struct thrdentry64 *)ctdb->saved_scheduler_param = te;
-
        if (thread_setsched(te.ti_tid, 0, SCHED_RR) == -1) {
                DEBUG(DEBUG_ERR, ("Unable to set scheduler to SCHED_RR (%s)\n",
                                  strerror(errno)));
@@ -357,16 +352,7 @@ void ctdb_set_scheduler(struct ctdb_context *ctdb)
 #else /* no AIX */
 #if HAVE_SCHED_SETSCHEDULER
        struct sched_param p;
-       if (ctdb->saved_scheduler_param == NULL) {
-               ctdb->saved_scheduler_param = talloc_size(ctdb, sizeof(p));
-       }
-
-       if (sched_getparam(0, (struct sched_param *)ctdb->saved_scheduler_param) == -1) {
-               DEBUG(DEBUG_ERR,("Unable to get old scheduler params\n"));
-               return;
-       }
 
-       p = *(struct sched_param *)ctdb->saved_scheduler_param;
        p.sched_priority = 1;
 
        if (sched_setscheduler(0, SCHED_FIFO, &p) == -1) {
@@ -386,28 +372,24 @@ void ctdb_restore_scheduler(struct ctdb_context *ctdb)
 {
 #ifdef _AIX_
 #if HAVE_THREAD_SETSCHED
-       struct thrdentry64 te, *saved;
+       struct thrdentry64 te;
        tid64_t ti;
 
        ti = 0ULL;
        if (getthrds64(getpid(), &te, sizeof(te), &ti, 1) != 1) {
                ctdb_fatal(ctdb, "Unable to get thread information\n");
        }
-       if (ctdb->saved_scheduler_param == NULL) {
-               ctdb_fatal(ctdb, "No saved scheduler parameters\n");
-       }
-       saved = (struct thrdentry64 *)ctdb->saved_scheduler_param;
-       if (thread_setsched(te.ti_tid, saved->ti_pri, saved->ti_policy) == -1) {
-               ctdb_fatal(ctdb, "Unable to restore old scheduler parameters\n");
+       if (thread_setsched(te.ti_tid, 0, SCHED_OTHER) == -1) {
+               ctdb_fatal(ctdb, "Unable to set scheduler to SCHED_OTHER\n");
        }
 #endif
 #else /* no AIX */
 #if HAVE_SCHED_SETSCHEDULER
-       if (ctdb->saved_scheduler_param == NULL) {
-               ctdb_fatal(ctdb, "No saved scheduler parameters\n");
-       }
-       if (sched_setscheduler(0, SCHED_OTHER, (struct sched_param *)ctdb->saved_scheduler_param) == -1) {
-               ctdb_fatal(ctdb, "Unable to restore old scheduler parameters\n");
+       struct sched_param p;
+
+       p.sched_priority = 0;
+       if (sched_setscheduler(0, SCHED_OTHER, &p) == -1) {
+               ctdb_fatal(ctdb, "Unable to set scheduler to SCHED_OTHER\n");
        }
 #endif
 #endif
index 81759786dd136d373df2d398509341bfa2f11871..8ebd1c55d9a78a53396a8a85e6fa6fb65fba99e8 100644 (file)
@@ -512,7 +512,6 @@ struct ctdb_context {
        bool do_checkpublicip;
        struct trbt_tree *server_ids; 
        bool do_setsched;
-       void *saved_scheduler_param;
        const char *event_script_dir;
        const char *notification_script;
        const char *default_public_interface;