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.133.124]) by sourceware.org (Postfix) with ESMTPS id BF7DE3AA9812 for ; Fri, 27 May 2022 13:33:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BF7DE3AA9812 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-oD1I-EtJMPGKDRgefid7sQ-1; Fri, 27 May 2022 09:33:00 -0400 X-MC-Unique: oD1I-EtJMPGKDRgefid7sQ-1 Received: by mail-qv1-f70.google.com with SMTP id kl23-20020a056214519700b0046200065604so3491096qvb.19 for ; Fri, 27 May 2022 06:33:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Xv3iOGwCNEZpWBFXq2u3enokivdSSaa8zH3J7z1giic=; b=vL8bRdjdn686xHg+80o4Bw7MkCdQ4FcZ2d6trskcrwGWeDA98jwAoNjJoOwEKq6xiD VQXsWiE3YZIhkowwW7bwq1EqIEzf0gD6IOmWAldwwQe3iWVXZ4Hbp3h7vEM38GVd34wP slMABCJSw1kvz4Y8GqiG5r2thlv+SXo32C7wbVDNv8gffA0ipdZTSmZG8tRBazKenDpd y0CTe2B/AQ0rqaEuRCHvFb9ziv4wjAT1cH4CMMxlSNtrpmbbqOA+ry8mFLevujnHMx6U Hhv3NoaBt1N5q/4Tgd2bJxotmdRJd4wlpzhqBjHjcOO305rIJBIHmdtOCmQXugDk8hfA JmCw== X-Gm-Message-State: AOAM533xnSnHdrmlYSa45EtvL/qH5mkZ2LdHjpa7nPGqUvVSbGZBbIro 08wE0HazF3guYivP6PA2/8aDspNxr4bf/MGt8PX20llonyg9MgW/qioeCeHoKj6MPZ2YGdq4Q9R YjzGsPPXASBO1vsQIaLFAJQ== X-Received: by 2002:a05:6214:234b:b0:461:f43b:cedd with SMTP id hu11-20020a056214234b00b00461f43bceddmr34570648qvb.90.1653658379674; Fri, 27 May 2022 06:32:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyW85vM/uwy5hLfor+A1YaCvCmGuHLCwf+p9hC6T6FuCtTB1QA86tQgeZBLrUIgdq9Kv0TB6Q== X-Received: by 2002:a05:6214:234b:b0:461:f43b:cedd with SMTP id hu11-20020a056214234b00b00461f43bceddmr34570609qvb.90.1653658379253; Fri, 27 May 2022 06:32:59 -0700 (PDT) Received: from localhost (host109-152-215-36.range109-152.btcentralplus.com. [109.152.215.36]) by smtp.gmail.com with ESMTPSA id h184-20020a37b7c1000000b0069fc347ef5dsm2678427qkf.74.2022.05.27.06.32.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 May 2022 06:32:58 -0700 (PDT) From: Andrew Burgess To: Ilya Leoshkevich , Tom Tromey Cc: Ulrich Weigand , Andreas Arnez , Pedro Alves , gdb-patches@sourceware.org, Ilya Leoshkevich Subject: Re: [PATCH 5/5] gdb.perf/: Add JIT performance test In-Reply-To: <20220525223711.845475-6-iii@linux.ibm.com> References: <20220525223711.845475-1-iii@linux.ibm.com> <20220525223711.845475-6-iii@linux.ibm.com> Date: Fri, 27 May 2022 14:32:56 +0100 Message-ID: <87leungkxj.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2022 13:33:04 -0000 Ilya Leoshkevich writes: > The test registers and unregisters 500 functions. The time it takes to > process each function (the more functions there are, the slower it is) > is written into a global array, which is then read and reported by the > GDB script. I'm basically happy with this, but I do have one suggestion... > --- > gdb/testsuite/gdb.perf/jit-check.exp | 25 ++++++++ > gdb/testsuite/gdb.perf/jit-check.py | 60 ++++++++++++++++++++ > gdb/testsuite/gdb.perf/jit-solib.c | 28 +++++++++ > gdb/testsuite/gdb.perf/jit.c | 85 ++++++++++++++++++++++++++++ > gdb/testsuite/gdb.perf/jit.exp | 37 ++++++++++++ > 5 files changed, 235 insertions(+) > create mode 100644 gdb/testsuite/gdb.perf/jit-check.exp > create mode 100644 gdb/testsuite/gdb.perf/jit-check.py > create mode 100644 gdb/testsuite/gdb.perf/jit-solib.c > create mode 100644 gdb/testsuite/gdb.perf/jit.c > create mode 100644 gdb/testsuite/gdb.perf/jit.exp > > diff --git a/gdb/testsuite/gdb.perf/jit-check.exp b/gdb/testsuite/gdb.perf/jit-check.exp > new file mode 100644 > index 00000000000..c124f294f7b > --- /dev/null > +++ b/gdb/testsuite/gdb.perf/jit-check.exp > @@ -0,0 +1,25 @@ > +# Copyright (C) 2022 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Benchmark registering and unregistering JITed code (run part). > + > +load_lib perftest.exp > +load_lib gen-perf-test.exp > + > +if [skip_perf_tests] { > + return 0 > +} > + > +GenPerfTest::standard_run_driver jit.exp make_testcase_config jit-check.py JitCheck > diff --git a/gdb/testsuite/gdb.perf/jit-check.py b/gdb/testsuite/gdb.perf/jit-check.py > new file mode 100644 > index 00000000000..c5b46a23ffc > --- /dev/null > +++ b/gdb/testsuite/gdb.perf/jit-check.py > @@ -0,0 +1,60 @@ > +# Copyright (C) 2022 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Benchmark for registering and unregistering JITed code. > + > +import os > +import shlex > + > +from perftest import measure > +from perftest import perftest > +from perftest import testresult > +from perftest import utils > + > + > +class JitCheck(perftest.TestCaseWithBasicMeasurements): > + def __init__(self, name, run_names, binfile): > + super(JitCheck, self).__init__(name) > + self.run_names = run_names > + self.binfile = binfile > + self.measurement = measure.MeasurementWallTime( > + testresult.SingleStatisticTestResult() > + ) > + self.measure.measurements.append(self.measurement) > + > + def warm_up(self): > + pass > + > + def execute_test(self): > + for run in self.run_names: > + exe = "{}-{}".format(self.binfile, utils.convert_spaces(run)) > + utils.select_file(exe) > + > + # Help the binary find the shared objects. > + pieces = os.path.join(os.path.dirname(exe), "pieces") > + gdb.execute("cd {}".format(shlex.quote(pieces))) > + > + # Measure the total run time. > + utils.runto_main() > + gdb.execute("tbreak done_breakpoint") > + self.measure.measure(lambda: gdb.execute("continue"), run) > + > + # Extract and record processing times for individual functions. > + for array_name in ("register_times", "unregister_times"): > + array_value = gdb.parse_and_eval(array_name) > + for i in range(*array_value.type.range()): > + parameter = "{}:{}:{}".format(run, array_name, i + 1) > + result = int(array_value[i]) / 1e6 > + self.measurement.result.record(parameter, result) > diff --git a/gdb/testsuite/gdb.perf/jit-solib.c b/gdb/testsuite/gdb.perf/jit-solib.c > new file mode 100644 > index 00000000000..1171f1b86da > --- /dev/null > +++ b/gdb/testsuite/gdb.perf/jit-solib.c > @@ -0,0 +1,28 @@ > +/* This test program is part of GDB, the GNU debugger. > + > + Copyright (C) 2022 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +/* Shared object for benchmarking registering and unregistering JITed code. > + It is simply copied into memory, so there should be no relocations. > + Must be compiled with -DSHLIB=. */ > + > +#define CAT_1(x, y) x##y > +#define CAT(x, y) CAT_1 (x, y) > +int > +CAT (jited_func_, SHLIB) (void) > +{ > + return SHLIB; > +} > diff --git a/gdb/testsuite/gdb.perf/jit.c b/gdb/testsuite/gdb.perf/jit.c > new file mode 100644 > index 00000000000..7fc8b4a6339 > --- /dev/null > +++ b/gdb/testsuite/gdb.perf/jit.c > @@ -0,0 +1,85 @@ > +/* This test program is part of GDB, the GNU debugger. > + > + Copyright (C) 2022 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +/* Benchmark for registering and unregistering JITed code. > + Must be compiled with -DSHLIB=. > */ Like I said on patch #3 I think we should change SHLIB to something else, so this file would need updating. > + > +#include "../gdb.base/jit-elf-util.h" > +#include "../gdb.base/jit-protocol-util.h" > +#include > +#include > + > +static struct jit_code_entry entries[SHLIB]; > +static uint64_t register_times[SHLIB]; > +static uint64_t unregister_times[SHLIB]; > + > +static uint64_t > +time_delta (struct timeval *start_time) > +{ > + struct timeval end_time; > + > + gettimeofday (&end_time, NULL); > + return (uint64_t)(end_time.tv_sec - start_time->tv_sec) * 1000000 > + + (end_time.tv_usec - start_time->tv_usec); > +} > + > +void __attribute__ ((noinline)) done_breakpoint (void) {} > + > +int > +main (void) > +{ > + struct timeval start_time; > + int i; > + > + /* Load and register shared libraries. */ > + for (i = 0; i < SHLIB; i++) > + { > + int (*jited_func) (void); > + size_t obj_size; > + char name[32]; > + void *addr; > + > + sprintf (name, "jit-lib%d.so", i); > + addr = load_elf (name, &obj_size, NULL); > + sprintf (name, "jited_func_%d", i); > + jited_func = addr + (uintptr_t)load_symbol (addr, name); > + > + entries[i].symfile_addr = addr; > + entries[i].symfile_size = obj_size; > + gettimeofday (&start_time, NULL); > + jit_push_back (&entries[i]); > + register_times[i] = time_delta (&start_time); > + > + if (jited_func () != i) > + { > + fprintf (stderr, "jited_func_%d () != %d\n", i, i); > + return 1; > + } > + } > + > + /* Now unregister them all in reverse order. */ > + for (i = SHLIB - 1; i >= 0; i--) > + { > + gettimeofday (&start_time, NULL); > + jit_pop_back (); > + unregister_times[i] = time_delta (&start_time); > + } > + > + done_breakpoint (); > + > + return 0; > +} > diff --git a/gdb/testsuite/gdb.perf/jit.exp b/gdb/testsuite/gdb.perf/jit.exp > new file mode 100644 > index 00000000000..02923b290d9 > --- /dev/null > +++ b/gdb/testsuite/gdb.perf/jit.exp > @@ -0,0 +1,37 @@ > +# Copyright (C) 2022 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Benchmark registering and unregistering JITed code (build part). > + > +load_lib perftest.exp > +load_lib gen-perf-test.exp > + > +if [skip_perf_tests] { > + return 0 > +} > + > +proc make_testcase_config { } { > + set program_name "jit" > + array set testcase [GenPerfTest::init_testcase $program_name] > + set testcase(language) c > + set testcase(binary_extra_sources) { { jit.c } } > + set testcase(binary_link_with_shlibs) { 0 } > + set testcase(gen_shlib_extra_sources) { { jit-solib.c } } > + set testcase(run_names) { 500-sos } > + set testcase(nr_gen_shlibs) { 500 } I think it would be nice if the '500' could be user controllable. While I was playing with this, I added this code before 'make_testcase_config': # make build-perf RUNTESTFLAGS='jit.exp SOLIB_COUNT=100' if ![info exists SOLIB_COUNT] { set SOLIB_COUNT 500 } And then made this change within make_testcase_config: - set testcase(run_names) { 500-sos } - set testcase(nr_gen_shlibs) { 500 } + set name "${::SOLIB_COUNT}-sos" + set testcase(run_names) [list $name] + set testcase(nr_gen_shlibs) ${::SOLIB_COUNT} Then, like the comment says, I'd build with: make build-perf RUNTESTFLAGS="jit.exp SOLIB_COUNT=100" And test with: make check-perf RUNTESTFLAGS="jit-check.exp SOLIB_COUNT=100" GDB_PERFTEST_MODE=run I think we should include something like this, and make sure that the new flag is documented, probably in the comment at the start of jit.exp. However, before this is merged, I'd really like to understand why the performance from gdb.base/jit-elf.exp is so different to the performance we get from this test. I'm assuming that it's something to do with how the test is compiled, but so far I've not been able to figure it out. Thanks, Andrew > + return [array get testcase] > +} > + > +GenPerfTest::standard_compile_driver jit.exp make_testcase_config > -- > 2.35.3