1*1fc766e3SEd Maste.\" SPDX-License-Identifier: BSD-2-Clause 2*1fc766e3SEd Maste.\" 3*1fc766e3SEd Maste.\" Copyright (c) 2024 The FreeBSD Foundation 4*1fc766e3SEd Maste.\" 5*1fc766e3SEd Maste.\" This documentation was written by Ed Maste <emaste@FreeBSD.org> 6*1fc766e3SEd Maste.\" under sponsorship from the FreeBSD Foundation. 7*1fc766e3SEd Maste.\" 8*1fc766e3SEd Maste.\" Redistribution and use in source and binary forms, with or without 9*1fc766e3SEd Maste.\" modification, are permitted provided that the following conditions 10*1fc766e3SEd Maste.\" are met: 11*1fc766e3SEd Maste.\" 1. Redistributions of source code must retain the above copyright 12*1fc766e3SEd Maste.\" notice, this list of conditions and the following disclaimer. 13*1fc766e3SEd Maste.\" 2. Redistributions in binary form must reproduce the above copyright 14*1fc766e3SEd Maste.\" notice, this list of conditions and the following disclaimer in the 15*1fc766e3SEd Maste.\" documentation and/or other materials provided with the distribution. 16*1fc766e3SEd Maste.\" 17*1fc766e3SEd Maste.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 18*1fc766e3SEd Maste.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19*1fc766e3SEd Maste.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20*1fc766e3SEd Maste.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 21*1fc766e3SEd Maste.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22*1fc766e3SEd Maste.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23*1fc766e3SEd Maste.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24*1fc766e3SEd Maste.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25*1fc766e3SEd Maste.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26*1fc766e3SEd Maste.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27*1fc766e3SEd Maste.\" SUCH DAMAGE. 28*1fc766e3SEd Maste.\" 29*1fc766e3SEd Maste.Dd October 6, 2024 30*1fc766e3SEd Maste.Dt MEMBARRIER 2 31*1fc766e3SEd Maste.Os 32*1fc766e3SEd Maste.Sh NAME 33*1fc766e3SEd Maste.Nm membarrier 34*1fc766e3SEd Maste.Nd memory barrier 35*1fc766e3SEd Maste.Sh LIBRARY 36*1fc766e3SEd Maste.Lb libc 37*1fc766e3SEd Maste.Sh SYNOPSIS 38*1fc766e3SEd Maste.In sys/membarrier.h 39*1fc766e3SEd Maste.Ft int 40*1fc766e3SEd Maste.Fn membarrier "int cmd" "unsigned flags" "int cpu_id" 41*1fc766e3SEd Maste.Sh DESCRIPTION 42*1fc766e3SEd MasteThe 43*1fc766e3SEd Maste.Nm 44*1fc766e3SEd Mastesystem call provides a memory barrier, ensuring ordering between memory 45*1fc766e3SEd Masteaccesses performed by different threads or processes within the same address 46*1fc766e3SEd Mastespace. 47*1fc766e3SEd Maste.Pp 48*1fc766e3SEd MasteThe following values for 49*1fc766e3SEd Maste.Fa cmd 50*1fc766e3SEd Mastemay be specified: 51*1fc766e3SEd Maste.Bl -tag -width Dv 52*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_QUERY 53*1fc766e3SEd MasteQuery supported commands. 54*1fc766e3SEd MasteA bitmask of commands supported by the kernel is returned. 55*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_GLOBAL 56*1fc766e3SEd MasteIssue a memory barrier for all threads from all processes. 57*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_SHARED 58*1fc766e3SEd MasteThis is an alias for 59*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_GLOBAL . 60*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_GLOBAL_EXPEDITED 61*1fc766e3SEd MasteExecute a memory barrier on all running threads of all processes registered 62*1fc766e3SEd Mastewith 63*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED 64*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED 65*1fc766e3SEd MasteRegister the process to receive 66*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_GLOBAL_EXPEDITED 67*1fc766e3SEd Mastememory barriers. 68*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED 69*1fc766e3SEd MasteExecute a memory barrier on each running thread belonging to the same process 70*1fc766e3SEd Masteas the thread calling 71*1fc766e3SEd Maste.Nm . 72*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED 73*1fc766e3SEd MasteRegister the process to receive 74*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED 75*1fc766e3SEd Mastememory barriers. 76*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 77*1fc766e3SEd MasteIn addition to the guarantees provided by 78*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED 79*1fc766e3SEd Masteit also executes machine-specific serialization instructions, which 80*1fc766e3SEd Masteensures that all possible speculative and out-of-order activities on the target 81*1fc766e3SEd MasteCPU are fenced. 82*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE 83*1fc766e3SEd MasteRegister the process to receive 84*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 85*1fc766e3SEd Mastememory barriers. 86*1fc766e3SEd Maste.El 87*1fc766e3SEd Maste.Pp 88*1fc766e3SEd MasteThe following 89*1fc766e3SEd Maste.Fa cmd 90*1fc766e3SEd Mastevalues are defined for source compatibility but are not yet supported: 91*1fc766e3SEd Maste.Pp 92*1fc766e3SEd Maste.Bl -tag -width Dv -compact 93*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ 94*1fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ 95*1fc766e3SEd Maste.El 96*1fc766e3SEd Maste.Pp 97*1fc766e3SEd MasteThe 98*1fc766e3SEd Maste.Fa flags 99*1fc766e3SEd Masteargument must be 0. 100*1fc766e3SEd MasteThe 101*1fc766e3SEd Maste.Fa cpu_id 102*1fc766e3SEd Masteargument is ignored. 103*1fc766e3SEd Maste.Sh RETURN VALUES 104*1fc766e3SEd MasteIf the 105*1fc766e3SEd Maste.Dv cmd 106*1fc766e3SEd Masteis MEMBARRIER_CMD_QUERY 107*1fc766e3SEd Mastea bitmask of supported commands is returned. 108*1fc766e3SEd MasteOtherwise, on success, 109*1fc766e3SEd Maste.Nm 110*1fc766e3SEd Mastereturns 0. 111*1fc766e3SEd MasteOn error, -1 is returned and 112*1fc766e3SEd Maste.Va errno 113*1fc766e3SEd Masteis set to indicate the error. 114*1fc766e3SEd Maste.Sh ERRORS 115*1fc766e3SEd Maste.Nm 116*1fc766e3SEd Mastemay fail with the following errors: 117*1fc766e3SEd Maste.Bl -tag -width Er 118*1fc766e3SEd Maste.It Bq Er EINVAL 119*1fc766e3SEd Maste.Fa cmd 120*1fc766e3SEd Mastedoes not specify a valid command. 121*1fc766e3SEd Maste.It Bq Er EINVAL 122*1fc766e3SEd Maste.Fa flags 123*1fc766e3SEd Masteis not 0. 124*1fc766e3SEd Maste.It Bq Er EPERM 125*1fc766e3SEd MasteAn attempt was made to use 126*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_GLOBAL_EXPEDITED , 127*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED , 128*1fc766e3SEd Masteor 129*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 130*1fc766e3SEd Masteby a process that did not previously register use with the corresponding 131*1fc766e3SEd Maste.Dv MEMBARRIER_CMD_REGISTER_* 132*1fc766e3SEd Maste.Fa cmd . 133*1fc766e3SEd Maste.El 134*1fc766e3SEd Maste.\" .Sh SEE ALSO 135*1fc766e3SEd Maste.Sh STANDARDS 136*1fc766e3SEd MasteThe 137*1fc766e3SEd Maste.Nm 138*1fc766e3SEd Mastesystem call originated in Linux. 139*1fc766e3SEd MasteThis implementation aims to be source-compatible with the Linux implementation. 140*1fc766e3SEd MasteCertain 141*1fc766e3SEd Maste.Fa cmd 142*1fc766e3SEd Masteand 143*1fc766e3SEd Maste.Fa flags 144*1fc766e3SEd Mastevalues are currently not supported by 145*1fc766e3SEd Maste.Fx . 146*1fc766e3SEd Maste.Sh HISTORY 147*1fc766e3SEd MasteThe 148*1fc766e3SEd Maste.Nm 149*1fc766e3SEd Mastefunction was introduced in 150*1fc766e3SEd Maste.Fx 14.1 . 151