From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by dpdk.org (Postfix) with ESMTP id CAF1B7FAD for ; Sat, 22 Nov 2014 22:33:50 +0100 (CET) Received: by mail-wi0-f173.google.com with SMTP id r20so2413464wiv.0 for ; Sat, 22 Nov 2014 13:44:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h0xTgvMWmPUBsE90R7IWEs4WcEalmcjiHw/8ccDoOB0=; b=JswkkPFTBRpt+lXtAL6Ws4OKU5Qqdgl5Mf7W4F97UERZoAnHuEULsLXWh5TBzshzm3 979+XUIldr0bzkapeFeSL/6e3bOG8ODfPCa9vgKjSzRxA6Ata3OODvWhi8MwaTEbtQMI z0+kquHFP86j4auVoF9aYPUAY8+x1XvXf3FbfYGXNtNCOhhZ001cFOZAHI0g/uxWFoGt B/XHXrNuBxS1Tstc60Vt1/bHnRmunVgMQ+TIbbs1by/gIRl/IBCy5Kv/oywaCqIX2Xg+ msIrTPdxdr7xMQLeYsUzE+AZIz/mTBgTY+m7R4Q6Fbgl7IdMJci5e2VpWQ1fD7Qen3ek B02w== X-Gm-Message-State: ALoCoQlFflyjWEbKEsqLLvCPBOdQFmZ0zebu25+h+Xue5zRYKDEA8RiR3UxBWeYGT6C3d+pwEdya X-Received: by 10.194.119.230 with SMTP id kx6mr20591657wjb.80.1416692671387; Sat, 22 Nov 2014 13:44:31 -0800 (PST) Received: from localhost.localdomain (136-92-190-109.dsl.ovh.fr. [109.190.92.136]) by mx.google.com with ESMTPSA id cz3sm13724087wjb.23.2014.11.22.13.44.29 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 22 Nov 2014 13:44:30 -0800 (PST) From: Thomas Monjalon To: dev@dpdk.org Date: Sat, 22 Nov 2014 22:43:41 +0100 Message-Id: <1416692622-28886-10-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1416692622-28886-1-git-send-email-thomas.monjalon@6wind.com> References: <1416692622-28886-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-dev] [PATCH 09/10] eal: get relative core index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Nov 2014 21:33:52 -0000 From: Patrick Lu EAL -c option allows the user to enable any lcore in the system. Often times, the user app wants to know 1st enabled core, 2nd enabled core, etc, rather than phyical core ID (rte_lcore_id().) The new API rte_lcore_index() will return an index from enabled lcores starting from zero. Signed-off-by: Patrick Lu Signed-off-by: Thomas Monjalon --- lib/librte_eal/common/eal_common_options.c | 13 ++++++++++--- lib/librte_eal/common/include/rte_lcore.h | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 18d03e3..c9df8f5 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -185,19 +185,23 @@ eal_parse_coremask(const char *coremask) return -1; } cfg->lcore_role[idx] = ROLE_RTE; + lcore_config[idx].core_index = count; if (count == 0) cfg->master_lcore = idx; count++; } else { cfg->lcore_role[idx] = ROLE_OFF; + lcore_config[idx].core_index = -1; } } } for (; i >= 0; i--) if (coremask[i] != '0') return -1; - for (; idx < RTE_MAX_LCORE; idx++) + for (; idx < RTE_MAX_LCORE; idx++) { cfg->lcore_role[idx] = ROLE_OFF; + lcore_config[idx].core_index = -1; + } if (count == 0) return -1; /* Update the count of enabled logical cores of the EAL configuration */ @@ -225,9 +229,11 @@ eal_parse_corelist(const char *corelist) while ((i > 0) && isblank(corelist[i - 1])) i--; - /* Reset core roles */ - for (idx = 0; idx < RTE_MAX_LCORE; idx++) + /* Reset config */ + for (idx = 0; idx < RTE_MAX_LCORE; idx++) { cfg->lcore_role[idx] = ROLE_OFF; + lcore_config[idx].core_index = -1; + } /* Get list of cores */ min = RTE_MAX_LCORE; @@ -250,6 +256,7 @@ eal_parse_corelist(const char *corelist) min = idx; for (idx = min; idx <= max; idx++) { cfg->lcore_role[idx] = ROLE_RTE; + lcore_config[idx].core_index = count; if (count == 0) cfg->master_lcore = idx; count++; diff --git a/lib/librte_eal/common/include/rte_lcore.h b/lib/librte_eal/common/include/rte_lcore.h index a0b4356..49b2c03 100644 --- a/lib/librte_eal/common/include/rte_lcore.h +++ b/lib/librte_eal/common/include/rte_lcore.h @@ -64,6 +64,7 @@ struct lcore_config { volatile enum rte_lcore_state_t state; /**< lcore state */ unsigned socket_id; /**< physical socket id for this lcore */ unsigned core_id; /**< core number on socket for this lcore */ + int core_index; /**< relative index, starting from 0 */ }; /** @@ -110,6 +111,25 @@ rte_lcore_count(void) } /** + * Return the index of the lcore starting from zero. + * The order is physical or given by command line (-l option). + * + * @param lcore_id + * The targeted lcore, or -1 for the current one. + * @return + * The relative index, or -1 if not enabled. + */ +static inline int +rte_lcore_index(int lcore_id) +{ + if (lcore_id >= RTE_MAX_LCORE) + return -1; + if (lcore_id < 0) + lcore_id = rte_lcore_id(); + return lcore_config[lcore_id].core_index; +} + +/** * Return the ID of the physical socket of the logical core we are * running on. * @return -- 2.1.3