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

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/xen/io/xnf.c
          +++ new/usr/src/uts/common/xen/io/xnf.c
↓ open down ↓ 358 lines elided ↑ open up ↑
 359  359                  gref = gnttab_claim_grant_reference(&xnfp->xnf_gref_head);
 360  360  
 361  361          } while ((gref == INVALID_GRANT_REF) &&
 362  362              (gnttab_alloc_grant_references(16, &xnfp->xnf_gref_head) == 0));
 363  363  
 364  364          mutex_exit(&xnfp->xnf_gref_lock);
 365  365  
 366  366          if (gref == INVALID_GRANT_REF) {
 367  367                  xnfp->xnf_stat_gref_failure++;
 368  368          } else {
 369      -                atomic_add_64(&xnfp->xnf_stat_gref_outstanding, 1);
      369 +                atomic_inc_64(&xnfp->xnf_stat_gref_outstanding);
 370  370                  if (xnfp->xnf_stat_gref_outstanding > xnfp->xnf_stat_gref_peak)
 371  371                          xnfp->xnf_stat_gref_peak =
 372  372                              xnfp->xnf_stat_gref_outstanding;
 373  373          }
 374  374  
 375  375          return (gref);
 376  376  }
 377  377  
 378  378  /*
 379  379   * Release a grant reference.
 380  380   */
 381  381  static void
 382  382  gref_put(xnf_t *xnfp, grant_ref_t gref)
 383  383  {
 384  384          ASSERT(gref != INVALID_GRANT_REF);
 385  385  
 386  386          mutex_enter(&xnfp->xnf_gref_lock);
 387  387          gnttab_release_grant_reference(&xnfp->xnf_gref_head, gref);
 388  388          mutex_exit(&xnfp->xnf_gref_lock);
 389  389  
 390      -        atomic_add_64(&xnfp->xnf_stat_gref_outstanding, -1);
      390 +        atomic_dec_64(&xnfp->xnf_stat_gref_outstanding);
 391  391  }
 392  392  
 393  393  /*
 394  394   * Acquire a transmit id.
 395  395   */
 396  396  static xnf_txid_t *
 397  397  txid_get(xnf_t *xnfp)
 398  398  {
 399  399          xnf_txid_t *tidp;
 400  400  
↓ open down ↓ 1944 lines elided ↑ open up ↑
2345 2345  
2346 2346          bdesc->free_rtn.free_func = xnf_buf_recycle;
2347 2347          bdesc->free_rtn.free_arg = (caddr_t)bdesc;
2348 2348          bdesc->xnfp = xnfp;
2349 2349          bdesc->buf_phys = dma_cookie.dmac_laddress;
2350 2350          bdesc->buf_mfn = pfn_to_mfn(xnf_btop(bdesc->buf_phys));
2351 2351          bdesc->len = dma_cookie.dmac_size;
2352 2352          bdesc->grant_ref = INVALID_GRANT_REF;
2353 2353          bdesc->gen = xnfp->xnf_gen;
2354 2354  
2355      -        atomic_add_64(&xnfp->xnf_stat_buf_allocated, 1);
     2355 +        atomic_inc_64(&xnfp->xnf_stat_buf_allocated);
2356 2356  
2357 2357          return (0);
2358 2358  
2359 2359  failure_2:
2360 2360          ddi_dma_mem_free(&bdesc->acc_handle);
2361 2361  
2362 2362  failure_1:
2363 2363          ddi_dma_free_handle(&bdesc->dma_handle);
2364 2364  
2365 2365  failure:
↓ open down ↓ 5 lines elided ↑ open up ↑
2371 2371  static void
2372 2372  xnf_buf_destructor(void *buf, void *arg)
2373 2373  {
2374 2374          xnf_buf_t *bdesc = buf;
2375 2375          xnf_t *xnfp = arg;
2376 2376  
2377 2377          (void) ddi_dma_unbind_handle(bdesc->dma_handle);
2378 2378          ddi_dma_mem_free(&bdesc->acc_handle);
2379 2379          ddi_dma_free_handle(&bdesc->dma_handle);
2380 2380  
2381      -        atomic_add_64(&xnfp->xnf_stat_buf_allocated, -1);
     2381 +        atomic_dec_64(&xnfp->xnf_stat_buf_allocated);
2382 2382  }
2383 2383  
2384 2384  static xnf_buf_t *
2385 2385  xnf_buf_get(xnf_t *xnfp, int flags, boolean_t readonly)
2386 2386  {
2387 2387          grant_ref_t gref;
2388 2388          xnf_buf_t *bufp;
2389 2389  
2390 2390          /*
2391 2391           * Usually grant references are more scarce than memory, so we
↓ open down ↓ 13 lines elided ↑ open up ↑
2405 2405  
2406 2406          bufp->grant_ref = gref;
2407 2407  
2408 2408          if (bufp->gen != xnfp->xnf_gen)
2409 2409                  xnf_buf_refresh(bufp);
2410 2410  
2411 2411          gnttab_grant_foreign_access_ref(bufp->grant_ref,
2412 2412              xvdi_get_oeid(bufp->xnfp->xnf_devinfo),
2413 2413              bufp->buf_mfn, readonly ? 1 : 0);
2414 2414  
2415      -        atomic_add_64(&xnfp->xnf_stat_buf_outstanding, 1);
     2415 +        atomic_inc_64(&xnfp->xnf_stat_buf_outstanding);
2416 2416  
2417 2417          return (bufp);
2418 2418  }
2419 2419  
2420 2420  static void
2421 2421  xnf_buf_put(xnf_t *xnfp, xnf_buf_t *bufp, boolean_t readonly)
2422 2422  {
2423 2423          if (bufp->grant_ref != INVALID_GRANT_REF) {
2424 2424                  (void) gnttab_end_foreign_access_ref(
2425 2425                      bufp->grant_ref, readonly ? 1 : 0);
2426 2426                  gref_put(xnfp, bufp->grant_ref);
2427 2427                  bufp->grant_ref = INVALID_GRANT_REF;
2428 2428          }
2429 2429  
2430 2430          kmem_cache_free(xnfp->xnf_buf_cache, bufp);
2431 2431  
2432      -        atomic_add_64(&xnfp->xnf_stat_buf_outstanding, -1);
     2432 +        atomic_dec_64(&xnfp->xnf_stat_buf_outstanding);
2433 2433  }
2434 2434  
2435 2435  /*
2436 2436   * Refresh any cached data about a buffer after resume.
2437 2437   */
2438 2438  static void
2439 2439  xnf_buf_refresh(xnf_buf_t *bdesc)
2440 2440  {
2441 2441          bdesc->buf_mfn = pfn_to_mfn(xnf_btop(bdesc->buf_phys));
2442 2442          bdesc->gen = bdesc->xnfp->xnf_gen;
↓ open down ↓ 317 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX