[PATCH] eal: support lcore usage ratio

fengchengwen fengchengwen at huawei.com
Mon Oct 23 14:02:56 CEST 2023


Hi Morten,

On 2023/10/23 16:58, Morten Brørup wrote:
>> From: Chengwen Feng [mailto:fengchengwen at 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 at 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);
>> +}
> 
> .
> 


More information about the dev mailing list