From patchwork Wed Nov 16 00:46:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniele Di Proietto X-Patchwork-Id: 695379 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 3tJQjQ4QzJz9s9c for ; Wed, 16 Nov 2016 11:53:14 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AA3BCC32; Wed, 16 Nov 2016 00:46:23 +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 0DB0DBED for ; Wed, 16 Nov 2016 00:46:18 +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 ECA1F2A8 for ; Wed, 16 Nov 2016 00:46:16 +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; Tue, 15 Nov 2016 16:45:44 -0800 Received: from sc9-mailhost3.vmware.com (htb-1n-eng-dhcp161.eng.vmware.com [10.33.74.161]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 8CBBF40215; Tue, 15 Nov 2016 16:46:15 -0800 (PST) From: Daniele Di Proietto To: Date: Tue, 15 Nov 2016 16:46:08 -0800 Message-ID: <20161116004612.79315-14-diproiettod@vmware.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161116004612.79315-1-diproiettod@vmware.com> References: <20161116004612.79315-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=-4.8 required=5.0 tests=BAYES_00,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: Daniele Di Proietto Subject: [ovs-dev] [PATCH 13/17] ovs-numa: Add new dump types. 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 They will be used by a future commit. This patch introduces some code duplication which will be removed in a future commit. Signed-off-by: Daniele Di Proietto --- lib/ovs-numa.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/ovs-numa.h | 4 ++- 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c index fc840c8..a6e999b 100644 --- a/lib/ovs-numa.c +++ b/lib/ovs-numa.c @@ -512,6 +512,91 @@ ovs_numa_dump_cores_on_numa(int numa_id) return dump; } +static struct cpu_core * +get_cpu_core(int core_id) +{ + struct cpu_core *core; + + 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 NULL; +} + +struct ovs_numa_dump * +ovs_numa_dump_cores_with_cmask(const char *cmask) +{ + struct ovs_numa_dump *dump = xmalloc(sizeof *dump); + int core_id = 0; + + hmap_init(&dump->dump); + + for (int i = strlen(cmask) - 1; i >= 0; i--) { + char hex = toupper((unsigned char) cmask[i]); + int bin, j; + + if (hex >= '0' && hex <= '9') { + bin = hex - '0'; + } else if (hex >= 'A' && hex <= 'F') { + bin = hex - 'A' + 10; + } else { + VLOG_WARN("Invalid cpu mask: %c", cmask[i]); + bin = 0; + } + + for (j = 0; j < 4; j++) { + if ((bin >> j) & 0x1) { + struct cpu_core *core = get_cpu_core(core_id); + + if (core) { + struct ovs_numa_info *info = xmalloc(sizeof *info); + + info->numa_id = core->numa->numa_id; + info->core_id = core->core_id; + hmap_insert(&dump->dump, &info->hmap_node, + hash_2words(info->numa_id, info->core_id)); + } + } + + core_id++; + } + } + + return dump; +} + +struct ovs_numa_dump * +ovs_numa_dump_n_cores_per_numa(int cores_per_numa) +{ + struct ovs_numa_dump *dump = xmalloc(sizeof *dump); + const struct numa_node *n; + + hmap_init(&dump->dump); + + HMAP_FOR_EACH(n, hmap_node, &all_numa_nodes) { + const struct cpu_core *core; + int i = 0; + + LIST_FOR_EACH(core, list_node, &n->cores) { + if (i++ >= cores_per_numa) { + break; + } + + struct ovs_numa_info *info = xmalloc(sizeof *info); + + info->numa_id = core->numa->numa_id; + info->core_id = core->core_id; + hmap_insert(&dump->dump, &info->hmap_node, + hash_2words(info->numa_id, info->core_id)); + } + } + + return dump; +} bool ovs_numa_dump_contains_core(const struct ovs_numa_dump *dump, diff --git a/lib/ovs-numa.h b/lib/ovs-numa.h index c0eae07..62bdb22 100644 --- a/lib/ovs-numa.h +++ b/lib/ovs-numa.h @@ -54,12 +54,14 @@ unsigned ovs_numa_get_unpinned_core_any(void); unsigned ovs_numa_get_unpinned_core_on_numa(int numa_id); void ovs_numa_unpin_core(unsigned core_id); struct ovs_numa_dump *ovs_numa_dump_cores_on_numa(int numa_id); +struct ovs_numa_dump *ovs_numa_dump_cores_with_cmask(const char *cmask); +struct ovs_numa_dump *ovs_numa_dump_n_cores_per_numa(int n); bool ovs_numa_dump_contains_core(const struct ovs_numa_dump *, int numa_id, unsigned core_id); void ovs_numa_dump_destroy(struct ovs_numa_dump *); int ovs_numa_thread_setaffinity_core(unsigned core_id); -#define FOR_EACH_CORE_ON_NUMA(ITER, DUMP) \ +#define FOR_EACH_CORE_ON_DUMP(ITER, DUMP) \ HMAP_FOR_EACH((ITER), hmap_node, &(DUMP)->dump) #endif /* ovs-numa.h */