Print this page
4777 ibdm shouldn't abuse ddi_get_time(9f)
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Albert Lee <albert.lee@nexenta.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/ib/mgt/ibdm/ibdm.c
          +++ new/usr/src/uts/common/io/ib/mgt/ibdm/ibdm.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   */
       24 +/*
       25 + * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
       26 + */
  24   27  
  25   28  /*
  26   29   * ibdm.c
  27   30   *
  28   31   * This file contains the InifiniBand Device Manager (IBDM) support functions.
  29   32   * IB nexus driver will only be the client for the IBDM module.
  30   33   *
  31   34   * IBDM registers with IBTF for HCA arrival/removal notification.
  32   35   * IBDM registers with SA access to send DM MADs to discover the IOC's behind
  33   36   * the IOU's.
  34   37   *
  35   38   * IB nexus driver registers with IBDM to find the information about the
  36   39   * HCA's and IOC's (behind the IOU) present on the IB fabric.
  37   40   */
  38   41  
       42 +#include <sys/sysmacros.h>
  39   43  #include <sys/systm.h>
  40   44  #include <sys/taskq.h>
  41   45  #include <sys/ib/mgt/ibdm/ibdm_impl.h>
  42   46  #include <sys/ib/mgt/ibmf/ibmf_impl.h>
  43   47  #include <sys/ib/ibtl/impl/ibtl_ibnex.h>
  44   48  #include <sys/modctl.h>
  45   49  
  46   50  /* Function Prototype declarations */
  47   51  static int      ibdm_free_iou_info(ibdm_dp_gidinfo_t *, ibdm_iou_info_t **);
  48   52  static int      ibdm_fini(void);
↓ open down ↓ 915 lines elided ↑ open up ↑
 964  968                  kmem_free(hca_attr, sizeof (ibt_hca_attr_t));
 965  969                  (void) ibt_close_hca(hca_hdl);
 966  970                  return;
 967  971          }
 968  972          hca_list = (ibdm_hca_list_t *)
 969  973              kmem_zalloc((sizeof (ibdm_hca_list_t)), KM_SLEEP);
 970  974          hca_list->hl_port_attr = (ibdm_port_attr_t *)kmem_zalloc(
 971  975              (sizeof (ibdm_port_attr_t) * hca_attr->hca_nports), KM_SLEEP);
 972  976          hca_list->hl_hca_guid = hca_attr->hca_node_guid;
 973  977          hca_list->hl_nports = hca_attr->hca_nports;
 974      -        hca_list->hl_attach_time = ddi_get_time();
      978 +        hca_list->hl_attach_time = gethrtime();
 975  979          hca_list->hl_hca_hdl = hca_hdl;
 976  980  
 977  981          /*
 978  982           * Init a dummy port attribute for the HCA node
 979  983           * This is for Per-HCA Node. Initialize port_attr :
 980  984           *      hca_guid & port_guid -> hca_guid
 981  985           *      npkeys, pkey_tbl is NULL
 982  986           *      port_num, sn_prefix is 0
 983  987           *      vendorid, product_id, dev_version from HCA
 984  988           *      pa_state is IBT_PORT_ACTIVE
↓ open down ↓ 3699 lines elided ↑ open up ↑
4684 4688          IBTF_DPRINTF_L4("ibdm", "\tibnex_unregister_callbacks");
4685 4689          mutex_enter(&ibdm.ibdm_ibnex_mutex);
4686 4690          ibdm.ibdm_ibnex_callback = NULL;
4687 4691          mutex_exit(&ibdm.ibdm_ibnex_mutex);
4688 4692  }
4689 4693  
4690 4694  /*
4691 4695   * ibdm_get_waittime()
4692 4696   *      Calculates the wait time based on the last HCA attach time
4693 4697   */
4694      -static time_t
4695      -ibdm_get_waittime(ib_guid_t hca_guid, int dft_wait)
     4698 +static clock_t
     4699 +ibdm_get_waittime(ib_guid_t hca_guid, int dft_wait_sec)
4696 4700  {
4697      -        int             ii;
4698      -        time_t          temp, wait_time = 0;
     4701 +        const hrtime_t  dft_wait = dft_wait_sec * NANOSEC;
     4702 +        hrtime_t        temp, wait_time = 0;
     4703 +        clock_t         usecs;
     4704 +        int             i;
4699 4705          ibdm_hca_list_t *hca;
4700 4706  
4701 4707          IBTF_DPRINTF_L4("ibdm", "\tget_waittime hcaguid:%llx"
4702 4708              "\tport settling time %d", hca_guid, dft_wait);
4703 4709  
4704 4710          ASSERT(mutex_owned(&ibdm.ibdm_hl_mutex));
4705 4711  
4706 4712          hca = ibdm.ibdm_hca_list_head;
4707 4713  
4708      -        if (hca_guid) {
4709      -                for (ii = 0; ii < ibdm.ibdm_hca_count; ii++) {
4710      -                        if ((hca_guid == hca->hl_hca_guid) &&
4711      -                            (hca->hl_nports != hca->hl_nports_active)) {
4712      -                                wait_time =
4713      -                                    ddi_get_time() - hca->hl_attach_time;
4714      -                                wait_time = ((wait_time >= dft_wait) ?
4715      -                                    0 : (dft_wait - wait_time));
4716      -                                break;
4717      -                        }
4718      -                        hca = hca->hl_next;
     4714 +        for (i = 0; i < ibdm.ibdm_hca_count; i++, hca = hca->hl_next) {
     4715 +                if (hca->hl_nports == hca->hl_nports_active)
     4716 +                        continue;
     4717 +
     4718 +                if (hca_guid && (hca_guid != hca->hl_hca_guid))
     4719 +                        continue;
     4720 +
     4721 +                temp = gethrtime() - hca->hl_attach_time;
     4722 +                temp = MAX(0, (dft_wait - temp));
     4723 +
     4724 +                if (hca_guid) {
     4725 +                        wait_time = temp;
     4726 +                        break;
4719 4727                  }
4720      -                IBTF_DPRINTF_L2("ibdm", "\tget_waittime: wait_time = %ld secs",
4721      -                    (long)wait_time);
4722      -                return (wait_time);
     4728 +
     4729 +                wait_time = MAX(temp, wait_time);
4723 4730          }
4724 4731  
4725      -        for (ii = 0; ii < ibdm.ibdm_hca_count; ii++) {
4726      -                if (hca->hl_nports != hca->hl_nports_active) {
4727      -                        temp = ddi_get_time() - hca->hl_attach_time;
4728      -                        temp = ((temp >= dft_wait) ? 0 : (dft_wait - temp));
4729      -                        wait_time = (temp > wait_time) ? temp : wait_time;
4730      -                }
4731      -                hca = hca->hl_next;
4732      -        }
4733      -        IBTF_DPRINTF_L2("ibdm", "\tget_waittime: wait_time = %ld secs",
4734      -            (long)wait_time);
4735      -        return (wait_time);
     4732 +        /* convert to microseconds */
     4733 +        usecs = MIN(wait_time, dft_wait) / (NANOSEC / MICROSEC);
     4734 +
     4735 +        IBTF_DPRINTF_L2("ibdm", "\tget_waittime: wait_time = %ld usecs",
     4736 +            (long)usecs);
     4737 +
     4738 +        return (drv_usectohz(usecs));
4736 4739  }
4737 4740  
4738 4741  void
4739 4742  ibdm_ibnex_port_settle_wait(ib_guid_t hca_guid, int dft_wait)
4740 4743  {
4741      -        time_t wait_time;
4742      -        clock_t delta;
     4744 +        clock_t wait_time;
4743 4745  
4744 4746          mutex_enter(&ibdm.ibdm_hl_mutex);
4745 4747  
4746      -        while ((wait_time = ibdm_get_waittime(hca_guid, dft_wait)) > 0) {
4747      -                if (wait_time > dft_wait) {
4748      -                        IBTF_DPRINTF_L1("ibdm",
4749      -                            "\tibnex_port_settle_wait: wait_time = %ld secs; "
4750      -                            "Resetting to %d secs",
4751      -                            (long)wait_time, dft_wait);
4752      -                        wait_time = dft_wait;
4753      -                }
4754      -                delta = drv_usectohz(wait_time * 1000000);
     4748 +        while ((wait_time = ibdm_get_waittime(hca_guid, dft_wait)) > 0)
4755 4749                  (void) cv_reltimedwait(&ibdm.ibdm_port_settle_cv,
4756      -                    &ibdm.ibdm_hl_mutex, delta, TR_CLOCK_TICK);
4757      -        }
     4750 +                    &ibdm.ibdm_hl_mutex, wait_time, TR_CLOCK_TICK);
4758 4751  
4759 4752          mutex_exit(&ibdm.ibdm_hl_mutex);
4760 4753  }
4761 4754  
4762 4755  
4763 4756  /*
4764 4757   * ibdm_ibnex_probe_hcaport
4765 4758   *      Probes the presence of HCA port (with HCA dip and port number)
4766 4759   *      Returns port attributes structure on SUCCESS
4767 4760   */
↓ open down ↓ 2540 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX