From patchwork Sun Jul 2 15:01:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 9821597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 79EF86035F for ; Sun, 2 Jul 2017 15:01:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C83127FC0 for ; Sun, 2 Jul 2017 15:01:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60F0E2810E; Sun, 2 Jul 2017 15:01:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0180028294 for ; Sun, 2 Jul 2017 15:01:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751983AbdGBPBx (ORCPT ); Sun, 2 Jul 2017 11:01:53 -0400 Received: from merlin.infradead.org ([205.233.59.134]:36376 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751978AbdGBPBv (ORCPT ); Sun, 2 Jul 2017 11:01:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:To:From:Sender:Reply-To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z+AzENG7SiOFUsI67Y9p9bHUUP8DSQN35DgUVCYYEj0=; b=b0b142I0YqwRM4MWqeuRoVqE0 Zobxwon2/0V37DvZJuKJC2Dytjx8r7BYjR2TqoNPFJG1fD79SOXjJ1h+HhZxLLXisWhaj87OQmziQ iZ/JWWuXSFfAU7L/SInFsrGqTEhKCyb97dOwUjs8kX3E7/w2SI3CIP23OLv6beMUDGrWV3BxNis6y SGWhmQk+HHarCB5g72G8oSDdWdNZTfQN01Ce5oCPIhbVawl68Ia3BCjMflSNnqWKeJSu5GAGUXpua PctTdJZgXKLiDdjjj/lDT90CTqoANJwuiGSrqxXuMYHSmSqUs8QC0FHcGvD+6jBvejwy2b/34aL1u BiKlhiPhg==; Received: from bzq-82-81-101-184.red.bezeqint.net ([82.81.101.184] helo=bombadil.infradead.org) by merlin.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1dRgNd-0007qh-Em; Sun, 02 Jul 2017 15:01:45 +0000 From: Sagi Grimberg To: linux-nvme@lists.infradead.org, Christoph Hellwig , James Smart , Keith Busch , linux-rdma@vger.kernel.org Subject: [PATCH rfc 2/3] RDMA/core: expose cpu affinity based completion vector lookup Date: Sun, 2 Jul 2017 18:01:33 +0300 Message-Id: <1499007694-7231-3-git-send-email-sagi@grimberg.me> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499007694-7231-1-git-send-email-sagi@grimberg.me> References: <1499007694-7231-1-git-send-email-sagi@grimberg.me> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A ULP might want to lookup an optimal completion vector based on a given cpu core affinity. Expose a lookup routine for it iterating on the device completion vectors searching a vector with affinity matching the given cpu. Signed-off-by: Sagi Grimberg --- drivers/infiniband/core/verbs.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/rdma/ib_verbs.h | 3 +++ 2 files changed, 44 insertions(+) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index 4792f5209ac2..f0dfb1ca952b 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -2099,3 +2099,44 @@ void ib_drain_qp(struct ib_qp *qp) ib_drain_rq(qp); } EXPORT_SYMBOL(ib_drain_qp); + +/** + * ib_find_cpu_vector() - Find the first completion vector mapped to a given cpu core + * @device: rdma device + * @cpu: cpu for the corresponding completion vector affinity + * @vector: output target completion vector + * + * If the device expose vector affinity we will search each of the vectors + * and if we find one that gives us the desired cpu core we return true + * and assign @vector to the corresponding completion vector. Otherwise + * we return false. We stop at the first appropriate completion vector + * we find as we don't have any preference for multiple vectors with the + * same affinity. + */ +bool ib_find_cpu_vector(struct ib_device *device, unsigned int cpu, + unsigned int *vector) +{ + bool found = false; + unsigned int c; + int vec; + + for (vec = 0; vec < device->num_comp_vectors; vec++) { + const struct cpumask *mask; + + mask = ib_get_vector_affinity(device, vec); + if (!mask) + goto out; + + for_each_cpu(c, mask) { + if (c == cpu) { + *vector = vec; + found = true; + goto out; + } + } + } + +out: + return found; +} +EXPORT_SYMBOL(ib_find_cpu_vector); diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 2349143297c9..8af48ef811f8 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -3662,4 +3662,7 @@ ib_get_vector_affinity(struct ib_device *device, int comp_vector) } +bool ib_find_cpu_vector(struct ib_device *device, unsigned int cpu, + unsigned int *vector); + #endif /* IB_VERBS_H */