From 2416a7c821652476107afbc77616f482cd0c97eb Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Mon, 10 Jan 2011 13:35:39 +1100 Subject: [PATCH] Revert scheduling back to use real-time processes 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 | 5 +++++ common/ctdb_util.c | 49 +++++++++++++++++++++++++++++++++++------- include/ctdb_private.h | 8 ++++--- server/ctdb_daemon.c | 5 ++++- server/ctdbd.c | 3 ++- 5 files changed, 57 insertions(+), 13 deletions(-) diff --git a/client/ctdb_client.c b/client/ctdb_client.c index 1abea127..99ff72d2 100644 --- a/client/ctdb_client.c +++ b/client/ctdb_client.c @@ -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) { diff --git a/common/ctdb_util.c b/common/ctdb_util.c index c7052495..80390899 100644 --- a/common/ctdb_util.c +++ b/common/ctdb_util.c @@ -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 +#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 } /* diff --git a/include/ctdb_private.h b/include/ctdb_private.h index ec41270d..deba46b2 100644 --- a/include/ctdb_private.h +++ b/include/ctdb_private.h @@ -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, diff --git a/server/ctdb_daemon.c b/server/ctdb_daemon.c index e3224532..72c72932 100644 --- a/server/ctdb_daemon.c +++ b/server/ctdb_daemon.c @@ -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); diff --git a/server/ctdbd.c b/server/ctdbd.c index b90dbcdf..bddd6582 100644 --- a/server/ctdbd.c +++ b/server/ctdbd.c @@ -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; -- 2.34.1