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 DBAB345C6B; Sun, 3 Nov 2024 11:37:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C8E7540264; Sun, 3 Nov 2024 11:37:44 +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 7C0E24021F for ; Sun, 3 Nov 2024 11:37:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730630262; 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=B3p6WPhXYEGaZvp8s3xmTQZQyT7ZuMTWAtRaxvaTZpGzJiZ9bQUbT/3I2Ij0dDbQxW43q1 DLzeYR86kOJZWGho24Ab9iIWIK8sdMMn461/W2jyEyFtuMGoh9y1doIN3J/aQGQyRs02E8 h4GUFA6QWNAm7lerOzzN9tcGlHbCVQE= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-413-EPvvKOQHPbifZInwSFn0Dg-1; Sun, 03 Nov 2024 05:37:38 -0500 X-MC-Unique: EPvvKOQHPbifZInwSFn0Dg-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-539e294566dso1930024e87.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=AQ09Aq7l95cDtml9dQhyj4Ukk+v6D8AVIYhIjUs2MQdsXgibkqF8WIVUWDBjyCWUM/ Jplry083bPUgTFKagwKjHXzTPua+cHPiHZDvKIxl55AKLpZFz+kkBaSnPI6v0HW4S1wB uNGluNOpwL4f+IjHwIba8dZFHpun7Gdm2e5iA9u1SJtxCAEAbmpmQSWTFPKu/W/j6ObR j56kbVUxlls4hl3VNpKSuceXHf5By4uleh5qpTLdJ4MpqywU5m8ZCwrAHE11YbTiVW3t 1+0AstKGmgL86p96FxFUuxbqHkJn9ekTJDRmEdxVLnR4ltp3Awz6SW8fZeN86WMMJ/0C g4WQ== X-Gm-Message-State: AOJu0Yx9VTF9iGWMRgf2SQkQ130cLl3UnabRZc0tfJaTPbFVwB5hJCA/ wb5C7dQqvoWd/BSzBkJ9XZJwvw6AWYxkRGcu1qgODiRhTW487CbvmFLFrscIbTk7wt9VJmyuDk5 3tz90B+9UU3PzACStCtH8q2ZSpyJhgX0xb/PYbU2La6X5GDq929yy4R2fTq2xf44VV1qpQfzSg4 xT9B7bbz85HX3AOzE= X-Received: by 2002:a05:6512:31c5:b0:53c:761c:2a14 with SMTP id 2adb3069b0e04-53c79e4c4aamr5715707e87.29.1730630257245; 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: 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 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