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 7562F45C6B for ; Sun, 3 Nov 2024 11:37:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A0BFD40264; Sun, 3 Nov 2024 11:37:42 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id AE02A4021F for ; Sun, 3 Nov 2024 11:37:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730630260; 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=P2hXXfUxK6nhqe59InHE0WFBBDFQ7qao3oDij3t1kJ0=; b=iiruea29HGYGK1Dq6honLzyzmcUXDYwFNvWrvhWcleMX2DgQygr99V6WVZlMFrY1Iyb4dB FU/aYgDRwuCtNfRXpApytzP4l7T1MtPskySwHVPP4yLZxM3YbCCuHwoN8Fd9O0uLsyRUYY QsmGKlrDGTRIQKL/n98XS21Jl2RpbiQ= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-397-3x8fuxQYOmSh1xS2WLUFGQ-1; Sun, 03 Nov 2024 05:37:39 -0500 X-MC-Unique: 3x8fuxQYOmSh1xS2WLUFGQ-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-539e294566dso1930025e87.3 for ; Sun, 03 Nov 2024 02:37:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730630257; x=1731235057; 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=P2hXXfUxK6nhqe59InHE0WFBBDFQ7qao3oDij3t1kJ0=; b=qn4mgtF8AhcztcgdMfCR+KJp4SAzdfPknxYv8B2HP3YsKujUnThlUF3Sp5ES8mxYP7 C9q5ixJs4EA2XpY/CGLhtodfUBRNvp6emOTQ2L8D2SwwNQ9ga0Z8n3mLUZgkJbwu/bjA asty1AOKEXnkgd+djmA0oF7ofR293HnKyz9/NKynaF7YCeKX60oTdwfX3xdEr8x2d7au CdMBTAGWkEwHr/cN55BPVqmUAfFbVyWVrGpNnY+fWGlfq4DSu2zALQkPN7J3LzurVMTt ljiileq414j8/RgfO6bxhs/48f6coRzcVplvy65TEgZu9CKhFB5MLp66oEjwLcaT/cnn oe6Q== X-Forwarded-Encrypted: i=1; AJvYcCVl27wlqLXXo1iJDwO6gavrF9m/OwAmuv7mZV/Yem/3SDrEG20dvNahk4ZetI713KwA21TIq7g=@dpdk.org X-Gm-Message-State: AOJu0YxYBt9P3DlTLCnpmWSBkVdp+EJ4x+f1Tn+XYFSnnXv3Zy3TMhyN YOEOuekOoVXr6n9eyQ/HFSj8TB3ffpWN07B0v1rdf39MxuNhASLYnWd/Ur9xUIPhHvkkawbHbui RYKik3YzQxBFtJDDO4RxMVjdGSX65V24Gz9yMasm5yre0j6wiMLyRNa5OIJ/D/bJhvwJsD+nKJq /T+JQoslpaDFC+PMCejBE= X-Received: by 2002:a05:6512:31c5:b0:53c:761c:2a14 with SMTP id 2adb3069b0e04-53c79e4c4aamr5715712e87.29.1730630257263; Sun, 03 Nov 2024 02:37:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwknB64bcrzCWclU4sNcz8yNH1bE1pEs57OhcUI1dczcqQQcvkqy7IC9q3NsZ1IExwWdA3DXMuo6qeCqinDLg= X-Received: by 2002:a05:6512:31c5:b0:53c:761c:2a14 with SMTP id 2adb3069b0e04-53c79e4c4aamr5715696e87.29.1730630256751; Sun, 03 Nov 2024 02:37:36 -0800 (PST) MIME-Version: 1.0 References: <20241102100839.2325651-1-david.marchand@redhat.com> <20241102125846.2d206e3a@hermes.local> In-Reply-To: <20241102125846.2d206e3a@hermes.local> From: David Marchand Date: Sun, 3 Nov 2024 11:37:25 +0100 Message-ID: Subject: Re: [PATCH] eal/unix: optimize thread creation with glibc To: Stephen Hemminger Cc: dev@dpdk.org, thomas@monjalon.net, luca.boccassi@gmail.com, stable@dpdk.org, Tyler Retzlaff X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On Sat, Nov 2, 2024 at 8:58=E2=80=AFPM Stephen Hemminger wrote: > > On Sat, 2 Nov 2024 11:08:39 +0100 > David Marchand wrote: > > > Setting the cpu affinity of the child thread from the parent thread is > > racy when using pthread_setaffinity_np, as the child thread may start > > running and initialize before affinity is set. > > > > On the other hand, setting the cpu affinity from the child thread itsel= f > > may fail, so the parent thread waits for the child thread to report > > whether this call succeeded. > > > > This synchronisation point resulted in a significant slow down of > > rte_thread_create() (as seen in the lcores_autotest unit tests, in OBS > > for some ARM systems). > > > > Another option for setting cpu affinity is to use the not portable > > pthread_attr_setaffinity_np, but it is not available with musl. > > Assume availability by relying on __USE_GNU that is not set with musl. > > > > Fixes: b28c6196b132 ("eal/unix: fix thread creation") > > Cc: stable@dpdk.org > > > > Signed-off-by: David Marchand > > --- > > Seems like a reasonable way forward but not sure. > > What about FreeBSD (which shares this code)? I did not investigate FreeBSD. Either we find a "good" #define, or we could add some detection in meson (probably the best option). > > Looking inside glibc, what it does is have the parent call sched_setaffin= ty() > after the clone system call with the thread id. So using attributes is > just as racy as the original code. It there was such a race in the glibc, I would call it a bug. Afaiu, the parent calls sched_setaffinity while holding a lock on the child thread, see CREATE THREAD NOTES: and stopped_start. --=20 David Marchand