Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/ipp/flowacct/flowacct.c
          +++ new/usr/src/uts/common/ipp/flowacct/flowacct.c
↓ open down ↓ 488 lines elided ↑ open up ↑
 489  489          item = flowacct_item_present(flow, header->dsfield, header->projid,
 490  490              header->uid);
 491  491          if (item == NULL) {
 492  492                  boolean_t just_once = B_TRUE;
 493  493                  /*
 494  494                   * For all practical purposes, we limit the no. of entries in
 495  495                   * the flow table - i.e. the max_limt that a user specifies is
 496  496                   * the maximum no. of flow items in the table.
 497  497                   */
 498  498          try_again:
 499      -                atomic_add_32(&flowacct_data->nflows, 1);
      499 +                atomic_inc_32(&flowacct_data->nflows);
 500  500                  if (flowacct_data->nflows > flowacct_data->max_limit) {
 501      -                        atomic_add_32(&flowacct_data->nflows, -1);
      501 +                        atomic_dec_32(&flowacct_data->nflows);
 502  502  
 503  503                          /* Try timing out once */
 504  504                          if (just_once) {
 505  505                                  /*
 506  506                                   * Need to release the lock, as this entry
 507  507                                   * could contain a flow that can be timed
 508  508                                   * out.
 509  509                                   */
 510  510                                  mutex_exit(&fhead->lock);
 511  511                                  flowacct_timer(FLOWACCT_JUST_ONE,
↓ open down ↓ 17 lines elided ↑ open up ↑
 529  529                  }
 530  530                  item = (flow_item_t *)kmem_zalloc(FLOWACCT_ITEM_SZ, KM_NOSLEEP);
 531  531                  if (item == NULL) {
 532  532                          flow->inuse = B_FALSE;
 533  533                          /* Need to remove the flow, if one was added */
 534  534                          if (added_flow) {
 535  535                                  flowacct_del_obj(fhead, flow->hdr,
 536  536                                      FLOWACCT_DEL_OBJ);
 537  537                          }
 538  538                          mutex_exit(&fhead->lock);
 539      -                        atomic_add_32(&flowacct_data->nflows, -1);
      539 +                        atomic_dec_32(&flowacct_data->nflows);
 540  540                          flowacct0dbg(("flowacct_update_flows_tbl: mem alloc "\
 541  541                              "error"));
 542  542                          return (-1);
 543  543                  }
 544  544                  item->hdr = flowacct_add_obj(ihead, ihead->tail, (void *)item);
 545  545                  if (item->hdr == NULL) {
 546  546                          flow->inuse = B_FALSE;
 547  547                          /* Need to remove the flow, if one was added */
 548  548                          if (added_flow) {
 549  549                                  flowacct_del_obj(fhead, flow->hdr,
 550  550                                      FLOWACCT_DEL_OBJ);
 551  551                          }
 552  552                          mutex_exit(&fhead->lock);
 553      -                        atomic_add_32(&flowacct_data->nflows, -1);
      553 +                        atomic_dec_32(&flowacct_data->nflows);
 554  554                          kmem_free(item, FLOWACCT_ITEM_SZ);
 555  555                          flowacct0dbg(("flowacct_update_flows_tbl: mem alloc "\
 556  556                              "error\n"));
 557  557                          return (-1);
 558  558                  }
 559  559                  /* If a flow was added, add it too */
 560  560                  if (added_flow) {
 561  561                          atomic_add_64(&flowacct_data->usedmem,
 562  562                              FLOWACCT_FLOW_RECORD_SZ);
 563  563                  }
↓ open down ↓ 316 lines elided ↑ open up ↑
 880  880  
 881  881          ASSERT(mp != NULL);
 882  882  
 883  883          /* If we don't find an M_DATA, return error */
 884  884          if (mp->b_datap->db_type != M_DATA) {
 885  885                  if ((mp->b_cont != NULL) &&
 886  886                      (mp->b_cont->b_datap->db_type == M_DATA)) {
 887  887                          mp = mp->b_cont;
 888  888                  } else {
 889  889                          flowacct0dbg(("flowacct_process: no data\n"));
 890      -                        atomic_add_64(&flowacct_data->epackets, 1);
      890 +                        atomic_inc_64(&flowacct_data->epackets);
 891  891                          return (EINVAL);
 892  892                  }
 893  893          }
 894  894  
 895  895          header = kmem_zalloc(FLOWACCT_HEADER_SZ, KM_NOSLEEP);
 896  896          if (header == NULL) {
 897  897                  flowacct0dbg(("flowacct_process: error allocing mem"));
 898      -                atomic_add_64(&flowacct_data->epackets, 1);
      898 +                atomic_inc_64(&flowacct_data->epackets);
 899  899                  return (ENOMEM);
 900  900          }
 901  901  
 902  902          /* Get all the required information into header. */
 903  903          if (flowacct_extract_header(mp, header) != 0) {
 904  904                  kmem_free(header, FLOWACCT_HEADER_SZ);
 905      -                atomic_add_64(&flowacct_data->epackets, 1);
      905 +                atomic_inc_64(&flowacct_data->epackets);
 906  906                  return (EINVAL);
 907  907          }
 908  908  
 909  909          /* Updated the flow table with this entry */
 910  910          if (flowacct_update_flows_tbl(header, flowacct_data) != 0) {
 911  911                  kmem_free(header, FLOWACCT_HEADER_SZ);
 912      -                atomic_add_64(&flowacct_data->epackets, 1);
      912 +                atomic_inc_64(&flowacct_data->epackets);
 913  913                  return (ENOMEM);
 914  914          }
 915  915  
 916  916          /* Update global stats */
 917      -        atomic_add_64(&flowacct_data->npackets, 1);
      917 +        atomic_inc_64(&flowacct_data->npackets);
 918  918          atomic_add_64(&flowacct_data->nbytes, header->pktlen);
 919  919  
 920  920          kmem_free(header, FLOWACCT_HEADER_SZ);
 921  921          if (flowacct_data->flow_tid == 0) {
 922  922                  flowacct_data->flow_tid = timeout(flowacct_timeout_flows,
 923  923                      flowacct_data, drv_usectohz(flowacct_data->timer));
 924  924          }
 925  925          return (0);
 926  926  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX