summaryrefslogtreecommitdiff
path: root/sys/kern/sysv_msg.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_msg.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_msg.c')
-rw-r--r--sys/kern/sysv_msg.c10
1 files changed, 5 insertions, 5 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);
}