From patchwork Wed May 20 14:05:40 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: 186990 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp657840ilb; Wed, 20 May 2020 07:15:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+vsX8beXJb9zsvlNKo0QJgeC0C0IklaL3k0X8ur8InjJapsSc8JVZJwy5eTFkOOQa56B2 X-Received: by 2002:a37:b303:: with SMTP id c3mr4749612qkf.397.1589984124059; Wed, 20 May 2020 07:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589984124; cv=none; d=google.com; s=arc-20160816; b=OfU19H0XT/zVxlNhWEt3yNgV+b8kY1evqVGp8IdsWRCcQkIiMtx16kmfZ/CwVNTTBn wkpA3WfvR9dnx4K/Bgl7SiQxHBf7KMNGZkxKx+CcFhqb9JhR/ugNgEaes4tztyyXfsQe x7ZYqKr6PfUizR8sWiTCz8hg/hqC97nkaSNkKGOlJQAnxW4XGQ3O1tS8SvtXxcV0qhwm ebS+oRsQ5hFrGcnVvmx6OabAFIEo6BDmve0uStxXNQ1Cgw7emls+dKZ4/0WmvFqmEPfq 3fNElXvUqY0i0oOhb9XZ7CBpYFCWVwstZ2J+UtqJMzJSr4IZue9+DhVyhMsAAXulYvEk j/Hg== 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=tVaA6VVKMxT5atPOq3mupoaoOxw2j2mNyFQd2GQU77U=; b=o5QV/seMtJH+cfp2/uSyH+IDVrmKm6xe6byeY6wryuJPEIeJKe6KRDHtz/BMzj0+lO oQgQB0kK5nmh1YkkC2nLxdjRFvCjVt+0PNCaQC0KUvl/tn4uF06EK35+Z05DijNsD0kT twUyL5r9svgaoTa6ECMifV/3/ib+t0ELDqZ5ceS6z1M7qXAnIJXLHxRomtFXhcyWDg/+ jnbWe82nxlopwVbJ4QjUA12B4GeNA8jN0v4JwNm6J4T2D9ca+xxEtB2NrTZyNkIY0xgI 2hz3CNSTDTzausB7XO+88a6Y0sKlTrX0zBX8uUiXdDUSGaQvL+y4DqB5k4neeVtSihT9 PUGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FcGiZMh0; 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 l17si1733698qki.167.2020.05.20.07.15.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 May 2020 07:15:24 -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=FcGiZMh0; 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]:33180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jbPVD-0006jL-Ge for patch@linaro.org; Wed, 20 May 2020 10:15:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jbPME-0000LO-5G for qemu-devel@nongnu.org; Wed, 20 May 2020 10:06:06 -0400 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]:34020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jbPMC-00022Q-Pj for qemu-devel@nongnu.org; Wed, 20 May 2020 10:06:05 -0400 Received: by mail-ej1-x643.google.com with SMTP id j21so3986517ejy.1 for ; Wed, 20 May 2020 07:06:04 -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=tVaA6VVKMxT5atPOq3mupoaoOxw2j2mNyFQd2GQU77U=; b=FcGiZMh0mR/7XmqKUTy7DPfOsaqDwIbdy4LZrUUlNMvGnlptykNuU61UfgovyZMh0T L29g1s2OvORb//bFqpZUsoOPfAUwEdJ9cjzMV6wkZU1UGiSL11YQyZWOWlYSldh+Zjvh 3bq6NwVHikpdhpg6eKFLWDFrV+wpTKrhz7ENdG4pqg6tPcABUlqlUweRofaobCOXaGnx ETOyygfgqABLLwXc3lY7LOsdGvrhKBmO+CXkv87xyjEtcfkOvC4fx5EVUc5poibIA2UQ wQuSrlN8s+9jQp8GPDts0HsaipNWuGa8rjB205Gb7s3nUimPrm5zPmjXy8GkIafZ+Orw cFSA== 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=tVaA6VVKMxT5atPOq3mupoaoOxw2j2mNyFQd2GQU77U=; b=sOlhn92b6zcXsWv4bbalqVKzvCQlqvg/5Gj3vzycD8MGM1MrzGiBHkqwqEgLZyGG9X 5bNBsj8ILld9+RZLC0K/tpVlwgJgsdQh8DRwiAQZvk32S94OuraVJjExFXoruvXksTIc Wt9rY6xS38ab+usCLlpTRKWDYua8tKOLVdMsagMxavVFC9ECOYYqZqcH8+zRMI2OvldJ Vq+iIuXIpuHS1sV9n3bXIhNzNoKuZrXX+P6TCbeQyzldHLky5Ubdj9lyWtvkVh09M//9 vrswu6+3uj6/Zi5kCqk2r7TaxAwc+p5jZkbE+NTg7UargV77tr/vVLbR9eGS63KErzMw VfkQ== X-Gm-Message-State: AOAM533U5HhiOd/3kk/v6fi5M0eReKwxX64IC2CAMpWRdgNvorsw7jRh pEXEUY5EEhgPmM5VxrnCywhwQg== X-Received: by 2002:a17:906:780b:: with SMTP id u11mr3625508ejm.341.1589983563430; Wed, 20 May 2020 07:06:03 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id dt12sm2017082ejb.102.2020.05.20.07.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 07:05:54 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 750B41FF9D; Wed, 20 May 2020 15:05:42 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 14/15] tests/tcg: add new threadcount test Date: Wed, 20 May 2020 15:05:40 +0100 Message-Id: <20200520140541.30256-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200520140541.30256-1-alex.bennee@linaro.org> References: <20200520140541.30256-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::643; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x643.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: Signed-off-by: Nikolay Igotti Signed-off-by: Alex Bennée --- v2 - add Nikolay's s-o-b - checkpatch fixes --- tests/tcg/multiarch/threadcount.c | 64 +++++++++++++++++++++++++++++ tests/tcg/multiarch/Makefile.target | 2 + 2 files changed, 66 insertions(+) create mode 100644 tests/tcg/multiarch/threadcount.c -- 2.20.1 diff --git a/tests/tcg/multiarch/threadcount.c b/tests/tcg/multiarch/threadcount.c new file mode 100644 index 00000000000..545a1c81466 --- /dev/null +++ b/tests/tcg/multiarch/threadcount.c @@ -0,0 +1,64 @@ +/* + * 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.