X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp%2Fapi%2Fapi.c;h=cf5d252e3471a2951f199ad6fcf372c863d4f124;hb=b7b929931a07fbb27b43d5cd105f366c3e29807e;hp=8bb11c960666bfb7a41bdc3c9cfba2df5afe13df;hpb=6c4dae27e75fc668f86c9cca0f3f58273b680621;p=vpp.git diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c index 8bb11c96066..cf5d252e347 100644 --- a/src/vpp/api/api.c +++ b/src/vpp/api/api.c @@ -2,7 +2,7 @@ *------------------------------------------------------------------ * api.c - message handler registration * - * Copyright (c) 2010-2016 Cisco and/or its affiliates. + * Copyright (c) 2010-2018 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -56,7 +56,7 @@ #undef BIHASH_TYPE #undef __included_bihash_template_h__ -#include +#include #include @@ -80,6 +80,7 @@ _(CLI_INBAND, cli_inband) \ _(GET_NODE_INDEX, get_node_index) \ _(ADD_NODE_NEXT, add_node_next) \ _(SHOW_VERSION, show_version) \ +_(SHOW_THREADS, show_threads) \ _(GET_NODE_GRAPH, get_node_graph) \ _(GET_NEXT_INDEX, get_next_index) \ @@ -254,6 +255,69 @@ vl_api_show_version_t_handler (vl_api_show_version_t * mp) /* *INDENT-ON* */ } +static void +get_thread_data (vl_api_thread_data_t * td, int index) +{ + vlib_worker_thread_t *w = vlib_worker_threads + index; + td->id = htonl (index); + if (w->name) + strncpy ((char *) td->name, (char *) w->name, ARRAY_LEN (td->name) - 1); + if (w->registration) + strncpy ((char *) td->type, (char *) w->registration->name, + ARRAY_LEN (td->type) - 1); + td->pid = htonl (w->lwp); + td->cpu_id = htonl (w->cpu_id); + td->core = htonl (w->core_id); + td->cpu_socket = htonl (w->socket_id); +} + +static void +vl_api_show_threads_t_handler (vl_api_show_threads_t * mp) +{ + vlib_main_t *vm = vlib_get_main (); + int rv = 0, count = 0; + +#if !defined(__powerpc64__) + vl_api_registration_t *reg; + vl_api_show_threads_reply_t *rmp; + vl_api_thread_data_t *td; + int i, msg_size = 0; + count = vec_len (vlib_worker_threads); + if (!count) + return; + + msg_size = sizeof (*rmp) + sizeof (rmp->thread_data[0]) * count; + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + + rmp = vl_msg_api_alloc (msg_size); + clib_memset (rmp, 0, msg_size); + rmp->_vl_msg_id = htons (VL_API_SHOW_THREADS_REPLY); + rmp->context = mp->context; + rmp->count = htonl (count); + td = rmp->thread_data; + + for (i = 0; i < count; i++) + { + get_thread_data (&td[i], i); + } + + vl_api_send_msg (reg, (u8 *) rmp); +#else + + /* unimplemented support */ + rv = -9; + clib_warning ("power pc does not support show threads api"); + /* *INDENT-OFF* */ + REPLY_MACRO2(VL_API_SHOW_THREADS_REPLY, + ({ + rmp->count = htonl(count); + })); + /* *INDENT-ON* */ +#endif +} + static void vl_api_get_node_index_t_handler (vl_api_get_node_index_t * mp) { @@ -367,7 +431,8 @@ vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp) vlib_main_t *vm = vlib_get_main (); void *oldheap; vl_api_get_node_graph_reply_t *rmp; - vlib_node_t ***node_dups; + static vlib_node_t ***node_dups; + static vlib_main_t **stat_vms; pthread_mutex_lock (&am->vlib_rp->mutex); oldheap = svm_push_data_heap (am->vlib_rp); @@ -378,9 +443,10 @@ vl_api_get_node_graph_t_handler (vl_api_get_node_graph_t * mp) vec_validate (vector, 16384); vec_reset_length (vector); - /* $$$$ FIXME */ - node_dups = vlib_node_get_nodes (vm, (u32) ~ 0 /* all threads */ , - 1 /* include stats */ ); + vlib_node_get_nodes (vm, 0 /* main threads */ , + 0 /* include stats */ , + 1 /* barrier sync */ , + &node_dups, &stat_vms); vector = vlib_node_serialize (vm, node_dups, vector, 1 /* include nexts */ , 1 /* include stats */ ); @@ -430,7 +496,7 @@ static void setup_message_id_table (api_main_t * am); /* * vpe_api_hookup * Add vpe's API message handlers to the table. - * vlib has alread mapped shared memory and + * vlib has already mapped shared memory and * added the client registration handlers. * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process() */ @@ -472,7 +538,7 @@ vpe_api_hookup (vlib_main_t * vm) VLIB_API_INIT_FUNCTION (vpe_api_hookup); -static clib_error_t * +clib_error_t * vpe_api_init (vlib_main_t * vm) { vpe_api_main_t *am = &vpe_api_main; @@ -490,9 +556,6 @@ vpe_api_init (vlib_main_t * vm) return 0; } -VLIB_INIT_FUNCTION (vpe_api_init); - - static clib_error_t * api_segment_config (vlib_main_t * vm, unformat_input_t * input) {