Revert scheduling back to use real-time processes
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 10 Jan 2011 02:35:39 +0000 (13:35 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 10 Jan 2011 02:35:39 +0000 (13:35 +1100)
Revert this patch:
commit 482c302d46e2162d0cf552f8456bc49573ae729d

We may need to use real-time processes for the main daemon and the recovery daemon to handle the cases where systems come under very high loads.

client/ctdb_client.c
common/ctdb_util.c
include/ctdb_private.h
server/ctdb_daemon.c
server/ctdbd.c

index 1abea127a989cf9bc21b0afed89a340a33c365fb..99ff72d2b1c6d69dfe903d8e679dd696170acab6 100644 (file)
@@ -3843,6 +3843,11 @@ int switch_from_server_to_client(struct ctdb_context *ctdb, const char *fmt, ...
        close(ctdb->daemon.sd);
        ctdb->daemon.sd = -1;
 
+       /* the client does not need to be realtime */
+       if (ctdb->do_setsched) {
+               ctdb_restore_scheduler(ctdb);
+       }
+
        /* initialise ctdb */
        ret = ctdb_socket_connect(ctdb);
        if (ret != 0) {
index c705249549d8e3b0da7dcb1dea62e7f1cfd0a157..80390899c7f46e0753e48fa6bbb3a0c3f541353f 100644 (file)
@@ -285,19 +285,52 @@ struct ctdb_rec_data *ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, st
        return r;
 }
 
+
+#if HAVE_SCHED_H
+#include <sched.h>
+#endif
+
 /*
-  if possible, make this task very high priority
+  if possible, make this task real time
  */
-void ctdb_high_priority(struct ctdb_context *ctdb)
+void ctdb_set_scheduler(struct ctdb_context *ctdb)
 {
-       errno = 0;
-       if (nice(-20) == -1 && errno != 0) {
-               DEBUG(DEBUG_WARNING,("Unable to renice self: %s\n",
-                                    strerror(errno)));
+#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) {
+               DEBUG(DEBUG_CRIT,("Unable to set scheduler to SCHED_FIFO (%s)\n", 
+                        strerror(errno)));
        } else {
-               DEBUG(DEBUG_NOTICE,("Scheduler says I'm nice: %i\n",
-                                   getpriority(PRIO_PROCESS, getpid())));
+               DEBUG(DEBUG_NOTICE,("Set scheduler to SCHED_FIFO\n"));
+       }
+#endif
+}
+
+/*
+  restore previous scheduler parameters
+ */
+void ctdb_restore_scheduler(struct ctdb_context *ctdb)
+{
+#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");
+       }
+#endif
 }
 
 /*
index ec41270de678a34fcb7fa889a3bb458d0833b32e..deba46b215883decb8ef5aa9da0b027fe1e5c60c 100644 (file)
@@ -454,7 +454,9 @@ struct ctdb_context {
        uint32_t recovery_master;
        struct ctdb_call_state *pending_calls;
        struct ctdb_client_ip *client_ip_list;
-       struct trbt_tree *server_ids;   
+       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;
@@ -989,8 +991,8 @@ void ctdb_call_resend_all(struct ctdb_context *ctdb);
 void ctdb_node_dead(struct ctdb_node *node);
 void ctdb_node_connected(struct ctdb_node *node);
 bool ctdb_blocking_freeze(struct ctdb_context *ctdb);
-void ctdb_high_priority(struct ctdb_context *ctdb);
-void ctdb_reduce_priority(struct ctdb_context *ctdb);
+void ctdb_set_scheduler(struct ctdb_context *ctdb);
+void ctdb_restore_scheduler(struct ctdb_context *ctdb);
 int32_t ctdb_control_takeover_ip(struct ctdb_context *ctdb, 
                                 struct ctdb_req_control *c,
                                 TDB_DATA indata, 
index e32245327279c90c7845b2b48d929413c88f1554..72c7293258c40b74a88b43a92c7d37b81b3fe586 100644 (file)
@@ -742,7 +742,10 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog,
 
        DEBUG(DEBUG_ERR, ("Starting CTDBD as pid : %u\n", ctdbd_pid));
 
-       ctdb_high_priority(ctdb);
+       if (ctdb->do_setsched) {
+               /* try to set us up as realtime */
+               ctdb_set_scheduler(ctdb);
+       }
 
        /* ensure the socket is deleted on exit of the daemon */
        domain_socket_name = talloc_strdup(talloc_autofree_context(), ctdb->daemon.name);
index b90dbcdf1e41683d3f61e30bdb9bf0bf26689a45..bddd658251f0f17dc355f564ab9a1e122b07c3fd 100644 (file)
@@ -132,7 +132,7 @@ int main(int argc, const char *argv[])
                { "dbdir-persistent", 0, POPT_ARG_STRING, &options.db_dir_persistent, 0, "directory for persistent tdb files", NULL },
                { "dbdir-state", 0, POPT_ARG_STRING, &options.db_dir_state, 0, "directory for internal state tdb files", NULL },
                { "reclock", 0, POPT_ARG_STRING, &options.recovery_lock_file, 0, "location of recovery lock file", "filename" },
-               { "valgrinding", 0, POPT_ARG_NONE, &options.valgrinding, 0, "make valgrind more effective", NULL },
+               { "valgrinding", 0, POPT_ARG_NONE, &options.valgrinding, 0, "disable setscheduler SCHED_FIFO call, use mmap for tdbs", NULL },
                { "syslog", 0, POPT_ARG_NONE, &options.use_syslog, 0, "log messages to syslog", NULL },
                { "start-as-disabled", 0, POPT_ARG_NONE, &options.start_as_disabled, 0, "Node starts in disabled state", NULL },
                { "start-as-stopped", 0, POPT_ARG_NONE, &options.start_as_stopped, 0, "Node starts in stopped state", NULL },
@@ -315,6 +315,7 @@ int main(int argc, const char *argv[])
        }
 
        ctdb->valgrinding = options.valgrinding;
+       ctdb->do_setsched = !ctdb->valgrinding;
 
        if (options.max_persistent_check_errors < 0) {
                ctdb->max_persistent_check_errors = 0xFFFFFFFFFFFFFFFFLL;