From patchwork Wed May 13 17:31:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 186666 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp656864ilb; Wed, 13 May 2020 10:33:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOksl/rl6HGO97qy88pyP58LsteeDJq7ga3qBfCAkBfj1pchOq1XBZVCqQZTCDeM2H12TI X-Received: by 2002:a05:620a:7c1:: with SMTP id 1mr788288qkb.227.1589391184135; Wed, 13 May 2020 10:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589391184; cv=none; d=google.com; s=arc-20160816; b=d9xjKuRDIdLHyM+eQlxpJNcSJILfZrguvdCuWgJMxjo1dOcFSoTlP0AtgcchdZbaW5 VSM4EJRsjfxkI+We5zFxt0zC65KqkR3SxaeEGPEyNMZy0kn42WjsG+2EskiTU7t5PCfD Noln6ltkUVtaGZcSMpcUaaStmtlXtM0i036V+8BPw7cov7Bxl8xnQ+HCiM4h5rrzyK7i Yb3vLP6MU8FpbZabq1cuN2BIQIJcBi3SXyaQZZRsZisZaQlB1GeVVRUjkdTrI0LBz0Hi 8SJ8WEPReZ+xvwFbYIJgsOF27nkQpjDzjAItcsHPKEYMWJn4yLu6laOsNPIzH6ijH+n8 QNIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=U+wDRXFAS4OV7UFOFmLqxoBwV2cM218whk06u8SrwM0=; b=Y0a3S2pzOrB7V0RjZcpWV0rhhjBCMKu6/k5Swth3ZeY402KkOkU05psuUMG0qMY0XD UHu36JzzOPS1ZsuTmbG/2RZMUlUHuQnabGozy7pkwvR1XQBpQI1ViLCIrXIR9sZ+tGoc BhRA59U9R85G1dY6Yec8WHM1PgnjI9+ECWjG7yx4Psw2U3bx3A3VJWZgt2indhMjlg67 O7p5I0dLoSu28t6P6xAUV6WLkYuLVIGin3sv2LyNOXtaf3CeHg9SInkX2gx4hbPNOFmP hHN8Qwhnjk69IxN3LGQ5Khy3IoMamJ26Nq7IFczGg5IqwLSptwmPDTDy3MM+UeCdgEyt uaKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RHdpc28E; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z11si74930qkf.220.2020.05.13.10.33.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 May 2020 10:33:04 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RHdpc28E; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYvFf-0004q7-Eb for patch@linaro.org; Wed, 13 May 2020 13:33:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYvEr-0004lH-3j for qemu-devel@nongnu.org; Wed, 13 May 2020 13:32:13 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]:33691) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYvEq-0007mO-5w for qemu-devel@nongnu.org; Wed, 13 May 2020 13:32:12 -0400 Received: by mail-wm1-x329.google.com with SMTP id d207so9442810wmd.0 for ; Wed, 13 May 2020 10:32:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U+wDRXFAS4OV7UFOFmLqxoBwV2cM218whk06u8SrwM0=; b=RHdpc28E4Tt6y22isUBMIn8q5whMNRVJj6Py0aVZ5o5Ebhh7Md+Y/fn18RcdZNk9bz ur/kzq1cGMyz/7gBQ8qQxRK3Ib0FtwlO7ru9+eW+Oj6tqOE16BmFziwo2tEFt7N+iprZ Q+TV3Z4lxeYvnhlLT8Slrir3hGuNfnlDdCwATV9VQvMrOppoMOgxRP9LOKxghTsru2Ec eO4T9D2gw7aOpvKf3ekL4kjsGuHQPAy9KPV5U1QyClvhaUYSqVVFd21TtooOsHNVeYWG Rc26eiezzzpZvBf0rhPMDlUwRRm/JvrRzt9s1D0uvvnLu1wLGwPeqruqOAO0zsrO7pmZ Jv8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U+wDRXFAS4OV7UFOFmLqxoBwV2cM218whk06u8SrwM0=; b=AF3+ebRCeX34NH4NmvoTYIpczQ5Vixkb8NylSUXfJG5W+N2rN1ZbEeHoNdTatmh9OW /zFDGH8Va9ClZlGrC2afVPSEddkvPE5yWejIlG57P9EeiewvRhjCuvPzJb75Jnweug1W LeP3FSBlDhJ4BFPUNLPDyiVWS5SME1/7P2I9Rook8JYloNjPPUZ6fgi8gwTabPGu+vyy BzvoiNekfAlKFkQzetTVEw4vD9xx0entCqviYSRBoTV9F2UHm4SDhS187k8j61UosY2y Bq/ypjfMaC/5ab+ZMfIYnrlElxb2pyC765YAKAh8qF/cR1vIbvw/Q6oH0ABh5yrC3+Ie EmFQ== X-Gm-Message-State: AOAM5320PJeSx+q9d0+4jdjQpAD5xozOIMuTXS29dsp2O+WjKE5BNtHh hHWe8IHzxaHEPECkYQdtpZ+GOg== X-Received: by 2002:a05:600c:206:: with SMTP id 6mr9916787wmi.170.1589391130775; Wed, 13 May 2020 10:32:10 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u12sm38461466wmu.25.2020.05.13.10.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 10:32:08 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 84FF01FF93; Wed, 13 May 2020 18:32:01 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 7/8] tests/tcg: add new threadcount test Date: Wed, 13 May 2020 18:31:59 +0100 Message-Id: <20200513173200.11830-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200513173200.11830-1-alex.bennee@linaro.org> References: <20200513173200.11830-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Nikolay Igotti Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Based on the original testcase by Nikolay Igotti. Message-ID: Cc: Nikolay Igotti [Nikolay can we have your signed of by to add the testcase?] Signed-off-by: Alex Bennée --- tests/tcg/multiarch/threadcount.c | 62 +++++++++++++++++++++++++++++ tests/tcg/multiarch/Makefile.target | 2 + 2 files changed, 64 insertions(+) create mode 100644 tests/tcg/multiarch/threadcount.c -- 2.20.1 Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé diff --git a/tests/tcg/multiarch/threadcount.c b/tests/tcg/multiarch/threadcount.c new file mode 100644 index 00000000000..546dd90eeb2 --- /dev/null +++ b/tests/tcg/multiarch/threadcount.c @@ -0,0 +1,62 @@ +/* + * Thread Exerciser + * + * Unlike testthread which is mainly concerned about testing thread + * semantics this test is used to exercise the thread creation and + * accounting. A version of this test found a problem with clashing + * cpu_indexes which caused a break in plugin handling. + * + * Based on the original test case by Nikolay Igotti. + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include + +int max_threads = 10; + +typedef struct { + int delay; +} ThreadArg; + +static void *thread_fn(void* varg) { + ThreadArg* arg = varg; + usleep(arg->delay); + free(arg); + return NULL; +} + +int main(int argc, char **argv) { + int i; + pthread_t *threads; + + if (argc > 1) { + max_threads = atoi(argv[1]); + } + threads = calloc(sizeof(pthread_t), max_threads); + + for (i = 0; i < max_threads; i++) { + ThreadArg* arg = calloc(sizeof(ThreadArg), 1); + arg->delay = i * 100; + pthread_create(threads + i, NULL, thread_fn, arg); + } + + printf("Created %d threads\n", max_threads); + + /* sleep until roughly half the threads have "finished" */ + usleep(max_threads * 50); + + for (i = 0; i < max_threads; i++) { + pthread_join(threads[i], NULL); + } + + printf("Done\n"); + + return 0; +} diff --git a/tests/tcg/multiarch/Makefile.target b/tests/tcg/multiarch/Makefile.target index 51fb75ecfdd..cb49cc9ccb2 100644 --- a/tests/tcg/multiarch/Makefile.target +++ b/tests/tcg/multiarch/Makefile.target @@ -28,6 +28,8 @@ run-float_%: float_% testthread: LDFLAGS+=-lpthread +threadcount: LDFLAGS+=-lpthread + # We define the runner for test-mmap after the individual # architectures have defined their supported pages sizes. If no # additional page sizes are defined we only run the default test.