* [PATCH] eal: support lcore usage ratio
@ 2023-10-23 4:08 Chengwen Feng
2023-10-23 8:58 ` Morten Brørup
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Chengwen Feng @ 2023-10-23 4:08 UTC (permalink / raw)
To: thomas, ferruh.yigit; +Cc: dev
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 <fengchengwen@huawei.com>
---
lib/eal/common/eal_common_lcore.c | 34 ++++++++++++++++++++++++++++---
1 file changed, 31 insertions(+), 3 deletions(-)
diff --git a/lib/eal/common/eal_common_lcore.c b/lib/eal/common/eal_common_lcore.c
index ceda714ca5..d1d0da2dd0 100644
--- a/lib/eal/common/eal_common_lcore.c
+++ b/lib/eal/common/eal_common_lcore.c
@@ -446,6 +446,12 @@ 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->busy_cycles * 100.0) / (usage->total_cycles == 0 ? 1 : usage->total_cycles);
+}
+
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%%)",
+ 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);
+}
+
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 +559,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 +591,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 +610,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 +624,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 +644,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);
}
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] eal: support lcore usage ratio
2023-10-23 4:08 [PATCH] eal: support lcore usage ratio Chengwen Feng
@ 2023-10-23 8:58 ` Morten Brørup
2023-10-23 12:02 ` fengchengwen
2023-10-23 12:29 ` [PATCH v2] " Chengwen Feng
2023-10-23 12:51 ` [PATCH v3] " Chengwen Feng
2 siblings, 1 reply; 8+ messages in thread
From: Morten Brørup @ 2023-10-23 8:58 UTC (permalink / raw)
To: Chengwen Feng, thomas, ferruh.yigit; +Cc: dev
> 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?
>
> 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;
> +
> 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.
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);
> +}
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] eal: support lcore usage ratio
2023-10-23 8:58 ` Morten Brørup
@ 2023-10-23 12:02 ` fengchengwen
0 siblings, 0 replies; 8+ messages in thread
From: fengchengwen @ 2023-10-23 12:02 UTC (permalink / raw)
To: Morten Brørup, thomas, ferruh.yigit; +Cc: dev
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);
>> +}
>
> .
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2] eal: support lcore usage ratio
2023-10-23 4:08 [PATCH] eal: support lcore usage ratio Chengwen Feng
2023-10-23 8:58 ` Morten Brørup
@ 2023-10-23 12:29 ` Chengwen Feng
2023-10-23 12:42 ` Morten Brørup
2023-10-23 12:51 ` [PATCH v3] " Chengwen Feng
2 siblings, 1 reply; 8+ messages in thread
From: Chengwen Feng @ 2023-10-23 12:29 UTC (permalink / raw)
To: thomas, ferruh.yigit; +Cc: dev, mb
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 <fengchengwen@huawei.com>
---
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..3135540941 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 %.2f%%)",
+ 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, "%.2f%%", 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);
}
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH v2] eal: support lcore usage ratio
2023-10-23 12:29 ` [PATCH v2] " Chengwen Feng
@ 2023-10-23 12:42 ` Morten Brørup
0 siblings, 0 replies; 8+ messages in thread
From: Morten Brørup @ 2023-10-23 12:42 UTC (permalink / raw)
To: Chengwen Feng, thomas, ferruh.yigit; +Cc: dev
> From: Chengwen Feng [mailto:fengchengwen@huawei.com]
> Sent: Monday, 23 October 2023 14.29
>
> 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.
[...]
> @@ -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 %.2f%%)",
The zero is missing in %.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, "%.2f%%", ratio);
Also zero missing in "%.02f%%" here.
With the two missing zeroes added,
Acked-by: Morten Brørup <mb@smartsharesystems.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3] eal: support lcore usage ratio
2023-10-23 4:08 [PATCH] eal: support lcore usage ratio Chengwen Feng
2023-10-23 8:58 ` Morten Brørup
2023-10-23 12:29 ` [PATCH v2] " Chengwen Feng
@ 2023-10-23 12:51 ` Chengwen Feng
2023-10-31 13:22 ` lihuisong (C)
2023-11-06 16:38 ` Thomas Monjalon
2 siblings, 2 replies; 8+ messages in thread
From: Chengwen Feng @ 2023-10-23 12:51 UTC (permalink / raw)
To: thomas, ferruh.yigit; +Cc: dev, mb
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 <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
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);
}
--
2.17.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] eal: support lcore usage ratio
2023-10-23 12:51 ` [PATCH v3] " Chengwen Feng
@ 2023-10-31 13:22 ` lihuisong (C)
2023-11-06 16:38 ` Thomas Monjalon
1 sibling, 0 replies; 8+ messages in thread
From: lihuisong (C) @ 2023-10-31 13:22 UTC (permalink / raw)
To: Chengwen Feng, thomas, ferruh.yigit; +Cc: dev, mb
lgtm,
Acked-by: Huisong Li <lihuisong@huawei.com>
在 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 <fengchengwen@huawei.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
>
> ---
> 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);
> }
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] eal: support lcore usage ratio
2023-10-23 12:51 ` [PATCH v3] " Chengwen Feng
2023-10-31 13:22 ` lihuisong (C)
@ 2023-11-06 16:38 ` Thomas Monjalon
1 sibling, 0 replies; 8+ messages in thread
From: Thomas Monjalon @ 2023-11-06 16:38 UTC (permalink / raw)
To: Chengwen Feng; +Cc: ferruh.yigit, dev, mb
23/10/2023 14: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 <fengchengwen@huawei.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
Added "telemetry" in the title,
and applied, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-11-06 16:38 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23 4:08 [PATCH] eal: support lcore usage ratio Chengwen Feng
2023-10-23 8:58 ` Morten Brørup
2023-10-23 12:02 ` fengchengwen
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
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).