From patchwork Wed Sep 26 18:37:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 147640 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1073592lji; Wed, 26 Sep 2018 11:45:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV626iujCiKOy7v8Nn89UbG1tgDRNrnjJTkXUD8kgIvBEQCqlx4esdcvKzIJnlBe9tj7uoT9N X-Received: by 2002:a0c:919d:: with SMTP id n29-v6mr5339045qvn.142.1537987533627; Wed, 26 Sep 2018 11:45:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537987533; cv=none; d=google.com; s=arc-20160816; b=LDeCfUmgW8Pt2Doj5hdNt39uoaDmfuyJAO8em7t73HGZGJfwn/YGiyO425xGnXD0L9 cdiC8NXB2d6k8RQZuOjJ+HexoScCk3eYdi+Afs1cFGVZt19x6Fw6zkGQh1Q87gV7D7QN p/7E3h72t67TDHCPueamVvY+Mhhw4yR1JMWlzGNQtWWPT+CAS1TsEh8Fq+G9VCt4b/lr i/mZ+yvoaeYhoh9R/e+RDa5dR3jDydMhWXIf244cs/+akd8DTESMy8b2Dmn92VKDMcWx 9pCtyGYDJYw7/xYqi+OzrEkMGf+GNBhiNYJtHpCe9D1pod0LUwQZow9BTh4eQs5VeVE+ HnZA== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=6O3y7EPp0gLOEI+mDlJAklujfyitZj2fuA3k8uoUzr8=; b=xWfJ8xNaKtynawh4UDyf/FoBiQpQczB73dJn/MrqBLU/ZkVWL/7m0U6ltN4wSA4dGY DYn2tnXvUG/1Je9x8BAvozuVG//ZHQy4Fx3MMqgVbWVMvMU7VWnDPdFfG7Rw17OFqbiV 7yCNwBRtaR462fY4D8C6U1Sn1tBOPXVjhOYuxWzWqnj/rNcijfTX8Fgkw/ioWa4AFGiO j4DXheRLCDTvVPEmeLg0SqGsH3P0CEEU2z5sJsEgC3fLrH5qvYNhs1zuaYL4wSh2EwTR cnwzsNeF2NiOMQJIZhuD9Pos66huXczRxHEL/oCkrBqi/OI/yRCsqGBJ5q1oqgpaIL9z NDpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kvqGDCLz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l189-v6si4655211qkd.32.2018.09.26.11.45.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Sep 2018 11:45:33 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=kvqGDCLz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60206 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5EoX-0001sP-0g for patch@linaro.org; Wed, 26 Sep 2018 14:45:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Egm-0001ax-B5 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5Egj-0007Of-Sr for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:32 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:42882) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g5Egg-0007Hv-33 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:27 -0400 Received: by mail-pf1-x443.google.com with SMTP id l9-v6so13887066pff.9 for ; Wed, 26 Sep 2018 11:37:24 -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=6O3y7EPp0gLOEI+mDlJAklujfyitZj2fuA3k8uoUzr8=; b=kvqGDCLzSZuGxLbzv8TA+HeX1tgA5ftS2s1apwwpWIeHtBdQ8YWoLhFMxBtVv64EtH LyYXKT7l/pURaIMnNRSYhzgXrSQaphu2k60REPxl14ZoJiUfiqAC0JltI32FCOCS1t19 CMrmxWP+pAxS4vGoYhNMC4VNAhRVL3+vakpfU= 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=6O3y7EPp0gLOEI+mDlJAklujfyitZj2fuA3k8uoUzr8=; b=lAFDU8ntrC4pBvM46wVChFtrk0o+Xb0+ecKCfU1LrcFTT95NSIAd+GPpWD9tE+TLJg km+X+tcQJ3udxj7I8mguBK4ExrPqGx3zXknjTK25c/sdr0yj199n33xbE5NpcARhGz+A uwJSrhy2zXzMgZaewEHlqSdINw72CsiKkJsrhN2UULiqJCUJQZ64pNaMXppEk6KrMJmj ePividzLLkzwqyiovw4pbymhajudyBI46oixlws6zjCHtaSTd/zyVusuw95g4qq+cC8U R79Dc91Xyh6wnQz81CDRRQVNTRRnNKE7ETfeKQyrapdk2VHXcvKX+luzaTWfFowFoUeY /kjw== X-Gm-Message-State: ABuFfohLgc9z3CQbr/6x+n9gIcAQJqVvk56kyGDDGNC6yO/HMLcwiOH5 ww3V3v7rfy6eyXP6w3Q6z9XnIrZ/KmU= X-Received: by 2002:a17:902:4e:: with SMTP id 72-v6mr7275285pla.318.1537987042845; Wed, 26 Sep 2018 11:37:22 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-8-179.tukw.qwest.net. [97.113.8.179]) by smtp.gmail.com with ESMTPSA id b14-v6sm9735952pfc.178.2018.09.26.11.37.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Sep 2018 11:37:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:37:03 -0700 Message-Id: <20180926183709.21293-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180926183709.21293-1-richard.henderson@linaro.org> References: <20180926183709.21293-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PULL 07/13] qht: drop ht argument from qht iterators X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Accessing the HT from an iterator results almost always in a deadlock. Given that only one qht-internal function uses this argument, drop it from the interface. Suggested-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- include/qemu/qht.h | 5 ++--- accel/tcg/translate-all.c | 6 ++---- tests/test-qht.c | 6 +++--- util/qht.c | 29 +++++++++++++++++++---------- util/qsp.c | 11 +++++------ 5 files changed, 31 insertions(+), 26 deletions(-) -- 2.17.1 diff --git a/include/qemu/qht.h b/include/qemu/qht.h index 3a9618db69..6484837487 100644 --- a/include/qemu/qht.h +++ b/include/qemu/qht.h @@ -43,9 +43,8 @@ struct qht_stats { }; typedef bool (*qht_lookup_func_t)(const void *obj, const void *userp); -typedef void (*qht_iter_func_t)(struct qht *ht, void *p, uint32_t h, void *up); -typedef bool (*qht_iter_bool_func_t)(struct qht *ht, void *p, uint32_t h, - void *up); +typedef void (*qht_iter_func_t)(void *p, uint32_t h, void *up); +typedef bool (*qht_iter_bool_func_t)(void *p, uint32_t h, void *up); #define QHT_MODE_AUTO_RESIZE 0x1 /* auto-resize when heavily loaded */ #define QHT_MODE_RAW_MUTEXES 0x2 /* bypass the profiler (QSP) */ diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 898c3bb3d1..9ffbbc2fbd 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1282,8 +1282,7 @@ void tb_flush(CPUState *cpu) */ #ifdef CONFIG_USER_ONLY -static void -do_tb_invalidate_check(struct qht *ht, void *p, uint32_t hash, void *userp) +static void do_tb_invalidate_check(void *p, uint32_t hash, void *userp) { TranslationBlock *tb = p; target_ulong addr = *(target_ulong *)userp; @@ -1304,8 +1303,7 @@ static void tb_invalidate_check(target_ulong address) qht_iter(&tb_ctx.htable, do_tb_invalidate_check, &address); } -static void -do_tb_page_check(struct qht *ht, void *p, uint32_t hash, void *userp) +static void do_tb_page_check(void *p, uint32_t hash, void *userp) { TranslationBlock *tb = p; int flags1, flags2; diff --git a/tests/test-qht.c b/tests/test-qht.c index 1ec039d636..4d23cefab6 100644 --- a/tests/test-qht.c +++ b/tests/test-qht.c @@ -98,7 +98,7 @@ static void check(int a, int b, bool expected) qht_statistics_destroy(&stats); } -static void count_func(struct qht *ht, void *p, uint32_t hash, void *userp) +static void count_func(void *p, uint32_t hash, void *userp) { unsigned int *curr = userp; @@ -122,7 +122,7 @@ static void iter_check(unsigned int count) g_assert_cmpuint(curr, ==, count); } -static void sum_func(struct qht *ht, void *p, uint32_t hash, void *userp) +static void sum_func(void *p, uint32_t hash, void *userp) { uint32_t *sum = userp; uint32_t a = *(uint32_t *)p; @@ -138,7 +138,7 @@ static void iter_sum_check(unsigned int expected) g_assert_cmpuint(sum, ==, expected); } -static bool rm_mod_func(struct qht *ht, void *p, uint32_t hash, void *userp) +static bool rm_mod_func(void *p, uint32_t hash, void *userp) { uint32_t a = *(uint32_t *)p; unsigned int mod = *(unsigned int *)userp; diff --git a/util/qht.c b/util/qht.c index c190e89f5b..50ed7a2102 100644 --- a/util/qht.c +++ b/util/qht.c @@ -746,7 +746,7 @@ bool qht_remove(struct qht *ht, const void *p, uint32_t hash) return ret; } -static inline void qht_bucket_iter(struct qht *ht, struct qht_bucket *head, +static inline void qht_bucket_iter(struct qht_bucket *head, const struct qht_iter *iter, void *userp) { struct qht_bucket *b = head; @@ -759,10 +759,10 @@ static inline void qht_bucket_iter(struct qht *ht, struct qht_bucket *head, } switch (iter->type) { case QHT_ITER_VOID: - iter->f.retvoid(ht, b->pointers[i], b->hashes[i], userp); + iter->f.retvoid(b->pointers[i], b->hashes[i], userp); break; case QHT_ITER_RM: - if (iter->f.retbool(ht, b->pointers[i], b->hashes[i], userp)) { + if (iter->f.retbool(b->pointers[i], b->hashes[i], userp)) { /* replace i with the last valid element in the bucket */ seqlock_write_begin(&head->sequence); qht_bucket_remove_entry(b, i); @@ -782,14 +782,14 @@ static inline void qht_bucket_iter(struct qht *ht, struct qht_bucket *head, } /* call with all of the map's locks held */ -static inline void qht_map_iter__all_locked(struct qht *ht, struct qht_map *map, +static inline void qht_map_iter__all_locked(struct qht_map *map, const struct qht_iter *iter, void *userp) { size_t i; for (i = 0; i < map->n_buckets; i++) { - qht_bucket_iter(ht, &map->buckets[i], iter, userp); + qht_bucket_iter(&map->buckets[i], iter, userp); } } @@ -800,8 +800,7 @@ do_qht_iter(struct qht *ht, const struct qht_iter *iter, void *userp) map = atomic_rcu_read(&ht->map); qht_map_lock_buckets(map); - /* Note: ht here is merely for carrying ht->mode; ht->map won't be read */ - qht_map_iter__all_locked(ht, map, iter, userp); + qht_map_iter__all_locked(map, iter, userp); qht_map_unlock_buckets(map); } @@ -825,9 +824,16 @@ void qht_iter_remove(struct qht *ht, qht_iter_bool_func_t func, void *userp) do_qht_iter(ht, &iter, userp); } -static void qht_map_copy(struct qht *ht, void *p, uint32_t hash, void *userp) +struct qht_map_copy_data { + struct qht *ht; + struct qht_map *new; +}; + +static void qht_map_copy(void *p, uint32_t hash, void *userp) { - struct qht_map *new = userp; + struct qht_map_copy_data *data = userp; + struct qht *ht = data->ht; + struct qht_map *new = data->new; struct qht_bucket *b = qht_map_to_bucket(new, hash); /* no need to acquire b->lock because no thread has seen this map yet */ @@ -845,6 +851,7 @@ static void qht_do_resize_reset(struct qht *ht, struct qht_map *new, bool reset) .f.retvoid = qht_map_copy, .type = QHT_ITER_VOID, }; + struct qht_map_copy_data data; old = ht->map; qht_map_lock_buckets(old); @@ -859,7 +866,9 @@ static void qht_do_resize_reset(struct qht *ht, struct qht_map *new, bool reset) } g_assert(new->n_buckets != old->n_buckets); - qht_map_iter__all_locked(ht, old, &iter, new); + data.ht = ht; + data.new = new; + qht_map_iter__all_locked(old, &iter, &data); qht_map_debug__all_locked(new); atomic_rcu_set(&ht->map, new); diff --git a/util/qsp.c b/util/qsp.c index b0c2575d10..2de3a97594 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -533,7 +533,7 @@ static gint qsp_tree_cmp(gconstpointer ap, gconstpointer bp, gpointer up) } } -static void qsp_sort(struct qht *ht, void *p, uint32_t h, void *userp) +static void qsp_sort(void *p, uint32_t h, void *userp) { QSPEntry *e = p; GTree *tree = userp; @@ -541,7 +541,7 @@ static void qsp_sort(struct qht *ht, void *p, uint32_t h, void *userp) g_tree_insert(tree, e, NULL); } -static void qsp_aggregate(struct qht *global_ht, void *p, uint32_t h, void *up) +static void qsp_aggregate(void *p, uint32_t h, void *up) { struct qht *ht = up; const QSPEntry *e = p; @@ -553,7 +553,7 @@ static void qsp_aggregate(struct qht *global_ht, void *p, uint32_t h, void *up) qsp_entry_aggregate(agg, e); } -static void qsp_iter_diff(struct qht *orig, void *p, uint32_t hash, void *htp) +static void qsp_iter_diff(void *p, uint32_t hash, void *htp) { struct qht *ht = htp; QSPEntry *old = p; @@ -583,8 +583,7 @@ static void qsp_diff(struct qht *orig, struct qht *new) qht_iter(orig, qsp_iter_diff, new); } -static void -qsp_iter_callsite_coalesce(struct qht *orig, void *p, uint32_t h, void *htp) +static void qsp_iter_callsite_coalesce(void *p, uint32_t h, void *htp) { struct qht *ht = htp; QSPEntry *old = p; @@ -603,7 +602,7 @@ qsp_iter_callsite_coalesce(struct qht *orig, void *p, uint32_t h, void *htp) e->n_acqs += old->n_acqs; } -static void qsp_ht_delete(struct qht *ht, void *p, uint32_t h, void *htp) +static void qsp_ht_delete(void *p, uint32_t h, void *htp) { g_free(p); }