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); |
Neale Ranns | 6bcc6a4 | 2019-10-15 15:47:55 +0000 | [diff] [blame] | 29 | void vl_api_force_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 30 | u16 vl_client_get_first_plugin_msg_id (const char *plugin_name); |
| 31 | void vl_api_send_pending_rpc_requests (vlib_main_t * vm); |
| 32 | u8 *vl_api_serialize_message_table (api_main_t * am, u8 * vector); |
| 33 | |
| 34 | always_inline void |
| 35 | vl_api_send_msg (vl_api_registration_t * rp, u8 * elem) |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 36 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 37 | if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM)) |
| 38 | { |
| 39 | vl_socket_api_send (rp, elem); |
| 40 | } |
| 41 | else |
| 42 | { |
| 43 | vl_msg_api_send_shmem (rp->vl_input_queue, (u8 *) & elem); |
| 44 | } |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 45 | } |
| 46 | |
Florin Coras | af0ff5a | 2018-01-10 08:17:03 -0800 | [diff] [blame] | 47 | always_inline int |
| 48 | vl_api_can_send_msg (vl_api_registration_t * rp) |
| 49 | { |
| 50 | if (PREDICT_FALSE (rp->registration_type > REGISTRATION_TYPE_SHMEM)) |
| 51 | return 1; |
| 52 | else |
| 53 | return vl_mem_api_can_send (rp->vl_input_queue); |
| 54 | } |
| 55 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 56 | always_inline vl_api_registration_t * |
| 57 | vl_api_client_index_to_registration (u32 index) |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 58 | { |
Florin Coras | 2881dec | 2018-10-02 18:29:25 -0700 | [diff] [blame] | 59 | if (vl_socket_api_registration_handle_is_valid (ntohl (index))) |
| 60 | return vl_socket_api_client_handle_to_registration (ntohl (index)); |
Ole Troan | 94495f2 | 2018-08-02 11:58:12 +0200 | [diff] [blame] | 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 | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 64 | always_inline u32 |
| 65 | vl_api_registration_file_index (vl_api_registration_t * reg) |
| 66 | { |
| 67 | return reg->clib_file_index; |
| 68 | } |
| 69 | |
| 70 | always_inline clib_file_t * |
| 71 | vl_api_registration_file (vl_api_registration_t * reg) |
| 72 | { |
| 73 | return clib_file_get (&file_main, vl_api_registration_file_index (reg)); |
| 74 | } |
| 75 | |
| 76 | always_inline void |
| 77 | vl_api_registration_del_file (vl_api_registration_t * reg) |
| 78 | { |
| 79 | clib_file_t *cf = vl_api_registration_file (reg); |
| 80 | if (cf) |
| 81 | clib_file_del (&file_main, cf); |
| 82 | } |
| 83 | |
| 84 | always_inline clib_error_t * |
Florin Coras | 466f289 | 2018-08-03 02:50:43 -0700 | [diff] [blame] | 85 | vl_api_send_fd_msg (vl_api_registration_t * reg, int fds[], int n_fds) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 86 | { |
| 87 | clib_file_t *cf = vl_api_registration_file (reg); |
| 88 | if (cf) |
Florin Coras | 466f289 | 2018-08-03 02:50:43 -0700 | [diff] [blame] | 89 | return vl_sock_api_send_fd_msg (cf->file_descriptor, fds, n_fds); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | always_inline clib_error_t * |
Florin Coras | 466f289 | 2018-08-03 02:50:43 -0700 | [diff] [blame] | 94 | vl_api_recv_fd_msg (vl_api_registration_t * reg, int fds[], int n_fds, |
| 95 | u32 wait) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 96 | { |
| 97 | clib_file_t *cf = vl_api_registration_file (reg); |
| 98 | if (cf) |
Florin Coras | 466f289 | 2018-08-03 02:50:43 -0700 | [diff] [blame] | 99 | return vl_sock_api_recv_fd_msg (cf->file_descriptor, fds, n_fds, wait); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 103 | /* |
| 104 | * vl_api_clnt process data used by transports (socket api in particular) |
| 105 | */ |
| 106 | extern vlib_node_registration_t vl_api_clnt_node; |
| 107 | extern volatile int **vl_api_queue_cursizes; |
| 108 | |
| 109 | typedef enum vl_api_clnt_process_events |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 110 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 111 | QUEUE_SIGNAL_EVENT = 1, |
| 112 | SOCKET_READ_EVENT |
| 113 | } vl_api_clnt_process_events_t; |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 114 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 115 | #define foreach_histogram_bucket \ |
| 116 | _(400) \ |
| 117 | _(200) \ |
| 118 | _(100) \ |
| 119 | _(10) |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 120 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 121 | typedef enum |
| 122 | { |
| 123 | #define _(n) SLEEP_##n##_US, |
| 124 | foreach_histogram_bucket |
| 125 | #undef _ |
| 126 | SLEEP_N_BUCKETS, |
| 127 | } histogram_index_t; |
Dave Barach | 59b2565 | 2017-09-10 15:04:27 -0400 | [diff] [blame] | 128 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 129 | extern u64 vector_rate_histogram[]; |
| 130 | |
| 131 | /* |
| 132 | * sockclnt APIs XXX are these actually used anywhere? |
| 133 | */ |
| 134 | vl_api_registration_t *sockclnt_get_registration (u32 index); |
| 135 | void socksvr_add_pending_output (struct clib_file *uf, |
| 136 | struct vl_api_registration_ *cf, |
| 137 | u8 * buffer, uword buffer_bytes); |
| 138 | void vl_socket_process_msg (struct clib_file *uf, |
| 139 | struct vl_api_registration_ *rp, i8 * input_v); |
| 140 | u32 sockclnt_open_index (char *client_name, char *hostname, int port); |
| 141 | void sockclnt_close_index (u32 index); |
| 142 | void vl_client_msg_api_send (vl_api_registration_t * cm, u8 * elem); |
| 143 | |
| 144 | #endif /* included_vlibmemory_api_common_h */ |
Damjan Marion | 7cd468a | 2016-12-19 23:05:39 +0100 | [diff] [blame] | 145 | |
| 146 | /* |
| 147 | * fd.io coding-style-patch-verification: ON |
| 148 | * |
| 149 | * Local Variables: |
| 150 | * eval: (c-set-style "gnu") |
| 151 | * End: |
| 152 | */ |