From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from YT5PR01CU002.outbound.protection.outlook.com (mail-canadacentralazon11021084.outbound.protection.outlook.com [40.107.192.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E340C1C5CC1 for ; Tue, 24 Dec 2024 16:20:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.192.84 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735057231; cv=fail; b=luQlkoiSHpnZ7QZi7gn2HwEP0J6quIKD+lccQLsFnKRpc4jTCkUPcmyMOr09fO1cVOuP0pYGdUnxWB3m7pD59AWW1h0vE//ULE5SVCB64gPxOdEZYCpKYGLyLYH5RtAHXQFaruvKM0lbP3+JCIRWHZeTasiHz5Q7MhpnCCxd144= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735057231; c=relaxed/simple; bh=6zrGBXxO3nna0VltpeVh4WFcef5BzLX4VR9KgfS6KdU=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=kIQ5ICMQ28VVbsk795DIGTDWMjV94/DTR26Kp4kc229WF2EH+wZK8a/BIb4JChnyqqaVyiCU89F1dymH2NYn0D+UgpipIf7xyKT8NYSOp2xr+k1ckWbM35ZiTytuoaP5mXiwebfU4feJdz/xkUOvsj9YOYLgCkNK0InZD2ntPto= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=RfcVfy8F; arc=fail smtp.client-ip=40.107.192.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="RfcVfy8F" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AFEgvGdgP3Rd5pOb2jPndQGF7K6VTjxR2qPFIcRQE/ip0iSqjZ3kGuUiKAkE6/ReHFrGYr6mvswf5nE0mowh1jQIgWANLub8yHop3rvBCR9DbkSVJt64/doppgeiQEH0KQQdOLGRp6t7eyidtrVoa8l3+24RM0szFVjoIhOOtgQqFqXfVhxcgO/KekX/hyr1hg2CZRpV+OohDZ/3xDh0v3hOJM4eFQwN++/WRZWcRjXE7ZDgPoich9+pwsp53+zOcb71Jk8boev4NP79yjhRPaoKSwnQCkvZbppUCe7M0IstBimp5XFveVUTtK3u5Pzm/aHK2rr1yi+oQtzdKJ9v4Q== 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=Skcyf3BjsheLuwpJyGPqN9g7trQ9NrFMc0ncNRnKaYo=; b=czDKPKuI08ElQF6tdlOdp1sMGGAb4I4zk4SBxW6ljA+Vd32+BD26zr0wNz2nDfugXZQRZBu9WyKdG1CK23rf5Js6INVPmy1LSP3dFCxfp8oSg37LSE9jgM5Omt40PinrtoFsw7w441ugjYbuuWg1ZUNvkIY/B8y1g9Jp6MIqiA+FMfaYTTGBSGgnS8XCpaaOT8XXhCr4uAL8ZtgxHuGxFQOFtN5Wq5QmK4H+TW8VMT7yKSg3ZPI5Q2WxieFfrk1iBJC9uDLZlhZ1ljL4YrTTpDlf1g76i6Jw4CSpD2Ve/TAYcs+OTC3nKvNkXVfmiH6opvnIgtcBlQ+5+EmETjozag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=efficios.com; dmarc=pass action=none header.from=efficios.com; dkim=pass header.d=efficios.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Skcyf3BjsheLuwpJyGPqN9g7trQ9NrFMc0ncNRnKaYo=; b=RfcVfy8FyHR3Bz45I1qIOb0JFECTyFfk8Nqx0A3MN4KXAi5g5q7cXexkuNp1N6VA7dGOUZ6I5RHU97LwK6Xmug1AEbVPN5V+1O74rNm0wIatqWshN1GbYbnx2xQrjL7IKuYVxlne94y1tADFHSuPPv1nkT5p+zQRW0uzcDNHn3K2m8xaKK1pYOx1XO2P2pmfUeVu7OxtDLg66n0LGaJNIRNAl5KMM1hRvkE5lbdVr1jpmogzoRmFJhbrWbkic4wpq37ECcS/iAgL/t2TuEjaMYEz/R52l1+817ur5kI1kkkJvR36eFWut2a0TeKIvZjfJQBa28WEJnQQ/k7JEWT9gw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=efficios.com; Received: from YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:be::5) by YT4PR01MB10245.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:e5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.14; Tue, 24 Dec 2024 16:20:24 +0000 Received: from YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM ([fe80::50f1:2e3f:a5dd:5b4]) by YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM ([fe80::50f1:2e3f:a5dd:5b4%4]) with mapi id 15.20.8293.000; Tue, 24 Dec 2024 16:20:24 +0000 Message-ID: <6c159869-8f01-4aa5-9df1-7a0d6e3c23b7@efficios.com> Date: Tue, 24 Dec 2024 11:20:18 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/3] rseq/selftests: Add test for mm_cid compaction To: Gabriele Monaco , Peter Zijlstra , Ingo Molnar , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Juri Lelli , Shuah Khan References: <20241216130909.240042-1-gmonaco@redhat.com> <20241216130909.240042-4-gmonaco@redhat.com> From: Mathieu Desnoyers Content-Language: en-US In-Reply-To: <20241216130909.240042-4-gmonaco@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: YQBPR01CA0094.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:3::30) To YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:be::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: YT2PR01MB9175:EE_|YT4PR01MB10245:EE_ X-MS-Office365-Filtering-Correlation-Id: ceaf39d8-a187-415b-4a02-08dd2436deb5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|376014|1800799024|7053199007; X-Microsoft-Antispam-Message-Info: =?utf-8?B?b2x5d0JmTHRjblNnWmNTVlVaSVEvVWVoV1ROWEorc1laTFZyaThRdUttYU5x?= =?utf-8?B?REsyL0NGaGRmN2M1STdOSUhaR3VVcGd1SmhTWTFXM01MRC90MHZRNm5YcUNS?= =?utf-8?B?K3JjYUxOK2dVdzNDRm1HUzVYY1dkTFg1d2FCWjQ3VmdoVnQxaC9paTZ0dGRi?= =?utf-8?B?aXBxVVpNMmZDWGk0M2xvNzdXZ0JvWk1UOUpHdXZlTkl2Z2c0eHFJWS9WU0t6?= =?utf-8?B?YmNld29MSE95cm0zQ0NlMlAvM1pOcnlpNHRiakNpaHY4aGozbFBsUFJwRk9Q?= =?utf-8?B?a2FuSGVpdkZHcjVibVd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vY0trbm1KSkE5QVZmeUVHeHRzOGxlQUxzWFJ5eDRKTmxWVkhyc1Z2d1Vz?= =?utf-8?B?UWU0Sk1zd24zNjZ6Q0dubzVwOS8rdWkzeVBhcTNvQXQyVEV3QkpkV3FBb2l4?= =?utf-8?B?QStwODQ4ODZLZHVoRnI2Nnlxai9KdFI1d2F4NXJicVJTNTE2bkhMa0x3ZHV3?= =?utf-8?B?T3UydWZJKzEwZ1RId3JOU2RXblZCcURudnV3bExhWWVTbEFCeUFWM1J3UlM1?= =?utf-8?B?YXRieXNvZXpWbkpRekF2aFFXVld0azY2dW4zN0VFeEk1ODVsMmkxdi9Halk4?= =?utf-8?B?cXJRM2FvUTlXSFFZSWJPazhMaWRTZUJOb2hOdTRkNjJoK1c2ZW1mL1dmUmpM?= =?utf-8?B?Y1BVckpHNEovMk83akVLQnE1Qkh3LzVZandGSDBkSEQzL3l0UGlhZEsvZU93?= =?utf-8?B?QU51eUN2RWZHeHdIU3NDL3lCSHZWMWNNNjkwZFNKYjJFL01NZnNac2dDVlhG?= =?utf-8?B?NXppUkFHaEs4ZUVRdE50S1lBNUF0VWFzdDRWTUg0NFlqYURIRnVGWEhuVE05?= =?utf-8?B?ZDAwdXA2U3BmY0xlSnhGYjRrY0xTQjJHT2hKMlIwN0ZyZnRZRFFSdmVab2lz?= =?utf-8?B?UCtmN1AzVGpQeDZIMUtFZz09?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(376014)(1800799024)(7053199007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bUFEbTF3YnhzbUZxaXVYZmE4azJIYkg5eFJsamowSEduSzRDR3V0UXpMM3J0?= =?utf-8?B?ZHJTMmpLdGF2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kZVSzhUNmU0bS9tVkxaZnhqVDJRY3BlQVREbXVXL1JaQUJrWlhqU3hCZFFp?= =?utf-8?B?blpHY1BGZE52Uk9Fb3FNdXJvdTBrUmYxbHMyczN3TEtqL2ZSQXIrMXU2dSs2?= =?utf-8?B?RzMxazB1WlNkcWVYcENzTnYyeFVYT3hnT296azl0TzdDY3RIYWdSeG9mbmtu?= =?utf-8?B?emdQUmpvcUpCTEprNEZvdUVaZzNzZHRjYk0xRURkMkF5Rlh2ZFJOaXF6akFP?= =?utf-8?B?TFliV01VL2UyakhPakEyM3Rnd1owMkZVSlVGUnZmSlBEeVFOV0xKUDBkWjZO?= =?utf-8?B?UnJRZWFLZVQzTjNFOFdxZUJVdjdUYTlHNnorWlhBS2Y2Y1dza0tWVU4rNFdJ?= =?utf-8?Q?lN/1vfaiiQ5zrjpJvOzjAsUjKSn0hhAeXEcsCXOX9o=3D?= X-OriginatorOrg: efficios.com X-MS-Exchange-CrossTenant-Network-Message-Id: ceaf39d8-a187-415b-4a02-08dd2436deb5 X-MS-Exchange-CrossTenant-AuthSource: YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Dec 2024 16:20:24.0746 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4f278736-4ab6-415c-957e-1f55336bd31e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: u407cCC1AhVokakEm7bcocwXyHw980aLwPzbWBi7qKGK/kv6QYgZha9AVnE9bcq5K9tN+8/x+ZKA3pR+WXKdDq2P4sxcuODokHrQXqyrRu8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YT4PR01MB10245 On 2024-12-16 08:09, Gabriele Monaco wrote: > A task in the kernel (task_mm_cid_work) runs somewhat periodically to > compact the mm_cid for each process, this test tries to validate that > it runs correctly and timely. > > The test spawns 1 thread pinned to each CPU, then each thread, including > the main one, runs in short bursts for some time. During this period, the > mm_cids should be spanning all numbers between 0 and nproc. > > At the end of this phase, a thread with high enough mm_cid (>= nproc/2) > is selected to be the new leader, all other threads terminate. > > After some time, the only running thread should see 0 as mm_cid, if that > doesn't happen, the compaction mechanism didn't work and the test fails. > > The test never fails if only 1 core is available, in which case, we > cannot test anything as the only available mm_cid is 0. > > To: Mathieu Desnoyers > Cc: Shuah Khan > Signed-off-by: Gabriele Monaco > --- > tools/testing/selftests/rseq/.gitignore | 1 + > tools/testing/selftests/rseq/Makefile | 2 +- > .../selftests/rseq/mm_cid_compaction_test.c | 190 ++++++++++++++++++ > 3 files changed, 192 insertions(+), 1 deletion(-) > create mode 100644 tools/testing/selftests/rseq/mm_cid_compaction_test.c > > diff --git a/tools/testing/selftests/rseq/.gitignore b/tools/testing/selftests/rseq/.gitignore > index 16496de5f6ce..2c89f97e4f73 100644 > --- a/tools/testing/selftests/rseq/.gitignore > +++ b/tools/testing/selftests/rseq/.gitignore > @@ -3,6 +3,7 @@ basic_percpu_ops_test > basic_percpu_ops_mm_cid_test > basic_test > basic_rseq_op_test > +mm_cid_compaction_test > param_test > param_test_benchmark > param_test_compare_twice > diff --git a/tools/testing/selftests/rseq/Makefile b/tools/testing/selftests/rseq/Makefile > index 5a3432fceb58..ce1b38f46a35 100644 > --- a/tools/testing/selftests/rseq/Makefile > +++ b/tools/testing/selftests/rseq/Makefile > @@ -16,7 +16,7 @@ OVERRIDE_TARGETS = 1 > > TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test param_test \ > param_test_benchmark param_test_compare_twice param_test_mm_cid \ > - param_test_mm_cid_benchmark param_test_mm_cid_compare_twice > + param_test_mm_cid_benchmark param_test_mm_cid_compare_twice mm_cid_compaction_test > > TEST_GEN_PROGS_EXTENDED = librseq.so > > diff --git a/tools/testing/selftests/rseq/mm_cid_compaction_test.c b/tools/testing/selftests/rseq/mm_cid_compaction_test.c > new file mode 100644 > index 000000000000..e5557b38a4e9 > --- /dev/null > +++ b/tools/testing/selftests/rseq/mm_cid_compaction_test.c > @@ -0,0 +1,190 @@ > +// SPDX-License-Identifier: LGPL-2.1 > +#define _GNU_SOURCE > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "../kselftest.h" > +#include "rseq.h" > + > +#define VERBOSE 0 > +#define printf_verbose(fmt, ...) \ > + do { \ > + if (VERBOSE) \ > + printf(fmt, ##__VA_ARGS__); \ > + } while (0) > + > +/* 0.5 s */ > +#define RUNNER_PERIOD 500000 > +/* Number of runs before we terminate or get the token */ > +#define THREAD_RUNS 5 > + > +/* > + * Number of times we check that the mm_cid were compacted. > + * Checks are repeated every RUNNER_PERIOD Minor style issue: missing period. > + */ > +#define MM_CID_COMPACT_TIMEOUT 10 > + > +struct thread_args { > + int cpu; > + int num_cpus; > + pthread_mutex_t *token; > + pthread_t *tinfo; > + struct thread_args *args_head; > +}; > + > +static void *thread_runner(void *arg) > +{ > + struct thread_args *args = arg; > + int i, ret, curr_mm_cid; > + cpu_set_t affinity; > + > + CPU_ZERO(&affinity); > + CPU_SET(args->cpu, &affinity); > + ret = pthread_setaffinity_np(pthread_self(), sizeof(affinity), &affinity); > + if (ret) { > + fprintf(stderr, > + "Error: failed to set affinity to thread %d (%d): %s\n", > + args->cpu, ret, strerror(ret)); > + assert(ret == 0); > + } > + for (i = 0; i < THREAD_RUNS; i++) > + usleep(RUNNER_PERIOD); > + curr_mm_cid = rseq_current_mm_cid(); > + /* > + * We select one thread with high enough mm_cid to be the new leader > + * all other threads (including the main thread) will terminate ^ missing period. > + * After some time, the mm_cid of the only remaining thread should > + * converge to 0, if not, the test fails ^ missing period. > + */ > + if (curr_mm_cid >= args->num_cpus / 2 && > + !pthread_mutex_trylock(args->token)) { > + printf_verbose("cpu%d has %d and will be the new leader\n", has mm_cid=%d ? > + sched_getcpu(), curr_mm_cid); > + for (i = 0; i < args->num_cpus; i++) { > + if (args->tinfo[i] == pthread_self()) > + continue; > + ret = pthread_join(args->tinfo[i], NULL); > + if (ret) { > + fprintf(stderr, > + "Error: failed to join thread %d (%d): %s\n", > + i, ret, strerror(ret)); > + assert(ret == 0); > + } > + } > + free(args->tinfo); > + free(args->token); > + free(args->args_head); > + > + for (i = 0; i < MM_CID_COMPACT_TIMEOUT; i++) { > + curr_mm_cid = rseq_current_mm_cid(); > + printf_verbose("run %d: mm_cid %d on cpu%d\n", i, mm_cid=%d (if we want consistent output) > + curr_mm_cid, sched_getcpu()); > + if (curr_mm_cid == 0) { > + printf_verbose( > + "mm_cids successfully compacted, exiting\n"); > + pthread_exit(NULL); > + } > + usleep(RUNNER_PERIOD); > + } > + assert(false); I suspect we'd want an explicit error message here with an abort() rather than an assertion which can be compiled-out with -DNDEBUG. > + } > + printf_verbose("cpu%d has %d and is going to terminate\n", > + sched_getcpu(), curr_mm_cid); > + pthread_exit(NULL); > +} > + > +void test_mm_cid_compaction(void) This function should return its error to the caller rather than assert. > +{ > + cpu_set_t affinity; > + int i, j, ret, num_threads; > + pthread_t *tinfo; > + pthread_mutex_t *token; > + struct thread_args *args; > + > + sched_getaffinity(0, sizeof(affinity), &affinity); > + num_threads = CPU_COUNT(&affinity); > + tinfo = calloc(num_threads, sizeof(*tinfo)); > + if (!tinfo) { > + fprintf(stderr, "Error: failed to allocate tinfo(%d): %s\n", > + errno, strerror(errno)); > + assert(ret == 0); > + } > + args = calloc(num_threads, sizeof(*args)); > + if (!args) { > + fprintf(stderr, "Error: failed to allocate args(%d): %s\n", > + errno, strerror(errno)); > + assert(ret == 0); > + } > + token = calloc(num_threads, sizeof(*token)); > + if (!token) { > + fprintf(stderr, "Error: failed to allocate token(%d): %s\n", > + errno, strerror(errno)); > + assert(ret == 0); > + } > + if (num_threads == 1) { > + printf_verbose( > + "Running on a single cpu, cannot test anything\n"); > + return; This should return a value telling the caller that the test is skipped (not an error per se). > + } > + pthread_mutex_init(token, NULL); > + /* The main thread runs on CPU0 */ > + for (i = 0, j = 0; i < CPU_SETSIZE && j < num_threads; i++) { > + if (CPU_ISSET(i, &affinity)) { We can save an indent level here by moving this in the for () condition: for (i = 0, j = 0; i < CPU_SETSIZE && CPU_ISSET(i, &affinity) && j < num_threads; i++) { > + args[j].num_cpus = num_threads; > + args[j].tinfo = tinfo; > + args[j].token = token; > + args[j].cpu = i; > + args[j].args_head = args; > + if (!j) { > + /* The first thread is the main one */ > + tinfo[0] = pthread_self(); > + ++j; > + continue; > + } > + ret = pthread_create(&tinfo[j], NULL, thread_runner, > + &args[j]); > + if (ret) { > + fprintf(stderr, > + "Error: failed to create thread(%d): %s\n", > + ret, strerror(ret)); > + assert(ret == 0); > + } > + ++j; > + } > + } > + printf_verbose("Started %d threads\n", num_threads); I think there is a missing rendez-vous point here. Assuming a sufficiently long unexpected delay (think of a guest VM VCPU preempted for a long time), the new leader can start poking into args and other thread's info while we are still creating threads here. Thanks, Mathieu > + > + /* Also main thread will terminate if it is not selected as leader */ > + thread_runner(&args[0]); > +} > + > +int main(int argc, char **argv) > +{ > + if (rseq_register_current_thread()) { > + fprintf(stderr, > + "Error: rseq_register_current_thread(...) failed(%d): %s\n", > + errno, strerror(errno)); > + goto error; > + } > + if (!rseq_mm_cid_available()) { > + fprintf(stderr, "Error: rseq_mm_cid unavailable\n"); > + goto error; > + } > + test_mm_cid_compaction(); > + if (rseq_unregister_current_thread()) { > + fprintf(stderr, > + "Error: rseq_unregister_current_thread(...) failed(%d): %s\n", > + errno, strerror(errno)); > + goto error; > + } > + return 0; > + > +error: > + return -1; > +} -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com