From patchwork Thu Aug 18 11:42:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 56854 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 80F1E3858403 for ; Thu, 18 Aug 2022 11:42:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80F1E3858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1660822968; bh=BjR5Bp5Lf8EG5/OVGjZXjqbWgTqS3FG/YFqOYIl7UgQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=yF9EWPo/hPgUVj4Ankoi/5vBYGFheN/wNSJajXgrmZrfzgdAsrJKBhg/QJ763zW0D jyinaQP/w3N7lwryzQPIU+7HMuEBe/V+ElmWx/NLHN/4uojDaB44Sb8ITGLli/JigZ Mv54anbP+ltg4i7GvI3ru2p2IqRKY/SM0yzx2GW0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80054.outbound.protection.outlook.com [40.107.8.54]) by sourceware.org (Postfix) with ESMTPS id 9E03B3858D28 for ; Thu, 18 Aug 2022 11:42:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E03B3858D28 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=ZGNCfCJ9VxmY1BJAsB6ngVb48UxHXHnccPCLhGAHEFzvrK6sJoinX3tli6ksujsJdGPpWiqRO1/eXRE0Y5EA4hHrpY8xodxgmc/MlBhDD+fqE9jrrulBKFqZr2xw6Q8Pp7KMfSN2oX+oHDXLyuI3T50z2VFO6AnVePYhaJwmo4XxBvOC7eCsziU5hIPccIlPO0k3nCKGaFlBAepFAD/7t9nPW9p42s4DMA09l0y5y5zy+LT7lwQ8YEfgiCE/7FBRXXqmvNbt6ERn5M+s1F3cw6IGDOSt0XTzxR0qMn+ZTGnHFwnxCBAdcmeiI815vjJMi28TddzMA9pMtWyUedUpsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BjR5Bp5Lf8EG5/OVGjZXjqbWgTqS3FG/YFqOYIl7UgQ=; b=KA+Zhq7KKGLDv1pW0yUF8a9lnKZpn0pOGwQEVso6x9aFxxXXOCPl82sP13YDAAWBp+8b9Hj81AKyMm35wq7hIAqeOdO1NB2TrQDty/92au1oiGsQYh+HLb11zUw72e9/tPrIoPSLagbmPW2i3Jq5rPd4Bcn/11vb7PQd+tAs9kxiSEo/88yQhIFfdlTYc5XaAAYAQVs2gbvxPXuIqUo0PYGKiiS9rwrIsQDKIdL54yC6xcSNzOybpMH1uDUVGyXL14wkK6Jyd2gpwd84vPi+ciLlYb8VBRcIR7LD2/w/jXAj845YZtW0MwxxB+/wkz6qTtNZErORm4hS1uGdkYk93A== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from DB6PR0802CA0037.eurprd08.prod.outlook.com (2603:10a6:4:a3::23) by DU0PR08MB7812.eurprd08.prod.outlook.com (2603:10a6:10:3b4::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16; Thu, 18 Aug 2022 11:42:23 +0000 Received: from DBAEUR03FT061.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a3:cafe::67) by DB6PR0802CA0037.outlook.office365.com (2603:10a6:4:a3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.16 via Frontend Transport; Thu, 18 Aug 2022 11:42:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT061.mail.protection.outlook.com (100.127.143.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5546.15 via Frontend Transport; Thu, 18 Aug 2022 11:42:22 +0000 Received: ("Tessian outbound cc6a8ab50b6b:v123"); Thu, 18 Aug 2022 11:42:22 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 74582802781bd6dc X-CR-MTA-TID: 64aa7808 Received: from aceb43c1107b.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9D501465-C193-484D-BA1F-881D9D772110.1; Thu, 18 Aug 2022 11:42:15 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id aceb43c1107b.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 18 Aug 2022 11:42:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aTAbMRC9wjZRkdwSHwwT/JlYlo5UcNvr2BAmkPvVni0BMRquetWglTfl80HBf4sYbvKGbylrd7/Hct02/8aQXO3gwxYSyWPtIGSOcPEPmKzHEjtpDqKl7guFPi65AWcdlBSN8VZFILJKI3LFGoSJVQSrL0B68wS2+SMgq4S6eQebLu1/DXQS0epf+iX7q9/9AIkanVNtT9NHkGpP0Gv8E7TB6iMJBoZdMWSv+Kb+3znsuPNaCiymCI9miv7GjTfVYZa/BbNCPOyCvGRd2QzKWXG6PeUCq+eRRG+gYSBvic4w8/gkmv3iKDDDvtrrrcthcU5qhm7nHUjtLbXs5s+aaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BjR5Bp5Lf8EG5/OVGjZXjqbWgTqS3FG/YFqOYIl7UgQ=; b=V7MvzyAPMzMhOcxZit5/woq218FvE4RJ4+s6Y3PXmPM0Sz8lEVmOK2qIASWwLz8BBi2fPyZ6R5SdI5+0gbdSuX+sau0ARqjFo+RXW35EqSLulDkN/M5juXPsvHwdZUUe3DtCppwblxuZpUN2Bqxe35M2AjMile9IzH+0cxnGyG7SVD6oWyHQ0OnEcTHheMK1sAHMBtxpij2xTv+1t8Rr9w6QUMH5X0H0TZES13cTsHKR0zTeIHPZyfCTlzfOtYJ2nj8bKjn4h9700YuFC6Oojl29NGluPUFT0ZuZZdVCbHe/oANIenENB4D7GxgjAm6Cw/pOmwC4t9uCfZKPaJI6cQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Received: from AM5PR0801MB1668.eurprd08.prod.outlook.com (2603:10a6:203:3c::14) by AM0PR08MB3427.eurprd08.prod.outlook.com (2603:10a6:208:d6::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.23; Thu, 18 Aug 2022 11:42:13 +0000 Received: from AM5PR0801MB1668.eurprd08.prod.outlook.com ([fe80::e434:1b13:e8ed:9e14]) by AM5PR0801MB1668.eurprd08.prod.outlook.com ([fe80::e434:1b13:e8ed:9e14%11]) with mapi id 15.20.5525.019; Thu, 18 Aug 2022 11:42:13 +0000 To: 'GNU C Library' Subject: [PATCH] benchtests: Add libc locking benchmark Thread-Topic: [PATCH] benchtests: Add libc locking benchmark Thread-Index: AQHYsvdVZa/B1B0J70KH99q/5pZKOA== Date: Thu, 18 Aug 2022 11:42:13 +0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-MS-Office365-Filtering-Correlation-Id: 9f56a4fd-af88-4759-3f36-08da810eb728 x-ms-traffictypediagnostic: AM0PR08MB3427:EE_|DBAEUR03FT061:EE_|DU0PR08MB7812:EE_ x-checkrecipientrouted: true nodisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: 8AQhC7gHdWBq/XI3c0ZJrrbU67gVn/tisSckukp1gehUCnU3W1lWhlD+t0Um1VRpIg1+qEr6TorcLOMF+olsvG/ES+lmdsfRQC/SRSU/oosSXptu+qDTBggfqV2Ypea9Q5FOFCpVS13/XWlvUe6gogvc5cD5N/+c1GsE7eIbphPV3eM0XHLbquMBRLyv2uSsviL1iP5SWa9Ja43Ctkg/mvMPKm/pH55mqi8vscEPLlLqA9j+wEBRL8T5DArj2JAtbNJ2kNapae0Ha1+NMZy+i95yePRzvinHSdotM4GeWzUBNHDKJF9VbY9SGbnwKGN9DUh/c3+41eJ6PHrKsSGCE8BA/1N1TIjr4HZESb1jUuORrtGG/utZ5w2IhjIle5V3ww9+//4v7qL1XtCsxPx8aglvtF3n62uU8yNt1cuLEaNcv4AcxA9a7J3ZWPJVGB+NQ2gZRYaMlrDsFf6GFheA4wj4kiHbrjtDkZ+AZZHbNo3T6xEwML0HbyA4yFvWWJuMQ6jDyaVlUUWBmWIsAYdf2KCVlIFP/oFcKpOaq5pm04+l/7hvfzqbuluoMBaNBuAidOYyu1WRbFlxoAG8LED2yrI2eVdfNxy8ugSasFDIx9KhULLPf7tLO4sp+bil+HSfIFIMraNgxtdbtGW2yoBHf0Hgdw8vGtt+YTWxtPDjM62T5FzsnYNL/sVFfHsaB2GZL3RdD4198P179NUabIeW7M5q16gUypxrfo/5nJWyU2rxOvu3NntR5b1+g7MuZ7Lo32t7ciEbdonRCG6iqF6JFjS+K+4DeZ77qsZQkSBapwV3r14A93qGWe/NYL6E3va8Ax0yjGDIU0LQhI+B4T2/fWFv38alkaNtVg0Chpheb6Q= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM5PR0801MB1668.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(366004)(376002)(396003)(136003)(346002)(91956017)(8676002)(71200400001)(66556008)(76116006)(66946007)(64756008)(38070700005)(83380400001)(186003)(41300700001)(5660300002)(66446008)(52536014)(8936002)(66476007)(478600001)(33656002)(6916009)(55016003)(38100700002)(86362001)(26005)(9686003)(122000001)(2906002)(7696005)(6506007)(316002)(2004002); DIR:OUT; SFP:1101; MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3427 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 5120a6f2-4ae1-420c-32de-08da810eb1c2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aYuxfM57bRhmLF/NkNMI5qmXlhPS2QFSPkLxwUqGwYaOULZToIYjPUrf2AVG16lOPXWjRMk/RQlnzQpa2Da4a0FH4rQuMz6hcl7M0uVgR5nFTI09nG1Bz+9SLl6rKUw7S1CHgrxetl3TcGgL8Cn0MXXSOaxX3RfrYWyI0NYWK87cddLCvqv7pZoCdTkXqoQFUWDM0rH3INYasd9WGpw28r3P14Jbb6R0nbR92wIXsTxS58260eDohrj5ZnvuJBfPqIYioANn/3Gcw4IZvWrTLcKX5zWVrRA3+CdlLXIbxuUBfMoS/KmbAjuY1aIBeQe8EXXI4rJ0WAu4Ys0hL34oQzqvcDre4IbEDJPKVZcjEB6x0Da+UqOhKUDCG4F2wGGChujOhih83DlUBss3OCT+BlZ4mz2JKIXnB4EeBQ/8yk7jk7/1/toVTY5BBdQfEt1FJIKsKVC+p9SOrz+NTv4BRx7WY6WFVSRH+9gSctxSrXei4MJam2bT1vLt1GzQi0WUpqR0Ecs64cfCfnnCIsk6Z954ERu83yUFIZjebdaMD1O1MgxBd22D0bT23ImkGp4WN8c2R+K3RevAFNEfsg85CYV/Epc/2H5wB9YBsz//xkJGfxHN0ayyJLXHL3DdaUtbDwQPjHXKFvNZRVFurZRDnTYzmLc+hzX5ypbHP8++BlvDG4PwZFto4wiNyF9qrOuZQf48l4CU8n5Y7vvl+M0l8lblEHX5r4dwmJJC6bKYxQKpccl0eVZodWtwBnPZ7Mng+Toq6Aoe4k/LpxS6oXh5J0UL5s+5QclxLX9OnEy2n8Du2k43xtytshVKTPFRyONx X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230016)(4636009)(346002)(39860400002)(136003)(376002)(396003)(40470700004)(36840700001)(46966006)(41300700001)(40460700003)(36860700001)(2906002)(82310400005)(7696005)(6506007)(336012)(5660300002)(6916009)(186003)(47076005)(52536014)(316002)(8936002)(26005)(81166007)(33656002)(82740400003)(83380400001)(356005)(478600001)(9686003)(70206006)(70586007)(86362001)(40480700001)(55016003)(8676002)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2022 11:42:22.8583 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f56a4fd-af88-4759-3f36-08da810eb728 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT061.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7812 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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: 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: Wilco Dijkstra via Libc-alpha From: Wilco Dijkstra Reply-To: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Add a simple libc locking benchmark to measure overhead of locking in both single- and multi-threaded cases. diff --git a/benchtests/Makefile b/benchtests/Makefile index d99771be74b40f8afa3953f61c0721b19658d4b7..1bef5bf9ef477a645c3cadc66b2c25774cefb5e5 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -236,6 +236,7 @@ hash-benchset := \ stdlib-benchset := \ arc4random \ strtod \ + libc-lock \ # stdlib-benchset stdio-common-benchset := sprintf diff --git a/benchtests/bench-libc-lock.c b/benchtests/bench-libc-lock.c new file mode 100644 index 0000000000000000000000000000000000000000..0057c1397a3867df7515759a47ab93430f9ce466 --- /dev/null +++ b/benchtests/bench-libc-lock.c @@ -0,0 +1,102 @@ +/* Benchmark internal libc locking functions. + Copyright (C) 2022 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#define TEST_MAIN +#define TEST_NAME "libc-locks" + +#include +#include +#include +#include "bench-timing.h" +#include "json-lib.h" + +json_ctx_t json_ctx; + + +/* Measure the overhead of __libc_lock_lock and __libc_lock_unlock by + calling rand(). */ +static void +bench_rand_lock (size_t iters) +{ + timing_t start, stop, total; + + srand (0); + for (int i = 0; i < iters / 4; i++) + (void) rand(); + + TIMING_NOW (start); + + for (int i = 0; i < iters; i++) + (void) rand(); + + TIMING_NOW (stop); + + TIMING_DIFF (total, start, stop); + + json_element_double (&json_ctx, (double) total / (double) iters); +} + +static void * +thread_start (void *p) +{ + return p; +} + +int +do_bench (void) +{ + size_t iters = 20000000; + + json_init (&json_ctx, 0, stdout); + + json_document_begin (&json_ctx); + + json_attr_string (&json_ctx, "timing_type", TIMING_TYPE); + json_attr_object_begin (&json_ctx, "functions"); + json_attr_object_begin (&json_ctx, "rand"); + json_attr_string (&json_ctx, "bench-variant", "single-threaded"); + json_array_begin (&json_ctx, "results"); + + /* Run benchmark single threaded. */ + bench_rand_lock (iters); + + json_array_end (&json_ctx); + json_attr_object_end (&json_ctx); + + json_attr_object_begin (&json_ctx, "rand"); + json_attr_string (&json_ctx, "bench-variant", "multi-threaded"); + json_array_begin (&json_ctx, "results"); + + pthread_t t; + pthread_create (&t, NULL, thread_start, NULL); + pthread_join (t, NULL); + + /* Repeat benchmark now SINGLE_THREAD_P == false. */ + bench_rand_lock (iters); + + json_array_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_attr_object_end (&json_ctx); + json_document_end (&json_ctx); + return 0; +} + +#define TEST_FUNCTION do_bench () + +#include "../test-skeleton.c" +