Set SCHED_RR
This commit is contained in:
parent
96a61cbac3
commit
53c9a57116
44
uvrrpd.c
44
uvrrpd.c
|
@ -25,6 +25,11 @@
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#ifdef _POSIX_PRIORITY_SCHEDULING
|
||||||
|
#include <sched.h>
|
||||||
|
#else
|
||||||
|
#warning "no sched rt"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "uvrrpd.h"
|
#include "uvrrpd.h"
|
||||||
#include "vrrp.h"
|
#include "vrrp.h"
|
||||||
|
@ -128,6 +133,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* lock procress's virtual address space into RAM */
|
/* lock procress's virtual address space into RAM */
|
||||||
mlockall(MCL_CURRENT | MCL_FUTURE);
|
mlockall(MCL_CURRENT | MCL_FUTURE);
|
||||||
|
/* set SCHED_RR */
|
||||||
|
uvrrpd_sched_set();
|
||||||
|
|
||||||
/* process */
|
/* process */
|
||||||
set_bit(KEEP_GOING, ®);
|
set_bit(KEEP_GOING, ®);
|
||||||
|
@ -412,3 +419,40 @@ static void ctrlfile(int vrid, int *fd)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uvrrpd_sched_set() - set SCHED_RR scheduler
|
||||||
|
*/
|
||||||
|
int uvrrpd_sched_set()
|
||||||
|
{
|
||||||
|
#ifdef _POSIX_PRIORITY_SCHEDULING
|
||||||
|
struct sched_param param;
|
||||||
|
|
||||||
|
param.sched_priority = sched_get_priority_max(SCHED_RR);
|
||||||
|
if (sched_setscheduler(0, SCHED_RR, ¶m) != 0) {
|
||||||
|
log_error("sched_setscheduler() - %m");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
nice(-20);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uvrrpd_sched_unset() - unset SCHED_RR scheduler
|
||||||
|
*/
|
||||||
|
int uvrrpd_sched_unset()
|
||||||
|
{
|
||||||
|
#ifdef _POSIX_PRIORITY_SCHEDULING
|
||||||
|
struct sched_param param;
|
||||||
|
|
||||||
|
param.sched_priority = sched_get_priority_max(SCHED_OTHER);
|
||||||
|
if (sched_setscheduler(0, SCHED_OTHER, ¶m) != 0) {
|
||||||
|
log_error("sched_setscheduler() - %m");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
3
uvrrpd.h
3
uvrrpd.h
|
@ -42,4 +42,7 @@ enum uvrrpd_control {
|
||||||
UVRRPD_RELOAD = BIT_MASK(3),
|
UVRRPD_RELOAD = BIT_MASK(3),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int uvrrpd_sched_set(void);
|
||||||
|
int uvrrpd_sched_unset(void);
|
||||||
|
|
||||||
#endif /* _UVRRPD_ */
|
#endif /* _UVRRPD_ */
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include "vrrp.h"
|
#include "vrrp.h"
|
||||||
#include "vrrp_exec.h"
|
#include "vrrp_exec.h"
|
||||||
|
#include "uvrrpd.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
@ -137,6 +138,7 @@ int vrrp_exec(struct vrrp *vrrp, const struct vrrp_net *vnet, vrrp_state state)
|
||||||
sigaction(SIGQUIT, &sa_ignore, &sa_origquit);
|
sigaction(SIGQUIT, &sa_ignore, &sa_origquit);
|
||||||
|
|
||||||
/* fork */
|
/* fork */
|
||||||
|
uvrrpd_sched_unset(); /* remove SCHED_RR */
|
||||||
pid_t child = fork();
|
pid_t child = fork();
|
||||||
int status, savedErrno;
|
int status, savedErrno;
|
||||||
|
|
||||||
|
@ -167,7 +169,8 @@ int vrrp_exec(struct vrrp *vrrp, const struct vrrp_net *vnet, vrrp_state state)
|
||||||
|
|
||||||
/* parent */
|
/* parent */
|
||||||
if (child > 0) {
|
if (child > 0) {
|
||||||
|
|
||||||
|
uvrrpd_sched_set(); /* restore SCHED_RR */
|
||||||
while (waitpid(child, &status, 0) == -1) {
|
while (waitpid(child, &status, 0) == -1) {
|
||||||
if (errno != EINTR) { /* Error other than EINTR */
|
if (errno != EINTR) { /* Error other than EINTR */
|
||||||
log_error("vrid %d :: waitpid - %m", vrrp->vrid);
|
log_error("vrid %d :: waitpid - %m", vrrp->vrid);
|
||||||
|
|
Loading…
Reference in New Issue