PERFORCE change 96686 for review
Kip Macy
kmacy at FreeBSD.org
Fri May 5 05:22:53 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=96686
Change 96686 by kmacy at kmacy_storage:sun4v_rwbuf on 2006/05/05 05:22:22
switch over to using hash field reference in preparation for handling an arbitrary number of collisions
Affected files ...
.. //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/tte_hash.c#19 edit
Differences ...
==== //depot/projects/kmacy_sun4v/src/sys/sun4v/sun4v/tte_hash.c#19 (text+ko) ====
@@ -224,9 +224,15 @@
free_tte_hash(th);
}
+static __inline void
+tte_hash_set_field(tte_hash_field_t field, uint64_t tag, tte_t tte)
+{
+ field->tte.tag = tag;
+ field->tte.data = tte | (field->tte.data & VTD_LOCK);
+}
static __inline tte_t
-tte_hash_lookup_inline(tte_hash_t th, vm_offset_t va, int *index)
+tte_hash_lookup_inline(tte_hash_t th, vm_offset_t va, tte_hash_field_t *field)
{
uint64_t hash_shift, hash_index;
tte_hash_field_t fields;
@@ -245,8 +251,8 @@
break;
}
}
- if (index)
- *index = i;
+ if (field && i < 4)
+ *field = &fields[i];
/*
* XXX handle the case of collisions > 3
*/
@@ -258,8 +264,8 @@
tte_hash_delete(tte_hash_t th, vm_offset_t va)
{
uint64_t hash_shift, hash_index;
- tte_hash_field_t fields;
- int i, vaindex, lastindex;
+ tte_hash_field_t fields, lookup_field, last_field;
+ int i;
tte_t tte_data;
/* XXX - only handle 8K pages for now */
@@ -270,7 +276,7 @@
hash_bucket_lock(fields);
- tte_data = tte_hash_lookup_inline(th, va, &vaindex);
+ tte_data = tte_hash_lookup_inline(th, va, &lookup_field);
if (tte_data == 0)
goto done;
@@ -279,16 +285,12 @@
for (i = 0; (i < 4) && (fields[i + 1].tte.tag != 0); i++)
;
- lastindex = i;
+ last_field = &fields[i];
- if (vaindex != lastindex) {
- fields[vaindex].tte.tag = fields[lastindex].tte.tag;
- fields[vaindex].tte.data = fields[lastindex].tte.data |
- (fields[vaindex].tte.data & VTD_LOCK);
- }
- fields[lastindex].tte.tag = 0;
- fields[lastindex].tte.data = 0 | (fields[lastindex].tte.data & VTD_LOCK);
-
+ if (lookup_field != last_field)
+ tte_hash_set_field(lookup_field, last_field->tte.tag, last_field->tte.data);
+
+ tte_hash_set_field(last_field, 0, 0);
done:
hash_bucket_unlock_inline(fields);
@@ -300,8 +302,7 @@
{
uint64_t hash_shift, hash_index, tte_tag;
- tte_hash_field_t fields;
- int cookie;
+ tte_hash_field_t fields, lookup_field;
tte_t otte_data;
@@ -313,17 +314,13 @@
tte_tag = (((uint64_t)th->th_context << TTARGET_CTX_SHIFT)|(va >> TTARGET_VA_SHIFT));
hash_bucket_lock(fields);
- otte_data = tte_hash_lookup_inline(th, va, &cookie);
+ otte_data = tte_hash_lookup_inline(th, va, &lookup_field);
#ifdef DEBUG
if (otte_data)
panic("mapping for va=0x%lx already exists tte_data=0x%lx\n", va, otte_data);
#endif
- fields[cookie].tte.data = tte_data | (fields[cookie].tte.data & VTD_LOCK);
- fields[cookie].tte.tag = tte_tag;
-
- if (cookie == 3)
- panic("collision handling unimplemented - please re-consider");
-
+ tte_hash_set_field(lookup_field, tte_tag, tte_data);
+
hash_bucket_unlock_inline(fields);
th->th_entries++;
}
@@ -397,25 +394,25 @@
tte_hash_update(tte_hash_t th, vm_offset_t va, tte_t tte_data)
{
uint64_t hash_shift, hash_index;
- tte_hash_field_t fields;
- int cookie;
+ tte_hash_field_t fields, lookup_field;
tte_t otte_data;
-
+ uint64_t tag;
+
/* XXX - only handle 8K pages for now */
hash_shift = PAGE_SHIFT;
hash_index = (va >> hash_shift) & HASH_MASK(th);
fields = (th->th_hashtable[hash_index].the_fields);
hash_bucket_lock(fields);
- otte_data = tte_hash_lookup_inline(th, va, &cookie);
+ otte_data = tte_hash_lookup_inline(th, va, &lookup_field);
#ifdef TTE_DEBUG
printf("tte_hash_update(va=0x%lx, tte_data=0x%lx, index=%d)\n", va, tte_data, cookie);
#endif
- if (cookie == 3)
- panic("collision handling unimplemented - please re-consider");
+
+ tag = (((uint64_t)th->th_context << TTARGET_CTX_SHIFT)|(va >> TTARGET_VA_SHIFT));
+
+ tte_hash_set_field(lookup_field, tag, tte_data);
- fields[cookie].tte.tag = (((uint64_t)th->th_context << TTARGET_CTX_SHIFT)|(va >> TTARGET_VA_SHIFT));
- fields[cookie].tte.data = tte_data | (fields[cookie].tte.data & VTD_LOCK);
hash_bucket_unlock_inline(fields);
if (otte_data == 0)
More information about the p4-projects
mailing list