Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 3 | * Copyright (c) 2009 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 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 18 | #ifndef included_vlibmemory_api_common_h |
| 19 | #define included_vlibmemory_api_common_h |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 20 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 21 | #include <svm/svm_common.h> |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 22 | #include <vlibapi/api.h> |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 23 | #include <vlibmemory/memory_api.h> |
| 24 | #include <vlibmemory/memory_client.h> |
| 25 | #include <vlibmemory/socket_api.h> |
| 26 | #include <vlibmemory/socket_client.h> |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 27 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 28 | void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
| 29 | u16 vl_client_get_first_plugin_msg_id (const char *plugin_name); |
| 30 | void vl_api_send_pending_rpc_requests (vlib_main_t * vm); |
| 31 | u8 *vl_api_serialize_message_table (api_main_t * am, u8 * vector); |
| 32 | |
| 33 | always_inline void |
| 34 | vl_api_send_msg (vl_api_registration_t * rp, u8 * elem) |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 35 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 36 | if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM)) |
| 37 | { |
| 38 | vl_socket_api_send (rp, elem); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | vl_msg_api_send_shmem (rp->vl_input_queue, (u8 *) & elem); |
| 43 | } |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 46 | always_inline int |
| 47 | vl_api_can_send_msg (vl_api_registration_t * rp) |
| 48 | { |
| 49 | if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM)) |
| 50 | return 1; |
| 51 | else |
| 52 | return vl_mem_api_can_send (rp->vl_input_queue); |
| 53 | } |
| 54 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 55 | always_inline vl_api_registration_t * |
| 56 | vl_api_client_index_to_registration (u32 index) |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 57 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 58 | if (PREDICT_FALSE (socket_main.current_rp != 0)) |
| 59 | return socket_main.current_rp; |
| 60 | |
| 61 | return (vl_mem_api_client_index_to_registration (index)); |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 64 | /* |
| 65 | * vl_api_clnt process data used by transports (socket api in particular) |
| 66 | */ |
| 67 | extern vlib_node_registration_t vl_api_clnt_node; |
| 68 | extern volatile int **vl_api_queue_cursizes; |
| 69 | |
| 70 | typedef enum vl_api_clnt_process_events |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 71 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 72 | QUEUE_SIGNAL_EVENT = 1, |
| 73 | SOCKET_READ_EVENT |
| 74 | } vl_api_clnt_process_events_t; |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 75 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 76 | #define foreach_histogram_bucket \ |
| 77 | _(400) \ |
| 78 | _(200) \ |
| 79 | _(100) \ |
| 80 | _(10) |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 81 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 82 | typedef enum |
| 83 | { |
| 84 | #define _(n) SLEEP_##n##_US, |
| 85 | foreach_histogram_bucket |
| 86 | #undef _ |
| 87 | SLEEP_N_BUCKETS, |
| 88 | } histogram_index_t; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 89 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 90 | extern u64 vector_rate_histogram[]; |
| 91 | |
| 92 | /* |
| 93 | * sockclnt APIs XXX are these actually used anywhere? |
| 94 | */ |
| 95 | vl_api_registration_t *sockclnt_get_registration (u32 index); |
| 96 | void socksvr_add_pending_output (struct clib_file *uf, |
| 97 | struct vl_api_registration_ *cf, |
| 98 | u8 * buffer, uword buffer_bytes); |
| 99 | void vl_socket_process_msg (struct clib_file *uf, |
| 100 | struct vl_api_registration_ *rp, i8 * input_v); |
| 101 | u32 sockclnt_open_index (char *client_name, char *hostname, int port); |
| 102 | void sockclnt_close_index (u32 index); |
| 103 | void vl_client_msg_api_send (vl_api_registration_t * cm, u8 * elem); |
| 104 | |
| 105 | #endif /* included_vlibmemory_api_common_h */ |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * fd.io coding-style-patch-verification: ON |
| 109 | * |
| 110 | * Local Variables: |
| 111 | * eval: (c-set-style "gnu") |
| 112 | * End: |
| 113 | */ |