win-pvdrivers

changeset 415:62dc0a1661e3

Performance and stability updates.
author James Harper <james.harper@bendigoit.com.au>
date Mon Aug 18 13:21:02 2008 +1000 (2008-08-18)
parents 7f1dd7920c57
children dd729c3bd53e
files common/include/xen_public.h xenpci/evtchn.c xenpci/gnttbl.c xenpci/xenpci.h xenpci/xenpci_pdo.c xenvbd/scsiport.c
line diff
     1.1 --- a/common/include/xen_public.h	Mon Aug 18 13:20:49 2008 +1000
     1.2 +++ b/common/include/xen_public.h	Mon Aug 18 13:21:02 2008 +1000
     1.3 @@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fi
     1.4  //{5C568AC5-9DDF-4FA5-A94A-39D67077819C}
     1.5  DEFINE_GUID(GUID_XEN_IFACE, 0x5C568AC5, 0x9DDF, 0x4FA5, 0xA9, 0x4A, 0x39, 0xD6, 0x70, 0x77, 0x81, 0x9C);
     1.6  
     1.7 +#define INVALID_GRANT_REF 0xFFFFFFFF
     1.8 +
     1.9  typedef PHYSICAL_ADDRESS
    1.10  (*PXEN_ALLOCMMIO)(PVOID Context, ULONG Length);
    1.11  
     2.1 --- a/xenpci/evtchn.c	Mon Aug 18 13:20:49 2008 +1000
     2.2 +++ b/xenpci/evtchn.c	Mon Aug 18 13:21:02 2008 +1000
     2.3 @@ -107,9 +107,11 @@ EvtChn_Interrupt(PKINTERRUPT Interrupt, 
     2.4          ev_action->ServiceRoutine(NULL, ev_action->ServiceContext);
     2.5          break;
     2.6        case EVT_ACTION_TYPE_IRQ:
     2.7 +/*
     2.8          synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
     2.9          sw_interrupt((UCHAR)ev_action->vector);
    2.10          break;
    2.11 +*/
    2.12        case EVT_ACTION_TYPE_DPC:
    2.13          synch_clear_bit(evt_bit, (volatile xen_long_t *)&shared_info_area->evtchn_pending[evt_word]);
    2.14          KeInsertQueueDpc(&ev_action->Dpc, NULL, NULL);
     3.1 --- a/xenpci/gnttbl.c	Mon Aug 18 13:20:49 2008 +1000
     3.2 +++ b/xenpci/gnttbl.c	Mon Aug 18 13:21:02 2008 +1000
     3.3 @@ -30,8 +30,8 @@ GntTbl_PutRef(PVOID Context, grant_ref_t
     3.4      ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
     3.5      KeAcquireSpinLock(&xpdd->grant_lock, &OldIrql);
     3.6    }
     3.7 -  xpdd->gnttab_list[ref] = xpdd->gnttab_list[0];
     3.8 -  xpdd->gnttab_list[0]  = ref;
     3.9 +  xpdd->gnttab_list[xpdd->gnttab_list_free] = ref;
    3.10 +  xpdd->gnttab_list_free++;
    3.11    if (xpdd->suspend_state != SUSPEND_STATE_HIGH_IRQL)
    3.12    {
    3.13      KeReleaseSpinLock(&xpdd->grant_lock, OldIrql);
    3.14 @@ -44,20 +44,26 @@ GntTbl_GetRef(PVOID Context)
    3.15    PXENPCI_DEVICE_DATA xpdd = Context;
    3.16    unsigned int ref;
    3.17    KIRQL OldIrql = PASSIVE_LEVEL;
    3.18 +  int suspend_state = xpdd->suspend_state;
    3.19    
    3.20    UNREFERENCED_PARAMETER(OldIrql);
    3.21  
    3.22 -  if (xpdd->suspend_state != SUSPEND_STATE_HIGH_IRQL)
    3.23 +  if (suspend_state != SUSPEND_STATE_HIGH_IRQL)
    3.24    {
    3.25      ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
    3.26      KeAcquireSpinLock(&xpdd->grant_lock, &OldIrql);
    3.27    }
    3.28 -  ref = xpdd->gnttab_list[0];
    3.29 -  xpdd->gnttab_list[0] = xpdd->gnttab_list[ref];
    3.30 -  if (xpdd->suspend_state != SUSPEND_STATE_HIGH_IRQL)
    3.31 +  if (!xpdd->gnttab_list_free)
    3.32    {
    3.33 +    if (suspend_state != SUSPEND_STATE_HIGH_IRQL)
    3.34 +      KeReleaseSpinLock(&xpdd->grant_lock, OldIrql);
    3.35 +    KdPrint((__DRIVER_NAME "     No free grant refs\n"));    
    3.36 +    return INVALID_GRANT_REF;
    3.37 +  }
    3.38 +  xpdd->gnttab_list_free--;
    3.39 +  ref = xpdd->gnttab_list[xpdd->gnttab_list_free];
    3.40 +  if (suspend_state != SUSPEND_STATE_HIGH_IRQL)
    3.41      KeReleaseSpinLock(&xpdd->grant_lock, OldIrql);
    3.42 -  }
    3.43  
    3.44    return ref;
    3.45  }
    3.46 @@ -98,13 +104,17 @@ GntTbl_GrantAccess(
    3.47  
    3.48    //KdPrint((__DRIVER_NAME "     Granting access to frame %08x\n", frame));
    3.49  
    3.50 -  if (ref == 0)
    3.51 +  if (ref == INVALID_GRANT_REF)
    3.52      ref = GntTbl_GetRef(Context);
    3.53 +  if (ref == INVALID_GRANT_REF)
    3.54 +    return ref;
    3.55 +  
    3.56    xpdd->gnttab_table[ref].frame = frame;
    3.57    xpdd->gnttab_table[ref].domid = domid;
    3.58  
    3.59    if (xpdd->gnttab_table[ref].flags)
    3.60      KdPrint((__DRIVER_NAME "     WARNING: Attempting to re-use grant entry that is already in use!\n"));
    3.61 +  ASSERT(!xpdd->gnttab_table[ref].flags);
    3.62  
    3.63    KeMemoryBarrier();
    3.64    readonly *= GTF_readonly;
    3.65 @@ -147,6 +157,8 @@ GntTbl_EndAccess(
    3.66  
    3.67    //KdPrint((__DRIVER_NAME " --> GntTbl_EndAccess\n"));
    3.68  
    3.69 +  ASSERT(ref != INVALID_GRANT_REF);
    3.70 +  
    3.71    nflags = xpdd->gnttab_table[ref].flags;
    3.72    do {
    3.73      if ((flags = nflags) & (GTF_reading|GTF_writing))
    3.74 @@ -221,6 +233,7 @@ GntTbl_InitMap(PXENPCI_DEVICE_DATA xpdd)
    3.75      xpdd->max_grant_frames = grant_frames;
    3.76    }
    3.77    RtlZeroMemory(xpdd->gnttab_list, sizeof(grant_ref_t) * grant_entries);
    3.78 +  xpdd->gnttab_list_free = 0;
    3.79    for (i = NR_RESERVED_ENTRIES; i < grant_entries; i++)
    3.80      GntTbl_PutRef(xpdd, i);
    3.81    
     4.1 --- a/xenpci/xenpci.h	Mon Aug 18 13:20:49 2008 +1000
     4.2 +++ b/xenpci/xenpci.h	Mon Aug 18 13:21:02 2008 +1000
     4.3 @@ -191,6 +191,7 @@ typedef struct {
     4.4    grant_entry_t *gnttab_table;
     4.5    PHYSICAL_ADDRESS gnttab_table_physical;
     4.6    grant_ref_t *gnttab_list;
     4.7 +  int gnttab_list_free;
     4.8    /* this is the maximum number of grant frames we have memory allocated for */
     4.9    /* after a resume it may not be the actual number of grant frames we have though */
    4.10    ULONG max_grant_frames;
    4.11 @@ -241,7 +242,6 @@ typedef struct {
    4.12    XENPCI_COMMON common;
    4.13    PDEVICE_OBJECT bus_pdo;
    4.14    PDEVICE_OBJECT bus_fdo;
    4.15 -  BOOLEAN eject_requested;
    4.16    BOOLEAN reported_missing;
    4.17    char path[128];
    4.18    char device[128];
     5.1 --- a/xenpci/xenpci_pdo.c	Mon Aug 18 13:20:49 2008 +1000
     5.2 +++ b/xenpci/xenpci_pdo.c	Mon Aug 18 13:21:02 2008 +1000
     5.3 @@ -186,7 +186,6 @@ XenPci_BackEndStateHandler(char *path, P
     5.4          if (xppdd->common.current_pnp_state == Started)
     5.5          {
     5.6            KdPrint((__DRIVER_NAME "     Sending RequestDeviceEject\n"));
     5.7 -          xppdd->eject_requested = TRUE;
     5.8            IoRequestDeviceEject(xppdd->common.pdo);
     5.9          }
    5.10          else
    5.11 @@ -526,7 +525,7 @@ XenPci_XenConfigDeviceSpecifyBuffers(PVO
    5.12          //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_RING - %s = %p\n", setting, address));
    5.13          SHARED_RING_INIT((struct dummy_sring *)address);
    5.14          if ((gref = GntTbl_GrantAccess(
    5.15 -          xpdd, 0, (ULONG)*MmGetMdlPfnArray(ring), FALSE, 0)) != 0)
    5.16 +          xpdd, 0, (ULONG)*MmGetMdlPfnArray(ring), FALSE, INVALID_GRANT_REF)) != INVALID_GRANT_REF)
    5.17          {
    5.18            RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
    5.19            XenBus_Printf(xpdd, XBT_NIL, path, "%d", gref);
    5.20 @@ -620,8 +619,9 @@ XenPci_XenConfigDeviceSpecifyBuffers(PVO
    5.21        __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, PtrToUlong(value));
    5.22        for (i = 0; i < PtrToUlong(value); i++)
    5.23        {
    5.24 -        __ADD_XEN_INIT_ULONG(&out_ptr, GntTbl_GetRef(xpdd));
    5.25 -        __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, GntTbl_GetRef(xpdd));
    5.26 +        gref = GntTbl_GetRef(xpdd);
    5.27 +        __ADD_XEN_INIT_ULONG(&out_ptr, gref);
    5.28 +        __ADD_XEN_INIT_ULONG(&xppdd->assigned_resources_ptr, gref);
    5.29        }
    5.30        break;
    5.31      }
    5.32 @@ -1094,15 +1094,8 @@ XenPci_Pnp_Pdo(PDEVICE_OBJECT device_obj
    5.33  
    5.34    case IRP_MN_QUERY_REMOVE_DEVICE:
    5.35      KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_REMOVE_DEVICE (status = %08x)\n", irp->IoStatus.Status));
    5.36 -    if (xppdd->eject_requested)
    5.37 -    {
    5.38 -      SET_PNP_STATE(&xppdd->common, RemovePending);
    5.39 -      status = STATUS_SUCCESS;
    5.40 -    }
    5.41 -    else
    5.42 -    {
    5.43 -      status = STATUS_UNSUCCESSFUL;
    5.44 -    }
    5.45 +    SET_PNP_STATE(&xppdd->common, RemovePending);
    5.46 +    status = STATUS_SUCCESS;
    5.47      break;
    5.48  
    5.49    case IRP_MN_REMOVE_DEVICE:
     6.1 --- a/xenvbd/scsiport.c	Mon Aug 18 13:20:49 2008 +1000
     6.2 +++ b/xenvbd/scsiport.c	Mon Aug 18 13:21:02 2008 +1000
     6.3 @@ -213,10 +213,14 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
     6.4          memcpy(&xvdd->vectors, value, sizeof(XENPCI_VECTORS));
     6.5        break;
     6.6      case XEN_INIT_TYPE_GRANT_ENTRIES:
     6.7 -      //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
     6.8 +      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
     6.9        xvdd->grant_entries = (USHORT)PtrToUlong(setting);
    6.10        memcpy(&xvdd->grant_free_list, value, sizeof(grant_ref_t) * xvdd->grant_entries);
    6.11        xvdd->grant_free = xvdd->grant_entries;
    6.12 +      for (i = 0; i < xvdd->grant_entries; i++)
    6.13 +      {
    6.14 +        KdPrint((__DRIVER_NAME "     grant_entry = %d\n", xvdd->grant_free_list[i]));
    6.15 +      }
    6.16        break;
    6.17      case XEN_INIT_TYPE_STATE_PTR:
    6.18        //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
    6.19 @@ -345,7 +349,7 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
    6.20      physical_address = MmGetPhysicalAddress(ptr);
    6.21      pfn = (ULONG)(physical_address.QuadPart >> PAGE_SHIFT);
    6.22      shadow->req.seg[shadow->req.nr_segments].gref = get_grant_from_freelist(xvdd);
    6.23 -    ASSERT(shadow->req.seg[shadow->req.nr_segments].gref);
    6.24 +    ASSERT(shadow->req.seg[shadow->req.nr_segments].gref != INVALID_GRANT_REF);
    6.25      xvdd->vectors.GntTbl_GrantAccess(xvdd->vectors.context, 0, pfn, 0, shadow->req.seg[shadow->req.nr_segments].gref);
    6.26      offset = (ULONG)(physical_address.QuadPart & (PAGE_SIZE - 1));
    6.27      ASSERT((offset & 511) == 0);
    6.28 @@ -667,6 +671,8 @@ XenVbd_MakeAutoSense(PXENVBD_DEVICE_DATA
    6.29    srb->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
    6.30  }
    6.31  
    6.32 +static ULONG counter = 0;
    6.33 +
    6.34  static BOOLEAN DDKAPI
    6.35  XenVbd_HwScsiInterrupt(PVOID DeviceExtension)
    6.36  {
    6.37 @@ -682,6 +688,10 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
    6.38  
    6.39    //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    6.40  
    6.41 +  if (counter & 0xFF == 0)
    6.42 +  {
    6.43 +    KdPrint((__DRIVER_NAME "     SCSI ISR IRQL = %d\n", KeGetCurrentIrql()));
    6.44 +  }
    6.45    if (xvdd->device_state->resume_state != RESUME_STATE_RUNNING)
    6.46    {
    6.47      //KdPrint((__DRIVER_NAME " --- " __FUNCTION__ " device_state event\n"));
    6.48 @@ -752,7 +762,8 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
    6.49          }
    6.50          for (j = 0; j < shadow->req.nr_segments; j++)
    6.51          {
    6.52 -          xvdd->vectors.GntTbl_EndAccess(xvdd->vectors.context, shadow->req.seg[j].gref, TRUE);
    6.53 +          BOOLEAN result = xvdd->vectors.GntTbl_EndAccess(xvdd->vectors.context, shadow->req.seg[j].gref, TRUE);
    6.54 +          ASSERT(result);
    6.55            put_grant_on_freelist(xvdd, shadow->req.seg[j].gref);
    6.56          }
    6.57  
    6.58 @@ -1122,12 +1133,12 @@ XenVbd_HwScsiResetBus(PVOID DeviceExtens
    6.59    UNREFERENCED_PARAMETER(DeviceExtension);
    6.60    UNREFERENCED_PARAMETER(PathId);
    6.61  
    6.62 -//  KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
    6.63 +  KdPrint((__DRIVER_NAME " --> HwScsiResetBus\n"));
    6.64  
    6.65 -//  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    6.66 +  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    6.67    ScsiPortNotification(NextRequest, DeviceExtension);
    6.68  
    6.69 -//  KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
    6.70 +  KdPrint((__DRIVER_NAME " <-- HwScsiResetBus\n"));
    6.71  
    6.72  
    6.73    return TRUE;