Print this page
4781 sd shouldn't abuse ddi_get_time(9f)
Reviewed by: Richard Elling <richard.elling@gmail.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/scsi/targets/sd.c
          +++ new/usr/src/uts/common/io/scsi/targets/sd.c
↓ open down ↓ 17 lines elided ↑ open up ↑
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   */
  25   25  /*
  26   26   * Copyright (c) 2011 Bayard G. Bell.  All rights reserved.
  27   27   * Copyright (c) 2012 by Delphix. All rights reserved.
  28      - * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
       28 + * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  29   29   * Copyright 2012 DEY Storage Systems, Inc.  All rights reserved.
  30   30   */
  31   31  /*
  32   32   * Copyright 2011 cyril.galibern@opensvc.com
  33   33   */
  34   34  
  35   35  /*
  36   36   * SCSI disk target driver.
  37   37   */
  38   38  #include <sys/scsi/scsi.h>
↓ open down ↓ 6495 lines elided ↑ open up ↑
6534 6534   *              layers of the driver.
6535 6535   *
6536 6536   *   Arguments: arg - driver soft state (unit) structure
6537 6537   *
6538 6538   *     Context: Executes in a timeout(9F) thread context
6539 6539   */
6540 6540  
6541 6541  static void
6542 6542  sd_pm_idletimeout_handler(void *arg)
6543 6543  {
     6544 +        const hrtime_t idletime = sd_pm_idletime * NANOSEC;
6544 6545          struct sd_lun *un = arg;
6545 6546  
6546      -        time_t  now;
6547      -
6548 6547          mutex_enter(&sd_detach_mutex);
6549 6548          if (un->un_detach_count != 0) {
6550 6549                  /* Abort if the instance is detaching */
6551 6550                  mutex_exit(&sd_detach_mutex);
6552 6551                  return;
6553 6552          }
6554 6553          mutex_exit(&sd_detach_mutex);
6555 6554  
6556      -        now = ddi_get_time();
6557 6555          /*
6558 6556           * Grab both mutexes, in the proper order, since we're accessing
6559 6557           * both PM and softstate variables.
6560 6558           */
6561 6559          mutex_enter(SD_MUTEX(un));
6562 6560          mutex_enter(&un->un_pm_mutex);
6563      -        if (((now - un->un_pm_idle_time) > sd_pm_idletime) &&
     6561 +        if (((gethrtime() - un->un_pm_idle_time) > idletime) &&
6564 6562              (un->un_ncmds_in_driver == 0) && (un->un_pm_count == 0)) {
6565 6563                  /*
6566 6564                   * Update the chain types.
6567 6565                   * This takes affect on the next new command received.
6568 6566                   */
6569 6567                  if (un->un_f_non_devbsize_supported) {
6570 6568                          un->un_buf_chain_type = SD_CHAIN_INFO_RMMEDIA;
6571 6569                  } else {
6572 6570                          un->un_buf_chain_type = SD_CHAIN_INFO_DISK;
6573 6571                  }
↓ open down ↓ 5880 lines elided ↑ open up ↑
12454 12452          if (ddi_xbuf_done(bp, un->un_xbuf_attr)) {
12455 12453                  mutex_enter(SD_MUTEX(un));
12456 12454  
12457 12455                  /*
12458 12456                   * Grab time when the cmd completed.
12459 12457                   * This is used for determining if the system has been
12460 12458                   * idle long enough to make it idle to the PM framework.
12461 12459                   * This is for lowering the overhead, and therefore improving
12462 12460                   * performance per I/O operation.
12463 12461                   */
12464      -                un->un_pm_idle_time = ddi_get_time();
     12462 +                un->un_pm_idle_time = gethrtime();
12465 12463  
12466 12464                  un->un_ncmds_in_driver--;
12467 12465                  ASSERT(un->un_ncmds_in_driver >= 0);
12468 12466                  SD_INFO(SD_LOG_IO, un,
12469 12467                      "sd_buf_iodone: un_ncmds_in_driver = %ld\n",
12470 12468                      un->un_ncmds_in_driver);
12471 12469  
12472 12470                  mutex_exit(SD_MUTEX(un));
12473 12471          }
12474 12472  
↓ open down ↓ 29 lines elided ↑ open up ↑
12504 12502  
12505 12503          mutex_enter(SD_MUTEX(un));
12506 12504  
12507 12505          /*
12508 12506           * Grab time when the cmd completed.
12509 12507           * This is used for determining if the system has been
12510 12508           * idle long enough to make it idle to the PM framework.
12511 12509           * This is for lowering the overhead, and therefore improving
12512 12510           * performance per I/O operation.
12513 12511           */
12514      -        un->un_pm_idle_time = ddi_get_time();
     12512 +        un->un_pm_idle_time = gethrtime();
12515 12513  
12516 12514          un->un_ncmds_in_driver--;
12517 12515          ASSERT(un->un_ncmds_in_driver >= 0);
12518 12516          SD_INFO(SD_LOG_IO, un, "sd_uscsi_iodone: un_ncmds_in_driver = %ld\n",
12519 12517              un->un_ncmds_in_driver);
12520 12518  
12521 12519          mutex_exit(SD_MUTEX(un));
12522 12520  
12523 12521          if (((struct uscsi_cmd *)(xp->xb_pktinfo))->uscsi_rqlen >
12524 12522              SENSE_LENGTH) {
↓ open down ↓ 19298 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX