Stop using eventhandlers for itimers subsystem exec and exit hooks.

While there, do some minor cleanup for kclocks.  They are only
registered from kern_time.c, make registration function static.
Remove event hooks, they are not used by both registered kclocks.
Add some consts.

Perhaps we can stop registering kclocks at all and statically
initialize them.

Reviewed by:	mjg
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D27305
This commit is contained in:
Konstantin Belousov 2020-11-21 21:43:36 +00:00
parent 2717b998b2
commit e68c619144
4 changed files with 40 additions and 51 deletions

View File

@ -67,6 +67,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/timers.h>
#include <sys/umtx.h>
#include <sys/vnode.h>
#include <sys/wait.h>
@ -1049,6 +1050,7 @@ exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv)
sigfastblock_clear(td);
umtx_exec(p);
itimers_exec(p);
EVENTHANDLER_DIRECT_INVOKE(process_exec, p, imgp);

View File

@ -72,6 +72,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sdt.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/timers.h>
#include <sys/umtx.h>
#ifdef KTRACE
#include <sys/ktrace.h>
@ -324,6 +325,8 @@ exit1(struct thread *td, int rval, int signo)
mtx_unlock(&ppeers_lock);
}
itimers_exit(p);
/*
* Check if any loadable modules need anything done at process exit.
* E.g. SYSV IPC stuff.

View File

@ -43,7 +43,6 @@ __FBSDID("$FreeBSD$");
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/sysproto.h>
#include <sys/eventhandler.h>
#include <sys/resourcevar.h>
#include <sys/signalvar.h>
#include <sys/kernel.h>
@ -99,8 +98,6 @@ static void itimer_enter(struct itimer *);
static void itimer_leave(struct itimer *);
static struct itimer *itimer_find(struct proc *, int);
static void itimers_alloc(struct proc *);
static void itimers_event_hook_exec(void *arg, struct proc *p, struct image_params *imgp);
static void itimers_event_hook_exit(void *arg, struct proc *p);
static int realtimer_create(struct itimer *);
static int realtimer_gettime(struct itimer *, struct itimerspec *);
static int realtimer_settime(struct itimer *, int,
@ -109,7 +106,7 @@ static int realtimer_delete(struct itimer *);
static void realtimer_clocktime(clockid_t, struct timespec *);
static void realtimer_expire(void *);
int register_posix_clock(int, struct kclock *);
static int register_posix_clock(int, const struct kclock *);
void itimer_fire(struct itimer *it);
int itimespecfix(struct timespec *ts);
@ -1086,12 +1083,11 @@ ppsratecheck(struct timeval *lasttime, int *curpps, int maxpps)
static void
itimer_start(void)
{
struct kclock rt_clock = {
static const struct kclock rt_clock = {
.timer_create = realtimer_create,
.timer_delete = realtimer_delete,
.timer_settime = realtimer_settime,
.timer_gettime = realtimer_gettime,
.event_hook = NULL
};
itimer_zone = uma_zcreate("itimer", sizeof(struct itimer),
@ -1101,14 +1097,10 @@ itimer_start(void)
p31b_setcfg(CTL_P1003_1B_TIMERS, 200112L);
p31b_setcfg(CTL_P1003_1B_DELAYTIMER_MAX, INT_MAX);
p31b_setcfg(CTL_P1003_1B_TIMER_MAX, TIMER_MAX);
EVENTHANDLER_REGISTER(process_exit, itimers_event_hook_exit,
(void *)ITIMER_EV_EXIT, EVENTHANDLER_PRI_ANY);
EVENTHANDLER_REGISTER(process_exec, itimers_event_hook_exec,
(void *)ITIMER_EV_EXEC, EVENTHANDLER_PRI_ANY);
}
int
register_posix_clock(int clockid, struct kclock *clk)
static int
register_posix_clock(int clockid, const struct kclock *clk)
{
if ((unsigned)clockid >= MAX_CLOCKS) {
printf("%s: invalid clockid\n", __func__);
@ -1714,46 +1706,41 @@ itimers_alloc(struct proc *p)
}
}
static void
itimers_event_hook_exec(void *arg, struct proc *p, struct image_params *imgp __unused)
{
itimers_event_hook_exit(arg, p);
}
/* Clean up timers when some process events are being triggered. */
static void
itimers_event_hook_exit(void *arg, struct proc *p)
itimers_event_exit_exec(int start_idx, struct proc *p)
{
struct itimers *its;
struct itimer *it;
int event = (int)(intptr_t)arg;
int i;
if (p->p_itimers != NULL) {
its = p->p_itimers;
for (i = 0; i < MAX_CLOCKS; ++i) {
if (posix_clocks[i].event_hook != NULL)
CLOCK_CALL(i, event_hook, (p, i, event));
}
/*
* According to susv3, XSI interval timers should be inherited
* by new image.
*/
if (event == ITIMER_EV_EXEC)
i = 3;
else if (event == ITIMER_EV_EXIT)
i = 0;
else
panic("unhandled event");
for (; i < TIMER_MAX; ++i) {
if ((it = its->its_timers[i]) != NULL)
kern_ktimer_delete(curthread, i);
}
if (its->its_timers[0] == NULL &&
its->its_timers[1] == NULL &&
its->its_timers[2] == NULL) {
free(its, M_SUBPROC);
p->p_itimers = NULL;
}
its = p->p_itimers;
if (its == NULL)
return;
for (i = start_idx; i < TIMER_MAX; ++i) {
if ((it = its->its_timers[i]) != NULL)
kern_ktimer_delete(curthread, i);
}
if (its->its_timers[0] == NULL && its->its_timers[1] == NULL &&
its->its_timers[2] == NULL) {
free(its, M_SUBPROC);
p->p_itimers = NULL;
}
}
void
itimers_exec(struct proc *p)
{
/*
* According to susv3, XSI interval timers should be inherited
* by new image.
*/
itimers_event_exit_exec(3, p);
}
void
itimers_exit(struct proc *p)
{
itimers_event_exit_exec(0, p);
}

View File

@ -107,13 +107,10 @@ struct kclock {
int (*timer_delete)(struct itimer * timer);
int (*timer_gettime)(struct itimer * timer,
struct itimerspec * cur_value);
void (*event_hook)(struct proc *p, clockid_t clock_id, int event);
};
/* Event values for event_hook() */
#define ITIMER_EV_EXEC 0
#define ITIMER_EV_EXIT 1
void itimers_exec(struct proc *p);
void itimers_exit(struct proc *p);
int itimer_accept(struct proc *p, int tid, ksiginfo_t *ksi);
#endif
#endif /* !_SYS_TIMERS_H_ */