diff options
author | Florin Coras <fcoras@cisco.com> | 2020-02-02 19:30:39 +0000 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2020-02-25 19:18:49 +0000 |
commit | 2de9c0f92bb486072d8371a24d9b23fd85e1aa80 (patch) | |
tree | a152a70c5df089ff4a8ea2b7cabab75daa0c712e | |
parent | d8f48e2166747b529aa23762ac314dd686590c89 (diff) |
svm: minimal initial fifo
Type: refactor
Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I4ee46a6c3c53c58199c275e20702f7fd11b60d9a
-rw-r--r-- | src/plugins/hs_apps/echo_client.c | 3 | ||||
-rw-r--r-- | src/plugins/hs_apps/echo_server.c | 1 | ||||
-rw-r--r-- | src/plugins/unittest/svm_fifo_test.c | 2 | ||||
-rw-r--r-- | src/svm/fifo_segment.c | 15 | ||||
-rw-r--r-- | src/svm/fifo_types.h | 1 | ||||
-rw-r--r-- | src/svm/svm_fifo.c | 7 | ||||
-rw-r--r-- | src/vnet/session/application.c | 2 | ||||
-rw-r--r-- | src/vnet/session/application_interface.h | 1 | ||||
-rw-r--r-- | src/vnet/session/segment_manager.c | 1 | ||||
-rw-r--r-- | src/vnet/session/segment_manager.h | 1 | ||||
-rw-r--r-- | src/vnet/session/session.api | 4 |
11 files changed, 24 insertions, 14 deletions
diff --git a/src/plugins/hs_apps/echo_client.c b/src/plugins/hs_apps/echo_client.c index 35cd608f40c..551e46b987e 100644 --- a/src/plugins/hs_apps/echo_client.c +++ b/src/plugins/hs_apps/echo_client.c @@ -635,7 +635,7 @@ echo_clients_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret) u32 prealloc_fifos, segment_size = 256 << 20; echo_client_main_t *ecm = &echo_client_main; vnet_app_attach_args_t _a, *a = &_a; - u64 options[16]; + u64 options[17]; int rv; clib_memset (a, 0, sizeof (*a)); @@ -661,6 +661,7 @@ echo_clients_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret) options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = prealloc_fifos; options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN; options[APP_OPTIONS_TLS_ENGINE] = ecm->tls_engine; + options[APP_OPTIONS_PCT_FIRST_ALLOC] = 100; if (appns_id) { options[APP_OPTIONS_FLAGS] |= appns_flags; diff --git a/src/plugins/hs_apps/echo_server.c b/src/plugins/hs_apps/echo_server.c index 0da7bc09b5a..362d278119c 100644 --- a/src/plugins/hs_apps/echo_server.c +++ b/src/plugins/hs_apps/echo_server.c @@ -351,6 +351,7 @@ echo_server_attach (u8 * appns_id, u64 appns_flags, u64 appns_secret) a->options[APP_OPTIONS_TX_FIFO_SIZE] = esm->fifo_size; a->options[APP_OPTIONS_PRIVATE_SEGMENT_COUNT] = esm->private_segment_count; a->options[APP_OPTIONS_TLS_ENGINE] = esm->tls_engine; + a->options[APP_OPTIONS_PCT_FIRST_ALLOC] = 100; a->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = esm->prealloc_fifos ? esm->prealloc_fifos : 1; diff --git a/src/plugins/unittest/svm_fifo_test.c b/src/plugins/unittest/svm_fifo_test.c index 8579cec15b4..16fcf8871f5 100644 --- a/src/plugins/unittest/svm_fifo_test.c +++ b/src/plugins/unittest/svm_fifo_test.c @@ -2086,6 +2086,7 @@ sfifo_test_fifo_segment_fifo_grow (int verbose) * Alloc fifo */ fs = fifo_segment_get_segment (sm, a->new_segment_indices[0]); + fs->h->pct_first_alloc = 100; f = fifo_segment_alloc_fifo (fs, fifo_size, FIFO_SEGMENT_RX_FIFO); SFIFO_TEST (f != 0, "svm_fifo_segment_alloc_fifo"); @@ -2464,6 +2465,7 @@ sfifo_test_fifo_segment_prealloc (int verbose) rv = fifo_segment_create (sm, a); SFIFO_TEST (!rv, "svm_fifo_segment_create returned %d", rv); fs = fifo_segment_get_segment (sm, a->new_segment_indices[0]); + fs->h->pct_first_alloc = 100; /* * Prealloc chunks and headers diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c index 88600b84e36..7b1163e0750 100644 --- a/src/svm/fifo_segment.c +++ b/src/svm/fifo_segment.c @@ -294,8 +294,7 @@ fs_chunk_size_is_valid (fifo_segment_header_t * fsh, u32 size) } static svm_fifo_t * -fs_try_alloc_fifo_freelist (fifo_segment_slice_t * fss, - u32 fl_index, u32 data_bytes) +fs_try_alloc_fifo_freelist (fifo_segment_slice_t * fss, u32 fl_index) { svm_fifo_chunk_t *c; svm_fifo_t *f; @@ -471,14 +470,16 @@ fs_try_alloc_fifo (fifo_segment_header_t * fsh, fifo_segment_slice_t * fss, u32 fifo_sz, fl_index; svm_fifo_t *f = 0; uword n_free_bytes; + u32 min_size; - fl_index = fs_freelist_for_size (data_bytes); + min_size = clib_max ((fsh->pct_first_alloc * data_bytes) / 100, 4096); + fl_index = fs_freelist_for_size (min_size); fifo_sz = sizeof (svm_fifo_t) + sizeof (svm_fifo_chunk_t); - fifo_sz += 1 << max_log2 (data_bytes); + fifo_sz += 1 << max_log2 (min_size); if (fss->free_fifos && fss->free_chunks[fl_index]) { - f = fs_try_alloc_fifo_freelist (fss, fl_index, data_bytes); + f = fs_try_alloc_fifo_freelist (fss, fl_index); if (f) { fsh_cached_bytes_sub (fsh, fs_freelist_index_to_size (fl_index)); @@ -494,7 +495,7 @@ fs_try_alloc_fifo (fifo_segment_header_t * fsh, fifo_segment_slice_t * fss, FIFO_SEGMENT_ALLOC_BATCH_SIZE)) goto done; - f = fs_try_alloc_fifo_freelist (fss, fl_index, data_bytes); + f = fs_try_alloc_fifo_freelist (fss, fl_index); if (f) fsh_cached_bytes_sub (fsh, fs_freelist_index_to_size (fl_index)); goto done; @@ -502,7 +503,7 @@ fs_try_alloc_fifo (fifo_segment_header_t * fsh, fifo_segment_slice_t * fss, if (fifo_sz <= n_free_bytes) { void *oldheap = ssvm_push_heap (fsh->ssvm_sh); - f = svm_fifo_alloc (data_bytes); + f = svm_fifo_alloc (min_size); ssvm_pop_heap (oldheap); if (f) { diff --git a/src/svm/fifo_types.h b/src/svm/fifo_types.h index f0a286d46a0..a80130b0e92 100644 --- a/src/svm/fifo_types.h +++ b/src/svm/fifo_types.h @@ -120,6 +120,7 @@ struct fifo_segment_header_ u8 n_slices; /**< Number of slices */ u8 high_watermark; /**< Memory pressure watermark high */ u8 low_watermark; /**< Memory pressure watermark low */ + u8 pct_first_alloc; /**< Pct of fifo size to alloc */ }; #endif /* SRC_SVM_FIFO_TYPES_H_ */ diff --git a/src/svm/svm_fifo.c b/src/svm/svm_fifo.c index 0168c08e49c..971eda351d5 100644 --- a/src/svm/svm_fifo.c +++ b/src/svm/svm_fifo.c @@ -368,7 +368,7 @@ void svm_fifo_init (svm_fifo_t * f, u32 size) { svm_fifo_chunk_t *c, *prev; - u32 first_chunk, min_alloc; + u32 min_alloc; f->size = size; f->ooos_list_head = OOO_SEGMENT_INVALID_INDEX; @@ -378,9 +378,8 @@ svm_fifo_init (svm_fifo_t * f, u32 size) f->head_chunk = f->tail_chunk = f->start_chunk; f->ooo_deq = f->ooo_enq = 0; - first_chunk = f->start_chunk->length; - min_alloc = first_chunk > 16 << 10 ? first_chunk >> 2 : 4096; - min_alloc = clib_min (first_chunk, 64 << 10); + min_alloc = size > 32 << 10 ? size >> 3 : 4096; + min_alloc = clib_min (min_alloc, 64 << 10); f->min_alloc = min_alloc; /* diff --git a/src/vnet/session/application.c b/src/vnet/session/application.c index 7777c7275b3..7923d2d050e 100644 --- a/src/vnet/session/application.c +++ b/src/vnet/session/application.c @@ -556,6 +556,8 @@ application_alloc_and_init (app_init_args_t * a) props->high_watermark = options[APP_OPTIONS_HIGH_WATERMARK]; if (options[APP_OPTIONS_LOW_WATERMARK]) props->low_watermark = options[APP_OPTIONS_LOW_WATERMARK]; + if (options[APP_OPTIONS_PCT_FIRST_ALLOC]) + props->pct_first_alloc = options[APP_OPTIONS_PCT_FIRST_ALLOC]; props->segment_type = seg_type; /* Add app to lookup by api_client_index table */ diff --git a/src/vnet/session/application_interface.h b/src/vnet/session/application_interface.h index 2ecabb03204..bf946769028 100644 --- a/src/vnet/session/application_interface.h +++ b/src/vnet/session/application_interface.h @@ -208,6 +208,7 @@ typedef enum APP_OPTIONS_MAX_FIFO_SIZE, APP_OPTIONS_HIGH_WATERMARK, APP_OPTIONS_LOW_WATERMARK, + APP_OPTIONS_PCT_FIRST_ALLOC, APP_OPTIONS_N_OPTIONS } app_attach_options_index_t; diff --git a/src/vnet/session/segment_manager.c b/src/vnet/session/segment_manager.c index eb3f63c9a6c..db38097602c 100644 --- a/src/vnet/session/segment_manager.c +++ b/src/vnet/session/segment_manager.c @@ -171,6 +171,7 @@ segment_manager_add_segment (segment_manager_t * sm, uword segment_size) */ fs->h->high_watermark = sm->high_watermark; fs->h->low_watermark = sm->low_watermark; + fs->h->pct_first_alloc = props->pct_first_alloc; fs->h->flags &= ~FIFO_SEGMENT_F_MEM_LIMIT; done: diff --git a/src/vnet/session/segment_manager.h b/src/vnet/session/segment_manager.h index 688711a3312..cd02d5480ae 100644 --- a/src/vnet/session/segment_manager.h +++ b/src/vnet/session/segment_manager.h @@ -38,6 +38,7 @@ typedef struct _segment_manager_props u32 max_fifo_size; /**< max fifo size */ u8 high_watermark; /**< memory usage high watermark % */ u8 low_watermark; /**< memory usage low watermark % */ + u8 pct_first_alloc; /**< pct of fifo size to alloc */ } segment_manager_props_t; typedef struct _segment_manager diff --git a/src/vnet/session/session.api b/src/vnet/session/session.api index 4f9ae12eeb3..8cfac3d048d 100644 --- a/src/vnet/session/session.api +++ b/src/vnet/session/session.api @@ -29,7 +29,7 @@ option version = "1.7.0"; u32 client_index; u32 context; u32 initial_segment_size; - u64 options[16]; + u64 options[17]; u8 namespace_id_len; u8 namespace_id [64]; }; @@ -72,7 +72,7 @@ define application_attach_reply { define app_attach { u32 client_index; u32 context; - u64 options[16]; + u64 options[17]; u8 namespace_id_len; u8 namespace_id[64]; }; |