From patchwork Wed Feb 26 07:39:14 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: 1244735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=gLLGSDTc; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48S74j1SjRz9sPR for ; Wed, 26 Feb 2020 18:40:21 +1100 (AEDT) Received: from localhost ([::1]:39128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6rIp-0000hu-3A for incoming@patchwork.ozlabs.org; Wed, 26 Feb 2020 02:40:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45991) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6rIC-0000TN-8W for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:39:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6rIB-0002SS-0f for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:39:40 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39713) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6rIA-0002QU-Q8 for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:39:38 -0500 Received: by mail-wr1-x444.google.com with SMTP id y17so1663912wrn.6 for ; Tue, 25 Feb 2020 23:39:38 -0800 (PST) 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=DS6xjOKuBaYBf8IY/DbbV4aFTgu3v5e6SUEcryP0kGA=; b=gLLGSDTcVPsEOO9YdO14Awcr1DRUGgWkLTDsKhbNl1pDBpVlAh6CKp2IZgxgsEKn6A 5P57UXvTs1GwkZA8E8hbaO4fehiDr2a7NLHNrqk0lDCpqx8fLRSdQ8gImYU2FXxQVu7j 6u2t1kjidrT9OgpRVDafQ3ZHIFEuW06Dj+rsfP9gvPsSvu6fMk7JjOHobZvRttUoMk3t PBRIcL9dv/85UKZtS+SLZ5zh1kL1PkIaTKsLZNzZHGMe8kJV0CYqPi6wMjiwEG1UZi9S Wj3v8w66c2nPlBBBs4uTrOip0+Sp12JgURJ8vXB61QPddu8CeybUcY7pmkC4kN0Axbl1 n3Gw== 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=DS6xjOKuBaYBf8IY/DbbV4aFTgu3v5e6SUEcryP0kGA=; b=ZvgVHJNnSKdP0akvhyP3AWoVCQFKedoi/DTBdHPGJ0/Gr2fPEqV44ShbEVD8n+DuKS AqnCSDh8MhFNC2P11wVxOWbZ9jqQGRz8Tr0uMImZ9RaX96g1JcjgqN16cEVXzRwaeQmP NkBTPSM/B2awExN7AZvhpxQ2YnYtydvRpdlc5AVVxsg+Q+6j1UzzFTtRKBxKz9dr/Dzi SYnhzmrlnoLwoXr2Gs7e9ZDe1PkgI3HDhcB4p/sma2BqJx81tTG09NjSBNpEgO41fEjO sSdbbeaU7lCiV6HHZeTE5Spvauskrg6zXbOGBM43D73YQir9nT1tTM/DNny22UWM2bZY RUww== X-Gm-Message-State: APjAAAVWKQ+JVbhXUX8LINt3jJfDts6KSdQybmLJPyTdsVAhtpPC054R 4HsIDM6e3c1hO9+wpgORSYkWyzzW/eA= X-Google-Smtp-Source: APXvYqyK5zTgxphys4BaKAPRwoj9ZdO8H/El4Fxjr1H7B2xCPrB5/0+ceKMnVWxUplByY2aoMByqcw== X-Received: by 2002:adf:eb46:: with SMTP id u6mr3860681wrn.239.1582702777780; Tue, 25 Feb 2020 23:39:37 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h128sm1795507wmh.33.2020.02.25.23.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 23:39:34 -0800 (PST) Received: from zen.home.arpa (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 97F3E1FF91; Wed, 26 Feb 2020 07:39:29 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 04/19] tests/rcutorture: mild documenting refactor of update thread Date: Wed, 26 Feb 2020 07:39:14 +0000 Message-Id: <20200226073929.28237-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200226073929.28237-1-alex.bennee@linaro.org> References: <20200226073929.28237-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 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: Paolo Bonzini , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is mainly to help with reasoning what the test is trying to do. We can move rcu_stress_idx to a local variable as there is only ever one updater thread. I've also added an assert to catch the case where we end up updating the current structure to itself which is the only way I can see the mberror cases we are seeing on Travis. We shall see if the rcutorture test failures go away now. Signed-off-by: Alex Bennée Reviewed-by: Paolo Bonzini Message-Id: <20200225124710.14152-5-alex.bennee@linaro.org> diff --git a/tests/rcutorture.c b/tests/rcutorture.c index 256d24ed5ba..732f03abdaa 100644 --- a/tests/rcutorture.c +++ b/tests/rcutorture.c @@ -230,13 +230,12 @@ static void uperftest(int nupdaters, int duration) #define RCU_STRESS_PIPE_LEN 10 struct rcu_stress { - int pipe_count; + int age; /* how many update cycles while not rcu_stress_current */ int mbtest; }; struct rcu_stress rcu_stress_array[RCU_STRESS_PIPE_LEN] = { { 0 } }; struct rcu_stress *rcu_stress_current; -int rcu_stress_idx; int n_mberror; /* Updates protected by counts_mutex */ @@ -261,7 +260,7 @@ static void *rcu_read_stress_test(void *arg) while (goflag == GOFLAG_RUN) { rcu_read_lock(); p = atomic_rcu_read(&rcu_stress_current); - if (p->mbtest == 0) { + if (atomic_read(&p->mbtest) == 0) { n_mberror++; } rcu_read_lock(); @@ -269,7 +268,7 @@ static void *rcu_read_stress_test(void *arg) garbage++; } rcu_read_unlock(); - pc = p->pipe_count; + pc = atomic_read(&p->age); rcu_read_unlock(); if ((pc > RCU_STRESS_PIPE_LEN) || (pc < 0)) { pc = RCU_STRESS_PIPE_LEN; @@ -288,32 +287,52 @@ static void *rcu_read_stress_test(void *arg) return NULL; } +/* + * Stress Test Updater + * + * The updater cycles around updating rcu_stress_current to point at + * one of the rcu_stress_array_entries and resets it's age. It + * then increments the age of all the other entries. The age + * will be read under an rcu_read_lock() and distribution of values + * calculated. The final result gives an indication of how many + * previously current rcu_stress entries are in flight until the RCU + * cycle complete. + */ static void *rcu_update_stress_test(void *arg) { - int i; - struct rcu_stress *p; + int i, rcu_stress_idx = 0; + struct rcu_stress *cp = atomic_read(&rcu_stress_current); rcu_register_thread(); - *(struct rcu_reader_data **)arg = &rcu_reader; + while (goflag == GOFLAG_INIT) { g_usleep(1000); } + while (goflag == GOFLAG_RUN) { - i = rcu_stress_idx + 1; - if (i >= RCU_STRESS_PIPE_LEN) { - i = 0; + struct rcu_stress *p; + rcu_stress_idx++; + if (rcu_stress_idx >= RCU_STRESS_PIPE_LEN) { + rcu_stress_idx = 0; } - p = &rcu_stress_array[i]; - p->mbtest = 0; + p = &rcu_stress_array[rcu_stress_idx]; + /* catching up with ourselves would be a bug */ + assert(p != cp); + atomic_set(&p->mbtest, 0); smp_mb(); - p->pipe_count = 0; - p->mbtest = 1; + atomic_set(&p->age, 0); + atomic_set(&p->mbtest, 1); atomic_rcu_set(&rcu_stress_current, p); - rcu_stress_idx = i; + cp = p; + /* + * New RCU structure is now live, update pipe counts on old + * ones. + */ for (i = 0; i < RCU_STRESS_PIPE_LEN; i++) { if (i != rcu_stress_idx) { - rcu_stress_array[i].pipe_count++; + atomic_set(&rcu_stress_array[i].age, + rcu_stress_array[i].age + 1); } } synchronize_rcu(); @@ -346,7 +365,7 @@ static void stresstest(int nreaders, int duration) int i; rcu_stress_current = &rcu_stress_array[0]; - rcu_stress_current->pipe_count = 0; + rcu_stress_current->age = 0; rcu_stress_current->mbtest = 1; for (i = 0; i < nreaders; i++) { create_thread(rcu_read_stress_test); @@ -376,7 +395,7 @@ static void gtest_stress(int nreaders, int duration) int i; rcu_stress_current = &rcu_stress_array[0]; - rcu_stress_current->pipe_count = 0; + rcu_stress_current->age = 0; rcu_stress_current->mbtest = 1; for (i = 0; i < nreaders; i++) { create_thread(rcu_read_stress_test);