From patchwork Mon Feb 19 22:38:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elizabeth Figura X-Patchwork-Id: 203318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp77221dyc; Mon, 19 Feb 2024 14:47:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWId2cu/5xwAgxYke7ILuBqExfptNe1cNDg6orY1SULw5evF/9OV0y/BoRa7x7Jj13dFNXwR5zRGMWrIBNtHdnZ5xR+DA== X-Google-Smtp-Source: AGHT+IEeuNEfdFpdO05ToFjf4RECzYigFmX5GXEfK9BDMRv0FVPQPD8JlPJ2Zxm7wLBHcMBoRYg2 X-Received: by 2002:a17:902:dac8:b0:1db:cea0:9d62 with SMTP id q8-20020a170902dac800b001dbcea09d62mr6968453plx.9.1708382870657; Mon, 19 Feb 2024 14:47:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708382870; cv=pass; d=google.com; s=arc-20160816; b=wUFwI4FEj0/CFT8i9VE+ZZfXqFGrDIbb7e3UubCkadccO2jb3LG4BamMOTA1WrZyNz 2KI4VjSdpQtihuSqbn1tPNeRTkrQOJcAJ7ih720jF7Z+khvqMIp6q7K0r7za6K6xqhSQ lwDpQdFzhOJULmyZEs6SRZyRlcj+FmjpNUvJht6PGKmzouPU9CcGdJB56+Q2RZelR/Nd 2Gp4RLO5Jm7+R5EXOc3jZ89I98Xv+I+7Ly6sGPqHEPiHLBFj+IEhQhQAm/NXZHHVZLRB nd/dErM6wXB8QYqvcEtCft8pMdR+UQasIZdDSFUvtZh8tgx9WP1u/rcNDIhu+fW0e3Nh ffGw== 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=hR3Xqo6s6FufP5gEw1XgbtLHrluZu7hd5XGp+hLIfiM=; b=m5YjriPiEAf/uLewvJyx26GYCokgLPCvtKns5OYRc6LBIjcmcINxYBvM6PLpcej0QP SdkbeOkhvAPi5SbDaWBvL0FPz2b8XzCwh9llgawlsV9LpgFa7oIbr7SWsP3fTOtepg13 xMlEXQNOBZiJWJeptPsPQFUP4y6BO3xzy7ke1djD9WwtbuTuGANEbOoosumgBo0Miln3 EFV3gJZyyfviDiKioEyqZxfADq0FPtLhR454IuYREiDzUj5K5DnltGEhXME7QhnFiX05 APUT0KeftIHsG1CCAoqhUkT4h4Y3j7dhe0Qx+4xFMRBGNYkLKsrZ+JBm2hL3I9+QZE9v 1AKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@codeweavers.com header.s=s1 header.b=R6SyU8KV; 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-72107-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72107-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=codeweavers.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h9-20020a170902f70900b001dba8205ef4si4194356plo.495.2024.02.19.14.47.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 14:47:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72107-ouuuleilei=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=R6SyU8KV; 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-72107-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72107-ouuuleilei=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 7A85128A42D for ; Mon, 19 Feb 2024 22:47:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65BE467C4C; Mon, 19 Feb 2024 22:39:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=codeweavers.com header.i=@codeweavers.com header.b="R6SyU8KV" 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 8BEA658AD0; Mon, 19 Feb 2024 22:39:41 +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=1708382383; cv=none; b=aeoxqm9WWfLNG3VhhqmsO6V8ZV/CcZGtSryW34eLQaMdyqHmpUNOyv9fWNNlrD31KvkQZuB/uXjQF8eO8IFcer2TJijecNAB8SXZLtM1a238cdulGq91R9dBVijk7Qto9P+vXQJzmQLCjrxlP6Xr3jE2Sg8GPH+BmuJcDpw4wJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708382383; c=relaxed/simple; bh=RxzO+9cowicVFB0C8g1tfr/5wcAsZKu2OdxghkIxD54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UqdtrBdbOaIB02s17C1AUINkPsdDWt9s3YuDQZBvpmsjSeO9nk1RQpeyae5iQeym7sUcp+oin/p8gwC22ZQb+mDCO1WvfATNnSGEpOQFDEHI33E49Rqv8QZLEtEnBaM3bdJN0i0oNbOvxw61WJf1zkqMn9I/CXWAmX1a/LZiELE= 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=R6SyU8KV; 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=R6SyU8KVTMRG8DXp/uI7INPBVq TPjYHdLJV3DG/Nqh2V1bhJJUD9SywCWN4dFiFBeeZNDR+usJc3aJNRtf3WTs+lud3hDyxHGCuKE+R gln0B+E9SXWEfvodHQn5OfGfw3W6prbo1CooK3VCLcDv09b9xDc4IFRlKInoOofDVAyN6s9mE0Alo 49jHQvOShFjVnRyrurreDtvvBpyrYPFghHhTp2gEMbhXG03Y46OBn9wjqoNMNj1ngGVQ86MzB7wzA GtT/RWhyWNC8qrM8Wy8X/hVN1kdyp3508kUQL5OT7nYBo/wVzQz/R9kIx92v90LhLo5XPjwPu6ipv lKXmRgaA==; 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 1rcCIU-0037Oz-1o; Mon, 19 Feb 2024 16:39:38 -0600 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_Almeida?= , Wolfram Sang , Arkadiusz Hiler , Peter Zijlstra , Andy Lutomirski , linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Randy Dunlap , Elizabeth Figura Subject: [PATCH v2 29/31] selftests: ntsync: Add a stress test for contended waits. Date: Mon, 19 Feb 2024 16:38:31 -0600 Message-ID: <20240219223833.95710-30-zfigura@codeweavers.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240219223833.95710-1-zfigura@codeweavers.com> References: <20240219223833.95710-1-zfigura@codeweavers.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791369276902220159 X-GMAIL-MSGID: 1791369276902220159 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