diff options
author | cheloha <cheloha@cvs.openbsd.org> | 2020-06-24 22:03:46 +0000 |
---|---|---|
committer | cheloha <cheloha@cvs.openbsd.org> | 2020-06-24 22:03:46 +0000 |
commit | ca98724d303a2d2852e5afc6ca4f8df91ce7c4f1 (patch) | |
tree | 78c03b913ca4a13ca82e30fea2eea3633977a5a0 /sys/kern | |
parent | d5d00fdfec2707a72d8f409ed3069c27bc916b04 (diff) |
kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)
time_second(9) and time_uptime(9) are widely used in the kernel to
quickly get the system UTC or system uptime as a time_t. However,
time_t is 64-bit everywhere, so it is not generally safe to use them
on 32-bit platforms: you have a split-read problem if your hardware
cannot perform atomic 64-bit reads.
This patch replaces time_second(9) with gettime(9), a safer successor
interface, throughout the kernel. Similarly, time_uptime(9) is replaced
with getuptime(9).
There is a performance cost on 32-bit platforms in exchange for
eliminating the split-read problem: instead of two register reads you
now have a lockless read loop to pull the values from the timehands.
This is really not *too* bad in the grand scheme of things, but
compared to what we were doing before it is several times slower.
There is no performance cost on 64-bit (__LP64__) platforms.
With input from visa@, dlg@, and tedu@.
Several bugs squashed by visa@.
ok kettenis@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/sysv_msg.c | 10 | ||||
-rw-r--r-- | sys/kern/sysv_sem.c | 8 | ||||
-rw-r--r-- | sys/kern/sysv_shm.c | 10 | ||||
-rw-r--r-- | sys/kern/vfs_sync.c | 6 | ||||
-rw-r--r-- | sys/kern/vfs_syscalls.c | 4 |
5 files changed, 19 insertions, 19 deletions
diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c index d518837a6aa..d09e3b32e61 100644 --- a/sys/kern/sysv_msg.c +++ b/sys/kern/sysv_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysv_msg.c,v 1.36 2019/12/30 15:48:12 mpi Exp $ */ +/* $OpenBSD: sysv_msg.c,v 1.37 2020/06/24 22:03:42 cheloha Exp $ */ /* $NetBSD: sysv_msg.c,v 1.19 1996/02/09 19:00:18 christos Exp $ */ /* * Copyright (c) 2009 Bret S. Lambert <blambert@openbsd.org> @@ -168,7 +168,7 @@ msgctl1(struct proc *p, int msqid, int cmd, caddr_t buf, (que->msqid_ds.msg_perm.mode & ~0777) | (tmp.msg_perm.mode & 0777); que->msqid_ds.msg_qbytes = tmp.msg_qbytes; - que->msqid_ds.msg_ctime = time_second; + que->msqid_ds.msg_ctime = gettime(); break; case IPC_STAT: @@ -414,7 +414,7 @@ que_create(key_t key, struct ucred *cred, int mode) que->msqid_ds.msg_perm.mode = mode & 0777; que->msqid_ds.msg_perm.seq = ++sequence & 0x7fff; que->msqid_ds.msg_qbytes = msginfo.msgmnb; - que->msqid_ds.msg_ctime = time_second; + que->msqid_ds.msg_ctime = gettime(); TAILQ_INIT(&que->que_msgs); @@ -549,7 +549,7 @@ msg_enqueue(struct que *que, struct msg *msg, struct proc *p) que->msqid_ds.msg_cbytes += msg->msg_len; que->msqid_ds.msg_qnum++; que->msqid_ds.msg_lspid = p->p_p->ps_pid; - que->msqid_ds.msg_stime = time_second; + que->msqid_ds.msg_stime = gettime(); TAILQ_INSERT_TAIL(&que->que_msgs, msg, msg_next); } @@ -560,7 +560,7 @@ msg_dequeue(struct que *que, struct msg *msg, struct proc *p) que->msqid_ds.msg_cbytes -= msg->msg_len; que->msqid_ds.msg_qnum--; que->msqid_ds.msg_lrpid = p->p_p->ps_pid; - que->msqid_ds.msg_rtime = time_second; + que->msqid_ds.msg_rtime = gettime(); TAILQ_REMOVE(&que->que_msgs, msg, msg_next); } diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c index b2222ba92ba..f9dc776842b 100644 --- a/sys/kern/sysv_sem.c +++ b/sys/kern/sysv_sem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysv_sem.c,v 1.57 2020/01/08 15:03:10 mpi Exp $ */ +/* $OpenBSD: sysv_sem.c,v 1.58 2020/06/24 22:03:42 cheloha Exp $ */ /* $NetBSD: sysv_sem.c,v 1.26 1996/02/09 19:00:25 christos Exp $ */ /* @@ -293,7 +293,7 @@ semctl1(struct proc *p, int semid, int semnum, int cmd, union semun *arg, semaptr->sem_perm.gid = sbuf.sem_perm.gid; semaptr->sem_perm.mode = (semaptr->sem_perm.mode & ~0777) | (sbuf.sem_perm.mode & 0777); - semaptr->sem_ctime = time_second; + semaptr->sem_ctime = gettime(); break; case IPC_STAT: @@ -478,7 +478,7 @@ sys_semget(struct proc *p, void *v, register_t *retval) (semseqs[semid] + 1) & 0x7fff; semaptr_new->sem_nsems = nsems; semaptr_new->sem_otime = 0; - semaptr_new->sem_ctime = time_second; + semaptr_new->sem_ctime = gettime(); sema[semid] = semaptr_new; semtot += nsems; } else { @@ -743,7 +743,7 @@ done: semptr->sempid = p->p_p->ps_pid; } - semaptr->sem_otime = time_second; + semaptr->sem_otime = gettime(); /* Do a wakeup if any semaphore was up'd. */ if (do_wakeup) { diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index 96c5abeea75..1fd99f5b95d 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysv_shm.c,v 1.76 2020/03/04 08:04:48 anton Exp $ */ +/* $OpenBSD: sysv_shm.c,v 1.77 2020/06/24 22:03:42 cheloha Exp $ */ /* $NetBSD: sysv_shm.c,v 1.50 1998/10/21 22:24:29 tron Exp $ */ /* @@ -169,7 +169,7 @@ shm_delete_mapping(struct vmspace *vm, struct shmmap_state *shmmap_s) end = round_page(shmmap_s->va+shmseg->shm_segsz); uvm_unmap(&vm->vm_map, trunc_page(shmmap_s->va), end); shmmap_s->shmid = -1; - shmseg->shm_dtime = time_second; + shmseg->shm_dtime = gettime(); if ((--shmseg->shm_nattch <= 0) && (shmseg->shm_perm.mode & SHMSEG_REMOVED)) { shm_deallocate_segment(shmseg); @@ -286,7 +286,7 @@ sys_shmat(struct proc *p, void *v, register_t *retval) shmmap_s->va = attach_va; shmmap_s->shmid = SCARG(uap, shmid); shmseg->shm_lpid = p->p_p->ps_pid; - shmseg->shm_atime = time_second; + shmseg->shm_atime = gettime(); *retval = attach_va; return (0); } @@ -331,7 +331,7 @@ sys_shmctl(struct proc *p, void *v, register_t *retval) shmseg->shm_perm.mode = (shmseg->shm_perm.mode & ~ACCESSPERMS) | (inbuf.shm_perm.mode & ACCESSPERMS); - shmseg->shm_ctime = time_second; + shmseg->shm_ctime = gettime(); break; case IPC_RMID: if ((error = ipcperm(cred, &shmseg->shm_perm, IPC_M)) != 0) @@ -449,7 +449,7 @@ shmget_allocate_segment(struct proc *p, shmseg->shm_cpid = p->p_p->ps_pid; shmseg->shm_lpid = shmseg->shm_nattch = 0; shmseg->shm_atime = shmseg->shm_dtime = 0; - shmseg->shm_ctime = time_second; + shmseg->shm_ctime = gettime(); shmseg->shm_internal = shm_handle; *retval = IXSEQ_TO_IPCID(segnum, shmseg->shm_perm); diff --git a/sys/kern/vfs_sync.c b/sys/kern/vfs_sync.c index 9a9231a3eee..62693a1d2f0 100644 --- a/sys/kern/vfs_sync.c +++ b/sys/kern/vfs_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_sync.c,v 1.63 2020/01/20 23:21:56 claudio Exp $ */ +/* $OpenBSD: vfs_sync.c,v 1.64 2020/06/24 22:03:41 cheloha Exp $ */ /* * Portions of this code are: @@ -142,7 +142,7 @@ syncer_thread(void *arg) int s; for (;;) { - starttime = time_second; + starttime = gettime(); /* * Push files whose dirty time has expired. @@ -228,7 +228,7 @@ syncer_thread(void *arg) * matter as we are just trying to generally pace the * filesystem activity. */ - if (time_second == starttime) + if (gettime() == starttime) tsleep_nsec(&lbolt, PPAUSE, "syncer", INFSLP); } } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 44dcf3c117e..f195ac991dc 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_syscalls.c,v 1.344 2020/03/19 13:55:20 anton Exp $ */ +/* $OpenBSD: vfs_syscalls.c,v 1.345 2020/06/24 22:03:42 cheloha Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */ /* @@ -251,7 +251,7 @@ update: */ error = VFS_MOUNT(mp, fspath, args, &nd, p); if (!error) { - mp->mnt_stat.f_ctime = time_second; + mp->mnt_stat.f_ctime = gettime(); } if (mp->mnt_flag & MNT_UPDATE) { vfs_unbusy(vp->v_mount); |