From patchwork Thu Dec 23 17:37:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 49216 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 A4990385800A for ; Thu, 23 Dec 2021 17:38:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4990385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1640281093; bh=17oGZNy7WFTY/K2u15G8sDw2US9/kL/g8/fv5Ee4gGY=; 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=GieAMeWVre1JEGmmFXZcdH1E36znbZMWGEkrKRzQc5lelhwTyaFoEcu1rXH/DP7cY hcenQ6SnWmI/uh2XedNW3lvw6fjDl2WvvzVEpYwup2OQhqVmH4DgbFkiDBDSiOx9l4 n5jA36iuFUT2cvbYH0zCZjrmkEMnhNRdNnS3NfnQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by sourceware.org (Postfix) with ESMTPS id 1913A385841C for ; Thu, 23 Dec 2021 17:37:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1913A385841C Received: by mail-qk1-x735.google.com with SMTP id m186so6146039qkb.4 for ; Thu, 23 Dec 2021 09:37:11 -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=17oGZNy7WFTY/K2u15G8sDw2US9/kL/g8/fv5Ee4gGY=; b=vA+0EElUi5q09ALo/gsAQgYyz/RJkQW5RiNmnuzHMG7Io2Gb2O6/WDuthy2aT38Nmu iL/Tk3xFG5foyiMTB9q9FYksCbAYcDx+Q2dljcKFkIoY857w06Gx4d/SMNacUsUCAWum aQeM3xkSipn/0YTpuJLqg3mXRIQYGobuMgBVxDjynNd8mpUXgjGy0QYIbSy8jZ/6ojZD Jbk3q9LrHz/LqnJdUVTTUMIU2yY5sY3bPIyoymhzCp8GRkYAymeXbf/3XuDqEPbnKdHt a7M2AXc8ACA/Fkcm96nRxP48Iq6nrnqhqnBa61bvhvUwS/lgvWbwvr2hUzO8RRaisHNu wpzw== X-Gm-Message-State: AOAM533W+bxtdmo4ICcSMuYaExxoDg+9gaPOGyZvpsH4QTh7Asxd0QIz 1jG0mdMmGRuWfDsGbrXwVn5bn2lu00ssQg== X-Google-Smtp-Source: ABdhPJx2ofFlHxm33Wjr+FguCe65sfNvdDgHJ7WiJzRfhlC/pjAiimmANgo2n52rk3KvVusIMrbHmw== X-Received: by 2002:a05:620a:4624:: with SMTP id br36mr2035549qkb.531.1640281030460; Thu, 23 Dec 2021 09:37:10 -0800 (PST) Received: from birita.. ([2804:431:c7cb:3b1e:1fd1:c581:58d8:4df2]) by smtp.gmail.com with ESMTPSA id w13sm4956531qko.20.2021.12.23.09.37.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 09:37:10 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 1/4] malloc: Remove atomic_* usage Date: Thu, 23 Dec 2021 14:37:03 -0300 Message-Id: <20211223173706.1179720-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211223173706.1179720-1-adhemerval.zanella@linaro.org> References: <20211223173706.1179720-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.8 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 Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" These typedef are used solely on memusage and can be replaced with generic types. --- malloc/memusage.c | 36 ++++++++++++++++++------------------ sysdeps/arc/memusage.h | 2 -- sysdeps/generic/memusage.h | 14 -------------- sysdeps/nios2/memusage.h | 2 -- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/malloc/memusage.c b/malloc/memusage.c index e99f0c1c14..de39ad1c1a 100644 --- a/malloc/memusage.c +++ b/malloc/memusage.c @@ -71,20 +71,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 unsigned long int calls[idx_last]; +static unsigned long int failed[idx_last]; +static size_t total[idx_last]; +static size_t grand_total; +static unsigned long int histogram[65536 / 16]; +static unsigned long int large; +static unsigned long int calls_total; +static unsigned long int inplace; +static unsigned long int decreasing; +static unsigned long int realloc_free; +static unsigned long int inplace_mremap; +static unsigned long int decreasing_mremap; +static size_t current_heap; +static size_t peak_use[3]; static __thread uintptr_t start_sp; /* A few macros to make the source more readable. */ @@ -111,7 +111,7 @@ struct entry }; static struct entry buffer[2 * DEFAULT_BUFFER_SIZE]; -static uatomic32_t buffer_cnt; +static uint32_t buffer_cnt; static struct entry first; @@ -128,7 +128,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 + size_t heap = catomic_exchange_and_add (¤t_heap, len - old_len) + len - old_len; catomic_max (&peak_heap, heap); @@ -161,14 +161,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); + 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); + 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