Re: [PATCH 8/8] tools: intel_sdsi: Add current meter support

From: Ilpo Järvinen
Date: Thu Feb 08 2024 - 09:53:16 EST


On Wed, 31 Jan 2024, David E. Box wrote:

> Add support to read the 'meter_current' file. The display is the same as
> the 'meter_certificate', but will show the current snapshot of the
> counters.
>
> Signed-off-by: David E. Box <david.e.box@xxxxxxxxxxxxxxx>
> ---
> tools/arch/x86/intel_sdsi/intel_sdsi.c | 48 +++++++++++++++++---------
> 1 file changed, 31 insertions(+), 17 deletions(-)
>
> diff --git a/tools/arch/x86/intel_sdsi/intel_sdsi.c b/tools/arch/x86/intel_sdsi/intel_sdsi.c
> index a8fb6d17405f..c9b3e457885d 100644
> --- a/tools/arch/x86/intel_sdsi/intel_sdsi.c
> +++ b/tools/arch/x86/intel_sdsi/intel_sdsi.c
> @@ -182,6 +182,7 @@ struct sdsi_dev {
> enum command {
> CMD_SOCKET_INFO,
> CMD_METER_CERT,
> + CMD_METER_CURRENT_CERT,
> CMD_STATE_CERT,
> CMD_PROV_AKC,
> CMD_PROV_CAP,
> @@ -329,7 +330,7 @@ static void get_feature(uint32_t encoding, char *feature)
> feature[0] = name[3];
> }
>
> -static int sdsi_meter_cert_show(struct sdsi_dev *s)
> +static int sdsi_meter_cert_show(struct sdsi_dev *s, bool show_current)
> {
> char buf[METER_CERT_MAX_SIZE] = {0};
> struct bundle_encoding_counter *bec;
> @@ -360,7 +361,11 @@ static int sdsi_meter_cert_show(struct sdsi_dev *s)
> return ret;
> }
>
> - cert_ptr = fopen("meter_certificate", "r");
> + if (!show_current)
> + cert_ptr = fopen("meter_certificate", "r");
> + else
> + cert_ptr = fopen("meter_current", "r");

Please calculate the filename only once:

cert_fname = show_current ? "meter_current" : "meter_certificate";
cert_ptr = fopen(cert_fname, "r");

> +
> if (!cert_ptr) {
> perror("Could not open 'meter_certificate' file");

This line still has 'meter_certificate' so you need to convert it to
fprintf() + strerror().

> return -1;
> @@ -368,7 +373,8 @@ static int sdsi_meter_cert_show(struct sdsi_dev *s)
>
> size = fread(buf, 1, sizeof(buf), cert_ptr);
> if (!size) {
> - fprintf(stderr, "Could not read 'meter_certificate' file\n");
> + fprintf(stderr, "Could not read '%s' file\n",
> + show_current ? "meter_current" : "meter_certificate");

Use the local variable from above.

--
i.