From patchwork Thu Dec 16 19:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 49021 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE10E3858003 for ; Thu, 16 Dec 2021 19:43:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE10E3858003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1639683810; bh=msMtjGsnSGOPcf6Hi0t+MMQPcD3qX7WWHEUsYuUkHpE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=QjhQuzPpV6tumuryQqFRox6fGNTtuehlbYov4R46lttxARRYHx7234JfGrSjHwuk7 S8AK1zqblIs31+gGz8BDNat6yrLu+usquOTFTVouFFPZfqy/L3ZFXsG+Tvs0RwitsG yHeBwJdhuYdCS4W3Ae3JIV/MlVepckjDEjvdAdcs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id D0ACB3858439 for ; Thu, 16 Dec 2021 19:42:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D0ACB3858439 Received: by mail-qv1-xf2e.google.com with SMTP id jo22so241023qvb.13 for ; Thu, 16 Dec 2021 11:42:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=msMtjGsnSGOPcf6Hi0t+MMQPcD3qX7WWHEUsYuUkHpE=; b=UlFJi7OdSGcB+GM+6V081WMiGtfCODVw0eflQhTkuuOk+z8QzZqdJTdLcQSCQTAj8f X7mVOBbxG2PnolJXYufu48zyrbuQ9OJJYeRUbbfSll16hvSY3dQIzb7Gsy2+4LwWtX1L jdGN9FQY/NG92NlcuEbQh945LFT1zIcmw8xfH+5J0jvGDxmv/vjftAYZarwEN42EEs1g PgPp1SW2bonGcd0BzY5Fo1U3142hXYAqfLona/iaGD7YPpNtTO38tSyRF4swwYYN54fp YFwllY8usJY6yCk+/vyvF7Ge1HcLiiIPOKdLo3Qd/0u3CnNNrzUMdFVcApc1H5fH6qj/ 76uw== X-Gm-Message-State: AOAM532f5n1aXd8XCdNbCUrGwiWbzFh8UTupnzmw5wQMKHxpRpDOlEL0 3PN3osPBBE4QYC996O7h3WQmJNvaKzxwiw== X-Google-Smtp-Source: ABdhPJx77kxE/ykZMtHmqY2kF4Anh8NoWNh7/y1ldVFH0jepAtou58CxX2aMJKNBRFmi2pvv98alJQ== X-Received: by 2002:ad4:5962:: with SMTP id eq2mr13764786qvb.105.1639683749247; Thu, 16 Dec 2021 11:42:29 -0800 (PST) Received: from birita.. ([2804:431:c7ca:103f:96e9:fe91:2aff:a44d]) by smtp.gmail.com with ESMTPSA id br13sm3503836qkb.10.2021.12.16.11.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Dec 2021 11:42:28 -0800 (PST) To: libc-alpha@sourceware.org, Stafford Horne Subject: [PATCH 2/5] malloc: Use C11 atomics on libmemusage Date: Thu, 16 Dec 2021 16:42:19 -0300 Message-Id: <20211216194222.186992-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211216194222.186992-1-adhemerval.zanella@linaro.org> References: <20211216194222.186992-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" It removes the usage of atomic-machine.h types. --- malloc/memusage.c | 37 +++++++++++++++++++------------------ sysdeps/arc/memusage.h | 2 -- sysdeps/generic/memusage.h | 14 -------------- sysdeps/nios2/memusage.h | 2 -- 4 files changed, 19 insertions(+), 36 deletions(-) diff --git a/malloc/memusage.c b/malloc/memusage.c index e99f0c1c14..d287a7aa82 100644 --- a/malloc/memusage.c +++ b/malloc/memusage.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -71,20 +72,20 @@ struct header #define MAGIC 0xfeedbeaf -static memusage_cntr_t calls[idx_last]; -static memusage_cntr_t failed[idx_last]; -static memusage_size_t total[idx_last]; -static memusage_size_t grand_total; -static memusage_cntr_t histogram[65536 / 16]; -static memusage_cntr_t large; -static memusage_cntr_t calls_total; -static memusage_cntr_t inplace; -static memusage_cntr_t decreasing; -static memusage_cntr_t realloc_free; -static memusage_cntr_t inplace_mremap; -static memusage_cntr_t decreasing_mremap; -static memusage_size_t current_heap; -static memusage_size_t peak_use[3]; +static atomic_ulong calls[idx_last]; +static atomic_ulong failed[idx_last]; +static atomic_size_t total[idx_last]; +static atomic_size_t grand_total; +static atomic_ulong histogram[65536 / 16]; +static atomic_ulong large; +static atomic_ulong calls_total; +static atomic_ulong inplace; +static atomic_ulong decreasing; +static atomic_ulong realloc_free; +static atomic_ulong inplace_mremap; +static atomic_ulong decreasing_mremap; +static atomic_size_t current_heap; +static atomic_size_t peak_use[3]; static __thread uintptr_t start_sp; /* A few macros to make the source more readable. */ @@ -111,7 +112,7 @@ struct entry }; static struct entry buffer[2 * DEFAULT_BUFFER_SIZE]; -static uatomic32_t buffer_cnt; +static _Atomic uint32_t buffer_cnt; static struct entry first; @@ -128,7 +129,7 @@ update_data (struct header *result, size_t len, size_t old_len) } /* Compute current heap usage and compare it with the maximum value. */ - memusage_size_t heap + atomic_size_t heap = catomic_exchange_and_add (¤t_heap, len - old_len) + len - old_len; catomic_max (&peak_heap, heap); @@ -161,14 +162,14 @@ update_data (struct header *result, size_t len, size_t old_len) /* Store the value only if we are writing to a file. */ if (fd != -1) { - uatomic32_t idx = catomic_exchange_and_add (&buffer_cnt, 1); + _Atomic uint32_t idx = catomic_exchange_and_add (&buffer_cnt, 1); if (idx + 1 >= 2 * buffer_size) { /* We try to reset the counter to the correct range. If this fails because of another thread increasing the counter it does not matter since that thread will take care of the correction. */ - uatomic32_t reset = (idx + 1) % (2 * buffer_size); + _Atomic uint32_t reset = (idx + 1) % (2 * buffer_size); catomic_compare_and_exchange_val_acq (&buffer_cnt, reset, idx + 1); if (idx >= 2 * buffer_size) idx = reset - 1; diff --git a/sysdeps/arc/memusage.h b/sysdeps/arc/memusage.h index 290252a92f..e8a508a8ff 100644 --- a/sysdeps/arc/memusage.h +++ b/sysdeps/arc/memusage.h @@ -18,6 +18,4 @@ #define GETSP() ({ register uintptr_t stack_ptr asm ("sp"); stack_ptr; }) -#define uatomic32_t unsigned int - #include diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h index 408e0b891b..c9bde5cd11 100644 --- a/sysdeps/generic/memusage.h +++ b/sysdeps/generic/memusage.h @@ -17,7 +17,6 @@ #include -#include #include #ifndef GETSP @@ -36,16 +35,3 @@ high = usecs >> 32; \ } #endif - -#if LONG_BIT == 32 -# define memusage_cntr_t uatomic32_t -#else -# define memusage_cntr_t uatomic64_t -#endif -#ifndef memusage_size_t -# if LONG_BIT == 32 -# define memusage_size_t uatomic32_t -# else -# define memusage_size_t uatomic64_t -# endif -#endif diff --git a/sysdeps/nios2/memusage.h b/sysdeps/nios2/memusage.h index 01618e44a8..6f1c78812d 100644 --- a/sysdeps/nios2/memusage.h +++ b/sysdeps/nios2/memusage.h @@ -18,6 +18,4 @@ #define GETSP() ({ register uintptr_t stack_ptr asm ("%sp"); stack_ptr; }) -#define uatomic32_t unsigned int - #include