From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id CFD563858C53 for ; Thu, 27 Jun 2024 14:20:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFD563858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CFD563858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719498045; cv=none; b=GP/jlCzU58y0hua+8jTgft6avZodioHJMPKdlhdi40CvPlkqrCN35xprvv0n1eyenPIvwsoqajP5/RTmLLyFr2ZVaz0t3EUPDrTiecX4XewI6kwtpnFcpjo9FSIAG+Kj7v9/oOLbPGtGOCQeN2Sd9kTtPOictqI3fLhHs3epo1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719498045; c=relaxed/simple; bh=Ykm/jIOi8N+yaxZIpxMDHY+PWGBOR79htTrqJgJ7fko=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=elwExK3VIUqbg8lR2nLZPTUrig0Hp8AfYfG7NiDpxsV/j9jb1dAZIsIm0lTfLlx8BxAQXvJ08cgLn1AP49UiCE15jT1/KOE3yyDmrqA6X08tlkgrYM6c0+vEGjgq8qwid5nqU17lLxe/oogpkTY2Tu6rFDArRHe89b6y4zjkXjU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719498037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8C0g0w0urwqLiSip0lXyDWiKGIdExIowLuBWQDGtgJU=; b=FrAO4/sQJ3lVMV/AUSCOAlqaelDw2LQYqPHKTFpmkca2GYmT4fPbXXiJCQ9TFZEWm8QRvE b/ydYUSRnkUo4d/0hugVR6WjiVwLCCYNrSD9ZPZlfS5qAgF2Ta1QEAQEkyY11gP6z5b8pm MXyBZrmb7I4BF3mB7yftsvaGfdhuEWQ= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-153-Kb7arygXN2G6gGZsAnTJqw-1; Thu, 27 Jun 2024 10:20:36 -0400 X-MC-Unique: Kb7arygXN2G6gGZsAnTJqw-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6b07ef34bfcso40879116d6.1 for ; Thu, 27 Jun 2024 07:20:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719498035; x=1720102835; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8C0g0w0urwqLiSip0lXyDWiKGIdExIowLuBWQDGtgJU=; b=cKSRgTG/3kyE8nHwxV61yl5dP1ml7n7cKPLdJ1NWVYsBYuhhE9oRnLKMyaE7ci1xPD P8l4b6G4PSEVsdJqqFrYNKEhN7Sr+nSqY+biF8F9OnQEPRWIAm9Y3dyFwd/autk0TPgU Yq6casFGTIKfnQdtJFNg9bVPpmyyaDQNuVgw379cHMOiko8wI4OsoAXWmq2cvQvnD7ep 1gsDM3iCFq2oy+Til8NK42l3Ln29sOPNZikofOztEIdhFQqCd/dVgwET0FC5o14a1oXc tBXoXsgOnU3Zqn0QoBB2JOZDJ4FGh0AiKuDxvv+c0AV8PlJNJl3iAo4WpL6koTM+SJuz XikQ== X-Gm-Message-State: AOJu0Yy9SjF7uV1Y06/v+MELC57b5//nIzq6b/w+6D+qAHk5+zn+mbBc GfpXt7VMWcO2b03135jVXxw5ih5MiVqFaVcYmEz0Qc4yc5WZgZLyuMiuLKr+wdIK5f3Q7TNHGd3 3XICJC+olPdUAfZoQaRn4L6uF8Q9H5Zy7Tvq59GqjtB+/tq52IW5U7sEJS/UHtlyVsGRA4Xtlqq k0zpBBlBbK+eAF+do8cC9qsMbDtQWp5WaRkPhdS3AlQA== X-Received: by 2002:a05:6214:240b:b0:6b5:1d2f:1d3 with SMTP id 6a1803df08f44-6b592f9882dmr34218296d6.0.1719498035123; Thu, 27 Jun 2024 07:20:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2ErRhajQgtDzeNZOXWTZgJdHKTl4rD+Y+9TZy4nr0PYSmZj0fXB3twlKQxo0K/IyenzSmIg== X-Received: by 2002:a05:6214:240b:b0:6b5:1d2f:1d3 with SMTP id 6a1803df08f44-6b592f9882dmr34217886d6.0.1719498034709; Thu, 27 Jun 2024 07:20:34 -0700 (PDT) Received: from lenovo-p1.mamux.org.com ([213.229.137.162]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b59241b5a5sm5442306d6.28.2024.06.27.07.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jun 2024 07:20:33 -0700 (PDT) From: =?UTF-8?q?Miguel=20Mart=C3=ADn?= To: libc-alpha@sourceware.org Subject: [PATCH 1/2] malloc: avoid global locks in tst-aligned_alloc-lib.c Date: Thu, 27 Jun 2024 16:20:22 +0200 Message-ID: <20240627142028.134709-2-mmartinv@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240627142028.134709-1-mmartinv@redhat.com> References: <20240627142028.134709-1-mmartinv@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Make sure the DSO used by aligned_alloc/calloc/malloc tests does not get a global lock on multithreaded tests. --- malloc/tst-aligned_alloc-lib.c | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/malloc/tst-aligned_alloc-lib.c b/malloc/tst-aligned_alloc-lib.c index 0205df5acf..9ef1f839c1 100644 --- a/malloc/tst-aligned_alloc-lib.c +++ b/malloc/tst-aligned_alloc-lib.c @@ -17,37 +17,38 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, see . */ -#include #include #include +#include extern void *__libc_malloc (size_t size); extern void *__libc_calloc (size_t n, size_t size); +__thread unsigned int seed = 0; + int aligned_alloc_count = 0; int libc_malloc_count = 0; int libc_calloc_count = 0; -/* Get a random alignment value. Biased towards the smaller values. Must be - a power of 2. */ -static size_t get_random_alignment (void) -{ - size_t aligns[] = { - 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384 - }; - - return aligns[random () % array_length (aligns)]; -} - -static void *get_random_alloc (size_t size) +static void * +get_random_alloc (size_t size) { void *retval; size_t align; + struct timespec tp; + + if (seed == 0) + { + clock_gettime (CLOCK_REALTIME, &tp); + seed = tp.tv_nsec; + } - switch (random() % 3) - { + switch (rand_r (&seed) % 3) + { case 1: - align = get_random_alignment (); + /* Get a random alignment value. Biased towards the smaller + * values up to 16384. Must be a power of 2. */ + align = 1 << rand_r (&seed) % 15; retval = aligned_alloc (align, size); aligned_alloc_count++; break; @@ -59,13 +60,13 @@ static void *get_random_alloc (size_t size) retval = __libc_malloc (size); libc_malloc_count++; break; - } + } return retval; } - -void * __random_malloc (size_t size) +void * +__random_malloc (size_t size) { return get_random_alloc (size); } -- Miguel Martín mmartinv@redhat.com