Print this page
4788 mac shouldn't abuse ddi_get_time(9f)

@@ -20,10 +20,13 @@
  */
 
 /*
  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  */
+/*
+ * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
+ */
 
 #include <sys/strsun.h>
 #include <sys/sdt.h>
 #include <sys/mac.h>
 #include <sys/mac_impl.h>

@@ -139,19 +142,19 @@
  * flooding the network with bogus transactions). They are not meant to be
  * user-modifiable so they are not exposed as linkprops.
  */
 static ulong_t  dhcp_max_pending_txn = 512;
 static ulong_t  dhcp_max_completed_txn = 512;
-static time_t   txn_cleanup_interval = 60;
+static hrtime_t txn_cleanup_interval = 60 * NANOSEC;
 
 /*
  * DHCPv4 transaction. It may be added to three different tables
  * (keyed by different fields).
  */
 typedef struct dhcpv4_txn {
         uint32_t                dt_xid;
-        time_t                  dt_timestamp;
+        hrtime_t                dt_timestamp;
         uint8_t                 dt_cid[DHCP_MAX_OPT_SIZE];
         uint8_t                 dt_cid_len;
         ipaddr_t                dt_ipaddr;
         avl_node_t              dt_node;
         avl_node_t              dt_ipnode;

@@ -184,11 +187,11 @@
  * DHCPv6 transaction. Unlike its v4 counterpart, this object gets freed up
  * as soon as the transaction completes or expires.
  */
 typedef struct dhcpv6_txn {
         uint32_t                dt_xid;
-        time_t                  dt_timestamp;
+        hrtime_t                dt_timestamp;
         dhcpv6_cid_t            *dt_cid;
         avl_node_t              dt_node;
         struct dhcpv6_txn       *dt_next;
 } dhcpv6_txn_t;
 

@@ -453,11 +456,11 @@
 
         if ((txn = kmem_zalloc(sizeof (*txn), KM_NOSLEEP)) == NULL)
                 return (NULL);
 
         txn->dt_xid = xid;
-        txn->dt_timestamp = ddi_get_time();
+        txn->dt_timestamp = gethrtime();
         if (cid_len > 0)
                 bcopy(cid, &txn->dt_cid, cid_len);
         txn->dt_cid_len = cid_len;
         txn->dt_ipaddr = ipaddr;
         return (txn);

@@ -510,12 +513,11 @@
          * Find stale pending transactions and place them on a list
          * to be removed.
          */
         for (txn = avl_first(&mcip->mci_v4_pending_txn); txn != NULL;
             txn = avl_walk(&mcip->mci_v4_pending_txn, txn, AVL_AFTER)) {
-                if (ddi_get_time() - txn->dt_timestamp >
-                    txn_cleanup_interval) {
+                if (gethrtime() - txn->dt_timestamp > txn_cleanup_interval) {
                         DTRACE_PROBE2(found__expired__txn,
                             mac_client_impl_t *, mcip,
                             dhcpv4_txn_t *, txn);
 
                         txn->dt_next = txn_list;

@@ -615,11 +617,11 @@
          * txns for retransmissions.
          */
         if ((txn = find_dhcpv4_pending_txn(mcip, dh4->xid)) != NULL) {
                 DTRACE_PROBE2(update, mac_client_impl_t *, mcip,
                     dhcpv4_txn_t *, txn);
-                txn->dt_timestamp = ddi_get_time();
+                txn->dt_timestamp = gethrtime();
                 goto done;
         }
 
         if (get_dhcpv4_option(dh4, end, CD_REQUESTED_IP_ADDR,
             &opt, &opt_len) != 0 || opt_len != sizeof (ipaddr)) {

@@ -1114,11 +1116,11 @@
         if ((txn = kmem_zalloc(sizeof (dhcpv6_txn_t), KM_NOSLEEP)) == NULL)
                 return (NULL);
 
         txn->dt_xid = xid;
         txn->dt_cid = cid;
-        txn->dt_timestamp = ddi_get_time();
+        txn->dt_timestamp = gethrtime();
         return (txn);
 }
 
 static void
 free_dhcpv6_txn(dhcpv6_txn_t *txn)

@@ -1181,12 +1183,11 @@
          * Find stale pending transactions and place them on a list
          * to be removed.
          */
         for (txn = avl_first(&mcip->mci_v6_pending_txn); txn != NULL;
             txn = avl_walk(&mcip->mci_v6_pending_txn, txn, AVL_AFTER)) {
-                if (ddi_get_time() - txn->dt_timestamp >
-                    txn_cleanup_interval) {
+                if (gethrtime() - txn->dt_timestamp > txn_cleanup_interval) {
                         DTRACE_PROBE2(found__expired__txn,
                             mac_client_impl_t *, mcip,
                             dhcpv6_txn_t *, txn);
 
                         txn->dt_next = txn_list;

@@ -1246,11 +1247,11 @@
         }
         xid = DHCPV6_GET_TRANSID(dh6);
         if ((txn = find_dhcpv6_pending_txn(mcip, xid)) != NULL) {
                 DTRACE_PROBE2(update, mac_client_impl_t *, mcip,
                     dhcpv6_txn_t *, txn);
-                txn->dt_timestamp = ddi_get_time();
+                txn->dt_timestamp = gethrtime();
                 goto done;
         }
         if ((txn = create_dhcpv6_txn(xid, cid)) == NULL)
                 goto done;
 

@@ -1355,22 +1356,22 @@
         if (!avl_is_empty(&mcip->mci_v4_pending_txn) ||
             !avl_is_empty(&mcip->mci_v6_pending_txn)) {
                 DTRACE_PROBE1(restarting__timer, mac_client_impl_t *, mcip);
 
                 mcip->mci_txn_cleanup_tid = timeout(txn_cleanup_timer, mcip,
-                    drv_usectohz(txn_cleanup_interval * 1000000));
+                    drv_usectohz(txn_cleanup_interval / (NANOSEC / MICROSEC)));
         }
         mutex_exit(&mcip->mci_protect_lock);
 }
 
 static void
 start_txn_cleanup_timer(mac_client_impl_t *mcip)
 {
         ASSERT(MUTEX_HELD(&mcip->mci_protect_lock));
         if (mcip->mci_txn_cleanup_tid == 0) {
                 mcip->mci_txn_cleanup_tid = timeout(txn_cleanup_timer, mcip,
-                    drv_usectohz(txn_cleanup_interval * 1000000));
+                    drv_usectohz(txn_cleanup_interval / (NANOSEC / MICROSEC)));
         }
 }
 
 static void
 cancel_txn_cleanup_timer(mac_client_impl_t *mcip)