From patchwork Sat Jul 29 00:46:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332752 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA1E015BD for ; Sat, 29 Jul 2023 00:32:11 +0000 (UTC) Received: from mgamail.intel.com (unknown [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53E6CE48 for ; Fri, 28 Jul 2023 17:32:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590730; x=1722126730; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Anlup+/S8CMrAde87dR1WlNsa5+8g75mgxiqhK7v2Hs=; b=USVqKv5MCUgDVznbdgx7DPApyho7vCVQiKxcKR+BoQAWD4+zeKRkzI9F Q0Fz2iYkLkSK3Bwc+DG3PNehOiv6SiKZN/2Q0B+CfUW7PW0eKXdmdxYRL egb+F17u9cZpry5U7xrHegfpjC+esZtBK8qBAFlK8SkB6d/tQeSMJ87WY 3SdTUlCAjEK/GgidklFhCSqnPHxPysdPPJzUnpDgbBatAtvdcSsRYZlSU yaPV9yHNKFiuTUUrcXs+6u5hIE5msJ0I7DEyn4eKyZfFhXJR9P7RiJZig WH61IQAjJceRubpbnX8SnH+P2ouXYPRx93IwzeN9kiHIdg1AKQ276++gP A==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="455069297" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="455069297" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="757358731" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="757358731" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga008.jf.intel.com with ESMTP; 28 Jul 2023 17:32:09 -0700 Subject: [net-next PATCH v1 1/9] net: Introduce new fields for napi and queue associations From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:46:56 -0700 Message-ID: <169059161688.3736.18170697577939556255.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add the napi pointer in netdev queue for tracking the napi instance for each queue. This achieves the queue<->napi mapping. Introduce new napi fields 'napi_rxq_list' and 'napi_txq_list' for rx and tx queue set associated with the napi. Add functions to associate the queue with the napi and handle their removal as well. This lists the queue/queue-set on the corresponding irq line for each napi instance. Signed-off-by: Amritha Nambiar --- include/linux/netdevice.h | 19 ++++++++++++++++ net/core/dev.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 84c36a7f873f..7299872bfdff 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -342,6 +342,14 @@ struct gro_list { */ #define GRO_HASH_BUCKETS 8 +/* + * napi queue container type + */ +enum queue_type { + NAPI_QUEUE_RX, + NAPI_QUEUE_TX, +}; + /* * Structure for NAPI scheduling similar to tasklet but with weighting */ @@ -376,6 +384,8 @@ struct napi_struct { /* control-path-only fields follow */ struct list_head dev_list; struct hlist_node napi_hash_node; + struct list_head napi_rxq_list; + struct list_head napi_txq_list; }; enum { @@ -651,6 +661,9 @@ struct netdev_queue { unsigned long state; + /* NAPI instance for the queue */ + struct napi_struct *napi; + struct list_head q_list; #ifdef CONFIG_BQL struct dql dql; #endif @@ -796,6 +809,9 @@ struct netdev_rx_queue { #ifdef CONFIG_XDP_SOCKETS struct xsk_buff_pool *pool; #endif + struct list_head q_list; + /* NAPI instance for the queue */ + struct napi_struct *napi; } ____cacheline_aligned_in_smp; /* @@ -2618,6 +2634,9 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, + enum queue_type type); + /* Default NAPI poll() weight * Device drivers are strongly advised to not use bigger value */ diff --git a/net/core/dev.c b/net/core/dev.c index b58674774a57..875023ab614c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6389,6 +6389,42 @@ int dev_set_threaded(struct net_device *dev, bool threaded) } EXPORT_SYMBOL(dev_set_threaded); +/** + * netif_napi_add_queue - Associate queue with the napi + * @napi: NAPI context + * @queue_index: Index of queue + * @queue_type: queue type as RX or TX + * + * Add queue with its corresponding napi context + */ +int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, + enum queue_type type) +{ + struct net_device *dev = napi->dev; + struct netdev_rx_queue *rxq; + struct netdev_queue *txq; + + if (!dev) + return -EINVAL; + + switch (type) { + case NAPI_QUEUE_RX: + rxq = __netif_get_rx_queue(dev, queue_index); + rxq->napi = napi; + list_add_rcu(&rxq->q_list, &napi->napi_rxq_list); + break; + case NAPI_QUEUE_TX: + txq = netdev_get_tx_queue(dev, queue_index); + txq->napi = napi; + list_add_rcu(&txq->q_list, &napi->napi_txq_list); + break; + default: + return -EINVAL; + } + return 0; +} +EXPORT_SYMBOL(netif_napi_add_queue); + void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight) { @@ -6424,6 +6460,9 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, */ if (dev->threaded && napi_kthread_create(napi)) dev->threaded = 0; + + INIT_LIST_HEAD(&napi->napi_rxq_list); + INIT_LIST_HEAD(&napi->napi_txq_list); } EXPORT_SYMBOL(netif_napi_add_weight); @@ -6485,6 +6524,18 @@ static void flush_gro_hash(struct napi_struct *napi) } } +static void napi_del_queues(struct napi_struct *napi) +{ + struct netdev_rx_queue *rx_queue, *rxq; + struct netdev_queue *tx_queue, *txq; + + list_for_each_entry_safe(rx_queue, rxq, &napi->napi_rxq_list, q_list) + list_del_rcu(&rx_queue->q_list); + + list_for_each_entry_safe(tx_queue, txq, &napi->napi_txq_list, q_list) + list_del_rcu(&tx_queue->q_list); +} + /* Must be called in process context */ void __netif_napi_del(struct napi_struct *napi) { @@ -6502,6 +6553,7 @@ void __netif_napi_del(struct napi_struct *napi) kthread_stop(napi->thread); napi->thread = NULL; } + napi_del_queues(napi); } EXPORT_SYMBOL(__netif_napi_del); From patchwork Sat Jul 29 00:47:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332753 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 564A114AA2 for ; Sat, 29 Jul 2023 00:32:16 +0000 (UTC) Received: from mgamail.intel.com (unknown [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 00B1EE48 for ; Fri, 28 Jul 2023 17:32:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590734; x=1722126734; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kI7o37m91co1mhwYMHt1BPyvqDEKIJ13aWaOHWFgjzc=; b=SWPWziH2Zormt9VXDPEcPLGIhcQ7bov7K+J9FBbXlpL/aJKZfmhBM85y grgCUJ+6kS1Mcd8uWxCRZQkZccJRnDbluDGpE0U6JM5pbrRUf+Xj9GVEm r1szFi8YerZycInWwvnmotyzU59Pw06xOaJG+NF1xM+enKs4hINxarxjX dsJHuhHL7+wk7urwmQuEZxbAZnei9Pec0DfEXFXSMnZvUSIRoAYiayAVR cn9idUQMQCrUfH36o436pfsbJtFU3NuBIttWLvI5OxSGDxU0hfuYccR09 x9Jo4sDVreGd8uijHm5ms6QqKX1imdz637ZpF8yLKMUzcFG6CDwhQ/Y+p A==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="455069307" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="455069307" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="757358741" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="757358741" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga008.jf.intel.com with ESMTP; 28 Jul 2023 17:32:14 -0700 Subject: [net-next PATCH v1 2/9] ice: Add support in the driver for associating napi with queue[s] From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:02 -0700 Message-ID: <169059162246.3736.8238877297708667866.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org After the napi context is initialized, map the napi instance with the queue/queue-set on the corresponding irq line. Signed-off-by: Amritha Nambiar --- drivers/net/ethernet/intel/ice/ice_lib.c | 57 +++++++++++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_lib.h | 4 ++ drivers/net/ethernet/intel/ice/ice_main.c | 4 ++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 077f2e91ae1a..171177db8fb4 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2464,6 +2464,12 @@ ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vsi_cfg_params *params) goto unroll_vector_base; ice_vsi_map_rings_to_vectors(vsi); + + /* Associate q_vector rings to napi */ + ret = ice_vsi_add_napi_queues(vsi); + if (ret) + goto unroll_vector_base; + vsi->stat_offsets_loaded = false; if (ice_is_xdp_ena_vsi(vsi)) { @@ -2943,6 +2949,57 @@ void ice_vsi_dis_irq(struct ice_vsi *vsi) synchronize_irq(vsi->q_vectors[i]->irq.virq); } +/** + * ice_q_vector_add_napi_queues - Add queue[s] associated with the napi + * @q_vector: q_vector pointer + * + * Associate the q_vector napi with all the queue[s] on the vector + * Returns 0 on success or < 0 on error + */ +int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector) +{ + struct ice_rx_ring *rx_ring; + struct ice_tx_ring *tx_ring; + int ret; + + ice_for_each_rx_ring(rx_ring, q_vector->rx) { + ret = netif_napi_add_queue(&q_vector->napi, rx_ring->q_index, + NAPI_QUEUE_RX); + if (ret) + return ret; + } + ice_for_each_tx_ring(tx_ring, q_vector->tx) { + ret = netif_napi_add_queue(&q_vector->napi, tx_ring->q_index, + NAPI_QUEUE_TX); + if (ret) + return ret; + } + + return ret; +} + +/** + * ice_vsi_add_napi_queues + * @vsi: VSI pointer + * + * Associate queue[s] with napi for all vectors + * Returns 0 on success or < 0 on error + */ +int ice_vsi_add_napi_queues(struct ice_vsi *vsi) +{ + int i, ret = 0; + + if (!vsi->netdev) + return ret; + + ice_for_each_q_vector(vsi, i) { + ret = ice_q_vector_add_napi_queues(vsi->q_vectors[i]); + if (ret) + return ret; + } + return ret; +} + /** * ice_napi_del - Remove NAPI handler for the VSI * @vsi: VSI for which NAPI handler is to be removed diff --git a/drivers/net/ethernet/intel/ice/ice_lib.h b/drivers/net/ethernet/intel/ice/ice_lib.h index dd53fe968ad8..26c427cddf63 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.h +++ b/drivers/net/ethernet/intel/ice/ice_lib.h @@ -93,6 +93,10 @@ void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc); struct ice_vsi * ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params); +int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector); + +int ice_vsi_add_napi_queues(struct ice_vsi *vsi); + void ice_napi_del(struct ice_vsi *vsi); int ice_vsi_release(struct ice_vsi *vsi); diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 20d5ed572a8c..d3a2fc20157c 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -3373,9 +3373,11 @@ static void ice_napi_add(struct ice_vsi *vsi) if (!vsi->netdev) return; - ice_for_each_q_vector(vsi, v_idx) + ice_for_each_q_vector(vsi, v_idx) { netif_napi_add(vsi->netdev, &vsi->q_vectors[v_idx]->napi, ice_napi_poll); + ice_q_vector_add_napi_queues(vsi->q_vectors[v_idx]); + } } /** From patchwork Sat Jul 29 00:47:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332754 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 678B364C for ; Sat, 29 Jul 2023 00:32:22 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6458110CB for ; Fri, 28 Jul 2023 17:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590740; x=1722126740; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IxxoaNp7UNt/KyXoeExTYZrIFjQUdv62vVvO3JcBYVo=; b=BnNdegfSZVeBqzU1hJgECHHuAJJmFabGlTfwargQmm8E/ntngTU2RcQF ++0tIrY9hIr0O6xMpDdFNl/qNhT7EEqO/PESq5bLVXjxlNhmasfjRhSMR eUtOGH7HNfV4amwVpa+a4Y0jmfD1j3Z4/n9+zMEtObrfO2JvUp0MVdr8q Mplh0eblMHv3YJXkRUN9BipuUvkc5GOttaDXujOAt4D7aLXVRai2UXgyl 16rBuBPE6SKKvEom6iZg3uMAERNjnX9I4jVCyFVdqDo9tUxFfMyweIFxH /ManWxGo6HtJ1EWXjRb2Uc1Z9rMJpnql+Bk+lXXdhBqgJQfgNMzajJVSS g==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="358742058" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="358742058" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="851403849" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="851403849" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga004.jf.intel.com with ESMTP; 28 Jul 2023 17:32:19 -0700 Subject: [net-next PATCH v1 3/9] netdev-genl: spec: Extend netdev netlink spec in YAML for NAPI From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:07 -0700 Message-ID: <169059162756.3736.16797255590375805440.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for napi related information. Add code generated from the spec. Signed-off-by: Amritha Nambiar --- Documentation/netlink/specs/netdev.yaml | 46 ++++++ include/uapi/linux/netdev.h | 18 +++ net/core/netdev-genl-gen.c | 17 ++ net/core/netdev-genl-gen.h | 2 net/core/netdev-genl.c | 10 + tools/include/uapi/linux/netdev.h | 18 +++ tools/net/ynl/generated/netdev-user.c | 220 +++++++++++++++++++++++++++++++ tools/net/ynl/generated/netdev-user.h | 63 +++++++++ 8 files changed, 394 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index 1c7284fd535b..507cea4f2319 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -68,6 +68,38 @@ attribute-sets: type: u32 checks: min: 1 + - + name: napi-info-entry + attributes: + - + name: napi-id + doc: napi id + type: u32 + - + name: rx-queues + doc: list of rx queues associated with a napi + type: u32 + multi-attr: true + - + name: tx-queues + doc: list of tx queues associated with a napi + type: u32 + multi-attr: true + - + name: napi + attributes: + - + name: ifindex + doc: netdev ifindex + type: u32 + checks: + min: 1 + - + name: napi-info + doc: napi information such as napi-id, napi queues etc. + type: nest + multi-attr: true + nested-attributes: napi-info-entry operations: list: @@ -101,6 +133,20 @@ operations: doc: Notification about device configuration being changed. notify: dev-get mcgrp: mgmt + - + name: napi-get + doc: napi information such as napi-id, napi queues etc. + attribute-set: napi + do: + request: + attributes: + - ifindex + reply: &napi-all + attributes: + - ifindex + - napi-info + dump: + reply: *napi-all mcast-groups: list: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index c1634b95c223..bc06f692d9fd 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -48,11 +48,29 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID = 1, + NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES, + NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES, + + __NETDEV_A_NAPI_INFO_ENTRY_MAX, + NETDEV_A_NAPI_INFO_ENTRY_MAX = (__NETDEV_A_NAPI_INFO_ENTRY_MAX - 1) +}; + +enum { + NETDEV_A_NAPI_IFINDEX = 1, + NETDEV_A_NAPI_NAPI_INFO, + + __NETDEV_A_NAPI_MAX, + NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) +}; + enum { NETDEV_CMD_DEV_GET = 1, NETDEV_CMD_DEV_ADD_NTF, NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, + NETDEV_CMD_NAPI_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/net/core/netdev-genl-gen.c b/net/core/netdev-genl-gen.c index ea9231378aa6..d09ce5db8b79 100644 --- a/net/core/netdev-genl-gen.c +++ b/net/core/netdev-genl-gen.c @@ -15,6 +15,11 @@ static const struct nla_policy netdev_dev_get_nl_policy[NETDEV_A_DEV_IFINDEX + 1 [NETDEV_A_DEV_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), }; +/* NETDEV_CMD_NAPI_GET - do */ +static const struct nla_policy netdev_napi_get_nl_policy[NETDEV_A_NAPI_IFINDEX + 1] = { + [NETDEV_A_NAPI_IFINDEX] = NLA_POLICY_MIN(NLA_U32, 1), +}; + /* Ops table for netdev */ static const struct genl_split_ops netdev_nl_ops[] = { { @@ -29,6 +34,18 @@ static const struct genl_split_ops netdev_nl_ops[] = { .dumpit = netdev_nl_dev_get_dumpit, .flags = GENL_CMD_CAP_DUMP, }, + { + .cmd = NETDEV_CMD_NAPI_GET, + .doit = netdev_nl_napi_get_doit, + .policy = netdev_napi_get_nl_policy, + .maxattr = NETDEV_A_NAPI_IFINDEX, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = NETDEV_CMD_NAPI_GET, + .dumpit = netdev_nl_napi_get_dumpit, + .flags = GENL_CMD_CAP_DUMP, + }, }; static const struct genl_multicast_group netdev_nl_mcgrps[] = { diff --git a/net/core/netdev-genl-gen.h b/net/core/netdev-genl-gen.h index 7b370c073e7d..46dab8ccd568 100644 --- a/net/core/netdev-genl-gen.h +++ b/net/core/netdev-genl-gen.h @@ -13,6 +13,8 @@ int netdev_nl_dev_get_doit(struct sk_buff *skb, struct genl_info *info); int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); +int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info); +int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb); enum { NETDEV_NLGRP_MGMT, diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 797c813c7c77..e35cfa3cd173 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -120,6 +120,16 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + return -EOPNOTSUPP; +} + +int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) +{ + return -EOPNOTSUPP; +} + static int netdev_genl_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index c1634b95c223..bc06f692d9fd 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -48,11 +48,29 @@ enum { NETDEV_A_DEV_MAX = (__NETDEV_A_DEV_MAX - 1) }; +enum { + NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID = 1, + NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES, + NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES, + + __NETDEV_A_NAPI_INFO_ENTRY_MAX, + NETDEV_A_NAPI_INFO_ENTRY_MAX = (__NETDEV_A_NAPI_INFO_ENTRY_MAX - 1) +}; + +enum { + NETDEV_A_NAPI_IFINDEX = 1, + NETDEV_A_NAPI_NAPI_INFO, + + __NETDEV_A_NAPI_MAX, + NETDEV_A_NAPI_MAX = (__NETDEV_A_NAPI_MAX - 1) +}; + enum { NETDEV_CMD_DEV_GET = 1, NETDEV_CMD_DEV_ADD_NTF, NETDEV_CMD_DEV_DEL_NTF, NETDEV_CMD_DEV_CHANGE_NTF, + NETDEV_CMD_NAPI_GET, __NETDEV_CMD_MAX, NETDEV_CMD_MAX = (__NETDEV_CMD_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index 68b408ca0f7f..e9a6c8cb5c68 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -18,6 +18,7 @@ static const char * const netdev_op_strmap[] = { [NETDEV_CMD_DEV_ADD_NTF] = "dev-add-ntf", [NETDEV_CMD_DEV_DEL_NTF] = "dev-del-ntf", [NETDEV_CMD_DEV_CHANGE_NTF] = "dev-change-ntf", + [NETDEV_CMD_NAPI_GET] = "napi-get", }; const char *netdev_op_str(int op) @@ -46,6 +47,17 @@ const char *netdev_xdp_act_str(enum netdev_xdp_act value) } /* Policies */ +struct ynl_policy_attr netdev_napi_info_entry_policy[NETDEV_A_NAPI_INFO_ENTRY_MAX + 1] = { + [NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES] = { .name = "rx-queues", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES] = { .name = "tx-queues", .type = YNL_PT_U32, }, +}; + +struct ynl_policy_nest netdev_napi_info_entry_nest = { + .max_attr = NETDEV_A_NAPI_INFO_ENTRY_MAX, + .table = netdev_napi_info_entry_policy, +}; + struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = { [NETDEV_A_DEV_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, [NETDEV_A_DEV_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, }, @@ -58,7 +70,78 @@ struct ynl_policy_nest netdev_dev_nest = { .table = netdev_dev_policy, }; +struct ynl_policy_attr netdev_napi_policy[NETDEV_A_NAPI_MAX + 1] = { + [NETDEV_A_NAPI_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_NAPI_INFO] = { .name = "napi-info", .type = YNL_PT_NEST, .nest = &netdev_napi_info_entry_nest, }, +}; + +struct ynl_policy_nest netdev_napi_nest = { + .max_attr = NETDEV_A_NAPI_MAX, + .table = netdev_napi_policy, +}; + /* Common nested types */ +void netdev_napi_info_entry_free(struct netdev_napi_info_entry *obj) +{ + free(obj->rx_queues); + free(obj->tx_queues); +} + +int netdev_napi_info_entry_parse(struct ynl_parse_arg *yarg, + const struct nlattr *nested) +{ + struct netdev_napi_info_entry *dst = yarg->data; + unsigned int n_rx_queues = 0; + unsigned int n_tx_queues = 0; + const struct nlattr *attr; + int i; + + if (dst->rx_queues) + return ynl_error_parse(yarg, "attribute already present (napi-info-entry.rx-queues)"); + if (dst->tx_queues) + return ynl_error_parse(yarg, "attribute already present (napi-info-entry.tx-queues)"); + + mnl_attr_for_each_nested(attr, nested) { + unsigned int type = mnl_attr_get_type(attr); + + if (type == NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.napi_id = 1; + dst->napi_id = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES) { + n_rx_queues++; + } else if (type == NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES) { + n_tx_queues++; + } + } + + if (n_rx_queues) { + dst->rx_queues = calloc(n_rx_queues, sizeof(*dst->rx_queues)); + dst->n_rx_queues = n_rx_queues; + i = 0; + mnl_attr_for_each_nested(attr, nested) { + if (mnl_attr_get_type(attr) == NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES) { + dst->rx_queues[i] = mnl_attr_get_u32(attr); + i++; + } + } + } + if (n_tx_queues) { + dst->tx_queues = calloc(n_tx_queues, sizeof(*dst->tx_queues)); + dst->n_tx_queues = n_tx_queues; + i = 0; + mnl_attr_for_each_nested(attr, nested) { + if (mnl_attr_get_type(attr) == NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES) { + dst->tx_queues[i] = mnl_attr_get_u32(attr); + i++; + } + } + } + + return 0; +} + /* ============== NETDEV_CMD_DEV_GET ============== */ /* NETDEV_CMD_DEV_GET - do */ void netdev_dev_get_req_free(struct netdev_dev_get_req *req) @@ -178,6 +261,143 @@ void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp) free(rsp); } +/* ============== NETDEV_CMD_NAPI_GET ============== */ +/* NETDEV_CMD_NAPI_GET - do */ +void netdev_napi_get_req_free(struct netdev_napi_get_req *req) +{ + free(req); +} + +void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp) +{ + unsigned int i; + + for (i = 0; i < rsp->n_napi_info; i++) + netdev_napi_info_entry_free(&rsp->napi_info[i]); + free(rsp->napi_info); + free(rsp); +} + +int netdev_napi_get_rsp_parse(const struct nlmsghdr *nlh, void *data) +{ + struct ynl_parse_arg *yarg = data; + struct netdev_napi_get_rsp *dst; + unsigned int n_napi_info = 0; + const struct nlattr *attr; + struct ynl_parse_arg parg; + int i; + + dst = yarg->data; + parg.ys = yarg->ys; + + if (dst->napi_info) + return ynl_error_parse(yarg, "attribute already present (napi.napi-info)"); + + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + unsigned int type = mnl_attr_get_type(attr); + + if (type == NETDEV_A_NAPI_IFINDEX) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.ifindex = 1; + dst->ifindex = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_NAPI_INFO) { + n_napi_info++; + } + } + + if (n_napi_info) { + dst->napi_info = calloc(n_napi_info, sizeof(*dst->napi_info)); + dst->n_napi_info = n_napi_info; + i = 0; + parg.rsp_policy = &netdev_napi_info_entry_nest; + mnl_attr_for_each(attr, nlh, sizeof(struct genlmsghdr)) { + if (mnl_attr_get_type(attr) == NETDEV_A_NAPI_NAPI_INFO) { + parg.data = &dst->napi_info[i]; + if (netdev_napi_info_entry_parse(&parg, attr)) + return MNL_CB_ERROR; + i++; + } + } + } + + return MNL_CB_OK; +} + +struct netdev_napi_get_rsp * +netdev_napi_get(struct ynl_sock *ys, struct netdev_napi_get_req *req) +{ + struct ynl_req_state yrs = { .yarg = { .ys = ys, }, }; + struct netdev_napi_get_rsp *rsp; + struct nlmsghdr *nlh; + int err; + + nlh = ynl_gemsg_start_req(ys, ys->family_id, NETDEV_CMD_NAPI_GET, 1); + ys->req_policy = &netdev_napi_nest; + yrs.yarg.rsp_policy = &netdev_napi_nest; + + if (req->_present.ifindex) + mnl_attr_put_u32(nlh, NETDEV_A_NAPI_IFINDEX, req->ifindex); + + rsp = calloc(1, sizeof(*rsp)); + yrs.yarg.data = rsp; + yrs.cb = netdev_napi_get_rsp_parse; + yrs.rsp_cmd = NETDEV_CMD_NAPI_GET; + + err = ynl_exec(ys, nlh, &yrs); + if (err < 0) + goto err_free; + + return rsp; + +err_free: + netdev_napi_get_rsp_free(rsp); + return NULL; +} + +/* NETDEV_CMD_NAPI_GET - dump */ +void netdev_napi_get_list_free(struct netdev_napi_get_list *rsp) +{ + struct netdev_napi_get_list *next = rsp; + + while ((void *)next != YNL_LIST_END) { + unsigned int i; + + rsp = next; + next = rsp->next; + + for (i = 0; i < rsp->obj.n_napi_info; i++) + netdev_napi_info_entry_free(&rsp->obj.napi_info[i]); + free(rsp->obj.napi_info); + free(rsp); + } +} + +struct netdev_napi_get_list *netdev_napi_get_dump(struct ynl_sock *ys) +{ + struct ynl_dump_state yds = {}; + struct nlmsghdr *nlh; + int err; + + yds.ys = ys; + yds.alloc_sz = sizeof(struct netdev_napi_get_list); + yds.cb = netdev_napi_get_rsp_parse; + yds.rsp_cmd = NETDEV_CMD_NAPI_GET; + yds.rsp_policy = &netdev_napi_nest; + + nlh = ynl_gemsg_start_dump(ys, ys->family_id, NETDEV_CMD_NAPI_GET, 1); + + err = ynl_exec_dump(ys, nlh, &yds); + if (err < 0) + goto free_list; + + return yds.first; + +free_list: + netdev_napi_get_list_free(yds.first); + return NULL; +} + static const struct ynl_ntf_info netdev_ntf_info[] = { [NETDEV_CMD_DEV_ADD_NTF] = { .alloc_sz = sizeof(struct netdev_dev_get_ntf), diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index 0952d3261f4d..9274711bd862 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -20,6 +20,18 @@ const char *netdev_op_str(int op); const char *netdev_xdp_act_str(enum netdev_xdp_act value); /* Common nested types */ +struct netdev_napi_info_entry { + struct { + __u32 napi_id:1; + } _present; + + __u32 napi_id; + unsigned int n_rx_queues; + __u32 *rx_queues; + unsigned int n_tx_queues; + __u32 *tx_queues; +}; + /* ============== NETDEV_CMD_DEV_GET ============== */ /* NETDEV_CMD_DEV_GET - do */ struct netdev_dev_get_req { @@ -84,4 +96,55 @@ struct netdev_dev_get_ntf { void netdev_dev_get_ntf_free(struct netdev_dev_get_ntf *rsp); +/* ============== NETDEV_CMD_NAPI_GET ============== */ +/* NETDEV_CMD_NAPI_GET - do */ +struct netdev_napi_get_req { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; +}; + +static inline struct netdev_napi_get_req *netdev_napi_get_req_alloc(void) +{ + return calloc(1, sizeof(struct netdev_napi_get_req)); +} +void netdev_napi_get_req_free(struct netdev_napi_get_req *req); + +static inline void +netdev_napi_get_req_set_ifindex(struct netdev_napi_get_req *req, __u32 ifindex) +{ + req->_present.ifindex = 1; + req->ifindex = ifindex; +} + +struct netdev_napi_get_rsp { + struct { + __u32 ifindex:1; + } _present; + + __u32 ifindex; + unsigned int n_napi_info; + struct netdev_napi_info_entry *napi_info; +}; + +void netdev_napi_get_rsp_free(struct netdev_napi_get_rsp *rsp); + +/* + * napi information such as napi-id, napi queues etc. + */ +struct netdev_napi_get_rsp * +netdev_napi_get(struct ynl_sock *ys, struct netdev_napi_get_req *req); + +/* NETDEV_CMD_NAPI_GET - dump */ +struct netdev_napi_get_list { + struct netdev_napi_get_list *next; + struct netdev_napi_get_rsp obj __attribute__ ((aligned (8))); +}; + +void netdev_napi_get_list_free(struct netdev_napi_get_list *rsp); + +struct netdev_napi_get_list *netdev_napi_get_dump(struct ynl_sock *ys); + #endif /* _LINUX_NETDEV_GEN_H */ From patchwork Sat Jul 29 00:47:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332755 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41418ECA for ; Sat, 29 Jul 2023 00:32:26 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DA2C2135 for ; Fri, 28 Jul 2023 17:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590745; x=1722126745; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gDlfG5Y0zxxXm2SsfnjyAs6hq+ELU7wDDomhVeUPLHg=; b=N6J/7bonRg4kpdViOxXGaSVtm1FqvxsnFFjve1d1qGKw4sYlFEbzC5Wy 1ijiVEk+Y5LIllGD1yRe4AurGpbt10g3XZq9vH5zZOfDmeBvxpPEHVrsj PX7vubDcG2/M6Le4VdJ/2WChPwJQwTPzL1BzaLbLpx8MrWTzJ/aSC1djh m3yNV2nPoTXfHhY99NAQCJhSJ0J5Bg2T7TgAqaANQfDYCLQIV8lkoGTU/ 1JD2yuZBRmYV3TtADaTX+mUkLgwcwx/oUjMSPl7w5YyRo2WNZkg3EUoPM yDAuCqdf+LwXyMagdxW4CGHoEnEFfMrb/XLwxerk/qJqY+8WOscy+LvV/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="358742094" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="358742094" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="901478093" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="901478093" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga005.jf.intel.com with ESMTP; 28 Jul 2023 17:32:24 -0700 Subject: [net-next PATCH v1 4/9] net: Move kernel helpers for queue index outside sysfs From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:12 -0700 Message-ID: <169059163270.3736.8406876462323444663.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The kernel helpers for retrieving tx/rx queue index (get_netdev_queue_index and get_netdev_rx_queue_index) are restricted to sysfs, move this out for more usability. Also, replace BUG_ON with DEBUG_NET_WARN_ON_ONCE. Signed-off-by: Amritha Nambiar --- include/linux/netdevice.h | 16 +++++++++++++--- net/core/net-sysfs.c | 11 ----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 7299872bfdff..7afbf346dfd1 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2515,6 +2515,18 @@ struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, return &dev->_tx[index]; } +static inline +unsigned int get_netdev_queue_index(struct netdev_queue *queue) +{ + struct net_device *dev = queue->dev; + unsigned int i; + + i = queue - dev->_tx; + DEBUG_NET_WARN_ON_ONCE(i >= dev->num_tx_queues); + + return i; +} + static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev, const struct sk_buff *skb) { @@ -3856,17 +3868,15 @@ __netif_get_rx_queue(struct net_device *dev, unsigned int rxq) return dev->_rx + rxq; } -#ifdef CONFIG_SYSFS static inline unsigned int get_netdev_rx_queue_index( struct netdev_rx_queue *queue) { struct net_device *dev = queue->dev; int index = queue - dev->_rx; - BUG_ON(index >= dev->num_rx_queues); + DEBUG_NET_WARN_ON_ONCE(index >= dev->num_rx_queues); return index; } -#endif int netif_get_num_default_rss_queues(void); diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 15e3f4606b5f..9b900d0b6513 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -1239,17 +1239,6 @@ static ssize_t tx_timeout_show(struct netdev_queue *queue, char *buf) return sysfs_emit(buf, fmt_ulong, trans_timeout); } -static unsigned int get_netdev_queue_index(struct netdev_queue *queue) -{ - struct net_device *dev = queue->dev; - unsigned int i; - - i = queue - dev->_tx; - BUG_ON(i >= dev->num_tx_queues); - - return i; -} - static ssize_t traffic_class_show(struct netdev_queue *queue, char *buf) { From patchwork Sat Jul 29 00:47:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332756 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D3AB1388 for ; Sat, 29 Jul 2023 00:32:32 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8308EE48 for ; Fri, 28 Jul 2023 17:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590750; x=1722126750; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=nncBB3t31kM6LU5KqTMFn19BzefFMgkNXWv8PCy0hhA=; b=JRR+Hd73R5UnTST5bsOKPjUk2JxGC5u++Sud0kBVa9pwrwZI39tQ0CVH T8ygdPRXtBluR9gQF8BKIfroLAKUnub1UQBYaFVn+RV+mOrrvILQ4jPNU lIYn+IOCX9Hbyczj9EdiaP8sl3v3ZPXRSuEQqDeu/TKeROxuO4M2ee8J0 pD3xkMVhwnqJujJZckcAdS/yXkFOaP4KykWzp7Lnxi7Bhr8/JL88DhANU D+bjgbg3ZKcimGJ1xcBCMlFt6TcZTlruE7pFOVpDUNVUYS7qo5zXuEqIT XXJdkfYEzWlhZ+ANcQ3hMTKmM/zNIzX8+Kswa/wpPdBC2oxM1lNR+l//z g==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="358742135" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="358742135" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="851403869" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="851403869" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga004.jf.intel.com with ESMTP; 28 Jul 2023 17:32:30 -0700 Subject: [net-next PATCH v1 5/9] netdev-genl: Add netlink framework functions for napi From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:17 -0700 Message-ID: <169059163779.3736.7602272507688648566.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Implement the netdev netlink framework functions for napi support. The netdev structure tracks all the napi instances and napi fields. The napi instances and associated queue[s] can be retrieved this way. Signed-off-by: Amritha Nambiar --- net/core/netdev-genl.c | 253 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 251 insertions(+), 2 deletions(-) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index e35cfa3cd173..ca3ed6eb457b 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -8,6 +8,20 @@ #include "netdev-genl-gen.h" +struct netdev_nl_dump_ctx { + int dev_entry_hash; + int dev_entry_idx; + int napi_idx; +}; + +static inline struct netdev_nl_dump_ctx * +netdev_dump_ctx(struct netlink_callback *cb) +{ + NL_ASSERT_DUMP_CTX_FITS(struct netdev_nl_dump_ctx); + + return (struct netdev_nl_dump_ctx *)cb->ctx; +} + static int netdev_nl_dev_fill(struct net_device *netdev, struct sk_buff *rsp, u32 portid, u32 seq, int flags, u32 cmd) @@ -120,14 +134,249 @@ int netdev_nl_dev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) return skb->len; } +static int +netdev_nl_napi_fill_one(struct sk_buff *msg, struct napi_struct *napi) +{ + struct netdev_rx_queue *rx_queue, *rxq; + struct netdev_queue *tx_queue, *txq; + unsigned int rx_qid, tx_qid; + struct nlattr *napi_info; + + napi_info = nla_nest_start(msg, NETDEV_A_NAPI_NAPI_INFO); + if (!napi_info) + return -EMSGSIZE; + + if (nla_put_u32(msg, NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID, napi->napi_id)) + goto nla_put_failure; + + list_for_each_entry_safe(rx_queue, rxq, &napi->napi_rxq_list, q_list) { + rx_qid = get_netdev_rx_queue_index(rx_queue); + if (nla_put_u32(msg, NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES, rx_qid)) + goto nla_put_failure; + } + + list_for_each_entry_safe(tx_queue, txq, &napi->napi_txq_list, q_list) { + tx_qid = get_netdev_queue_index(tx_queue); + if (nla_put_u32(msg, NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES, tx_qid)) + goto nla_put_failure; + } + + nla_nest_end(msg, napi_info); + return 0; +nla_put_failure: + nla_nest_cancel(msg, napi_info); + return -EMSGSIZE; +} + +static int +netdev_nl_napi_fill(struct net_device *netdev, struct sk_buff *msg, int *start) +{ + struct napi_struct *napi, *n; + int i = 0; + + list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list) { + if (i < *start) { + i++; + continue; + } + if (netdev_nl_napi_fill_one(msg, napi)) + return -EMSGSIZE; + *start = ++i; + } + return 0; +} + +static int +netdev_nl_napi_prepare_fill(struct net_device *netdev, u32 portid, u32 seq, + int flags, u32 cmd) +{ + struct nlmsghdr *nlh; + struct sk_buff *skb; + bool last = false; + int index = 0; + void *hdr; + int err; + + while (!last) { + int tmp_index = index; + + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + hdr = genlmsg_put(skb, portid, seq, &netdev_nl_family, + flags | NLM_F_MULTI, cmd); + if (!hdr) { + err = -EMSGSIZE; + goto nla_put_failure; + } + err = netdev_nl_napi_fill(netdev, skb, &index); + if (!err) + last = true; + else if (err != -EMSGSIZE || tmp_index == index) + goto nla_put_failure; + + genlmsg_end(skb, hdr); + err = genlmsg_unicast(dev_net(netdev), skb, portid); + if (err) + return err; + } + + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + nlh = nlmsg_put(skb, portid, seq, NLMSG_DONE, 0, flags | NLM_F_MULTI); + if (!nlh) { + err = -EMSGSIZE; + goto nla_put_failure; + } + + return genlmsg_unicast(dev_net(netdev), skb, portid); + +nla_put_failure: + nlmsg_free(skb); + return err; +} + +static int +netdev_nl_napi_info_fill(struct net_device *netdev, u32 portid, u32 seq, + int flags, u32 cmd) +{ + struct sk_buff *skb; + void *hdr; + int err; + + skb = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + hdr = genlmsg_put(skb, portid, seq, &netdev_nl_family, flags, cmd); + if (!hdr) { + err = -EMSGSIZE; + goto err_free_msg; + } + if (nla_put_u32(skb, NETDEV_A_NAPI_IFINDEX, netdev->ifindex)) { + genlmsg_cancel(skb, hdr); + err = -EINVAL; + goto err_free_msg; + } + + genlmsg_end(skb, hdr); + + err = genlmsg_unicast(dev_net(netdev), skb, portid); + if (err) + return err; + + return netdev_nl_napi_prepare_fill(netdev, portid, seq, flags, cmd); + +err_free_msg: + nlmsg_free(skb); + return err; +} + int netdev_nl_napi_get_doit(struct sk_buff *skb, struct genl_info *info) { - return -EOPNOTSUPP; + struct net_device *netdev; + u32 ifindex; + int err; + + if (GENL_REQ_ATTR_CHECK(info, NETDEV_A_NAPI_IFINDEX)) + return -EINVAL; + + ifindex = nla_get_u32(info->attrs[NETDEV_A_NAPI_IFINDEX]); + + rtnl_lock(); + + netdev = __dev_get_by_index(genl_info_net(info), ifindex); + if (netdev) + err = netdev_nl_napi_info_fill(netdev, info->snd_portid, + info->snd_seq, 0, info->genlhdr->cmd); + else + err = -ENODEV; + + rtnl_unlock(); + + return err; +} + +static int +netdev_nl_napi_dump_entry(struct net_device *netdev, struct sk_buff *rsp, + struct netlink_callback *cb, int *start) +{ + int index = *start; + int tmp_index = index; + void *hdr; + int err; + + hdr = genlmsg_put(rsp, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, + &netdev_nl_family, NLM_F_MULTI, NETDEV_CMD_NAPI_GET); + if (!hdr) + return -EMSGSIZE; + + if (nla_put_u32(rsp, NETDEV_A_NAPI_IFINDEX, netdev->ifindex)) + goto nla_put_failure; + + err = netdev_nl_napi_fill(netdev, rsp, &index); + if (err && (err != -EMSGSIZE || tmp_index == index)) + goto nla_put_failure; + + *start = index; + genlmsg_end(rsp, hdr); + + return err; + +nla_put_failure: + genlmsg_cancel(rsp, hdr); + return -EINVAL; } int netdev_nl_napi_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) { - return -EOPNOTSUPP; + struct netdev_nl_dump_ctx *ctx = netdev_dump_ctx(cb); + struct net *net = sock_net(skb->sk); + struct net_device *netdev; + int idx = 0, s_idx, n_idx; + int h, s_h; + int err; + + s_h = ctx->dev_entry_hash; + s_idx = ctx->dev_entry_idx; + n_idx = ctx->napi_idx; + + rtnl_lock(); + + for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { + struct hlist_head *head; + + idx = 0; + head = &net->dev_index_head[h]; + hlist_for_each_entry(netdev, head, index_hlist) { + if (idx < s_idx) + goto cont; + err = netdev_nl_napi_dump_entry(netdev, skb, cb, &n_idx); + if (err == -EMSGSIZE) + goto out; + n_idx = 0; + if (err < 0) + break; +cont: + idx++; + } + } + + rtnl_unlock(); + + return err; + +out: + rtnl_unlock(); + + ctx->dev_entry_idx = idx; + ctx->dev_entry_hash = h; + ctx->napi_idx = n_idx; + cb->seq = net->dev_base_seq; + + return skb->len; } static int netdev_genl_netdevice_event(struct notifier_block *nb, From patchwork Sat Jul 29 00:47:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332757 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A731617D3 for ; Sat, 29 Jul 2023 00:32:36 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95877E48 for ; Fri, 28 Jul 2023 17:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590755; x=1722126755; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pN86Nb9ofYrUeAEZEQ/+GNk9EIeYvGrgheIHarCI7CA=; b=LeYiuKhYPMX3Aoh8MhCRSMtTCm1cM3u1I9LrxJHEkKBqurXrC9Bl4iCo XeksfQMUf1U53XzxkTI072p7CfYwF08+txo8bcV78DHhgGYvEHpQlozRA mWVY4b2XMpkHi1bb6KP2CFVwW97mVNId9/mx8te1tH4gqCiHj1JyUx8s5 V8w7FiqM5Rev0V5f5I1Zt296HHf2qhLv8sxOp+mV3SE6YTdV49ZuzbvJv MSOKLDDwINxAce8ilRH/Jt7k8Gb8L2DnLjCvYqlFGu6hrQm0ReAcz7ZgW 0RsWebcNK8OxHvILZOvsddMnkBCHSMb/M4FRyZ1FtKy3DFNmgGTM4FzyZ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="358742160" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="358742160" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="851403913" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="851403913" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga004.jf.intel.com with ESMTP; 28 Jul 2023 17:32:35 -0700 Subject: [net-next PATCH v1 6/9] netdev-genl: spec: Add irq in netdev netlink YAML spec From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:22 -0700 Message-ID: <169059164289.3736.17134833730695570684.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for interrupt number among the NAPI attributes. Add code generated from the spec. Signed-off-by: Amritha Nambiar --- Documentation/netlink/specs/netdev.yaml | 4 ++++ include/uapi/linux/netdev.h | 1 + tools/include/uapi/linux/netdev.h | 1 + tools/net/ynl/generated/netdev-user.c | 6 ++++++ tools/net/ynl/generated/netdev-user.h | 2 ++ 5 files changed, 14 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index 507cea4f2319..c7f72038184d 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -85,6 +85,10 @@ attribute-sets: doc: list of tx queues associated with a napi type: u32 multi-attr: true + - + name: irq + doc: The associated interrupt vector number for the napi + type: u32 - name: napi attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index bc06f692d9fd..17782585be72 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -52,6 +52,7 @@ enum { NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID = 1, NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES, NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES, + NETDEV_A_NAPI_INFO_ENTRY_IRQ, __NETDEV_A_NAPI_INFO_ENTRY_MAX, NETDEV_A_NAPI_INFO_ENTRY_MAX = (__NETDEV_A_NAPI_INFO_ENTRY_MAX - 1) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index bc06f692d9fd..17782585be72 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -52,6 +52,7 @@ enum { NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID = 1, NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES, NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES, + NETDEV_A_NAPI_INFO_ENTRY_IRQ, __NETDEV_A_NAPI_INFO_ENTRY_MAX, NETDEV_A_NAPI_INFO_ENTRY_MAX = (__NETDEV_A_NAPI_INFO_ENTRY_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index e9a6c8cb5c68..74c24be5641c 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -51,6 +51,7 @@ struct ynl_policy_attr netdev_napi_info_entry_policy[NETDEV_A_NAPI_INFO_ENTRY_MA [NETDEV_A_NAPI_INFO_ENTRY_NAPI_ID] = { .name = "napi-id", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES] = { .name = "rx-queues", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES] = { .name = "tx-queues", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_INFO_ENTRY_IRQ] = { .name = "irq", .type = YNL_PT_U32, }, }; struct ynl_policy_nest netdev_napi_info_entry_nest = { @@ -113,6 +114,11 @@ int netdev_napi_info_entry_parse(struct ynl_parse_arg *yarg, n_rx_queues++; } else if (type == NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES) { n_tx_queues++; + } else if (type == NETDEV_A_NAPI_INFO_ENTRY_IRQ) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.irq = 1; + dst->irq = mnl_attr_get_u32(attr); } } diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index 9274711bd862..a0833eb9a52f 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -23,6 +23,7 @@ const char *netdev_xdp_act_str(enum netdev_xdp_act value); struct netdev_napi_info_entry { struct { __u32 napi_id:1; + __u32 irq:1; } _present; __u32 napi_id; @@ -30,6 +31,7 @@ struct netdev_napi_info_entry { __u32 *rx_queues; unsigned int n_tx_queues; __u32 *tx_queues; + __u32 irq; }; /* ============== NETDEV_CMD_DEV_GET ============== */ From patchwork Sat Jul 29 00:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332758 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48C6D1FC9 for ; Sat, 29 Jul 2023 00:32:41 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7C51E48 for ; Fri, 28 Jul 2023 17:32:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590760; x=1722126760; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qLP6bTGRaY6Hat5ponHRxDF0S86ONNymnH4iDGEz8oU=; b=J7mCbcZ7r7107jqVUO9FsP0FSN3t3D2f4RuQ/Q2YEpZh7tnVkFHrYYuJ O+9dhZIYQAsvf5Dg11Btgcb+tjpBSFq/c5fZmtJP+Kjfjk58Ng92gkeYz DwOVEDYdkf3PlXrV3g7M7yaogGx3grBzoeiyU+YQ7qIBZF74BJISEJGE3 aMW95kRVHzd7L2ebAVMiqhzffPEXJRvQ9gcAbed8onEnZKJK6m4UVPG2v EYcrIRhOz7ieJZlRxDjWyOG580cg9xuUFLfcCprUhLv87fM4g0YoJPTpZ NDRGGNhZDSIgtAzM9ysoo1JdBKauzkq5PqDBPRq23JG9Sa5XgesPW45hb Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="358742184" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="358742184" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="851403966" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="851403966" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga004.jf.intel.com with ESMTP; 28 Jul 2023 17:32:40 -0700 Subject: [net-next PATCH v1 7/9] net: Add NAPI IRQ support From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:28 -0700 Message-ID: <169059164799.3736.4793522919350631917.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support to associate the interrupt vector number for a NAPI instance. Signed-off-by: Amritha Nambiar --- drivers/net/ethernet/intel/ice/ice_lib.c | 3 +++ include/linux/netdevice.h | 6 ++++++ net/core/dev.c | 1 + net/core/netdev-genl.c | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/drivers/net/ethernet/intel/ice/ice_lib.c b/drivers/net/ethernet/intel/ice/ice_lib.c index 171177db8fb4..1ebd293ca7de 100644 --- a/drivers/net/ethernet/intel/ice/ice_lib.c +++ b/drivers/net/ethernet/intel/ice/ice_lib.c @@ -2975,6 +2975,9 @@ int ice_q_vector_add_napi_queues(struct ice_q_vector *q_vector) return ret; } + /* Also set the interrupt number for the NAPI */ + napi_set_irq(&q_vector->napi, q_vector->irq.virq); + return ret; } diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 7afbf346dfd1..a0ae6de1a4aa 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -386,6 +386,7 @@ struct napi_struct { struct hlist_node napi_hash_node; struct list_head napi_rxq_list; struct list_head napi_txq_list; + int irq; }; enum { @@ -2646,6 +2647,11 @@ static inline void *netdev_priv(const struct net_device *dev) */ #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) +static inline void napi_set_irq(struct napi_struct *napi, int irq) +{ + napi->irq = irq; +} + int netif_napi_add_queue(struct napi_struct *napi, unsigned int queue_index, enum queue_type type); diff --git a/net/core/dev.c b/net/core/dev.c index 875023ab614c..118f0b957b6e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6463,6 +6463,7 @@ void netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi, INIT_LIST_HEAD(&napi->napi_rxq_list); INIT_LIST_HEAD(&napi->napi_txq_list); + napi->irq = -1; } EXPORT_SYMBOL(netif_napi_add_weight); diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index ca3ed6eb457b..8401f646a10b 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -161,6 +161,10 @@ netdev_nl_napi_fill_one(struct sk_buff *msg, struct napi_struct *napi) goto nla_put_failure; } + if (napi->irq >= 0) + if (nla_put_u32(msg, NETDEV_A_NAPI_INFO_ENTRY_IRQ, napi->irq)) + goto nla_put_failure; + nla_nest_end(msg, napi_info); return 0; nla_put_failure: From patchwork Sat Jul 29 00:47:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332759 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53E987C for ; Sat, 29 Jul 2023 00:32:48 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5CA935A0 for ; Fri, 28 Jul 2023 17:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590765; x=1722126765; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=G3M70G3UVMFvC69ARVZ1G0JHf+/eAjDk5iT62sTYQJA=; b=OICH6mewVonMtfP4SkGPgoTfvm606FESGLKNWAbUY+lAdxvaLGmreaGP NhdNdk3dOSqIj1ojNqPlajfXdU3UzTww9CPnvqK7vcxkUqmIRwgK0MoUk ODGy6dQ2j57uSWoN1hDJE/SfazfW2RZHINoVGxj8Y9qcSjhcx2NTI+FPX Pz+GKj0EzlyH7a98ZJshcZF2pfm876pQCFKMTu34cLBd2bmFn48+vmNV4 o8jA07uWdsY1yzRk4WDORrNtCBPQqW7OvdNCtz734GEVQmy6/aVMW7tYb jE4NnUiRd9A2jLtTLtmljuMcBdedej1ftOS2bRQS245ARNnby6EveKNLa A==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="358742229" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="358742229" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="901478238" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="901478238" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by orsmga005.jf.intel.com with ESMTP; 28 Jul 2023 17:32:45 -0700 Subject: [net-next PATCH v1 8/9] netdev-genl: spec: Add PID in netdev netlink YAML spec From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:33 -0700 Message-ID: <169059165317.3736.10093661858792590128.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add support in netlink spec(netdev.yaml) for PID of the NAPI thread. Add code generated from the spec. Signed-off-by: Amritha Nambiar --- Documentation/netlink/specs/netdev.yaml | 4 ++++ include/uapi/linux/netdev.h | 1 + tools/include/uapi/linux/netdev.h | 1 + tools/net/ynl/generated/netdev-user.c | 6 ++++++ tools/net/ynl/generated/netdev-user.h | 2 ++ 5 files changed, 14 insertions(+) diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml index c7f72038184d..8cbdf1f72527 100644 --- a/Documentation/netlink/specs/netdev.yaml +++ b/Documentation/netlink/specs/netdev.yaml @@ -89,6 +89,10 @@ attribute-sets: name: irq doc: The associated interrupt vector number for the napi type: u32 + - + name: pid + doc: PID of the napi thread + type: s32 - name: napi attributes: diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h index 17782585be72..d01db79615e4 100644 --- a/include/uapi/linux/netdev.h +++ b/include/uapi/linux/netdev.h @@ -53,6 +53,7 @@ enum { NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES, NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES, NETDEV_A_NAPI_INFO_ENTRY_IRQ, + NETDEV_A_NAPI_INFO_ENTRY_PID, __NETDEV_A_NAPI_INFO_ENTRY_MAX, NETDEV_A_NAPI_INFO_ENTRY_MAX = (__NETDEV_A_NAPI_INFO_ENTRY_MAX - 1) diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h index 17782585be72..d01db79615e4 100644 --- a/tools/include/uapi/linux/netdev.h +++ b/tools/include/uapi/linux/netdev.h @@ -53,6 +53,7 @@ enum { NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES, NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES, NETDEV_A_NAPI_INFO_ENTRY_IRQ, + NETDEV_A_NAPI_INFO_ENTRY_PID, __NETDEV_A_NAPI_INFO_ENTRY_MAX, NETDEV_A_NAPI_INFO_ENTRY_MAX = (__NETDEV_A_NAPI_INFO_ENTRY_MAX - 1) diff --git a/tools/net/ynl/generated/netdev-user.c b/tools/net/ynl/generated/netdev-user.c index 74c24be5641c..51f69a4ea59b 100644 --- a/tools/net/ynl/generated/netdev-user.c +++ b/tools/net/ynl/generated/netdev-user.c @@ -52,6 +52,7 @@ struct ynl_policy_attr netdev_napi_info_entry_policy[NETDEV_A_NAPI_INFO_ENTRY_MA [NETDEV_A_NAPI_INFO_ENTRY_RX_QUEUES] = { .name = "rx-queues", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_INFO_ENTRY_TX_QUEUES] = { .name = "tx-queues", .type = YNL_PT_U32, }, [NETDEV_A_NAPI_INFO_ENTRY_IRQ] = { .name = "irq", .type = YNL_PT_U32, }, + [NETDEV_A_NAPI_INFO_ENTRY_PID] = { .name = "pid", .type = YNL_PT_U32, }, }; struct ynl_policy_nest netdev_napi_info_entry_nest = { @@ -119,6 +120,11 @@ int netdev_napi_info_entry_parse(struct ynl_parse_arg *yarg, return MNL_CB_ERROR; dst->_present.irq = 1; dst->irq = mnl_attr_get_u32(attr); + } else if (type == NETDEV_A_NAPI_INFO_ENTRY_PID) { + if (ynl_attr_validate(yarg, attr)) + return MNL_CB_ERROR; + dst->_present.pid = 1; + dst->pid = mnl_attr_get_u32(attr); } } diff --git a/tools/net/ynl/generated/netdev-user.h b/tools/net/ynl/generated/netdev-user.h index a0833eb9a52f..942f377876b0 100644 --- a/tools/net/ynl/generated/netdev-user.h +++ b/tools/net/ynl/generated/netdev-user.h @@ -24,6 +24,7 @@ struct netdev_napi_info_entry { struct { __u32 napi_id:1; __u32 irq:1; + __u32 pid:1; } _present; __u32 napi_id; @@ -32,6 +33,7 @@ struct netdev_napi_info_entry { unsigned int n_tx_queues; __u32 *tx_queues; __u32 irq; + __s32 pid; }; /* ============== NETDEV_CMD_DEV_GET ============== */ From patchwork Sat Jul 29 00:47:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nambiar, Amritha" X-Patchwork-Id: 13332760 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9F247C for ; Sat, 29 Jul 2023 00:32:52 +0000 (UTC) Received: from mgamail.intel.com (unknown [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D682135 for ; Fri, 28 Jul 2023 17:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690590771; x=1722126771; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MQXLUmc+tBe1giHyCfOBX9wafJYsxG10XeXcCZFyB+A=; b=h3w9hokWEszRZ7X4krhSxtHSo64Gu4pEoz3xVpj7HpkvZUe7O14Fc8yY TH1r1XQ2de87Kf7IG0eWiZqIX3osyboJunTPdC1fYFhmGiUXceqaiaxfT hGWlCNAgBscT1ftpZLtArlQBQq6blT2E8V2o2/UoTfD6aSLPrL5NirDnd P1a7FnnV7am79ZRsuzpHxJj7HJOgBNCSWh9cqmK0HyOywxzdCy7RHw3hY X70LGEkVsZdY0MCIAA8mfHmDAYncGfAKRsoKwco29MoHumTbvPUWyXQID sYyBWUc3EF6SoMQ7oyn1Gy6dTZuwxzxkzxh10AQ0FZG4HWqXebuQDlXFA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="435001873" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="435001873" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jul 2023 17:32:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10785"; a="974255924" X-IronPort-AV: E=Sophos;i="6.01,238,1684825200"; d="scan'208";a="974255924" Received: from anambiarhost.jf.intel.com ([10.166.29.163]) by fmsmga006.fm.intel.com with ESMTP; 28 Jul 2023 17:32:50 -0700 Subject: [net-next PATCH v1 9/9] netdev-genl: Add PID for the NAPI thread From: Amritha Nambiar To: netdev@vger.kernel.org, kuba@kernel.org, davem@davemloft.net Cc: sridhar.samudrala@intel.com, amritha.nambiar@intel.com Date: Fri, 28 Jul 2023 17:47:38 -0700 Message-ID: <169059165828.3736.1595843116804085813.stgit@anambiarhost.jf.intel.com> In-Reply-To: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> References: <169059098829.3736.381753570945338022.stgit@anambiarhost.jf.intel.com> User-Agent: StGit/unknown-version Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In the threaded NAPI mode, expose the PID of the NAPI thread. Signed-off-by: Amritha Nambiar --- net/core/netdev-genl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/net/core/netdev-genl.c b/net/core/netdev-genl.c index 8401f646a10b..60af99ffb9ec 100644 --- a/net/core/netdev-genl.c +++ b/net/core/netdev-genl.c @@ -141,6 +141,7 @@ netdev_nl_napi_fill_one(struct sk_buff *msg, struct napi_struct *napi) struct netdev_queue *tx_queue, *txq; unsigned int rx_qid, tx_qid; struct nlattr *napi_info; + pid_t pid; napi_info = nla_nest_start(msg, NETDEV_A_NAPI_NAPI_INFO); if (!napi_info) @@ -165,6 +166,12 @@ netdev_nl_napi_fill_one(struct sk_buff *msg, struct napi_struct *napi) if (nla_put_u32(msg, NETDEV_A_NAPI_INFO_ENTRY_IRQ, napi->irq)) goto nla_put_failure; + if (napi->thread) { + pid = task_pid_nr(napi->thread); + if (nla_put_s32(msg, NETDEV_A_NAPI_INFO_ENTRY_PID, pid)) + goto nla_put_failure; + } + nla_nest_end(msg, napi_info); return 0; nla_put_failure: