From owner-p4-projects@FreeBSD.ORG Fri May 5 05:22:53 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 371DC16A402; Fri, 5 May 2006 05:22:53 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EBECC16A401 for ; Fri, 5 May 2006 05:22:52 +0000 (UTC) (envelope-from kmacy@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id AF9FD43D45 for ; Fri, 5 May 2006 05:22:52 +0000 (GMT) (envelope-from kmacy@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k455Mq9r009685 for ; Fri, 5 May 2006 05:22:52 GMT (envelope-from kmacy@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k455MqpW009676 for perforce@freebsd.org; Fri, 5 May 2006 05:22:52 GMT (envelope-from kmacy@freebsd.org) Date: Fri, 5 May 2006 05:22:52 GMT Message-Id: <200605050522.k455MqpW009676@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to kmacy@freebsd.org using -f From: Kip Macy To: Perforce Change Reviews Cc: Subject: PERFORCE change 96686 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 May 2006 05:22:53 -0000 http://perforce.freebsd.org/chv.cgi?CH=96686 Change 96686 by kmacy@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)