From patchwork Thu Dec 23 17:37:05 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: 49217 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 9B1603858012 for ; Thu, 23 Dec 2021 17:38:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B1603858012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1640281135; bh=/i00R2+wpGimzRTJVnX9Vps3ncpYmt6si96oLt1JrP8=; 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=lBKp02veSWMT3VRRx1entCpGYw4gmMj4N73kQUyaBGwL4E5qFjq2VphL7ad1CdDyy 7+2I30V/WouUW0KBFWWyOY9WjJIKslZoMbkEv/ydB/FqmYtUh1dGoLqv87+AIpisWc fCEldC9O7x9C0gMecydCsJ+QXSLV3mVpevNu8YP8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 4909D3858436 for ; Thu, 23 Dec 2021 17:37:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4909D3858436 Received: by mail-qk1-x733.google.com with SMTP id w27so28432qkj.7 for ; Thu, 23 Dec 2021 09:37:13 -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=/i00R2+wpGimzRTJVnX9Vps3ncpYmt6si96oLt1JrP8=; b=d4m0ABpuW4oKvc1Jl3oL8EVWnjRGEoYboTJNTjyAUUYZLdyzaxte/r05d3wqEq7Yo7 L3zmUmNFj78DYFlEz+KR2n+2RKrKMyVgNMTO5DEaQfYnAVK+MnT+7ojQ+Z+qxxdBuSts +yhk68MuMtqq1aVE6lg4OSqQPKwVM1IV1w14vSPegDm+Bx3E9gJwOVYSLe5WSSnxiiX2 35QRXhAsLogxjwESEBjnN3oIqRkn2P6Su/vBrb2BQCsfH6S3R25PTVW5XdTF4Jkgm1+n g1dgzG+Q2Ys+iQM86PDtWFOQrTRbHuu5NU8Q9QeDi4P2HSrt70c8fr/1Cy9KFJ1C71w2 CoNQ== X-Gm-Message-State: AOAM530eAL9o4c5ukiVWFm//yBJMurpbY55201d/epXbTN/RsCFxs3c5 elCTlw8IsYpB+N79jNW5Nvcakj3/NEHoow== X-Google-Smtp-Source: ABdhPJzinNuvDv88ENx8/UboQJ7ZPKvIZzTbqgFCbrX9zVdloYJbNtE+vzrVRE5CnAA6Dv+ndSI01g== X-Received: by 2002:a05:620a:2891:: with SMTP id j17mr2135389qkp.386.1640281032675; Thu, 23 Dec 2021 09:37:12 -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.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Dec 2021 09:37:12 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2 3/4] malloc: Use hp-timing on libmemusage Date: Thu, 23 Dec 2021 14:37:05 -0300 Message-Id: <20211223173706.1179720-4-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, KAM_SHORT, 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" Instead of reimplemeting on GETTIME macro. --- malloc/memusage.c | 15 ++++++++++++--- sysdeps/generic/memusage.h | 12 ------------ sysdeps/i386/i686/memusage.h | 1 - sysdeps/ia64/memusage.h | 7 ------- sysdeps/x86_64/memusage.h | 1 - 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/malloc/memusage.c b/malloc/memusage.c index de39ad1c1a..179dd1c683 100644 --- a/malloc/memusage.c +++ b/malloc/memusage.c @@ -34,6 +34,7 @@ #include #include +#include /* Pointer to the real functions. These are determined used `dlsym' when really needed. */ @@ -114,6 +115,14 @@ static struct entry buffer[2 * DEFAULT_BUFFER_SIZE]; static uint32_t buffer_cnt; static struct entry first; +static void +gettime (struct entry *e) +{ + hp_timing_t now; + HP_TIMING_NOW (now); + e->time_low = now & 0xffffffff; + e->time_high = now >> 32; +} /* Update the global data after a successful function call. */ static void @@ -177,7 +186,7 @@ update_data (struct header *result, size_t len, size_t old_len) buffer[idx].heap = current_heap; buffer[idx].stack = current_stack; - GETTIME (buffer[idx].time_low, buffer[idx].time_high); + gettime (&buffer[idx]); /* Write out buffer if it is full. */ if (idx + 1 == buffer_size) @@ -267,7 +276,7 @@ me (void) /* Write the first entry. */ first.heap = 0; first.stack = 0; - GETTIME (first.time_low, first.time_high); + gettime (&first); /* Write it two times since we need the starting and end time. */ write (fd, &first, sizeof (first)); write (fd, &first, sizeof (first)); @@ -818,7 +827,7 @@ dest (void) stack. */ first.heap = peak_heap; first.stack = peak_stack; - GETTIME (first.time_low, first.time_high); + gettime (&first); write (fd, &first, sizeof (struct entry)); /* Close the file. */ diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h index c9bde5cd11..514bd058d2 100644 --- a/sysdeps/generic/memusage.h +++ b/sysdeps/generic/memusage.h @@ -23,15 +23,3 @@ # warning "GETSP is not defined for this architecture." # define GETSP 0 #endif - -#ifndef GETTIME -# define GETTIME(low,high) \ - { \ - struct __timespec64 now; \ - uint64_t usecs; \ - __clock_gettime64 (CLOCK_REALTIME, &now); \ - usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \ - low = usecs & 0xffffffff; \ - high = usecs >> 32; \ - } -#endif diff --git a/sysdeps/i386/i686/memusage.h b/sysdeps/i386/i686/memusage.h index 08b7831e12..07b241263c 100644 --- a/sysdeps/i386/i686/memusage.h +++ b/sysdeps/i386/i686/memusage.h @@ -16,6 +16,5 @@ . */ #define GETSP() ({ register uintptr_t stack_ptr asm ("esp"); stack_ptr; }) -#define GETTIME(low,high) asm ("rdtsc" : "=a" (low), "=d" (high)) #include diff --git a/sysdeps/ia64/memusage.h b/sysdeps/ia64/memusage.h index 3c3a526007..33fd6ec899 100644 --- a/sysdeps/ia64/memusage.h +++ b/sysdeps/ia64/memusage.h @@ -18,12 +18,5 @@ #include #define GETSP() ({ register uintptr_t stack_ptr asm ("%r12"); stack_ptr; }) -#define GETTIME(low, high) \ - { \ - hp_timing_t __now; \ - HP_TIMING_NOW (__now); \ - low = __now & 0xffffffff; \ - high = __now >> 32; \ - } #include diff --git a/sysdeps/x86_64/memusage.h b/sysdeps/x86_64/memusage.h index 568dd5512d..6652fc5da1 100644 --- a/sysdeps/x86_64/memusage.h +++ b/sysdeps/x86_64/memusage.h @@ -16,6 +16,5 @@ . */ #define GETSP() ({ register uintptr_t stack_ptr asm ("rsp"); stack_ptr; }) -#define GETTIME(low,high) asm ("rdtsc" : "=a" (low), "=d" (high)) #include