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
}
/*