* [PATCH] Use mallinfo2 with glibc >= 2.33
@ 2022-09-07 17:02 François Dumont
2022-09-07 17:10 ` Jonathan Wakely
0 siblings, 1 reply; 4+ messages in thread
From: François Dumont @ 2022-09-07 17:02 UTC (permalink / raw)
To: libstdc++; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 447 bytes --]
libstdc++: Use glibc >= 2.33 mallinfo2 function
mallinfo started to be deprecated which makes performance tests failed
to build, just
adopt mallinfo2.
libstdcxx-v3/ChangeLog:
* testsuite/util/testsuite_performance.h (__mallinfo): New, our
own mallinfo
struct with just what we need. When using glibc >= 2.33 use
mallinfo2 to
populate it.
Tested under Linux x86_64,
Ok to commit ?
François
[-- Attachment #2: mallinfo.patch --]
[-- Type: text/x-patch, Size: 2521 bytes --]
diff --git a/libstdc++-v3/testsuite/util/testsuite_performance.h b/libstdc++-v3/testsuite/util/testsuite_performance.h
index 2e05bef8460..dc002b8c390 100644
--- a/libstdc++-v3/testsuite/util/testsuite_performance.h
+++ b/libstdc++-v3/testsuite/util/testsuite_performance.h
@@ -35,37 +35,49 @@
#include <cxxabi.h>
#include <testsuite_common_types.h>
-#if defined (__linux__) || defined (__GLIBC__)
-#include <malloc.h>
-#elif defined (__FreeBSD__)
extern "C"
{
- struct mallinfo
+ struct __mallinfo
{
- int uordblks;
- int hblkhd;
+ size_t uordblks;
+ size_t hblkhd;
};
+}
- struct mallinfo
- mallinfo(void)
+#if defined (__linux__) || defined (__GLIBC__)
+#include <malloc.h>
+extern "C"
+{
+ struct __mallinfo
+ __mallinfo(void)
+ {
+#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 33
+ struct mallinfo2 mi = mallinfo2();
+ struct __mallinfo m = { mi.uordblks, mi.hblkhd };
+#else
+ struct mallinfo mi = mallinfo();
+ struct __mallinfo m = { mi.uordblks, mi.hblkhd };
+#endif
+ return m;
+ }
+}
+#elif defined (__FreeBSD__)
+extern "C"
+{
+ struct __mallinfo
+ __mallinfo(void)
{
- struct mallinfo m = { (((std::size_t) sbrk (0) + 1023) / 1024), 0 };
+ struct __mallinfo m = { (((std::size_t) sbrk (0) + 1023) / 1024), 0 };
return m;
}
}
#elif !defined (__hpux__)
extern "C"
{
- struct mallinfo
- {
- int uordblks;
- int hblkhd;
- };
-
- struct mallinfo empty = { 0, 0 };
+ struct __mallinfo empty = { 0, 0 };
- struct mallinfo
- mallinfo(void)
+ struct __mallinfo
+ __mallinfo(void)
{ return empty; }
}
#endif
@@ -146,8 +158,8 @@ namespace __gnu_test
int who;
rusage rusage_begin;
rusage rusage_end;
- struct mallinfo allocation_begin;
- struct mallinfo allocation_end;
+ struct __mallinfo allocation_begin;
+ struct __mallinfo allocation_end;
public:
resource_counter(int i = RUSAGE_SELF) : who(i)
@@ -168,7 +180,7 @@ namespace __gnu_test
if (getrusage(who, &rusage_begin) != 0 )
memset(&rusage_begin, 0, sizeof(rusage_begin));
void* p __attribute__((unused)) = malloc(0); // Needed for some implementations.
- allocation_begin = mallinfo();
+ allocation_begin = __mallinfo();
}
void
@@ -176,7 +188,7 @@ namespace __gnu_test
{
if (getrusage(who, &rusage_end) != 0 )
memset(&rusage_end, 0, sizeof(rusage_end));
- allocation_end = mallinfo();
+ allocation_end = __mallinfo();
}
int
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Use mallinfo2 with glibc >= 2.33
2022-09-07 17:02 [PATCH] Use mallinfo2 with glibc >= 2.33 François Dumont
@ 2022-09-07 17:10 ` Jonathan Wakely
2022-09-08 5:03 ` François Dumont
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2022-09-07 17:10 UTC (permalink / raw)
To: François Dumont; +Cc: libstdc++, gcc-patches
On Wed, 7 Sept 2022 at 18:03, François Dumont via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
> libstdc++: Use glibc >= 2.33 mallinfo2 function
>
> mallinfo started to be deprecated which makes performance tests failed
> to build, just
> adopt mallinfo2.
>
> libstdcxx-v3/ChangeLog:
>
> * testsuite/util/testsuite_performance.h (__mallinfo): New, our
> own mallinfo
There's no reason to use a reserved name here, this isn't a header
that users include.
I would call the struct MallocInfo and the function malloc_info().
Even better, put them both in namespace __gnu_test, as
__gnu_test::MallocInfo and __gnu_test::malloc_info (without the extern
"C" language linkage). If we're not calling the glibc function
directly, but via our own wrapper, then there's no reason it has to
use the name "mallinfo", no reason it has to be in the global
namespace, and no reason it has to be extern "C" (in fact, I don't
think there was ever a reason for it to be extern "C").
> struct with just what we need. When using glibc >= 2.33 use
> mallinfo2 to
> populate it.
>
> Tested under Linux x86_64,
>
> Ok to commit ?
>
> François
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Use mallinfo2 with glibc >= 2.33
2022-09-07 17:10 ` Jonathan Wakely
@ 2022-09-08 5:03 ` François Dumont
2022-09-08 8:48 ` Jonathan Wakely
0 siblings, 1 reply; 4+ messages in thread
From: François Dumont @ 2022-09-08 5:03 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 1811 bytes --]
libstdc++: glibc mallinfo deprecated, use mallinfo2 when version =>
2.33
glibc mallinfo is now deprecated resulting in make check-performance
failure. When glibc => 2.33 prefer mallinfo2.
libstdcxx-v3/ChangeLog:
* testsuite/util/testsuite_performance.h
(__gnu_test::MallocInfo): New.
(__gnu_test::malloc_info): New, replace mallinfo on current
platform
supporting it and use mallinfo2 when glibc >= 2.33.
Tested under Linux x86_64.
Ok to commit ?
François
On 07/09/22 19:10, Jonathan Wakely wrote:
> On Wed, 7 Sept 2022 at 18:03, François Dumont via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
>> libstdc++: Use glibc >= 2.33 mallinfo2 function
>>
>> mallinfo started to be deprecated which makes performance tests failed
>> to build, just
>> adopt mallinfo2.
>>
>> libstdcxx-v3/ChangeLog:
>>
>> * testsuite/util/testsuite_performance.h (__mallinfo): New, our
>> own mallinfo
> There's no reason to use a reserved name here, this isn't a header
> that users include.
>
> I would call the struct MallocInfo and the function malloc_info().
> Even better, put them both in namespace __gnu_test, as
> __gnu_test::MallocInfo and __gnu_test::malloc_info (without the extern
> "C" language linkage). If we're not calling the glibc function
> directly, but via our own wrapper, then there's no reason it has to
> use the name "mallinfo", no reason it has to be in the global
> namespace, and no reason it has to be extern "C" (in fact, I don't
> think there was ever a reason for it to be extern "C").
>
>
>
>> struct with just what we need. When using glibc >= 2.33 use
>> mallinfo2 to
>> populate it.
>>
>> Tested under Linux x86_64,
>>
>> Ok to commit ?
>>
>> François
[-- Attachment #2: mallinfo.patch --]
[-- Type: text/x-patch, Size: 2604 bytes --]
diff --git a/libstdc++-v3/testsuite/util/testsuite_performance.h b/libstdc++-v3/testsuite/util/testsuite_performance.h
index 2e05bef8460..4f8b1eab8b9 100644
--- a/libstdc++-v3/testsuite/util/testsuite_performance.h
+++ b/libstdc++-v3/testsuite/util/testsuite_performance.h
@@ -36,42 +36,39 @@
#include <testsuite_common_types.h>
#if defined (__linux__) || defined (__GLIBC__)
-#include <malloc.h>
-#elif defined (__FreeBSD__)
-extern "C"
-{
- struct mallinfo
- {
- int uordblks;
- int hblkhd;
- };
+#include <malloc.h> // For mallinfo.
+#endif
- struct mallinfo
- mallinfo(void)
- {
- struct mallinfo m = { (((std::size_t) sbrk (0) + 1023) / 1024), 0 };
- return m;
- }
-}
-#elif !defined (__hpux__)
-extern "C"
+namespace __gnu_test
{
- struct mallinfo
+ struct MallocInfo
{
- int uordblks;
- int hblkhd;
- };
+ MallocInfo() : uordblks(0), hblkhd(0) { }
+ MallocInfo(std::size_t uordblocks, std::size_t hblockhd)
+ : uordblks(uordblocks), hblkhd(hblockhd)
+ { }
- struct mallinfo empty = { 0, 0 };
+ std::size_t uordblks;
+ std::size_t hblkhd;
+ };
- struct mallinfo
- mallinfo(void)
- { return empty; }
-}
+ MallocInfo
+ malloc_info()
+ {
+#if defined (__linux__) || defined (__hpux__) || defined (__GLIBC__)
+#if __GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 33
+ struct mallinfo2 mi = mallinfo2();
+#else
+ struct mallinfo mi = mallinfo();
+#endif
+ return MallocInfo(mi.uordblks, mi.hblkhd);
+#elif defined (__FreeBSD__)
+ return MallocInfo((((std::size_t) sbrk (0) + 1023) / 1024), 0);
+#else
+ return MallocInfo();
#endif
+ }
-namespace __gnu_test
-{
class time_counter
{
private:
@@ -146,8 +143,8 @@ namespace __gnu_test
int who;
rusage rusage_begin;
rusage rusage_end;
- struct mallinfo allocation_begin;
- struct mallinfo allocation_end;
+ MallocInfo allocation_begin;
+ MallocInfo allocation_end;
public:
resource_counter(int i = RUSAGE_SELF) : who(i)
@@ -168,7 +165,7 @@ namespace __gnu_test
if (getrusage(who, &rusage_begin) != 0 )
memset(&rusage_begin, 0, sizeof(rusage_begin));
void* p __attribute__((unused)) = malloc(0); // Needed for some implementations.
- allocation_begin = mallinfo();
+ allocation_begin = malloc_info();
}
void
@@ -176,7 +173,7 @@ namespace __gnu_test
{
if (getrusage(who, &rusage_end) != 0 )
memset(&rusage_end, 0, sizeof(rusage_end));
- allocation_end = mallinfo();
+ allocation_end = malloc_info();
}
int
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Use mallinfo2 with glibc >= 2.33
2022-09-08 5:03 ` François Dumont
@ 2022-09-08 8:48 ` Jonathan Wakely
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2022-09-08 8:48 UTC (permalink / raw)
To: François Dumont; +Cc: libstdc++, gcc-patches
On Thu, 8 Sept 2022 at 06:03, François Dumont <frs.dumont@gmail.com> wrote:
>
> libstdc++: glibc mallinfo deprecated, use mallinfo2 when version =>
> 2.33
>
> glibc mallinfo is now deprecated resulting in make check-performance
> failure. When glibc => 2.33 prefer mallinfo2.
>
> libstdcxx-v3/ChangeLog:
>
> * testsuite/util/testsuite_performance.h
> (__gnu_test::MallocInfo): New.
> (__gnu_test::malloc_info): New, replace mallinfo on current
> platform
> supporting it and use mallinfo2 when glibc >= 2.33.
>
> Tested under Linux x86_64.
>
> Ok to commit ?
Yes, looks good, thanks!
>
> François
>
> On 07/09/22 19:10, Jonathan Wakely wrote:
> > On Wed, 7 Sept 2022 at 18:03, François Dumont via Libstdc++
> > <libstdc++@gcc.gnu.org> wrote:
> >> libstdc++: Use glibc >= 2.33 mallinfo2 function
> >>
> >> mallinfo started to be deprecated which makes performance tests failed
> >> to build, just
> >> adopt mallinfo2.
> >>
> >> libstdcxx-v3/ChangeLog:
> >>
> >> * testsuite/util/testsuite_performance.h (__mallinfo): New, our
> >> own mallinfo
> > There's no reason to use a reserved name here, this isn't a header
> > that users include.
> >
> > I would call the struct MallocInfo and the function malloc_info().
> > Even better, put them both in namespace __gnu_test, as
> > __gnu_test::MallocInfo and __gnu_test::malloc_info (without the extern
> > "C" language linkage). If we're not calling the glibc function
> > directly, but via our own wrapper, then there's no reason it has to
> > use the name "mallinfo", no reason it has to be in the global
> > namespace, and no reason it has to be extern "C" (in fact, I don't
> > think there was ever a reason for it to be extern "C").
> >
> >
> >
> >> struct with just what we need. When using glibc >= 2.33 use
> >> mallinfo2 to
> >> populate it.
> >>
> >> Tested under Linux x86_64,
> >>
> >> Ok to commit ?
> >>
> >> François
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-08 8:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-07 17:02 [PATCH] Use mallinfo2 with glibc >= 2.33 François Dumont
2022-09-07 17:10 ` Jonathan Wakely
2022-09-08 5:03 ` François Dumont
2022-09-08 8:48 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).