From patchwork Mon Sep 2 11:27:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1156592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.b="DP8rdTSR"; dkim-atps=neutral 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 46MSWD1qr2z9s7T for ; Mon, 2 Sep 2019 21:28:08 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A651CDA7; Mon, 2 Sep 2019 11:27:25 +0000 (UTC) X-Original-To: ovs-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 D77A5D9C for ; Mon, 2 Sep 2019 11:27:24 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 553B77DB for ; Mon, 2 Sep 2019 11:27:24 +0000 (UTC) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20190902112722euoutp01f3401ad5d4217e1fb4787eab907936d9~Am3_p4aL82557125571euoutp01v for ; Mon, 2 Sep 2019 11:27:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20190902112722euoutp01f3401ad5d4217e1fb4787eab907936d9~Am3_p4aL82557125571euoutp01v DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1567423642; bh=QYIe/k0ftndR1Tr3EFfW2tK1faE8EjrX3kcGZDthFpQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DP8rdTSRz6pm3HS3oTIDJO8G0pn2B4qsyzLaKoABZ65aXi/iwfIzO8Q5tJtYtOK6P h9FNzlxdqw0SlrZupL+goeWVK21/sCNn5ZWZvoyRBepxrQc4/+TUXvQq9tV12Pxjz6 sumdBTPxzTtfaxybQliZVyaluscU4dp/+zI34lcU= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20190902112722eucas1p1373ecedad2b9f600ebbff0a18368f5cd~Am3_C6TnD1979819798eucas1p1t; Mon, 2 Sep 2019 11:27:22 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 95.76.04374.99CFC6D5; Mon, 2 Sep 2019 12:27:22 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20190902112721eucas1p1d554e13c4d7821dfd851400869cb7518~Am39I6yI61512315123eucas1p1f; Mon, 2 Sep 2019 11:27:21 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20190902112721eusmtrp2fd2f0cab291165f0a390d12f3fa5a74f~Am3865S5-2554125541eusmtrp2V; Mon, 2 Sep 2019 11:27:21 +0000 (GMT) X-AuditID: cbfec7f5-4ddff70000001116-60-5d6cfc99fede Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 4C.F9.04166.99CFC6D5; Mon, 2 Sep 2019 12:27:21 +0100 (BST) Received: from imaximets.rnd.samsung.ru (unknown [106.109.129.180]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20190902112720eusmtip1e97a48b6d67ad77580a53bf429fd1d93~Am38Zl4WB2536925369eusmtip1F; Mon, 2 Sep 2019 11:27:20 +0000 (GMT) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Mon, 2 Sep 2019 14:27:09 +0300 Message-Id: <20190902112711.2919-2-i.maximets@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190902112711.2919-1-i.maximets@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrGIsWRmVeSWpSXmKPExsWy7djPc7qz/uTEGnRNYrTYvqKLzeJK+092 i40Pz7JarD30gd1i7qfnjBbXL/E4sHnsnHWX3WPxnpdMHs9u/mf0eL/vKptH35ZVjAGsUVw2 Kak5mWWpRfp2CVwZp16tYS+YJFux8fAPlgbGdWJdjJwcEgImEs3Xn7F2MXJxCAmsYJS49HUb O4TzhVHidu9RNgjnM6PE5PVHGGFalp5+AVW1nFFi8/lrbCAJIYEfjBJX7piC2GwCOhKnVkM0 iAhIS7zufQO2g1ngMKPErt6HYA3CAt4S63+tAprEwcEioCqx4Rc3SJhXwEri5N6pzBDL5CVW bzgAZnMKWEt0bFwIdpGEwGs2iWNH7rFAFLlInLx/HMoWlnh1fAs7hC0j8X/nfCYIu17ifstL RojmDkaJ6Yf+QSXsJba8Pgd2BLOApsT6XfoQYUeJX/vnsoCEJQT4JG68FQQJMwOZk7ZNZ4YI 80p0tAlBVKtI/D64HOpkKYmb7z5DXeAhcf1wIzSs+hgldqyewDaBUX4WwrIFjIyrGMVTS4tz 01OLjfNSy/WKE3OLS/PS9ZLzczcxAlPD6X/Hv+5g3Pcn6RCjAAejEg8vx6fsWCHWxLLiytxD j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vpQW9VLqUo sRRnJBpqMRcVJwIAclKMymsCAAA= X-CMS-MailID: 20190902112721eucas1p1d554e13c4d7821dfd851400869cb7518 X-Msg-Generator: CA X-RootMTR: 20190902112721eucas1p1d554e13c4d7821dfd851400869cb7518 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20190902112721eucas1p1d554e13c4d7821dfd851400869cb7518 References: <20190902112711.2919-1-i.maximets@samsung.com> X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 , David Marchand Subject: [ovs-dev] [PATCH v2 1/3] ovs-numa: Add dump based thread affinity functions. 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: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org New functions to get and set CPU affinity using CPU dumps. This will abstract OS specific implementation details from the cross-platform code. Signed-off-by: Ilya Maximets Reviewed-by: David Marchand --- lib/ovs-numa.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++---- lib/ovs-numa.h | 2 ++ 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/lib/ovs-numa.c b/lib/ovs-numa.c index 24edeab2a..eb608edc4 100644 --- a/lib/ovs-numa.c +++ b/lib/ovs-numa.c @@ -532,22 +532,69 @@ ovs_numa_dump_destroy(struct ovs_numa_dump *dump) free(dump); } -int ovs_numa_thread_setaffinity_core(unsigned core_id OVS_UNUSED) +struct ovs_numa_dump * +ovs_numa_thread_getaffinity_dump(void) { if (dummy_numa) { - /* Nothing to do */ + /* Nothing to do. */ + return NULL; + } + +#ifndef __linux__ + return NULL; +#else + struct ovs_numa_dump *dump; + const struct numa_node *n; + cpu_set_t cpuset; + int err; + + CPU_ZERO(&cpuset); + err = pthread_getaffinity_np(pthread_self(), sizeof cpuset, &cpuset); + if (err) { + VLOG_ERR("Thread getaffinity error: %s", ovs_strerror(err)); + return NULL; + } + + dump = ovs_numa_dump_create(); + + HMAP_FOR_EACH (n, hmap_node, &all_numa_nodes) { + const struct cpu_core *core; + + LIST_FOR_EACH (core, list_node, &n->cores) { + if (CPU_ISSET(core->core_id, &cpuset)) { + ovs_numa_dump_add(dump, core->numa->numa_id, core->core_id); + } + } + } + + if (!ovs_numa_dump_count(dump)) { + ovs_numa_dump_destroy(dump); + return NULL; + } + return dump; +#endif /* __linux__ */ +} + +int +ovs_numa_thread_setaffinity_dump(struct ovs_numa_dump *dump) +{ + if (!dump || dummy_numa) { + /* Nothing to do. */ return 0; } #ifdef __linux__ + struct ovs_numa_info_core *core; cpu_set_t cpuset; int err; CPU_ZERO(&cpuset); - CPU_SET(core_id, &cpuset); - err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset); + FOR_EACH_CORE_ON_DUMP (core, dump) { + CPU_SET(core->core_id, &cpuset); + } + err = pthread_setaffinity_np(pthread_self(), sizeof cpuset, &cpuset); if (err) { - VLOG_ERR("Thread affinity error %d",err); + VLOG_ERR("Thread setaffinity error: %s", ovs_strerror(err)); return err; } @@ -556,3 +603,18 @@ int ovs_numa_thread_setaffinity_core(unsigned core_id OVS_UNUSED) return EOPNOTSUPP; #endif /* __linux__ */ } + +int ovs_numa_thread_setaffinity_core(unsigned core_id) +{ + struct ovs_numa_dump *affinity = ovs_numa_dump_create(); + struct cpu_core *core = get_core_by_core_id(core_id); + int ret = EINVAL; + + if (core) { + ovs_numa_dump_add(affinity, core->numa->numa_id, core->core_id); + ret = ovs_numa_thread_setaffinity_dump(affinity); + } + + ovs_numa_dump_destroy(affinity); + return ret; +} diff --git a/lib/ovs-numa.h b/lib/ovs-numa.h index 088fcb8c3..88352a93e 100644 --- a/lib/ovs-numa.h +++ b/lib/ovs-numa.h @@ -60,6 +60,8 @@ 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); size_t ovs_numa_dump_count(const struct ovs_numa_dump *); +struct ovs_numa_dump * ovs_numa_thread_getaffinity_dump(void); +int ovs_numa_thread_setaffinity_dump(struct ovs_numa_dump *); void ovs_numa_dump_destroy(struct ovs_numa_dump *); int ovs_numa_thread_setaffinity_core(unsigned core_id);