From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 7E856A0096 for ; Fri, 7 Jun 2019 10:26:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C37D4F64; Fri, 7 Jun 2019 10:26:38 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 227DC3DC for ; Fri, 7 Jun 2019 10:26:36 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2019 01:26:36 -0700 X-ExtLoop1: 1 Received: from irsmsx110.ger.corp.intel.com ([163.33.3.25]) by orsmga005.jf.intel.com with ESMTP; 07 Jun 2019 01:26:35 -0700 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.227]) by irsmsx110.ger.corp.intel.com ([169.254.15.167]) with mapi id 14.03.0415.000; Fri, 7 Jun 2019 09:26:34 +0100 From: "Hajkowski, MarcinX" To: "Gosiewski, LukaszX" , "Hunt, David" CC: "dev@dpdk.org" , "Krakowiak, LukaszX" , "Gosiewski, LukaszX" Thread-Topic: [dpdk-dev] [PATCH v3 1/2] power: add fifo per core for JSON interface Thread-Index: AQHU+nbm3KIz4tblJUKFFNX5erqfoqaQHksw Date: Fri, 7 Jun 2019 08:26:34 +0000 Message-ID: <7AE8A440E9E11A43ABE083B4E74B60F94CE09B@IRSMSX104.ger.corp.intel.com> References: <20190408104518.21960-1-lukaszx.krakowiak@intel.com> <20190424082152.5396-1-lukaszx.gosiewski@intel.com> <20190424082152.5396-2-lukaszx.gosiewski@intel.com> In-Reply-To: <20190424082152.5396-2-lukaszx.gosiewski@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDUzNDkzMTktZmFkOC00MWIzLTlmNmMtZDJiZjU2MzZmYTZhIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoicjRsc0dUcXVmSExwY05vNEJNckdpMmRxWXFCdkJzaitPZGxZblZGaFFjeFwvTVp4NlRPdXVDSFR0czA2Tk41UjEifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v3 1/2] power: add fifo per core for JSON interface X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Lukasz Gosiewski > Sent: Wednesday, April 24, 2019 10:22 AM > To: Hunt, David > Cc: dev@dpdk.org; Krakowiak, LukaszX ; > Gosiewski, LukaszX > Subject: [dpdk-dev] [PATCH v3 1/2] power: add fifo per core for JSON > interface >=20 > From: Lukasz Krakowiak >=20 > This patch implement a separate FIFO for each cpu core. > For proper handling JSON interface, removed fields from cmds: > core_list, resource_id, name. >=20 > Signed-off-by: Lukasz Krakowiak > Signed-off-by: Lukasz Gosiewski I belive there should be information provided that patch depends on http://= patchwork.dpdk.org/patch/52186/.=20 >=20 > --- > v2: > * updated handling vm_name (use proper buff size) > * rebase to master changes >=20 > v3: > * improvement to coding style > --- > examples/vm_power_manager/channel_manager.c | 85 +++++++++++++----- > - examples/vm_power_manager/channel_manager.h | 7 +- > examples/vm_power_manager/channel_monitor.c | 91 +++++++++++++++--- > --- > examples/vm_power_manager/main.c | 2 +- > 4 files changed, 129 insertions(+), 56 deletions(-) >=20 > diff --git a/examples/vm_power_manager/channel_manager.c > b/examples/vm_power_manager/channel_manager.c > index 05c0eea44..d19276839 100644 > --- a/examples/vm_power_manager/channel_manager.c > +++ b/examples/vm_power_manager/channel_manager.c > @@ -346,10 +346,22 @@ setup_channel_info(struct virtual_machine_info > **vm_info_dptr, > return 0; > } >=20 > -static void > -fifo_path(char *dst, unsigned int len) > +static int > +fifo_path(char *dst, unsigned int len, unsigned int id) > { > - snprintf(dst, len, "%sfifo", CHANNEL_MGR_SOCKET_PATH); > + int cnt; > + > + cnt =3D snprintf(dst, len, "%s%s%d", CHANNEL_MGR_SOCKET_PATH, > + CHANNEL_MGR_FIFO_PATTERN_NAME, id); > + > + if ((cnt < 0) || (cnt > (int)len - 1)) { > + RTE_LOG(ERR, CHANNEL_MANAGER, "Could not create > proper " > + "string for fifo path\n"); > + > + return -1; > + } > + > + return 0; > } >=20 > static int > @@ -535,40 +547,59 @@ add_channels(const char *vm_name, unsigned > *channel_list, } >=20 > int > -add_host_channel(void) > +add_host_channels(void) > { > struct channel_info *chan_info; > char socket_path[PATH_MAX]; > int num_channels_enabled =3D 0; > int ret; > + struct core_info *ci; >=20 > - fifo_path(socket_path, sizeof(socket_path)); > - > - ret =3D mkfifo(socket_path, 0660); > - if ((errno !=3D EEXIST) && (ret < 0)) { > - RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot create fifo '%s' > error: " > - "%s\n", socket_path, strerror(errno)); > + ci =3D get_core_info(); > + if (ci =3D=3D NULL) { > + RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot allocate > memory for > +core_info\n"); > return 0; > } >=20 > - if (access(socket_path, F_OK) < 0) { > - RTE_LOG(ERR, CHANNEL_MANAGER, "Channel path '%s' > error: " > - "%s\n", socket_path, strerror(errno)); > - return 0; > - } > - chan_info =3D rte_malloc(NULL, sizeof(*chan_info), 0); > - if (chan_info =3D=3D NULL) { > - RTE_LOG(ERR, CHANNEL_MANAGER, "Error allocating > memory for " > - "channel '%s'\n", socket_path); > - return 0; > - } > - rte_strlcpy(chan_info->channel_path, socket_path, > UNIX_PATH_MAX); > + do { > + if (ci->cd[num_channels_enabled].global_enabled_cpus =3D=3D 0) > + continue; >=20 > - if (setup_host_channel_info(&chan_info, 0) < 0) { > - rte_free(chan_info); > - return 0; > - } > - num_channels_enabled++; > + ret =3D fifo_path(socket_path, sizeof(socket_path), > + > num_channels_enabled); > + if (ret < 0) > + return 0; > + > + ret =3D mkfifo(socket_path, 0660); > + RTE_LOG(DEBUG, CHANNEL_MANAGER, "TRY CREATE fifo > '%s'\n", > + socket_path); > + if ((errno !=3D EEXIST) && (ret < 0)) { > + RTE_LOG(ERR, CHANNEL_MANAGER, "Cannot create > fifo '%s' error: " > + "%s\n", socket_path, > strerror(errno)); > + return 0; > + } > + > + if (access(socket_path, F_OK) < 0) { > + RTE_LOG(ERR, CHANNEL_MANAGER, "Channel path > '%s' error: " > + "%s\n", socket_path, > strerror(errno)); > + return 0; > + } > + chan_info =3D rte_malloc(NULL, sizeof(*chan_info), 0); > + if (chan_info =3D=3D NULL) { > + RTE_LOG(ERR, CHANNEL_MANAGER, "Error allocating > memory for " > + "channel '%s'\n", socket_path); > + return 0; > + } > + snprintf(chan_info->channel_path, > + sizeof(chan_info->channel_path), > + "%s", socket_path); > + > + if (setup_host_channel_info(&chan_info, > + num_channels_enabled) < 0) { > + rte_free(chan_info); > + return 0; > + } > + } while (++num_channels_enabled <=3D ci->core_count); >=20 > return num_channels_enabled; > } > diff --git a/examples/vm_power_manager/channel_manager.h > b/examples/vm_power_manager/channel_manager.h > index c3cdce492..7fddaf6a6 100644 > --- a/examples/vm_power_manager/channel_manager.h > +++ b/examples/vm_power_manager/channel_manager.h > @@ -28,6 +28,9 @@ extern "C" { > /* File socket directory */ > #define CHANNEL_MGR_SOCKET_PATH "/tmp/powermonitor/" >=20 > +/* FIFO file name template */ > +#define CHANNEL_MGR_FIFO_PATTERN_NAME "fifo" > + > #ifndef UNIX_PATH_MAX > struct sockaddr_un _sockaddr_un; > #define UNIX_PATH_MAX sizeof(_sockaddr_un.sun_path) @@ -212,13 > +215,13 @@ int add_channels(const char *vm_name, unsigned > *channel_list, > unsigned num_channels); >=20 > /** > - * Set up a fifo by which host applications can send command an policies > + * Set up fifos by which host applications can send command an policies > * through a fifo to the vm_power_manager > * > * @return > * - 0 for success > */ > -int add_host_channel(void); > +int add_host_channels(void); >=20 > /** > * Remove a channel definition from the channel manager. This must only = be > diff --git a/examples/vm_power_manager/channel_monitor.c > b/examples/vm_power_manager/channel_monitor.c > index 74df0fe20..41ee8671d 100644 > --- a/examples/vm_power_manager/channel_monitor.c > +++ b/examples/vm_power_manager/channel_monitor.c > @@ -29,6 +29,7 @@ > #include > #include > #include > +#include >=20 > #include > #include "channel_monitor.h" > @@ -51,7 +52,7 @@ static volatile unsigned run_loop =3D 1; static int > global_event_fd; static unsigned int policy_is_set; static struct epoll= _event > *global_events_list; -static struct policy policies[MAX_CLIENTS]; > +static struct policy policies[POWER_MGR_MAX_CPUS]; POWER_MGR_MAX_CPUS was deleted. RTE_MAX_LCORE should be used instead I thin= k. >=20 > #ifdef USE_JANSSON >=20 > @@ -130,13 +131,45 @@ set_policy_mac(struct channel_packet *pkt, int idx, > char *mac) > return 0; > } >=20 > +static char* > +get_resource_name_from_chn_path(const char *channel_path) { > + char *substr =3D NULL; > + > + substr =3D strstr(channel_path, > CHANNEL_MGR_FIFO_PATTERN_NAME); > + > + return substr; > +} >=20 > static int > -parse_json_to_pkt(json_t *element, struct channel_packet *pkt) > +get_resource_id_from_vmname(const char *vm_name) { > + int result =3D -1; > + int off =3D 0; > + > + if (vm_name =3D=3D NULL) > + return -1; > + > + while (vm_name[off] !=3D '\0') { > + if (isdigit(vm_name[off])) > + break; > + off++; > + } > + result =3D atoi(&vm_name[off]); > + if ((result =3D=3D 0) && (vm_name[off] !=3D '0')) > + return -1; > + > + return result; > +} > + > +static int > +parse_json_to_pkt(json_t *element, struct channel_packet *pkt, > + const char *vm_name) > { > const char *key; > json_t *value; > int ret; > + int resource_id; >=20 > memset(pkt, 0, sizeof(struct channel_packet)); >=20 > @@ -147,19 +180,23 @@ parse_json_to_pkt(json_t *element, struct > channel_packet *pkt) > pkt->command =3D PKT_POLICY; > pkt->core_type =3D CORE_TYPE_PHYSICAL; >=20 > + if (vm_name =3D=3D NULL) { > + RTE_LOG(ERR, CHANNEL_MONITOR, > + "vm_name is NULL, request rejected !\n"); > + return -1; > + } > + > json_object_foreach(element, key, value) { > if (!strcmp(key, "policy")) { > /* Recurse in to get the contents of profile */ > - ret =3D parse_json_to_pkt(value, pkt); > + ret =3D parse_json_to_pkt(value, pkt, vm_name); > if (ret) > return ret; > } else if (!strcmp(key, "instruction")) { > /* Recurse in to get the contents of instruction */ > - ret =3D parse_json_to_pkt(value, pkt); > + ret =3D parse_json_to_pkt(value, pkt, vm_name); > if (ret) > return ret; > - } else if (!strcmp(key, "name")) { > - strcpy(pkt->vm_name, json_string_value(value)); > } else if (!strcmp(key, "command")) { > char command[32]; > strlcpy(command, json_string_value(value), 32); @@ > -222,16 +259,6 @@ parse_json_to_pkt(json_t *element, struct > channel_packet *pkt) > json_array_get(value, i)); > pkt->timer_policy.quiet_hours[i] =3D hour; > } > - } else if (!strcmp(key, "core_list")) { > - unsigned int i; > - size_t size =3D json_array_size(value); > - > - for (i =3D 0; i < size; i++) { > - int core =3D (int)json_integer_value( > - json_array_get(value, i)); > - pkt->vcpu_to_control[i] =3D core; > - } > - pkt->num_vcpu =3D size; > } else if (!strcmp(key, "mac_list")) { > unsigned int i; > size_t size =3D json_array_size(value); @@ -270,13 > +297,21 @@ parse_json_to_pkt(json_t *element, struct channel_packet > *pkt) > "Invalid command received in > JSON\n"); > return -1; > } > - } else if (!strcmp(key, "resource_id")) { > - pkt->resource_id =3D > (uint32_t)json_integer_value(value); > } else { > RTE_LOG(ERR, CHANNEL_MONITOR, > "Unknown key received in JSON string: %s\n", > key); > } > + > + resource_id =3D get_resource_id_from_vmname(vm_name); > + if (resource_id < 0) { > + RTE_LOG(ERR, CHANNEL_MONITOR, > + "Could not get resource_id from > vm_name:%s\n", > + vm_name); > + return -1; > + } > + rte_strlcpy(pkt->vm_name, vm_name, VM_MAX_NAME_SZ); > + pkt->resource_id =3D resource_id; > } > return 0; > } > @@ -426,13 +461,13 @@ update_policy(struct channel_packet *pkt) { >=20 > unsigned int updated =3D 0; > - int i; > + unsigned int i; >=20 >=20 > RTE_LOG(INFO, CHANNEL_MONITOR, > "Applying policy for %s\n", pkt->vm_name); >=20 > - for (i =3D 0; i < MAX_CLIENTS; i++) { > + for (i =3D 0; i < RTE_DIM(policies); i++) { > if (strcmp(policies[i].pkt.vm_name, pkt->vm_name) =3D=3D 0) { > /* Copy the contents of *pkt into the policy.pkt */ > policies[i].pkt =3D *pkt; > @@ -447,7 +482,7 @@ update_policy(struct channel_packet *pkt) > } > } > if (!updated) { > - for (i =3D 0; i < MAX_CLIENTS; i++) { > + for (i =3D 0; i < RTE_DIM(policies); i++) { > if (policies[i].enabled =3D=3D 0) { > policies[i].pkt =3D *pkt; > get_pcpu_to_control(&policies[i]); > @@ -465,13 +500,13 @@ update_policy(struct channel_packet *pkt) static > int remove_policy(struct channel_packet *pkt __rte_unused) { > - int i; > + unsigned int i; >=20 > /* > * Disabling the policy is simply a case of setting > * enabled to 0 > */ > - for (i =3D 0; i < MAX_CLIENTS; i++) { > + for (i =3D 0; i < RTE_DIM(policies); i++) { > if (strcmp(policies[i].pkt.vm_name, pkt->vm_name) =3D=3D 0) { > policies[i].enabled =3D 0; > return 0; > @@ -792,6 +827,8 @@ read_json_packet(struct channel_info *chan_info) > int n_bytes, ret; > json_t *root; > json_error_t error; > + const char *resource_name; > + >=20 > /* read opening brace to closing brace */ > do { > @@ -828,13 +865,15 @@ read_json_packet(struct channel_info *chan_info) > root =3D json_loads(json_data, 0, &error); >=20 > if (root) { > + resource_name =3D > get_resource_name_from_chn_path( > + chan_info->channel_path); > /* > * Because our data is now in the json > * object, we can overwrite the pkt > * with a channel_packet struct, using > * parse_json_to_pkt() > */ > - ret =3D parse_json_to_pkt(root, &pkt); > + ret =3D parse_json_to_pkt(root, &pkt, resource_name); > json_decref(root); > if (ret) { > RTE_LOG(ERR, CHANNEL_MONITOR, > @@ -891,9 +930,9 @@ run_channel_monitor(void) > } > rte_delay_us(time_period_ms*1000); > if (policy_is_set) { > - int j; > + unsigned int j; >=20 > - for (j =3D 0; j < MAX_CLIENTS; j++) { > + for (j =3D 0; j < RTE_DIM(policies); j++) { > if (policies[j].enabled =3D=3D 1) > apply_policy(&policies[j]); > } > diff --git a/examples/vm_power_manager/main.c > b/examples/vm_power_manager/main.c > index 893bf4cdd..9f24cf69b 100644 > --- a/examples/vm_power_manager/main.c > +++ b/examples/vm_power_manager/main.c > @@ -421,7 +421,7 @@ main(int argc, char **argv) > return -1; > } >=20 > - add_host_channel(); > + add_host_channels(); >=20 > printf("Running core monitor on lcore id %d\n", lcore_id); > rte_eal_remote_launch(run_core_monitor, NULL, lcore_id); > -- > 2.17.1 Tested-by: Marcin Hajkowski