summaryrefslogtreecommitdiff
path: root/sys/kern/sysv_shm.c
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2020-06-24 22:03:46 +0000
committercheloha <cheloha@cvs.openbsd.org>2020-06-24 22:03:46 +0000
commitca98724d303a2d2852e5afc6ca4f8df91ce7c4f1 (patch)
tree78c03b913ca4a13ca82e30fea2eea3633977a5a0 /sys/kern/sysv_shm.c
parentd5d00fdfec2707a72d8f409ed3069c27bc916b04 (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/sysv_shm.c')
-rw-r--r--sys/kern/sysv_shm.c10
1 files changed, 5 insertions, 5 deletions
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);