common/util: Use AIX specific code for setting high priority for CTDB daemon
authorAmitay Isaacs <amitay@gmail.com>
Thu, 26 Sep 2013 08:47:27 +0000 (18:47 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Tue, 22 Oct 2013 03:33:56 +0000 (14:33 +1100)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
common/ctdb_util.c
configure.ac

index d4bfeeb56a59432cb2a1679e10964ba22abef72f..d4f85416c0cf8f96761bf781fd3ea1e32657a759 100644 (file)
@@ -322,17 +322,45 @@ struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, st
 #include <sched.h>
 #endif
 
+#if HAVE_PROCINFO_H
+#include <procinfo.h>
+#endif
+
 /*
   if possible, make this task real time
  */
 void ctdb_set_scheduler(struct ctdb_context *ctdb)
 {
-#if HAVE_SCHED_SETSCHEDULER    
+#ifdef _AIX_
+#if HAVE_THREAD_SETSCHED
+       struct thrdentry64 te;
+       tid64_t ti;
+
+       ti = 0ULL;
+       if (getthrds64(getpid(), &te, sizeof(te), &ti, 1) != 1) {
+               DEBUG(DEBUG_ERR, ("Unable to get thread information\n"));
+               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)));
+       } else {
+               DEBUG(DEBUG_NOTICE, ("Set scheduler to SCHED_RR\n"));
+       }
+#endif
+#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;
@@ -348,6 +376,7 @@ void ctdb_set_scheduler(struct ctdb_context *ctdb)
                DEBUG(DEBUG_NOTICE,("Set scheduler to SCHED_FIFO\n"));
        }
 #endif
+#endif
 }
 
 /*
@@ -355,7 +384,25 @@ void ctdb_set_scheduler(struct ctdb_context *ctdb)
  */
 void ctdb_restore_scheduler(struct ctdb_context *ctdb)
 {
-#if HAVE_SCHED_SETSCHEDULER    
+#ifdef _AIX_
+#if HAVE_THREAD_SETSCHED
+       struct thrdentry64 te, *saved;
+       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");
+       }
+#endif
+#else /* no AIX */
+#if HAVE_SCHED_SETSCHEDULER
        if (ctdb->saved_scheduler_param == NULL) {
                ctdb_fatal(ctdb, "No saved scheduler parameters\n");
        }
@@ -363,6 +410,7 @@ void ctdb_restore_scheduler(struct ctdb_context *ctdb)
                ctdb_fatal(ctdb, "Unable to restore old scheduler parameters\n");
        }
 #endif
+#endif
 }
 
 void set_nonblocking(int fd)
index 37b5a6402fffa02bc066116499763e58070e4599..f3d2033aa93c4ef8954117029eac7bfb472c0b7a 100644 (file)
@@ -26,6 +26,7 @@ case `uname` in
   AIX*)
     CTDB_SYSTEM_OBJ=common/system_aix.o
     CTDB_SCSI_IO=
+    CPPFLAGS="$CPPFLAGS -D_AIX_=1"
     CTDB_PCAP_LDFLAGS=-lpcap
     ;;
   GNU/kFreeBSD)
@@ -97,12 +98,14 @@ m4_include(lib/socket_wrapper/config.m4)
 m4_include(utils/pmda/config.m4)
 
 AC_CHECK_HEADERS(sched.h)
+AC_CHECK_HEADERS(procinfo.h)
 
 AC_CHECK_DECL([ETIME], [],[AC_DEFINE([ETIME], ETIMEDOUT, [ETIME on non-supporting platforms])], [
 #include <errno.h>
 ])
 
 AC_CHECK_FUNCS(sched_setscheduler)
+AC_CHECK_FUNCS(thread_setsched)
 AC_CHECK_FUNCS(mlockall)
 
 AC_CACHE_CHECK([for sin_len in sock],ctdb_cv_HAVE_SOCK_SIN_LEN,[