[Accel-config] Re: [PATCH] accel-config: Refactor handling of cdev_minor at wq enable/disable

Dave Jiang <dave.jiang at intel.com>
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
On 5/18/2021 6:08 PM, ramesh.thomas(a)intel.com wrote:
> From: Ramesh Thomas <ramesh.thomas(a)intel.com>
>
> cdev_minor depends on wq being enabled, of type "user" and in non uacce
> mode. Update the cached value of cdev_minor when wq state changes by
> reading sysfs. If the read fails, a negative value will be stored
> indicating it is not valid for the current state of the wq.
>
> Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
Reviewed-by: Dave Jiang <dave.jiang(a)intel.com>
> ---
>   accfg/lib/libaccfg.c | 64 ++++++--------------------------------------
>   1 file changed, 8 insertions(+), 56 deletions(-)
>
> diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c
> index 0796f08..1463a4d 100644
> --- a/accfg/lib/libaccfg.c
> +++ b/accfg/lib/libaccfg.c
> @@ -1925,62 +1925,16 @@ ACCFG_EXPORT int accfg_wq_priority_boundary(struct accfg_wq *wq)
>   
>   static int accfg_wq_retrieve_cdev_minor(struct accfg_wq *wq)
>   {
> +	int dfd;
>   	struct accfg_ctx *ctx = accfg_wq_get_ctx(wq);
> -	char *path = wq->wq_buf;
> -	char buf[SYSFS_ATTR_SIZE];
> -	int rc;
> -
> -	rc = sprintf(wq->wq_buf, "%s/%s", wq->wq_path, "cdev_minor");
> -	if (rc < 0)
> -		return -errno;
> -
> -	if (sysfs_read_attr(ctx, path, buf) < 0) {
> -		err(ctx, "%s: retrieve cdev minor failed: '%s': %s\n",
> -				__func__, wq->wq_path, strerror(errno));
> -		return -errno;
> -	}
> -
> -	wq->cdev_minor = atoi(buf);
> -	return 0;
> -}
>   
> -static int accfg_wq_post_enable(struct accfg_wq *wq)
> -{
> -	enum accfg_wq_type type;
> -	int rc;
> -
> -	type = accfg_wq_get_type(wq);
> -
> -	if (type == ACCFG_WQT_USER) {
> -		rc = accfg_wq_retrieve_cdev_minor(wq);
> -		if (rc < 0)
> -			return rc;
> -	}
> -
> -	return 0;
> -}
> -
> -static int accfg_wq_post_disable(struct accfg_wq *wq)
> -{
> -	enum accfg_wq_type type;
> -
> -	type = accfg_wq_get_type(wq);
> -
> -	if (type == ACCFG_WQT_USER)
> -		wq->cdev_minor = -1;
> +	dfd = open(wq->wq_path, O_PATH);
> +	if (dfd < 0)
> +		return -ENXIO;
>   
> -	return 0;
> -}
> +	wq->cdev_minor = accfg_get_param_long(ctx, dfd, "cdev_minor");
>   
> -static int accfg_wq_control_post_processing(struct accfg_wq *wq,
> -		enum accfg_control_flag flag)
> -{
> -	if (flag == ACCFG_WQ_ENABLE)
> -		return accfg_wq_post_enable(wq);
> -	else if (flag == ACCFG_WQ_DISABLE)
> -		return accfg_wq_post_disable(wq);
> -	else
> -		return -EINVAL;
> +	close(dfd);
>   
>   	return 0;
>   }
> @@ -2052,10 +2006,8 @@ static int accfg_wq_control(struct accfg_wq *wq, enum accfg_control_flag flag,
>   		return -ENXIO;
>   	}
>   
> -	/* post processing */
> -	rc = accfg_wq_control_post_processing(wq, flag);
> -	if (rc < 0)
> -		return rc;
> +	if (accfg_wq_retrieve_cdev_minor(wq))
> +		return -ENXIO;
>   
>   	return 0;
>   }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.