LCOV - code coverage report
Current view: top level - vppinfra - interrupt.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 17 37 45.9 %
Date: 2023-07-05 22:20:52 Functions: 2 2 100.0 %

          Line data    Source code
       1             : 
       2             : /*
       3             :  * Copyright (c) 2020 Cisco and/or its affiliates.
       4             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5             :  * you may not use this file except in compliance with the License.
       6             :  * You may obtain a copy of the License at:
       7             :  *
       8             :  *     http://www.apache.org/licenses/LICENSE-2.0
       9             :  *
      10             :  * Unless required by applicable law or agreed to in writing, software
      11             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13             :  * See the License for the specific language governing permissions and
      14             :  * limitations under the License.
      15             :  */
      16             : 
      17             : #include <vppinfra/clib.h>
      18             : #include <vppinfra/vec.h>
      19             : #include <vppinfra/interrupt.h>
      20             : #include <vppinfra/format.h>
      21             : 
      22             : __clib_export void
      23         757 : clib_interrupt_init (void **data, uword n_int)
      24             : {
      25             :   clib_interrupt_header_t *h;
      26         757 :   uword sz = sizeof (clib_interrupt_header_t);
      27         757 :   uword data_size = round_pow2 (n_int, CLIB_CACHE_LINE_BYTES * 8) / 8;
      28             : 
      29         757 :   sz += 2 * data_size;
      30         757 :   h = data[0] = clib_mem_alloc_aligned (sz, CLIB_CACHE_LINE_BYTES);
      31         757 :   clib_memset (data[0], 0, sz);
      32         757 :   h->n_int = n_int;
      33         757 :   h->n_uword_alloc = (data_size * 8) >> log2_uword_bits;
      34         757 : }
      35             : 
      36             : __clib_export void
      37       16471 : clib_interrupt_resize (void **data, uword n_int)
      38             : {
      39       16471 :   clib_interrupt_header_t *h = data[0];
      40             : 
      41       16471 :   if (data[0] == 0)
      42             :     {
      43         703 :       clib_interrupt_init (data, n_int);
      44         703 :       return;
      45             :     }
      46             : 
      47       15768 :   if (n_int < h->n_int)
      48             :     {
      49             :       uword *old_bmp, *old_abp, v;
      50           0 :       old_bmp = clib_interrupt_get_bitmap (data[0]);
      51           0 :       old_abp = clib_interrupt_get_atomic_bitmap (data[0]);
      52           0 :       for (uword i = 0; i < h->n_uword_alloc; i++)
      53             :         {
      54           0 :           v = old_abp[i];
      55           0 :           old_abp[i] = 0;
      56           0 :           if (n_int > ((i + 1) * uword_bits))
      57           0 :             old_bmp[i] |= v;
      58           0 :           else if (n_int > (i * uword_bits))
      59           0 :             old_bmp[i] = (old_bmp[i] | v) & pow2_mask (n_int - i * uword_bits);
      60             :           else
      61           0 :             old_bmp[i] = 0;
      62             :         }
      63             :     }
      64       15768 :   else if (n_int > h->n_uword_alloc * uword_bits)
      65             :     {
      66           0 :       void *old = data[0];
      67             :       uword *old_bmp, *old_abp, *new_bmp;
      68           0 :       uword n_uwords = round_pow2 (h->n_int, uword_bits) / uword_bits;
      69             : 
      70           0 :       clib_interrupt_init (data, n_int);
      71           0 :       h = data[0];
      72             : 
      73           0 :       new_bmp = clib_interrupt_get_bitmap (data[0]);
      74           0 :       old_bmp = clib_interrupt_get_bitmap (old);
      75           0 :       old_abp = clib_interrupt_get_atomic_bitmap (old);
      76             : 
      77           0 :       for (uword i = 0; i < n_uwords; i++)
      78           0 :         new_bmp[i] = old_bmp[i] | old_abp[i];
      79             : 
      80           0 :       clib_mem_free (old);
      81             :     }
      82       15768 :   h->n_int = n_int;
      83             : }
      84             : 
      85             : /*
      86             :  * fd.io coding-style-patch-verification: ON
      87             :  *
      88             :  * Local Variables:
      89             :  * eval: (c-set-style "gnu")
      90             :  * End:
      91             :  */

Generated by: LCOV version 1.14