From: Andrew Tridgell Date: Thu, 12 Jul 2007 23:35:46 +0000 (+1000) Subject: fully save/restore scheduler parameters X-Git-Tag: tevent-0.9.20~348^2~2453 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d2a5af7eb800612f02c72018e169bc676e23b3ba;p=thirdparty%2Fsamba.git fully save/restore scheduler parameters (This used to be ctdb commit 59408eabe7515d49a6eef3b6fb2590a1cd1df956) --- diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c index f8f7cb5150a..4890a141ea7 100644 --- a/ctdb/common/ctdb_util.c +++ b/ctdb/common/ctdb_util.c @@ -192,20 +192,42 @@ struct ctdb_rec_data *ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid, /* if possible, make this task real time */ -void ctdb_set_realtime(bool enable) +void ctdb_set_scheduler(struct ctdb_context *ctdb) { -#if HAVE_SCHED_SETSCHEDULER +#if HAVE_SCHED_SETSCHEDULER struct sched_param p; - p.__sched_priority = 1; - - if (enable) { - if (sched_setscheduler(getpid(), SCHED_FIFO, &p) == -1) { - DEBUG(0,("Unable to set scheduler to SCHED_FIFO (%s)\n", strerror(errno))); - } else { - DEBUG(0,("Set scheduler to SCHED_FIFO\n")); - } + + 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(0,("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(0,("Unable to set scheduler to SCHED_FIFO (%s)\n", strerror(errno))); } else { - sched_setscheduler(getpid(), SCHED_OTHER, &p); + DEBUG(0,("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/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index b584794f1c9..be3b832832a 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -308,6 +308,7 @@ struct ctdb_context { struct ctdb_tcp_list *tcp_list; struct ctdb_client_ip *client_ip_list; bool do_setsched; + void *saved_scheduler_param; }; struct ctdb_db_context { @@ -948,7 +949,8 @@ int ctdb_ctrl_set_rsn_nonempty(struct ctdb_context *ctdb, struct timeval timeout uint32_t destnode, uint32_t db_id, uint64_t rsn); int ctdb_ctrl_delete_low_rsn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t db_id, uint64_t rsn); -void ctdb_set_realtime(bool enable); +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/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index ce84db3e685..546c7fca019 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -646,7 +646,7 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork) if (ctdb->do_setsched) { /* try to set us up as realtime */ - ctdb_set_realtime(true); + ctdb_set_scheduler(ctdb); } /* ensure the socket is deleted on exit of the daemon */ diff --git a/ctdb/server/eventscript.c b/ctdb/server/eventscript.c index fab9175ed29..f40cda18bdb 100644 --- a/ctdb/server/eventscript.c +++ b/ctdb/server/eventscript.c @@ -167,7 +167,7 @@ int ctdb_event_script_callback(struct ctdb_context *ctdb, if (state->child == 0) { close(state->fd[0]); if (ctdb->do_setsched) { - ctdb_set_realtime(false); + ctdb_restore_scheduler(ctdb); } set_close_on_exec(state->fd[1]); va_start(ap, fmt);