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

Krishna Kumar krkumar at us.ibm.com
Tue Nov 2 12:09:42 PST 2004


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;
 }

@@ -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;
 	}
 }





More information about the general mailing list