From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7DD5D41D75; Sat, 25 Feb 2023 11:16:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1B84140DDC; Sat, 25 Feb 2023 11:16:58 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 7375B40DDA for ; Sat, 25 Feb 2023 11:16:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677320215; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q0vAVMJ7R4KAbiNSGRI8lpfOJK32GW4/IzlkjSCUmuM=; b=E7j//wRtdqo80wnHxea4jJpOfcQNGstNf9kQDNZ3x46EPwjrSGgGrC9c5/In2Hg4WGhwnV 1C8fOlRxHpVa87nIKFHuJqRow+Te+MZ2uHkQTaQblfBIuljkQQwpXJ5c9JI8MMw/AC6CWF tXJkkYHimc6tCIkEa9oj0pDwWKNEt6I= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-460-yZPxDJmTPiSh-FZf7tCRaQ-1; Sat, 25 Feb 2023 05:16:54 -0500 X-MC-Unique: yZPxDJmTPiSh-FZf7tCRaQ-1 Received: by mail-pf1-f199.google.com with SMTP id w3-20020aa78583000000b005d244af158eso833239pfn.23 for ; Sat, 25 Feb 2023 02:16:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q0vAVMJ7R4KAbiNSGRI8lpfOJK32GW4/IzlkjSCUmuM=; b=N3gd89iyCnPcn0Oi11Y2wOwb+KHLwjJnNFYg6lS/EGzFBrNGdKXwgVPU6xBWINkj6b xxbUhi9lAob82pUaJr0NuJu4xdbXLz8PFbQCTtK50fvwLCb+JDnFq3q1YGFjsBTSB+y9 bwIZUjnxFxSx7msnaV6VsgXxVQdK6gZ0hEhzgK1LiBspRQ9xUfryuZ4FxxqkNlolVWUy Oavci4Vn2NHBLU54IRFBaSVWoBrP0XZNBglu2YozNqjaSwH+JXDgFu9Ohz/Zglp/zM5C igabLRxmi2ki38D30V+upeymr6SJWw8RKLAdq7gGzN/vAwn67SWPKoXBzJ8PGOMSFVEG W1iQ== X-Gm-Message-State: AO0yUKX/nKNgtwt6DVV9oCM+KYRLWOw7Oem1+w4Zc5hAC0U7fbWcxSF8 KBeBzuOSZqJkj7j409sdFnDNxI/Q9ki3UweThxpmTGGkkAq2XjcuU4nLev/LwGED+nJlgC0HyOt 0/E8vyAszCIDi7OHloDGJrPtYJKY= X-Received: by 2002:a17:902:f544:b0:19a:fa2f:559e with SMTP id h4-20020a170902f54400b0019afa2f559emr1376941plf.3.1677320212977; Sat, 25 Feb 2023 02:16:52 -0800 (PST) X-Google-Smtp-Source: AK7set/lgtPoX9EVVPc0g5/YIybY8e/YJQlRe11dBKUBJdWmf8eqK/9jdIlbv8xE7vmwnLItjHhX7CHKQId5NIBNErM= X-Received: by 2002:a17:902:f544:b0:19a:fa2f:559e with SMTP id h4-20020a170902f54400b0019afa2f559emr1376934plf.3.1677320212461; Sat, 25 Feb 2023 02:16:52 -0800 (PST) MIME-Version: 1.0 References: <20230224081642.2566619-1-david.marchand@redhat.com> <20230224151143.3274897-1-david.marchand@redhat.com> <095511d4-4fbb-47a8-a8a5-f2a3b932c01f@app.fastmail.com> In-Reply-To: <095511d4-4fbb-47a8-a8a5-f2a3b932c01f@app.fastmail.com> From: David Marchand Date: Sat, 25 Feb 2023 11:16:41 +0100 Message-ID: Subject: Re: [PATCH v2 00/20] Enable lock annotations on most libraries and drivers To: =?UTF-8?Q?Ga=C3=ABtan_Rivet?= Cc: dev@dpdk.org, Thomas Monjalon X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Salut Ga=C3=ABtan, On Fri, Feb 24, 2023 at 4:59 PM Ga=C3=ABtan Rivet wrote: > > FreeBSD libc pthread API has lock annotations while Linux glibc has > > none. > > We could simply disable the check on FreeBSD, but having this check, > > a few issues got raised in drivers that are built with FreeBSD. > > For now, I went with a simple #ifdef FreeBSD for pthread mutex related > > annotations in our code. > > > > Hi David, > > This is a great change, thanks for doing it. > However I am not sure I understand the logic regarding the '#ifdef FREEBS= D'. > > These annotations provide static hints to clang's thread safety analysis. > What is the dependency on FreeBSD glibc? FreeBSD libc added clang annotations, while glibc did not. FreeBSD 13.1 libc: int pthread_mutex_lock(pthread_mutex_t * __mutex) __locks_exclusive(*__mutex); With: #if __has_extension(c_thread_safety_attributes) #define __lock_annotate(x) __attribute__((x)) #else #define __lock_annotate(x) #endif /* Function acquires an exclusive or shared lock. */ #define __locks_exclusive(...) \ __lock_annotate(exclusive_lock_function(__VA_ARGS__)) glibc: extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __THROWNL __nonnull ((1)); Since glibc does not declare that pthread_mutex_t is lockable, adding an annotation triggers an error for Linux (taking eal_common_proc.c patch 14 as an example): ../lib/eal/common/eal_common_proc.c:911:2: error: 'exclusive_locks_required' attribute requires arguments whose type is annotated with 'capability' attribute; type here is 'pthread_mutex_t' [-Werror,-Wthread-safety-attributes] __rte_exclusive_locks_required(pending_requests.lock) ^ ../lib/eal/include/rte_lock_annotations.h:23:17: note: expanded from macro '__rte_exclusive_locks_required' __attribute__((exclusive_locks_required(__VA_ARGS__))) ^ We could wrap this annotation in a new construct (which would require some build time check wrt pthread API state). Not sure it is worth the effort though, for now. --=20 David Marchand