lkml.org 
[lkml]   [2023]   [Nov]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH v2 04/26] selftests/resctrl: Refactor get_cbm_mask() and rename to get_full_cbm()
From
Hi Ilpo,

On 11/20/2023 3:13 AM, Ilpo Järvinen wrote:
> Callers of get_cbm_mask() are required to pass a string into which the
> capacity bitmask (CBM) is read. Neither CAT nor CMT tests need the
> bitmask as string but just convert it into an unsigned long value.
>
> Another limitation is that the bit mask reader can only read
> .../cbm_mask files.
>
> Generalize the bit mask reading function into get_bit_mask() such that
> it can be used to handle other files besides the .../cbm_mask and
> handles the unsigned long conversion within get_bit_mask() using
> fscanf(). Change get_cbm_mask() to use get_bit_mask() and rename it to
> get_full_cbm() to better indicates what the function does.

"to better indicates" -> "to better indicate"

>
> Also mark cache_type const while at it and remove useless comments that
> are related to processing of CBM bits.
>
> Co-developed-by: Fenghua Yu <fenghua.yu@intel.com>
> Signed-off-by: Fenghua Yu <fenghua.yu@intel.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---

...

> @@ -229,6 +228,32 @@ int get_cbm_mask(char *cache_type, char *cbm_mask)
> return 0;
> }
>
> +/*
> + * get_full_cbm - Get full Cache Bit Mask (CBM)
> + * @cache_type: Cache type as "L2" or "L3"
> + * @mask: Full cache bit mask representing the maximal portion of cache
> + * available for allocation, returned as unsigned long.
> + *
> + * Return: = 0 on success, < 0 on failure.
> + */
> +int get_full_cbm(const char *cache_type, unsigned long *mask)
> +{
> + char cbm_path[PATH_MAX];
> + int ret;
> +
> + if (!cache_type)
> + return -1;
> +
> + snprintf(cbm_path, sizeof(cbm_path), "%s/%s/cbm_mask",
> + INFO_PATH, cache_type);
> +
> + ret = get_bit_mask(cbm_path, mask);
> + if (ret)
> + return -1;
> +
> + return 0;

Can this just be "return get_bit_mask()" ? But actually, I would
like to propose that this also returns a failure if the returned
mask is zero. This would make the code more robust, especially looking
ahead at utility like cache_portion_size() that divides by this full
mask.

Reinette

\
 
 \ /
  Last update: 2023-11-28 23:11    [W:0.430 / U:0.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site