1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

fully save/restore scheduler parameters

(This used to be ctdb commit 59408eabe7515d49a6eef3b6fb2590a1cd1df956)
This commit is contained in:
Andrew Tridgell 2007-07-13 09:35:46 +10:00
parent 698a8bc909
commit d2a5af7eb8
4 changed files with 37 additions and 13 deletions

View File

@ -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
}

View File

@ -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,

View File

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

View File

@ -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);