Re: git: 805d759338a2 - main - mlx4: Move DEFINE_MUTEX() outside function body.

From: Hans Petter Selasky <hselasky_at_freebsd.org>
Date: Sun, 21 May 2023 22:13:26 UTC
On 5/21/23 23:37, Hans Petter Selasky wrote:
> DEFINE_MUTEX is Linux’s API, implemented in LinuxKPI. So Linux’s 
> behaviour is absolutely relevant. Any deviation from Linux’s semantics 
> is an incompatibility that requires patching any sources that are built 
> for FreeBSD using LinuxKPI. It is generally best to minimise that.

Jess, listen:

Probably at some point, there could be an initialization macro for the 
SX locks used in the LinuxKPI, being of type SX_NOWITNESS, simply 
plotting in the constants needed in the sx structure, exactly like they 
do under Linux.

Then neither SYSINITs, nor my patch will be needed for the sake of 
DEFINE_MUTEX(). Can we wait for that?

The reason for this is Linux has a bad habit of not destroying locks, so 
FreeBSD cannot add any WITNESS objects for locks that are not destroyed 
anyway. Most of the work done by sx_init() is putting a few constants 
into various SX structure fields. Only the WITNESS part needs execution, 
if you get what I mean.

This change is made so I can let others easily test another patchset. 
Also this change is harmless as such.

Looking at the whole Linux tree, the most common way is to use 
DEFINE_MUTEX() outside macros and functions:

# grep -r DEFINE_MUTEX * | grep -vE ":static " | grep -vE 
":DEFINE_MUTEX" | wc -l
       57

# grep -r DEFINE_MUTEX * | wc -l
     1293

--HPS