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 F2535431E2; Mon, 23 Oct 2023 14:03:00 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E223440A77; Mon, 23 Oct 2023 14:03:00 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 65ADC40270 for ; Mon, 23 Oct 2023 14:02:59 +0200 (CEST) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SDYd90hXyzVm88; Mon, 23 Oct 2023 19:59:09 +0800 (CST) Received: from [10.67.121.161] (10.67.121.161) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 23 Oct 2023 20:02:56 +0800 Subject: Re: [PATCH] eal: support lcore usage ratio To: =?UTF-8?Q?Morten_Br=c3=b8rup?= , , CC: References: <20231023040811.46038-1-fengchengwen@huawei.com> <98CBD80474FA8B44BF855DF32C47DC35E9EF6A@smartserver.smartshare.dk> From: fengchengwen Message-ID: <93e66e30-6095-ef96-16e7-8f2b946d9eab@huawei.com> Date: Mon, 23 Oct 2023 20:02:56 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9EF6A@smartserver.smartshare.dk> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.121.161] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml100024.china.huawei.com (7.185.36.115) 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 Hi Morten, On 2023/10/23 16:58, Morten Brørup wrote: >> From: Chengwen Feng [mailto:fengchengwen@huawei.com] >> Sent: Monday, 23 October 2023 06.08 >> >> 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. > > Usage ratio in percentage is only useful if it doesn't vary much over time. Which use cases don't have a varying traffic pattern with busy hours and off-peak hours? Yes, it indeed. There have too way: 1\ only compare increment of busy&total, which this ratio have less reference. 2\ clean the busy&total before do an metrics, then this ratio become usefull > >> >> Signed-off-by: Chengwen Feng >> --- > > [...] > >> +static float >> +calc_usage_ratio(const struct rte_lcore_usage *usage) >> +{ >> + return (usage->busy_cycles * 100.0) / (usage->total_cycles == 0 ? 1 : >> usage->total_cycles); >> +} > > This correctly prevents division by zero. If total_cycles by some freak accident isn't updated, the result will be a very big number. You might consider this alternative: > > return usage->total_cycles != 0 ? (usage->busy_cycles * 100.0) / usage->total_cycles : (float)0; ok > >> + >> static int >> lcore_dump_cb(unsigned int lcore_id, void *arg) >> { >> @@ -462,8 +468,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 %.3f%%)", > > Is "%.3f%%" the community preference for human readable CPU usage percentages? > > I prefer "%.02f%%", but don't object to the suggested format. maybe %.02f is more common, will change in v2 > > NB: The format also applies to format_usage_ratio() below. > >> + usage.busy_cycles, usage.total_cycles, >> + calc_usage_ratio(&usage)) < 0) { >> return -ENOMEM; >> } >> } >> @@ -511,11 +518,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, "%.3f%%", ratio); >> +} > > . >