From patchwork Thu Apr 24 18:05:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 110949 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 285463858C42 for ; Thu, 24 Apr 2025 18:08:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 285463858C42 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=WbCQZAcw; dkim=pass (1024-bit key, unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=R5rLXpyz X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id F3DB43858D3C for ; Thu, 24 Apr 2025 18:06:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3DB43858D3C Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F3DB43858D3C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1745517980; cv=pass; b=kWuQnjm1HximYjbJbGY4xYK0pE8ltGriMCdFkA3qEl12Tk65D90W3ixVnUurz1WfOqYwbnFVaDM1V1O1XUTuJh1SQ8nF1+XkETDL5LmhK6AqxfCGL7rNar73SHuKAdAoUmJOwIHVCUvInPPBH3FeMOhMARNVqWe2qI5YldsNWew= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1745517980; c=relaxed/simple; bh=N7dgzWrudl4fOTzIGdEaqnXCpTyufYJ7wVXqAnhZMHM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=iWWN2fHuzscMOJ+G2bgoy2hBN5KGQHNW7S7DSNgiNzvybQN6f9iw8QQb8vs/JiPFpWHFZLtOg2CAjVpFyeOZf7p+sfdQcx8XtMgoniLwHj6NLR9D5iMxWmPMScNoMqCcEpG3H0+Ew5zq1iD9CfXszWOKSK7QVa0XCO18D+APrBo= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3DB43858D3C Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53OFgV1B013553; Thu, 24 Apr 2025 18:06:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=corp-2023-11-20; bh=KgvGFW9fwwi1cuar 0PBLeDylOrP3MAxGryw2glUwZK8=; b=WbCQZAcwdfNWFbkKEuRHfItpG+hiQzfa m4M+cL3OB9iK0lnf81ntkfMe8qSf3292pNkD76igNSasS8pXKMZ+IwElkH6x/g5T jd1tkoI1stgEIwVmp9UA5OSwtzV1WLYkDw2Ia74Qw0M9094kFblwOZoDwcNuqkU9 7EukTQuISDUK8yk5yXkhkPExgHqM0b9uayntaVzo0O20zRhHjYzGJGStOcTbTf0Q JxYGITPyTD6SquSXhn9hbBr8efBzRKO/hTP17rM1PsZ7GMrwj0Pdxc99eHor40yv eJ9d18/dpm3JybagSGfm8icGSNTKxjos+gitfyzcQCwBOLtXavsVHw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 467r620new-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Apr 2025 18:06:11 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53OI0uah025226; Thu, 24 Apr 2025 18:06:09 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2040.outbound.protection.outlook.com [104.47.58.40]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 466jbse8hv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Apr 2025 18:06:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=YE9TX1dW940988ptvGI2wJSbMCVThdzz6boliSAYuUkE2ZIzpvn8vlfAGxFPucd1MLZ6UGhwYSXjIaAcYK5JbyckUT2myHctxRQ97Yu3eSFhNO4dNBqZWRprpBeMhBtTCDYMBvge9LQqXeLCNZsQ1ynbLGfWG0PcQmliDzl0eHIZh5DtYsGWaHC5C5y5fpVXYiSzsgM0BWko44APqFMeAjGUVMbuewxJB3q4372pvyKQHzIigp3j2uqLdags5Mtq8ErZbjzXbhM3fyAsjtIAct2WuiGVAZeuKRBkY6yMURk1VMYa6C/elTUiX228+dD82yflp4oVL3KwfRoYee7Dfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=KgvGFW9fwwi1cuar0PBLeDylOrP3MAxGryw2glUwZK8=; b=FYCKzdTZNkGddSuJfuGTdRcy+X7YdEK1hraQvHFlzvejqDO26IFA+z0ePPtCimzYqkOPCpZ1ZI4i9TL1IG1d8DfDpANG/DSBASOpI+CMnsejguoC0xn0Zex6BDVQ36mPThkbEVktss6hV/tNvyF24Rgzc6zIAkTRZ0thYbnHZhUNFvWQPGenrOVPSB00ZVpk57rzBz55epABFSH0VJDwSRNwq9cYNXQoiHVSDxbv2Nalh2/AJz1WHJKabRpfPU0RyCRHH++pjKoFT9oqLB/w9y4hFAO65N+zfKMBRgM70sQaYH4FGLLV9wK/qVAIb8qXxTx9cvFWHpjlD/We1o+UMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KgvGFW9fwwi1cuar0PBLeDylOrP3MAxGryw2glUwZK8=; b=R5rLXpyzF56USSXZUpdkfjkB2BfqJNYYqjcW++izrALbST/Un5jiuz5wu65bBjXNSZT89Nsl0OQq/hV9ZXBriNfC+ohtPGTEJPDohO1w827oznOzh5RD0zD2z8W0KNDxYzcXE77r96/K5gJnlKJPb9mVdjiplmgvn92rMZWjxlA= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by BLAPR10MB4897.namprd10.prod.outlook.com (2603:10b6:208:30f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8655.35; Thu, 24 Apr 2025 18:06:06 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::5033:84a3:f348:fefb%4]) with mapi id 15.20.8678.021; Thu, 24 Apr 2025 18:06:06 +0000 From: Cupertino Miranda To: libc-alpha@sourceware.org Cc: jose.marchesi@oracle.com, elena.zannoni@oracle.com, Wilco.Dijkstra@arm.com, dj@redhat.com, fweimer@redhat.com, Cupertino Miranda Subject: [PATCH] benchtest: malloc tcache hotpath benchtest. Date: Thu, 24 Apr 2025 19:05:58 +0100 Message-Id: <20250424180558.45764-1-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 X-ClientProxiedBy: SG2PR02CA0056.apcprd02.prod.outlook.com (2603:1096:4:54::20) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|BLAPR10MB4897:EE_ X-MS-Office365-Filtering-Correlation-Id: 23e65795-70d7-4b09-1511-08dd835aae91 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: ZO2TAF96Fm21SQ9F6uXClhqS+ZjHTF0btReO7Vw1nA+879RtOjYVcQgYe5ITBXHBuLUCzOv1C/WtJz1eAXuBwNQLA3l5sZxH05sVYSvxMrKDif71eCUR9ToxaNkeW16MpUdp/JLJQV5g886Fdt+HWfixCN0mbweYZ6lB3IYdu98Cf3keGyAE619LKDl60FjaIETY1KNcyt0QdRtNusfD6yUzSrM19Z9CCo+usd7A01GvRr10R17pgtG9fRqsaJwHbJodi3AqW/uilzgNpujv5IxIVo+3PYWKHq3QPeonB9xNEE5zKxulV3hIPp+PIQcy0pyK9NGsxAlO3HFaGhzcBOdYM3YGQFKFo18Eg2JS3ndCPRcPPtFhmLvgFyixBk+TbFQktY2sNPg1fCUKU2KpAaul2PDJxtd5EIfNxwPcMAxA7gnQQR0ulTKNstV4BmsjWedpspeb45HT12mKW7Xms58p7clOSJw7kOlw6PAj9C1LIJdcM8GJEyOVIAVPQuCnaWqvnI+5efRavN/vHGP3rD/s9ohYumrDTDABbMHJ8OwgEN7i0r099rhK3Mo1nRmAZFr9A1SvT1ICi+MWY2USToMP5uXni+SUTUv6mU0amvUCpVxXK34zPGtcedHZTubYRx3PrZuj/P9VXG1AHqSrMprksr1Y2RhvLwgs9Oi1mRMhfoa+tOeLuYUe4WNzPOkebMhaC/s7sCk2BE7PRFO739Kgpf0HoNUKvyhhcyIqvjfhomLz4E18o4aRKJUn/HM1eIUPlj4fEN79Wz56H8dnJkTeDFwrYyVE2dXug7ynXFWRNSVE+zSl6rjrMUKmcXSpBb2QTB61YeiRfYQk4HuSwFuz3G7CP2B/iYQY+CwHceGz3Ri1rxxQTi2vSQ/7wd/ctEawoCSgtKNy5foLz5edy37eWdyINtt9guCs6DOZxHdz0gkAv+KOmjUqDAjQ/dXUtwcitk+bxOG0VAFwzSoZLx5ehUhMjflDQsYkumXV3UPPjIDakO18sDgaQvZGgiC3KlzckAC7l1+PcdhSsNR4M3ewq54Wwsg4IWT5kW/Ya2ncjOlS4lfigBNHsZCdl3amk6USWfKY6zDdC/wHLZjB8I8/VvaZaFQtncU1nAKx/2juwOnC0TQiOkJ45wmdXKdr89AAONpmVMr/oRePCzu4wB9YOS8HwLh0kGaDgVnzm3z69VCVjqZauv8CbACCNBwW6IVsvuBVnRnNa1r7X62cLESbxzHh2+lo0+R8J96lmRtv8Q4zbe2wU6Il6fUvUh8MjSVHkHPrlnhAqA2tAsEDXELEBMy+ZIOz1YE7pfKhPQks128HzWfOLLaTidHCvVge4NTz1HBj63AN4Tu7UOFg8sD3tT3G/KuIlKbotzHbRxXq6wtJYJVmVJf6w0dCketlhGatIKWxAorh4BBTaeW/RCq4/cAOak30xqbP66HoebE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4382.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014); DIR: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QikQZGfQfhsNwNRbaTnA8wbKzds0Ev3cRBCpOlAbzQAp1TU3R6/v37HiAHMzakLfnno42OdnjircOn/eRxbgYAdlhE/+kJ1wgLJ6Kh/3QydBt8Y7fzSP6CPZLVByOwnYL3QzSlPMspcgWQ9Nyno9u5nT1/diGJLnSg10eQ74haVkTrU3d402Ng22HAfuCzMeU4it+xtmb48HbU/dsjjbCJzNdTyeBxK5hCJ4QT2vl4RJA/cM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23e65795-70d7-4b09-1511-08dd835aae91 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2025 18:06:06.0353 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zg8c1zO5UZk2cZ4cVXEeq3rZhkiAnYU1z4eF2yf2OrwjaRyJ9SqpX/rdlcK3EHW1Y34nGx2m1WD3di6rCzkc2Lh+HnOSN7EFmMVMW8p2lCM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4897 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-24_08,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 bulkscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2504070000 definitions=main-2504240125 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNDI0MDEyNSBTYWx0ZWRfX3RSdbGteGVfo sg6g9CBYe6vso3yo9z7SZoMyJfh0w1IZTvCpGQLZRZZEjnsdbxxOujwrPnO46gA7DhwRb3NWo2S D025RUNS7DFLsa2dLa9mEWO3f7+7sIX67Vfk5CU2BN9WEKzZfJJIeMegV1qJDBUZYJz+ag1XsTn L2xPrHHE1ox7JdWUPtrMbxr1R3zaZk715xv6I9EgZ4dN6t5IW1Bye06wJs3dImuxkIDGfZVIOpD Ct/WIpptSgwkwuHUXsIppuk9W5XoxipjAPtuo32GIStTm4/oolNLwKh88Tme0KL0vGGr4CeZeGy Q3E47zla/cP8dJR0oBbDp79AQ5s7IZiPpglrdug7JUAwHWkTmd6xjFxukexJhn5PKj4jys4wU78 vyHTfKwZ X-Proofpoint-ORIG-GUID: IYha9IvziIvGx0sEMUTaNzWsf1GQ0P4r X-Proofpoint-GUID: IYha9IvziIvGx0sEMUTaNzWsf1GQ0P4r X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Hi everyone, This patch is introduces an adaptation of bench-malloc-thread, however forcing all measured allocs and frees to only use tcache, making it a preferable benchmark to evaluate performance improvements or degradation from tcache hotpath changes. Experiments so far show much less fluctuation of similar consecutive executions. Looking forward to your comments. Best regards, Cupertino Existing benchtests for malloc infrastructure seem to be rather generic to test global malloc implementation performance. This new benchtest focus on reducing any non tcache related side effects, allowing to more realistically predict performance impacts of tcache code changes. The test was inpired in bench-[cm]alloc-thread code, with the following changes: - forces single thread execution, reducing concurrency side-effects, like cache incoherence penalties due to simultaneous parallel writes to same cache pages; - it prefills and saturates all tcache bins with chunks, before starting to collect any measurements; - input argument is now a max_allocation multipler, allowing it to increase max_allocation. For the purpose of measuring current overhead on tcache hotpaths, only the execution with argument as 1 is relevant, since current tcaches are limitted to allocations up to 1kb. --- benchtests/Makefile | 7 + benchtests/bench-malloc-tcache.c | 268 +++++++++++++++++++++++++++++++ 2 files changed, 275 insertions(+) create mode 100644 benchtests/bench-malloc-tcache.c diff --git a/benchtests/Makefile b/benchtests/Makefile index cccee62eb0..5275bed457 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -331,6 +331,7 @@ bench-malloc := \ calloc-thread \ malloc-simple \ malloc-thread \ + malloc-tcache \ # bench-malloc else bench-malloc := $(filter malloc-%,${BENCHSET}) @@ -456,6 +457,7 @@ VALIDBENCHSETNAMES := \ hash-benchset \ malloc-simple \ malloc-thread \ + malloc-tcache \ math-benchset \ stdio-benchset \ stdio-common-benchset \ @@ -498,6 +500,11 @@ bench-malloc: $(binaries-bench-malloc) echo "Running $${run} $${thr}"; \ $(run-bench) $${thr} > $${run}-$${thr}.out; \ done;\ + elif basename $${run} | grep -q "bench-[cm]alloc-tcache"; then \ + for thr in 1 8 32 128 512 2048 4096; do \ + echo "Running $${run} $${thr}"; \ + $(run-bench) $${thr} > $${run}-$${thr}.out; \ + done;\ else \ for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \ echo "Running $${run} $${thr}"; \ diff --git a/benchtests/bench-malloc-tcache.c b/benchtests/bench-malloc-tcache.c new file mode 100644 index 0000000000..c1dbd81b3d --- /dev/null +++ b/benchtests/bench-malloc-tcache.c @@ -0,0 +1,268 @@ +/* Benchmark tcache hotpath allocations. + Copyright (C) 2013-2025 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 + . */ + +#ifndef TEST_FUNC +# define TEST_FUNC(size) malloc(size) +# define TEST_NAME "malloc" +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "bench-timing.h" +#include "json-lib.h" + +/* Benchmark duration in seconds. */ +#define BENCHMARK_DURATION 10 +#define RAND_SEED 88 + +/* Maximum memory that can be allocated at any one time is: + + WORKING_SET_SIZE * MAX_ALLOCATION_SIZE * alloc_multiplier + + However due to the distribution of the random block sizes + the typical amount allocated will be much smaller. */ +#define WORKING_SET_SIZE 1024 + +#define MIN_ALLOCATION_SIZE 4 +#define MAX_ALLOCATION_SIZE 1024 + +#define TCACHE_FILL_COUNT 7 +#define TCACHE_SIZE_OFFSET 16 + +size_t alloc_multiplier; + +/* Get a random block size with an inverse square distribution. */ +static unsigned int +get_block_size (unsigned int rand_data) +{ + /* Inverse square. */ + const float exponent = -2; + /* Minimum value of distribution. */ + const float dist_min = MIN_ALLOCATION_SIZE; + /* Maximum value of distribution. */ + const float dist_max = MAX_ALLOCATION_SIZE * alloc_multiplier; + + float min_pow = powf (dist_min, exponent + 1); + float max_pow = powf (dist_max, exponent + 1); + + float r = (float) rand_data / RAND_MAX; + + return (unsigned int) powf ((max_pow - min_pow) * r + min_pow, + 1 / (exponent + 1)); +} + +#define NUM_BLOCK_SIZES 8000 +#define NUM_OFFSETS ((WORKING_SET_SIZE) * 4) + +static unsigned int random_block_sizes[NUM_BLOCK_SIZES]; +static unsigned int random_offsets[NUM_OFFSETS]; + +static void +init_random_values (void) +{ + for (size_t i = 0; i < NUM_BLOCK_SIZES; i++) + random_block_sizes[i] = get_block_size (rand ()); + + for (size_t i = 0; i < NUM_OFFSETS; i++) + random_offsets[i] = rand () % WORKING_SET_SIZE; +} + +static unsigned int +get_random_block_size (unsigned int *state) +{ + unsigned int idx = *state; + + if (idx >= NUM_BLOCK_SIZES - 1) + idx = 0; + else + idx++; + + *state = idx; + + return random_block_sizes[idx]; +} + +static unsigned int +get_random_offset (unsigned int *state) +{ + unsigned int idx = *state; + + if (idx >= NUM_OFFSETS - 1) + idx = 0; + else + idx++; + + *state = idx; + + return random_offsets[idx]; +} + +static volatile bool timeout; + +static void +alarm_handler (int signum) +{ + timeout = true; +} + +/* Allocate and free blocks in a random order. */ +static size_t +malloc_benchmark_loop (void **ptr_arr) +{ + unsigned int offset_state = 0, block_state = 0; + size_t iters = 0; + + while (!timeout) + { + unsigned int next_idx = get_random_offset (&offset_state); + unsigned int next_block = get_random_block_size (&block_state); + + free (ptr_arr[next_idx]); + + ptr_arr[next_idx] = TEST_FUNC (next_block); + + iters++; + } + + return iters; +} + +static void +fill_tcache(void) +{ + void *ptrs[TCACHE_FILL_COUNT]; + for (int i = MIN_ALLOCATION_SIZE; + i <= MAX_ALLOCATION_SIZE; + i += TCACHE_SIZE_OFFSET) + { + for (int j = 0; j < TCACHE_FILL_COUNT; j++) + ptrs[j] = TEST_FUNC (i); + + for (int j = 0; j < TCACHE_FILL_COUNT; j++) + free (ptrs[j]); + } +} + +static timing_t +do_benchmark (size_t *iters) +{ + timing_t elapsed = 0; + + timing_t start, stop; + void *working_set[WORKING_SET_SIZE]; + + memset (working_set, 0, sizeof (working_set)); + + /* Fill tcache bins with freed chunks. */ + fill_tcache (); + + TIMING_NOW (start); + *iters = malloc_benchmark_loop (working_set); + TIMING_NOW (stop); + + TIMING_DIFF (elapsed, start, stop); + + return elapsed; +} + +static void usage(const char *name) +{ + fprintf (stderr, "%s: \n", name); + exit (1); +} +int +main (int argc, char **argv) +{ + timing_t cur; + size_t iters = 0; + json_ctx_t json_ctx; + double d_total_s, d_total_i; + struct sigaction act; + + if (argc == 1) + alloc_multiplier = 1; + else if (argc == 2) + { + long ret; + + errno = 0; + ret = strtol(argv[1], NULL, 10); + + if (errno || ret == 0) + usage(argv[0]); + + alloc_multiplier = ret; + } + else + usage(argv[0]); + init_random_values (); + + 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, TEST_NAME); + + json_attr_object_begin (&json_ctx, ""); + + memset (&act, 0, sizeof (act)); + act.sa_handler = &alarm_handler; + + sigaction (SIGALRM, &act, NULL); + + alarm (BENCHMARK_DURATION); + + cur = do_benchmark (&iters); + + struct rusage usage; + getrusage(RUSAGE_SELF, &usage); + + d_total_s = cur; + d_total_i = iters; + + json_attr_double (&json_ctx, "duration", d_total_s); + json_attr_double (&json_ctx, "iterations", d_total_i); + json_attr_double (&json_ctx, "time_per_iteration", d_total_s / d_total_i); + json_attr_double (&json_ctx, "max_rss", usage.ru_maxrss); + + json_attr_double (&json_ctx, "min_size", MIN_ALLOCATION_SIZE); + json_attr_double (&json_ctx, "max_size", MAX_ALLOCATION_SIZE * alloc_multiplier); + json_attr_double (&json_ctx, "random_seed", RAND_SEED); + + json_attr_object_end (&json_ctx); + + json_attr_object_end (&json_ctx); + + json_attr_object_end (&json_ctx); + + json_document_end (&json_ctx); + + return 0; +}