[PATCH v4.7 4/7] net/ncsi: Rework request index allocation

Joel Stanley joel at jms.id.au
Wed Sep 28 15:34:59 AEST 2016


On Wed, 2016-09-28 at 12:48 +1000, Gavin Shan wrote:
> This reworks request index allocation for: (A) @ndp->request_id
> should
> represent last allocated request index instead of accumulated request
> indexes; (B) The request index (1) is reserved according to section
> 6.3.1.1 in v1.1.0 NCSI spec.
> 
> Signed-off-by: Gavin Shan <gwshan at linux.vnet.ibm.com>

The commit message could be clearer. Code makes sense though.

Signed-off-by: Joel Stanley <joel at jms.id.au>

> ---
>  net/ncsi/internal.h    |  1 +
>  net/ncsi/ncsi-manage.c | 17 +++++++++--------
>  2 files changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/net/ncsi/internal.h b/net/ncsi/internal.h
> index 0a5c580..821f1d3 100644
> --- a/net/ncsi/internal.h
> +++ b/net/ncsi/internal.h
> @@ -259,6 +259,7 @@ struct ncsi_dev_priv {
>  	struct list_head    packages;        /* List of
> packages           */
>  	struct ncsi_request requests[256];   /* Request
> table              */
>  	unsigned int        request_id;      /* Last used request
> ID       */
> +#define NCSI_REQ_START_IDX	1
>  	unsigned int        pending_req_num; /* Number of pending
> requests */
>  	struct ncsi_package *active_package; /* Currently handled
> package  */
>  	struct ncsi_channel *active_channel; /* Currently handled
> channel  */
> diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
> index 8011d51..282be06 100644
> --- a/net/ncsi/ncsi-manage.c
> +++ b/net/ncsi/ncsi-manage.c
> @@ -415,30 +415,31 @@ struct ncsi_request *ncsi_alloc_request(struct
> ncsi_dev_priv *ndp, bool driven)
>  
>  	/* Check if there is one available request until the ceiling
> */
>  	spin_lock_irqsave(&ndp->lock, flags);
> -	for (i = ndp->request_id; !nr && i < limit; i++) {
> +	for (i = ndp->request_id; i < limit; i++) {
>  		if (ndp->requests[i].used)
>  			continue;
>  
>  		nr = &ndp->requests[i];
>  		nr->used = true;
>  		nr->driven = driven;
> -		if (++ndp->request_id >= limit)
> -			ndp->request_id = 0;
> +		ndp->request_id = i + 1;
> +		goto found;
>  	}
>  
>  	/* Fail back to check from the starting cursor */
> -	for (i = 0; !nr && i < ndp->request_id; i++) {
> +	for (i = NCSI_REQ_START_IDX; i < ndp->request_id; i++) {
>  		if (ndp->requests[i].used)
>  			continue;
>  
>  		nr = &ndp->requests[i];
>  		nr->used = true;
>  		nr->driven = driven;
> -		if (++ndp->request_id >= limit)
> -			ndp->request_id = 0;
> +		ndp->request_id = i + 1;
> +		goto found;
>  	}
> -	spin_unlock_irqrestore(&ndp->lock, flags);
>  
> +found:
> +	spin_unlock_irqrestore(&ndp->lock, flags);
>  	return nr;
>  }
>  
> @@ -1121,7 +1122,7 @@ struct ncsi_dev *ncsi_register_dev(struct
> net_device *dev,
>  	/* Initialize private NCSI device */
>  	spin_lock_init(&ndp->lock);
>  	INIT_LIST_HEAD(&ndp->packages);
> -	ndp->request_id = 0;
> +	ndp->request_id = NCSI_REQ_START_IDX;
>  	for (i = 0; i < ARRAY_SIZE(ndp->requests); i++) {
>  		ndp->requests[i].id = i;
>  		ndp->requests[i].ndp = ndp;
> 


More information about the openbmc mailing list