[openib-general] [RFC] [PATCH] Optimize access to method->agent using bitops

Hal Rosenstock halr at voltaire.com
Tue Nov 2 14:30:39 PST 2004


On Tue, 2004-11-02 at 15:09, Krishna Kumar wrote:
> I am not entirely sure that I understand the bitwise operator being
> used in the code. Following patch is assuming that I have got it
> right :-).
> 
> thanks,
> 
> - KK
> 
> diff -ruNp 5/mad.c 6/mad.c
> --- 5/mad.c	2004-11-02 12:07:51.000000000 -0800
> +++ 6/mad.c	2004-11-02 12:08:32.000000000 -0800
> @@ -537,9 +537,13 @@ static int check_method_table(struct ib_
>  {
>  	int i;
> 
> -	for (i = 0; i < IB_MGMT_MAX_METHODS; i++)
> -		if (method->agent[i])
> -			return 1;
> +	for (i = find_first_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS);
> +	     i < IB_MGMT_MAX_METHODS;
> +	     i = find_next_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS,
> +			       1+i)) {
> +		/* if we entered the loop, we have found an agent bit set */
> +		return 1;
> +	}
>  	return 0;
>  }

This is no longer checking the method table. It is checking the
registration request. Also, a pointer to the registration request
would need to be passed into this routine if it is to be used. 

> @@ -561,11 +565,13 @@ static void remove_methods_mad_agent(str
>  {
>  	int i;
> 
> -	/* Remove any methods for this mad agent */
> -	for (i = 0; i < IB_MGMT_MAX_METHODS; i++) {
> -		if (method->agent[i] == agent) {
> -			method->agent[i] = NULL;
> -		}
> +	/* Remove all methods for this mad agent */
> +	for (i = find_first_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS);
> +	     i < IB_MGMT_MAX_METHODS;
> +	     i = find_next_bit(mad_reg_req->method_mask, IB_MGMT_MAX_METHODS,
> +			       1+i)) {
> +		BUG_ON(method->agent[i] != agent);
> +		method->agent[i] = NULL;
>  	}
>  }

Same compilation issue as above:
A pointer to the registration request would need to be passed into this
routine if it is to be used. 

-- Hal




More information about the general mailing list