From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6PVaDRJClWIQVAkAWB0awg (envelope-from ) for ; Mon, 30 May 2022 18:15:46 -0400 Received: by simark.ca (Postfix, from userid 112) id 322EA1E221; Mon, 30 May 2022 18:15:46 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=j/txEK9P; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 120791E01D for ; Mon, 30 May 2022 18:15:45 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFBEB384B0CC for ; Mon, 30 May 2022 22:15:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFBEB384B0CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1653948944; bh=RT33k+b82u1JarQ/ld2etDvStTwrNGm0PNznkxdy6HQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=j/txEK9Pe+kbeQtf50Cxw67fjfg0psH/JlZrOXs/Utb8I4amFkp8zO9pybQ+jA7Du cXo1sxAba4y1leyPUG1eW+pukEfqu0Ch9l4QLpwv2PfYdRG8ZIH8JMnJzifn7AXABd W0FFCg7+bLb0CArPqf4+F/fZdjC2fx2VJ7RMnS2s= Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 7541C38485B9 for ; Mon, 30 May 2022 22:12:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7541C38485B9 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24ULhtQh023506; Mon, 30 May 2022 22:12:49 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gd63egaww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 22:12:49 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24UMCmhw033528; Mon, 30 May 2022 22:12:48 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gd63egawr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 22:12:48 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24UM7FdF006075; Mon, 30 May 2022 22:12:46 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04ams.nl.ibm.com with ESMTP id 3gbcae377m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 May 2022 22:12:46 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24UMBcYB28705276 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 30 May 2022 22:11:38 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 060974C04A; Mon, 30 May 2022 22:12:42 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9EA094C040; Mon, 30 May 2022 22:12:41 +0000 (GMT) Received: from heavy.ibmuc.com (unknown [9.171.0.196]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 30 May 2022 22:12:41 +0000 (GMT) To: Tom Tromey , Andrew Burgess Subject: [PATCH v2 7/7] gdb.perf/: Add JIT performance test Date: Tue, 31 May 2022 00:11:47 +0200 Message-Id: <20220530221147.1991835-8-iii@linux.ibm.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220530221147.1991835-1-iii@linux.ibm.com> References: <20220530221147.1991835-1-iii@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: JYHaOH4qZDYN5f_ui9j4ncBfGgPEHL6j X-Proofpoint-GUID: DZeGKSXfL84wFaEft_5TVBHBhILML-Yx Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-05-30_09,2022-05-30_03,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 priorityscore=1501 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2205300117 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: , From: Ilya Leoshkevich via Gdb-patches Reply-To: Ilya Leoshkevich Cc: Ulrich Weigand , Andreas Arnez , gdb-patches@sourceware.org, Pedro Alves , Ilya Leoshkevich Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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. --- gdb/testsuite/gdb.perf/jit-check.exp | 25 ++++++++ gdb/testsuite/gdb.perf/jit-check.py | 60 +++++++++++++++++++ gdb/testsuite/gdb.perf/jit-solib.c | 27 +++++++++ gdb/testsuite/gdb.perf/jit.c | 87 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.perf/jit.exp | 79 +++++++++++++++++++++++++ 5 files changed, 278 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..b2f70fc16e8 --- /dev/null +++ b/gdb/testsuite/gdb.perf/jit-solib.c @@ -0,0 +1,27 @@ +/* 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. + 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..5fb373a753f --- /dev/null +++ b/gdb/testsuite/gdb.perf/jit.c @@ -0,0 +1,87 @@ +/* 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 -DTOTAL_NR_SHLIBS=. */ + +#include "../gdb.base/jit-elf-util.h" +#include "../gdb.base/jit-protocol-util.h" +#include +#include + +static struct jit_code_entry entries[TOTAL_NR_SHLIBS]; +static uint64_t register_times[TOTAL_NR_SHLIBS]; +static uint64_t unregister_times[TOTAL_NR_SHLIBS]; + +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 < TOTAL_NR_SHLIBS; i++) + { + int (*jited_func) (void); + size_t obj_size; + char name[32]; + void *addr; + + sprintf (name, "jit-lib%d.so", i); + void *load_addr = n_jit_so_address (i + 1); + addr = load_elf (name, &obj_size, load_addr); + sprintf (name, "jited_func_%d", i); + jited_func = 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 = TOTAL_NR_SHLIBS - 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..8423312c07a --- /dev/null +++ b/gdb/testsuite/gdb.perf/jit.exp @@ -0,0 +1,79 @@ +# 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). +# +# Usage example: +# +# make build-perf RUNTESTFLAGS='jit.exp SOLIB_COUNT=100' +# +# Supported options: +# +# - SOLIB_COUNT: How many shared objects to build (default: 500). + +load_lib jit-elf-helpers.exp +load_lib perftest.exp +load_lib gen-perf-test.exp + +if [skip_perf_tests] { + return 0 +} + +if ![info exists SOLIB_COUNT] { + set SOLIB_COUNT 500 +} + +# Adjust binary compile options. +proc jit_binary_adjust_compile_options { options nr_gen_shlibs } { + # Specify shared library load addresses. + global jit_compile_options + set options [concat $options $jit_compile_options] + + # Specify the total number of shared libraries. + lappend options additional_flags=-DTOTAL_NR_SHLIBS=$nr_gen_shlibs + + return $options +} + +# Adjust solib compile options. +proc jit_solib_adjust_compile_options { options so_nr } { + # Disable debuginfo (see compile_and_download_n_jit_so for explanations). + set debug [lsearch -exact $options debug] + if {$debug != -1} { + set options [lreplace $options $debug $debug] + } + + # Specify a load address for this solib. + lappend options text_segment=[format 0x%x [n_jit_so_address $so_nr]] + + return $options +} + +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) { false } + set testcase(binary_adjust_compile_options) { jit_binary_adjust_compile_options } + set testcase(gen_shlib_extra_sources) { { jit-solib.c } } + set testcase(gen_shlib_adjust_compile_options) { jit_solib_adjust_compile_options } + set name "${::SOLIB_COUNT}-sos" + set testcase(run_names) [list $name] + set testcase(nr_gen_shlibs) ${::SOLIB_COUNT} + return [array get testcase] +} + +GenPerfTest::standard_compile_driver jit.exp make_testcase_config -- 2.35.3