From patchwork Mon Jan 9 03:15:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Di Proietto X-Patchwork-Id: 712490 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3txgRG3hnxz9t0q for ; Mon, 9 Jan 2017 14:21:14 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A0F31C04; Mon, 9 Jan 2017 03:15:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 0745FB7D for ; Mon, 9 Jan 2017 03:15:29 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from EX13-EDG-OU-001.vmware.com (ex13-edg-ou-001.vmware.com [208.91.0.189]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9E5A1148 for ; Mon, 9 Jan 2017 03:15:28 +0000 (UTC) Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-001.vmware.com (10.113.208.155) with Microsoft SMTP Server id 15.0.1156.6; Sun, 8 Jan 2017 19:14:51 -0800 Received: from sc9-mailhost1.vmware.com (unknown [10.113.228.104]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 829A7403AB; Sun, 8 Jan 2017 19:15:27 -0800 (PST) From: Daniele Di Proietto To: Date: Sun, 8 Jan 2017 19:15:12 -0800 Message-ID: <20170109031516.47731-15-diproiettod@vmware.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170109031516.47731-1-diproiettod@vmware.com> References: <20170109031516.47731-1-diproiettod@vmware.com> MIME-Version: 1.0 Received-SPF: None (EX13-EDG-OU-001.vmware.com: diproiettod@vmware.com does not designate permitted sender hosts) X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ilya Maximets , Daniele Di Proietto Subject: [ovs-dev] [PATCH v3 14/18] ovs-numa: Don't use hmap_first_with_hash(). X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org I think it's better to iterate the hmap than to use hmap_first_with_hash(), because it handles hash collisions. Signed-off-by: Daniele Di Proietto --- lib/ovs-numa.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c index 61c31cf69..f8a37b1ea 100644 --- a/lib/ovs-numa.c +++ b/lib/ovs-numa.c @@ -241,30 +241,32 @@ discover_numa_and_core(void) static struct cpu_core* get_core_by_core_id(unsigned core_id) { - struct cpu_core *core = NULL; + struct cpu_core *core; - if (ovs_numa_core_id_is_valid(core_id)) { - core = CONTAINER_OF(hmap_first_with_hash(&all_cpu_cores, - hash_int(core_id, 0)), - struct cpu_core, hmap_node); + HMAP_FOR_EACH_WITH_HASH (core, hmap_node, hash_int(core_id, 0), + &all_cpu_cores) { + if (core->core_id == core_id) { + return core; + } } - return core; + return NULL; } /* Gets 'struct numa_node' by 'numa_id'. */ static struct numa_node* get_numa_by_numa_id(int numa_id) { - struct numa_node *numa = NULL; + struct numa_node *numa; - if (ovs_numa_numa_id_is_valid(numa_id)) { - numa = CONTAINER_OF(hmap_first_with_hash(&all_numa_nodes, - hash_int(numa_id, 0)), - struct numa_node, hmap_node); + HMAP_FOR_EACH_WITH_HASH (numa, hmap_node, hash_int(numa_id, 0), + &all_numa_nodes) { + if (numa->numa_id == numa_id) { + return numa; + } } - return numa; + return NULL; }