Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2107634lqo; Sun, 19 May 2024 14:00:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWiXHEPprnwqRlHtslXGaF0qGbbeZZBJELxmzCujLdPqgulcgBk7Tr4s12mIBqrpRQjWhOfTcfvAmv4UppBJFhOP3sKSIgqUTcsbtmTg== X-Google-Smtp-Source: AGHT+IE5zn+Fcd9lzea6mZDBVBSC5/BKLEiYwcNmfkPpsgCYZI8L9GfUVcJ+0u00g3/9D3jmG4V0 X-Received: by 2002:a05:6e02:2169:b0:36d:b8cd:7c76 with SMTP id e9e14a558f8ab-36db8cd7e71mr145233415ab.8.1716152432978; Sun, 19 May 2024 14:00:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716152432; cv=pass; d=google.com; s=arc-20160816; b=SsJ7sVAraNa2KvrOaRLdbaPhJgwgxh2Ew9hrLy6Yo5Vd68y8rJcc/0IXVl4AAz3vIn hWHoAP4X1e2zPBILJWeUe0E6oIiY0dCHHddfkKpGlD+a/OmTHBzlQ6koXmADzyAqRXp0 YLynReTV5HwSfspkeBiwKe7FeOmZDGKaLSa0LCZ5Syt/52h3lOag/ciit37ceX4HkW42 w2HCyXkWke8B38PoEEthTF8ySstaTz7H6FSjcGRbTh9u3NoAQ0VdT16C0AP/E7p+v5Fg Y6KfGil+8wdFiokIB8ZICAE2ObckPCiRFmRQqsXJZLM0cjS4Sz+7pwf65iaqaKGVD4+V QV7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=oYv/7gpkTd7m3dOtwqdlHd+jUV1xxytJ6Ebv/6cbmco=; fh=eVY06L/C5FDTmF2RNqfudsnjwkB3tbhT/y33cGhZc0I=; b=GOqEmJZMakflw0KnZpm4K4MFxZL0UESe3Nz071dc++PncEQNggKnzuo1SSmt1vL5kF yLNNp0UNqziF6Wc29rm4e4a0NL72em2zlTfI/GzkYjVRHpbd2pFkTT1zcfBmT64EuUr1 XwMr1ag6Pyoef4KyrF0fahTq162Ohdac8qEQbRMc9yi/Af/7rJOVwyyVMxYsaHhxG8/T cnVenIELKBlkPKF9aKMNSgwl3k4C7yD6Ijlsyua+D/vn9zH2Jec9jsjhWeBeXK++zL6G 9iJU6wk77oI8IsOYzldBlx8lbxEaWNUiPF7U1pYdu5cotW8aURYX4X8QEhrS1gQ9NCA+ OiXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Am5lCtnq; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-183257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-66b1c7c102esi1044692a12.728.2024.05.19.14.00.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 May 2024 14:00:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=Am5lCtnq; arc=pass (i=1 spf=pass spfdomain=codeweavers.com dkim=pass dkdomain=codeweavers.com dmarc=pass fromdomain=codeweavers.com); spf=pass (google.com: domain of linux-kernel+bounces-183257-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183257-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 271C328351E for ; Sun, 19 May 2024 20:31:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F8E881AC3; Sun, 19 May 2024 20:25:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="Am5lCtnq" Received: from mail.codeweavers.com (mail.codeweavers.com [4.36.192.163]) (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 9870F74C08; Sun, 19 May 2024 20:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=4.36.192.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716150320; cv=none; b=QS0IaCj+D8EignYaUdlFgcLHK8Hw0/BppiQm4uddY9BpSth9F6P64Jedy526ojrq1CAti+2wbrFZDdUKJ4GlIV5mFiyIy9S+8JTTjYZZ+GvC/MF9ob/W2DEf/7T8i55It/4E5YCHLJDH3rAfrKpE3sDJykEdMovt2IQUT86tyec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716150320; c=relaxed/simple; bh=RxzO+9cowicVFB0C8g1tfr/5wcAsZKu2OdxghkIxD54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ss6xWPYx/r8cQx2vENq0aiDb20Ni0ZrfV7I3RoI2a2ogEMMcEnRuEGFzpMHZ+PLstI3KBsHl//m7hLYN7gFg7uaigzhMF5dgLYpB9zrf3dUZVY4kB0Em85FddlbAmAfiIPexDAAF+GlhJBom99TBP4WV8VFmLtMLjnAWPBgge80= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com; spf=pass smtp.mailfrom=codeweavers.com; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b=Am5lCtnq; arc=none smtp.client-ip=4.36.192.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeweavers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeweavers.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=codeweavers.com; s=s1; h=Message-ID:Date:Subject:Cc:To:From:Sender; bh=oYv/7gpkTd7m3dOtwqdlHd+jUV1xxytJ6Ebv/6cbmco=; b=Am5lCtnqztGBM28U4zpjs03U+s jaw2gc0+azG93hztW+pTRaS3V9N766l8LpYdgKcYoyIapxJ+Pd5edMvcbQmFwEDzs8gnTMfCXeQTB CV3kMqQJhYqSw9rkxb4onIkWtFB1FxbU3sz3SPjljhiEAnVtJekyNgadmLdTOH+DWLvD6yfDtdroJ zf+aBr23Q/xn7fovimaY79ZMIIKcHsQzWC1OBywtk09gzgDZCPPp6zexaRrEFsRpeJ1BhATLxyvvO rRIUCce818lHkNu0POOX4B/37d4AprBoc6ypEQV8Wn1suAx2sJ20cdtjwNs6A/7ho/u1Od0X2csx2 L5xwUnFg==; Received: from cw137ip160.mn.codeweavers.com ([10.69.137.160] helo=camazotz.mn.codeweavers.com) by mail.codeweavers.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1s8n5i-008wIn-1d; Sun, 19 May 2024 15:25:10 -0500 From: Elizabeth Figura To: Arnd Bergmann , Greg Kroah-Hartman , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, wine-devel@winehq.org, =?UTF-8?q?Andr=C3=A9=20Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Randy Dunlap , Ingo Molnar , Will Deacon , Waiman Long , Boqun Feng , Elizabeth Figura Subject: [PATCH v5 25/28] selftests: ntsync: Add a stress test for contended waits. Date: Sun, 19 May 2024 15:24:51 -0500 Message-ID: <20240519202454.1192826-26-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240519202454.1192826-1-zfigura@codeweavers.com> References: <20240519202454.1192826-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Test a more realistic usage pattern, and one with heavy contention, in order to actually exercise ntsync's internal synchronization. This test has several threads in a tight loop acquiring a mutex, modifying some shared data, and then releasing the mutex. At the end we check if the data is consistent. Signed-off-by: Elizabeth Figura --- .../testing/selftests/drivers/ntsync/ntsync.c | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tools/testing/selftests/drivers/ntsync/ntsync.c b/tools/testing/selftests/drivers/ntsync/ntsync.c index 968874d7e325..5fa2c9a0768c 100644 --- a/tools/testing/selftests/drivers/ntsync/ntsync.c +++ b/tools/testing/selftests/drivers/ntsync/ntsync.c @@ -1330,4 +1330,78 @@ TEST(alert_all) close(fd); } +#define STRESS_LOOPS 10000 +#define STRESS_THREADS 4 + +static unsigned int stress_counter; +static int stress_device, stress_start_event, stress_mutex; + +static void *stress_thread(void *arg) +{ + struct ntsync_wait_args wait_args = {0}; + __u32 index, count, i; + int ret; + + wait_args.timeout = UINT64_MAX; + wait_args.count = 1; + wait_args.objs = (uintptr_t)&stress_start_event; + wait_args.owner = gettid(); + wait_args.index = 0xdeadbeef; + + ioctl(stress_device, NTSYNC_IOC_WAIT_ANY, &wait_args); + + wait_args.objs = (uintptr_t)&stress_mutex; + + for (i = 0; i < STRESS_LOOPS; ++i) { + ioctl(stress_device, NTSYNC_IOC_WAIT_ANY, &wait_args); + + ++stress_counter; + + unlock_mutex(stress_mutex, wait_args.owner, &count); + } + + return NULL; +} + +TEST(stress_wait) +{ + struct ntsync_event_args event_args; + struct ntsync_mutex_args mutex_args; + pthread_t threads[STRESS_THREADS]; + __u32 signaled, i; + int ret; + + stress_device = open("/dev/ntsync", O_CLOEXEC | O_RDONLY); + ASSERT_LE(0, stress_device); + + mutex_args.owner = 0; + mutex_args.count = 0; + ret = ioctl(stress_device, NTSYNC_IOC_CREATE_MUTEX, &mutex_args); + EXPECT_EQ(0, ret); + stress_mutex = mutex_args.mutex; + + event_args.manual = 1; + event_args.signaled = 0; + ret = ioctl(stress_device, NTSYNC_IOC_CREATE_EVENT, &event_args); + EXPECT_EQ(0, ret); + stress_start_event = event_args.event; + + for (i = 0; i < STRESS_THREADS; ++i) + pthread_create(&threads[i], NULL, stress_thread, NULL); + + ret = ioctl(stress_start_event, NTSYNC_IOC_EVENT_SET, &signaled); + EXPECT_EQ(0, ret); + + for (i = 0; i < STRESS_THREADS; ++i) { + ret = pthread_join(threads[i], NULL); + EXPECT_EQ(0, ret); + } + + EXPECT_EQ(STRESS_LOOPS * STRESS_THREADS, stress_counter); + + close(stress_start_event); + close(stress_mutex); + close(stress_device); +} + TEST_HARNESS_MAIN -- 2.43.0