From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2ECCF43252; Tue, 31 Oct 2023 14:22:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1ECC44029E; Tue, 31 Oct 2023 14:22:47 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 4BBF040284 for ; Tue, 31 Oct 2023 14:22:42 +0100 (CET) Received: from kwepemm000004.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4SKW2G72mlz1P7cx; Tue, 31 Oct 2023 21:19:34 +0800 (CST) Received: from [10.67.121.59] (10.67.121.59) by kwepemm000004.china.huawei.com (7.193.23.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 31 Oct 2023 21:22:34 +0800 Message-ID: <0f768360-10d4-cd2c-9a19-42eaa0476899@huawei.com> Date: Tue, 31 Oct 2023 21:22:34 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v3] eal: support lcore usage ratio To: Chengwen Feng , , CC: , References: <20231023040811.46038-1-fengchengwen@huawei.com> <20231023125132.4216-1-fengchengwen@huawei.com> From: "lihuisong (C)" In-Reply-To: <20231023125132.4216-1-fengchengwen@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.121.59] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm000004.china.huawei.com (7.193.23.18) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org lgtm, Acked-by: Huisong Li 在 2023/10/23 20:51, Chengwen Feng 写道: > Current, the lcore usage only display two key fields: busy_cycles and > total_cycles, which is inconvenient to obtain the usage ratio > immediately. So adds lcore usage ratio field. > > Signed-off-by: Chengwen Feng > Acked-by: Morten Brørup > > --- > v3: change %.2f to %.02f according Morten's comments. > v2: address Morten's comments. > > --- > lib/eal/common/eal_common_lcore.c | 35 ++++++++++++++++++++++++++++--- > 1 file changed, 32 insertions(+), 3 deletions(-) > > diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c > index ceda714ca5..a35fa9a3e7 100644 > --- a/lib/eal/common/eal_common_lcore.c > +++ b/lib/eal/common/eal_common_lcore.c > @@ -446,6 +446,13 @@ rte_lcore_register_usage_cb(rte_lcore_usage_cb cb) > lcore_usage_cb = cb; > } > > +static float > +calc_usage_ratio(const struct rte_lcore_usage *usage) > +{ > + return usage->total_cycles != 0 ? > + (usage->busy_cycles * 100.0) / usage->total_cycles : (float)0; > +} > + > static int > lcore_dump_cb(unsigned int lcore_id, void *arg) > { > @@ -462,8 +469,9 @@ lcore_dump_cb(unsigned int lcore_id, void *arg) > /* Guard against concurrent modification of lcore_usage_cb. */ > usage_cb = lcore_usage_cb; > if (usage_cb != NULL && usage_cb(lcore_id, &usage) == 0) { > - if (asprintf(&usage_str, ", busy cycles %"PRIu64"/%"PRIu64, > - usage.busy_cycles, usage.total_cycles) < 0) { > + if (asprintf(&usage_str, ", busy cycles %"PRIu64"/%"PRIu64" (ratio %.02f%%)", > + usage.busy_cycles, usage.total_cycles, > + calc_usage_ratio(&usage)) < 0) { > return -ENOMEM; > } > } > @@ -511,11 +519,19 @@ struct lcore_telemetry_info { > struct rte_tel_data *d; > }; > > +static void > +format_usage_ratio(char *buf, uint16_t size, const struct rte_lcore_usage *usage) > +{ > + float ratio = calc_usage_ratio(usage); > + snprintf(buf, size, "%.02f%%", ratio); > +} > + > static int > lcore_telemetry_info_cb(unsigned int lcore_id, void *arg) > { > struct rte_config *cfg = rte_eal_get_configuration(); > struct lcore_telemetry_info *info = arg; > + char ratio_str[RTE_TEL_MAX_STRING_LEN]; > struct rte_lcore_usage usage; > struct rte_tel_data *cpuset; > rte_lcore_usage_cb usage_cb; > @@ -544,6 +560,8 @@ lcore_telemetry_info_cb(unsigned int lcore_id, void *arg) > if (usage_cb != NULL && usage_cb(lcore_id, &usage) == 0) { > rte_tel_data_add_dict_uint(info->d, "total_cycles", usage.total_cycles); > rte_tel_data_add_dict_uint(info->d, "busy_cycles", usage.busy_cycles); > + format_usage_ratio(ratio_str, sizeof(ratio_str), &usage); > + rte_tel_data_add_dict_string(info->d, "usage_ratio", ratio_str); > } > > return 0; > @@ -574,11 +592,13 @@ struct lcore_telemetry_usage { > struct rte_tel_data *lcore_ids; > struct rte_tel_data *total_cycles; > struct rte_tel_data *busy_cycles; > + struct rte_tel_data *usage_ratio; > }; > > static int > lcore_telemetry_usage_cb(unsigned int lcore_id, void *arg) > { > + char ratio_str[RTE_TEL_MAX_STRING_LEN]; > struct lcore_telemetry_usage *u = arg; > struct rte_lcore_usage usage; > rte_lcore_usage_cb usage_cb; > @@ -591,6 +611,8 @@ lcore_telemetry_usage_cb(unsigned int lcore_id, void *arg) > rte_tel_data_add_array_uint(u->lcore_ids, lcore_id); > rte_tel_data_add_array_uint(u->total_cycles, usage.total_cycles); > rte_tel_data_add_array_uint(u->busy_cycles, usage.busy_cycles); > + format_usage_ratio(ratio_str, sizeof(ratio_str), &usage); > + rte_tel_data_add_array_string(u->usage_ratio, ratio_str); > } > > return 0; > @@ -603,15 +625,19 @@ handle_lcore_usage(const char *cmd __rte_unused, const char *params __rte_unused > struct lcore_telemetry_usage usage; > struct rte_tel_data *total_cycles; > struct rte_tel_data *busy_cycles; > + struct rte_tel_data *usage_ratio; > struct rte_tel_data *lcore_ids; > > lcore_ids = rte_tel_data_alloc(); > total_cycles = rte_tel_data_alloc(); > busy_cycles = rte_tel_data_alloc(); > - if (lcore_ids == NULL || total_cycles == NULL || busy_cycles == NULL) { > + usage_ratio = rte_tel_data_alloc(); > + if (lcore_ids == NULL || total_cycles == NULL || busy_cycles == NULL || > + usage_ratio == NULL) { > rte_tel_data_free(lcore_ids); > rte_tel_data_free(total_cycles); > rte_tel_data_free(busy_cycles); > + rte_tel_data_free(usage_ratio); > return -ENOMEM; > } > > @@ -619,12 +645,15 @@ handle_lcore_usage(const char *cmd __rte_unused, const char *params __rte_unused > rte_tel_data_start_array(lcore_ids, RTE_TEL_UINT_VAL); > rte_tel_data_start_array(total_cycles, RTE_TEL_UINT_VAL); > rte_tel_data_start_array(busy_cycles, RTE_TEL_UINT_VAL); > + rte_tel_data_start_array(usage_ratio, RTE_TEL_STRING_VAL); > rte_tel_data_add_dict_container(d, "lcore_ids", lcore_ids, 0); > rte_tel_data_add_dict_container(d, "total_cycles", total_cycles, 0); > rte_tel_data_add_dict_container(d, "busy_cycles", busy_cycles, 0); > + rte_tel_data_add_dict_container(d, "usage_ratio", usage_ratio, 0); > usage.lcore_ids = lcore_ids; > usage.total_cycles = total_cycles; > usage.busy_cycles = busy_cycles; > + usage.usage_ratio = usage_ratio; > > return rte_lcore_iterate(lcore_telemetry_usage_cb, &usage); > }