From: fengchengwen <fengchengwen@huawei.com>
To: "Morten Brørup" <mb@smartsharesystems.com>,
thomas@monjalon.net, ferruh.yigit@amd.com
Cc: <dev@dpdk.org>
Subject: Re: [PATCH] eal: support lcore usage ratio
Date: Mon, 23 Oct 2023 20:02:56 +0800 [thread overview]
Message-ID: <93e66e30-6095-ef96-16e7-8f2b946d9eab@huawei.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9EF6A@smartserver.smartshare.dk>
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 <fengchengwen@huawei.com>
>> ---
>
> [...]
>
>> +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);
>> +}
>
> .
>
next prev parent reply other threads:[~2023-10-23 12:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 4:08 Chengwen Feng
2023-10-23 8:58 ` Morten Brørup
2023-10-23 12:02 ` fengchengwen [this message]
2023-10-23 12:29 ` [PATCH v2] " Chengwen Feng
2023-10-23 12:42 ` Morten Brørup
2023-10-23 12:51 ` [PATCH v3] " Chengwen Feng
2023-10-31 13:22 ` lihuisong (C)
2023-11-06 16:38 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=93e66e30-6095-ef96-16e7-8f2b946d9eab@huawei.com \
--to=fengchengwen@huawei.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=mb@smartsharesystems.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).