xref: /freebsd/lib/libsys/membarrier.2 (revision 92cd5abb64dd70c305535c9504c6a2b73552147f)
11fc766e3SEd Maste.\" SPDX-License-Identifier: BSD-2-Clause
21fc766e3SEd Maste.\"
31fc766e3SEd Maste.\" Copyright (c) 2024 The FreeBSD Foundation
41fc766e3SEd Maste.\"
51fc766e3SEd Maste.\" This documentation was written by Ed Maste <emaste@FreeBSD.org>
61fc766e3SEd Maste.\" under sponsorship from the FreeBSD Foundation.
71fc766e3SEd Maste.\"
81fc766e3SEd Maste.\" Redistribution and use in source and binary forms, with or without
91fc766e3SEd Maste.\" modification, are permitted provided that the following conditions
101fc766e3SEd Maste.\" are met:
111fc766e3SEd Maste.\" 1. Redistributions of source code must retain the above copyright
121fc766e3SEd Maste.\"    notice, this list of conditions and the following disclaimer.
131fc766e3SEd Maste.\" 2. Redistributions in binary form must reproduce the above copyright
141fc766e3SEd Maste.\"    notice, this list of conditions and the following disclaimer in the
151fc766e3SEd Maste.\"    documentation and/or other materials provided with the distribution.
161fc766e3SEd Maste.\"
171fc766e3SEd Maste.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
181fc766e3SEd Maste.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191fc766e3SEd Maste.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201fc766e3SEd Maste.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
211fc766e3SEd Maste.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221fc766e3SEd Maste.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231fc766e3SEd Maste.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241fc766e3SEd Maste.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251fc766e3SEd Maste.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261fc766e3SEd Maste.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271fc766e3SEd Maste.\" SUCH DAMAGE.
281fc766e3SEd Maste.\"
291fc766e3SEd Maste.Dd October 6, 2024
301fc766e3SEd Maste.Dt MEMBARRIER 2
311fc766e3SEd Maste.Os
321fc766e3SEd Maste.Sh NAME
331fc766e3SEd Maste.Nm membarrier
341fc766e3SEd Maste.Nd memory barrier
351fc766e3SEd Maste.Sh LIBRARY
361fc766e3SEd Maste.Lb libc
371fc766e3SEd Maste.Sh SYNOPSIS
381fc766e3SEd Maste.In sys/membarrier.h
391fc766e3SEd Maste.Ft int
401fc766e3SEd Maste.Fn membarrier "int cmd" "unsigned flags" "int cpu_id"
411fc766e3SEd Maste.Sh DESCRIPTION
421fc766e3SEd MasteThe
431fc766e3SEd Maste.Nm
441fc766e3SEd Mastesystem call provides a memory barrier, ensuring ordering between memory
451fc766e3SEd Masteaccesses performed by different threads or processes within the same address
461fc766e3SEd Mastespace.
471fc766e3SEd Maste.Pp
481fc766e3SEd MasteThe following values for
491fc766e3SEd Maste.Fa cmd
501fc766e3SEd Mastemay be specified:
511fc766e3SEd Maste.Bl -tag -width Dv
521fc766e3SEd Maste.It Dv MEMBARRIER_CMD_QUERY
531fc766e3SEd MasteQuery supported commands.
541fc766e3SEd MasteA bitmask of commands supported by the kernel is returned.
551fc766e3SEd Maste.It Dv MEMBARRIER_CMD_GLOBAL
561fc766e3SEd MasteIssue a memory barrier for all threads from all processes.
571fc766e3SEd Maste.It Dv MEMBARRIER_CMD_SHARED
581fc766e3SEd MasteThis is an alias for
591fc766e3SEd Maste.Dv MEMBARRIER_CMD_GLOBAL .
601fc766e3SEd Maste.It Dv MEMBARRIER_CMD_GLOBAL_EXPEDITED
611fc766e3SEd MasteExecute a memory barrier on all running threads of all processes registered
621fc766e3SEd Mastewith
63*92cd5abbSEd Maste.Dv MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED .
641fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED
651fc766e3SEd MasteRegister the process to receive
661fc766e3SEd Maste.Dv MEMBARRIER_CMD_GLOBAL_EXPEDITED
671fc766e3SEd Mastememory barriers.
681fc766e3SEd Maste.It Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED
691fc766e3SEd MasteExecute a memory barrier on each running thread belonging to the same process
701fc766e3SEd Masteas the thread calling
711fc766e3SEd Maste.Nm .
721fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED
731fc766e3SEd MasteRegister the process to receive
741fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED
751fc766e3SEd Mastememory barriers.
761fc766e3SEd Maste.It Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE
771fc766e3SEd MasteIn addition to the guarantees provided by
781fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED
791fc766e3SEd Masteit also executes machine-specific serialization instructions, which
801fc766e3SEd Masteensures that all possible speculative and out-of-order activities on the target
811fc766e3SEd MasteCPU are fenced.
821fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE
831fc766e3SEd MasteRegister the process to receive
841fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE
851fc766e3SEd Mastememory barriers.
861fc766e3SEd Maste.El
871fc766e3SEd Maste.Pp
881fc766e3SEd MasteThe following
891fc766e3SEd Maste.Fa cmd
901fc766e3SEd Mastevalues are defined for source compatibility but are not yet supported:
911fc766e3SEd Maste.Pp
921fc766e3SEd Maste.Bl -tag -width Dv -compact
931fc766e3SEd Maste.It Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ
941fc766e3SEd Maste.It Dv MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ
951fc766e3SEd Maste.El
961fc766e3SEd Maste.Pp
971fc766e3SEd MasteThe
981fc766e3SEd Maste.Fa flags
991fc766e3SEd Masteargument must be 0.
1001fc766e3SEd MasteThe
1011fc766e3SEd Maste.Fa cpu_id
1021fc766e3SEd Masteargument is ignored.
1031fc766e3SEd Maste.Sh RETURN VALUES
1041fc766e3SEd MasteIf the
105*92cd5abbSEd Maste.Fa cmd
106*92cd5abbSEd Masteis
107*92cd5abbSEd Maste.Dv MEMBARRIER_CMD_QUERY
1081fc766e3SEd Mastea bitmask of supported commands is returned.
1091fc766e3SEd MasteOtherwise, on success,
1101fc766e3SEd Maste.Nm
1111fc766e3SEd Mastereturns 0.
1121fc766e3SEd MasteOn error, -1 is returned and
1131fc766e3SEd Maste.Va errno
1141fc766e3SEd Masteis set to indicate the error.
1151fc766e3SEd Maste.Sh ERRORS
1161fc766e3SEd Maste.Nm
1171fc766e3SEd Mastemay fail with the following errors:
1181fc766e3SEd Maste.Bl -tag -width Er
1191fc766e3SEd Maste.It Bq Er EINVAL
1201fc766e3SEd Maste.Fa cmd
1211fc766e3SEd Mastedoes not specify a valid command.
1221fc766e3SEd Maste.It Bq Er EINVAL
1231fc766e3SEd Maste.Fa flags
1241fc766e3SEd Masteis not 0.
1251fc766e3SEd Maste.It Bq Er EPERM
1261fc766e3SEd MasteAn attempt was made to use
1271fc766e3SEd Maste.Dv MEMBARRIER_CMD_GLOBAL_EXPEDITED ,
1281fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED ,
1291fc766e3SEd Masteor
1301fc766e3SEd Maste.Dv MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE
1311fc766e3SEd Masteby a process that did not previously register use with the corresponding
1321fc766e3SEd Maste.Dv MEMBARRIER_CMD_REGISTER_*
1331fc766e3SEd Maste.Fa cmd .
1341fc766e3SEd Maste.El
1351fc766e3SEd Maste.\" .Sh SEE ALSO
1361fc766e3SEd Maste.Sh STANDARDS
1371fc766e3SEd MasteThe
1381fc766e3SEd Maste.Nm
1391fc766e3SEd Mastesystem call originated in Linux.
1401fc766e3SEd MasteThis implementation aims to be source-compatible with the Linux implementation.
1411fc766e3SEd MasteCertain
1421fc766e3SEd Maste.Fa cmd
1431fc766e3SEd Masteand
1441fc766e3SEd Maste.Fa flags
1451fc766e3SEd Mastevalues are currently not supported by
1461fc766e3SEd Maste.Fx .
1471fc766e3SEd Maste.Sh HISTORY
1481fc766e3SEd MasteThe
1491fc766e3SEd Maste.Nm
1501fc766e3SEd Mastefunction was introduced in
1511fc766e3SEd Maste.Fx 14.1 .
152