Print this page
5042 stop using deprecated atomic functions

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/os/errorq.c
          +++ new/usr/src/uts/common/os/errorq.c
↓ open down ↓ 547 lines elided ↑ open up ↑
 548  548          bcopy(data, eep->eqe_data, MIN(eqp->eq_size, len));
 549  549  
 550  550          if (len < eqp->eq_size)
 551  551                  bzero((caddr_t)eep->eqe_data + len, eqp->eq_size - len);
 552  552  
 553  553          for (;;) {
 554  554                  old = eqp->eq_pend;
 555  555                  eep->eqe_prev = old;
 556  556                  membar_producer();
 557  557  
 558      -                if (casptr(&eqp->eq_pend, old, eep) == old)
      558 +                if (atomic_cas_ptr(&eqp->eq_pend, old, eep) == old)
 559  559                          break;
 560  560          }
 561  561  
 562  562          atomic_add_64(&eqp->eq_kstat.eqk_dispatched.value.ui64, 1);
 563  563  
 564  564          if (flag == ERRORQ_ASYNC && eqp->eq_id != NULL)
 565  565                  ddi_trigger_softintr(eqp->eq_id);
 566  566  }
 567  567  
 568  568  /*
↓ open down ↓ 20 lines elided ↑ open up ↑
 589  589          ASSERT(eqp != NULL);
 590  590          mutex_enter(&eqp->eq_lock);
 591  591  
 592  592          /*
 593  593           * If there are one or more pending errors, set eq_ptail to point to
 594  594           * the first element on the pending list and then attempt to compare-
 595  595           * and-swap NULL to the pending list.  We use membar_producer() to
 596  596           * make sure that eq_ptail will be visible to errorq_panic() below
 597  597           * before the pending list is NULLed out.  This section is labeled
 598  598           * case (1) for errorq_panic, below.  If eq_ptail is not yet set (1A)
 599      -         * eq_pend has all the pending errors.  If casptr fails or has not
 600      -         * been called yet (1B), eq_pend still has all the pending errors.
 601      -         * If casptr succeeds (1C), eq_ptail has all the pending errors.
      599 +         * eq_pend has all the pending errors.  If atomic_cas_ptr fails or
      600 +         * has not been called yet (1B), eq_pend still has all the pending
      601 +         * errors.  If atomic_cas_ptr succeeds (1C), eq_ptail has all the
      602 +         * pending errors.
 602  603           */
 603  604          while ((eep = eqp->eq_pend) != NULL) {
 604  605                  eqp->eq_ptail = eep;
 605  606                  membar_producer();
 606  607  
 607      -                if (casptr(&eqp->eq_pend, eep, NULL) == eep)
      608 +                if (atomic_cas_ptr(&eqp->eq_pend, eep, NULL) == eep)
 608  609                          break;
 609  610          }
 610  611  
 611  612          /*
 612  613           * If no errors were pending, assert that eq_ptail is set to NULL,
 613  614           * drop the consumer lock, and return without doing anything.
 614  615           */
 615  616          if (eep == NULL) {
 616  617                  ASSERT(eqp->eq_ptail == NULL);
 617  618                  mutex_exit(&eqp->eq_lock);
↓ open down ↓ 125 lines elided ↑ open up ↑
 743  744          uint64_t loggedtmp;
 744  745          uint64_t logged = 0;
 745  746  
 746  747          for (eqp = errorq_list; eqp != NULL; eqp = eqp->eq_next) {
 747  748                  if ((eqp->eq_flags & (ERRORQ_VITAL | ERRORQ_NVLIST)) != what)
 748  749                          continue; /* do not drain this queue on this pass */
 749  750  
 750  751                  loggedtmp = eqp->eq_kstat.eqk_logged.value.ui64;
 751  752  
 752  753                  /*
 753      -                 * In case (1B) above, eq_ptail may be set but the casptr may
 754      -                 * not have been executed yet or may have failed.  Either way,
 755      -                 * we must log errors in chronological order.  So we search
 756      -                 * the pending list for the error pointed to by eq_ptail.  If
 757      -                 * it is found, we know that all subsequent errors are also
 758      -                 * still on the pending list, so just NULL out eq_ptail and let
 759      -                 * errorq_drain(), below, take care of the logging.
      754 +                 * In case (1B) above, eq_ptail may be set but the
      755 +                 * atomic_cas_ptr may not have been executed yet or may have
      756 +                 * failed.  Either way, we must log errors in chronological
      757 +                 * order.  So we search the pending list for the error
      758 +                 * pointed to by eq_ptail.  If it is found, we know that all
      759 +                 * subsequent errors are also still on the pending list, so
      760 +                 * just NULL out eq_ptail and let errorq_drain(), below,
      761 +                 * take care of the logging.
 760  762                   */
 761  763                  for (eep = eqp->eq_pend; eep != NULL; eep = eep->eqe_prev) {
 762  764                          if (eep == eqp->eq_ptail) {
 763  765                                  ASSERT(eqp->eq_phead == NULL);
 764  766                                  eqp->eq_ptail = NULL;
 765  767                                  break;
 766  768                          }
 767  769                  }
 768  770  
 769  771                  /*
↓ open down ↓ 13 lines elided ↑ open up ↑
 783  785                          eqp->eq_ptail = NULL;
 784  786                  }
 785  787  
 786  788                  /*
 787  789                   * In cases (3) and (4) above (or after case (1C/2) handling),
 788  790                   * eq_phead will be set to the oldest error on the processing
 789  791                   * list.  We log each error and return it to the free pool.
 790  792                   *
 791  793                   * Unlike errorq_drain(), we don't need to worry about updating
 792  794                   * eq_phead because errorq_panic() will be called at most once.
 793      -                 * However, we must use casptr to update the freelist in case
 794      -                 * errors are still being enqueued during panic.
      795 +                 * However, we must use atomic_cas_ptr to update the
      796 +                 * freelist in case errors are still being enqueued during
      797 +                 * panic.
 795  798                   */
 796  799                  for (eep = eqp->eq_phead; eep != NULL; eep = nep) {
 797  800                          eqp->eq_func(eqp->eq_private, eep->eqe_data, eep);
 798  801                          eqp->eq_kstat.eqk_logged.value.ui64++;
 799  802  
 800  803                          nep = eep->eqe_next;
 801  804                          eep->eqe_next = NULL;
 802  805  
 803  806                          /*
 804  807                           * On panic, we add the element to the dump list for
↓ open down ↓ 102 lines elided ↑ open up ↑
 907  910          if (eqep == NULL || !(eqp->eq_flags & ERRORQ_ACTIVE)) {
 908  911                  atomic_add_64(&eqp->eq_kstat.eqk_commit_fail.value.ui64, 1);
 909  912                  return;
 910  913          }
 911  914  
 912  915          for (;;) {
 913  916                  old = eqp->eq_pend;
 914  917                  eqep->eqe_prev = old;
 915  918                  membar_producer();
 916  919  
 917      -                if (casptr(&eqp->eq_pend, old, eqep) == old)
      920 +                if (atomic_cas_ptr(&eqp->eq_pend, old, eqep) == old)
 918  921                          break;
 919  922          }
 920  923  
 921  924          atomic_add_64(&eqp->eq_kstat.eqk_committed.value.ui64, 1);
 922  925  
 923  926          if (flag == ERRORQ_ASYNC && eqp->eq_id != NULL)
 924  927                  ddi_trigger_softintr(eqp->eq_id);
 925  928  }
 926  929  
 927  930  /*
↓ open down ↓ 107 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX