From: "Ted Unangst" Subject: Re: sysctl: unlock KERN_CONSBUF and KERN_MSGBUF To: "Alexander Bluhm" Cc: "Vitaliy Makkoveev" , tech@openbsd.org Date: Thu, 08 May 2025 12:24:57 -0400 On 2025-05-08, Alexander Bluhm wrote: > I was considering memset() and mutex again. Although clang does > not optimize away the memset stores, the processor still could to > this. But putting a mutex barrier between clearing and filling the > memory of struct ump prevents all optimization. > > Of course sysctl(2) is not the hot path, it does not matter for > speed, and I have no benchmarks. It is more about MP programming > in general. I like this, if only because it makes the mtx_enter a little easier to see. > > What do you think? > > bluhm > > Index: kern/kern_sysctl.c > =================================================================== > RCS file: /data/mirror/openbsd/cvs/src/sys/kern/kern_sysctl.c,v > diff -u -p -r1.467 kern_sysctl.c > --- kern/kern_sysctl.c 6 May 2025 18:34:26 -0000 1.467 > +++ kern/kern_sysctl.c 8 May 2025 12:58:42 -0000 > @@ -598,8 +598,8 @@ kern_sysctl(int *name, u_int namelen, vo > } else > return (0); > > - memset(&ump, 0, sizeof(ump)); > mtx_enter(&log_mtx); > + memset(&ump, 0, sizeof(ump)); > ump.msg_magic = mp->msg_magic; > ump.msg_bufs = mp->msg_bufs; > ump.msg_bufx = mp->msg_bufx; > >