bidirect guest channel
v2 cover bidirect guest channel
From: Marcin Hajkowski <[email protected]>
Extend guest channel API to allow bidirectional communication. Modify power manager host and guest side to communicate in both directions.
v2:
* send ack only if power operation return positive value
* log diffent error for unexpected incoming command and error during ack/nak cmd sending
Marcin Hajkowski (4):
power: fix invalid socket indicator value
power: extend guest channel api for reading
power: process incoming confirmation cmds
power: send confirmation cmd to vm guest
examples/vm_power_manager/channel_monitor.c | 67 ++++++++++++++++-- examples/vm_power_manager/guest_cli/Makefile | 1 + .../guest_cli/vm_power_cli_guest.c | 65 +++++++++++++---- lib/librte_power/channel_commands.h | 5 ++ lib/librte_power/guest_channel.c | 69 +++++++++++++++++-- lib/librte_power/guest_channel.h | 35 ++++++++++ lib/librte_power/rte_power_version.map | 1 + 7 files changed, 219 insertions(+), 24 deletions(-)
Signature · 1 line
2.17.2
PATCH v2 1/4 power: fix invalid socket indicator value
From: Marcin Hajkowski <[email protected]>
Currently 0 is being used for not connected slot indication. This is not consistent with linux doc which identifies 0 as valid (connected) slot, thus modification was done to change it.
--- lib/librte_power/guest_channel.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
lib/librte_power/guest_channel.c +6 -6
@@ -19,7 +19,7 @@#define RTE_LOGTYPE_GUEST_CHANNEL RTE_LOGTYPE_USER1 -static int global_fds[RTE_MAX_LCORE ]; +static int global_fds[RTE_MAX_LCORE ] = { [0 ...RTE_MAX_LCORE -1 ] =-1 };int guest_channel_host_connect (const char *path,unsigned int lcore_id)
@@ -35,7 +35,7 @@ guest_channel_host_connect(const char *path, unsigned int lcore_id)return -1 ; }/* check if path is already open */ -if (global_fds[lcore_id] !=0 ) { +if (global_fds[lcore_id] !=-1 ) {RTE_LOG (ERR ,GUEST_CHANNEL ,"Channel(%u) is already open with fd %d\n" , lcore_id, global_fds[lcore_id]);return -1 ;
@@ -84,7 +84,7 @@ guest_channel_host_connect(const char *path, unsigned int lcore_id)return 0 ; error:close (fd); - global_fds[lcore_id] =0 ; + global_fds[lcore_id] =-1 ;return -1 ; }
@@ -100,7 +100,7 @@ guest_channel_send_msg(struct channel_packet *pkt, unsigned int lcore_id)return -1 ; } -if (global_fds[lcore_id] ==0 ) { +if (global_fds[lcore_id] <0 ) {RTE_LOG (ERR ,GUEST_CHANNEL ,"Channel is not connected\n" );return -1 ; }
@@ -134,8 +134,8 @@ guest_channel_host_disconnect(unsigned int lcore_id) lcore_id, RTE_MAX_LCORE-1);return ; } -if (global_fds[lcore_id] ==0 ) +if (global_fds[lcore_id] <0 )return ;close (global_fds[lcore_id]); - global_fds[lcore_id] =0 ; + global_fds[lcore_id] =-1 ; }
Signature · 1 line
2.17.2
PATCH v2 2/4 power: extend guest channel api for reading
In reply to HajkowskiFrom: Marcin Hajkowski <[email protected]>
Added new experimental API rte_power_guest_channel_receive_msg which gives possibility to receive messages send to guest.
--- lib/librte_power/channel_commands.h | 5 +++ lib/librte_power/guest_channel.c | 57 ++++++++++++++++++++++++++ lib/librte_power/guest_channel.h | 35 ++++++++++++++++ lib/librte_power/rte_power_version.map | 1 + 4 files changed, 98 insertions(+)
lib/librte_power/channel_commands.h +5 -0
@@ -28,6 +28,11 @@ extern "C" {#define CPU_POWER_SCALE_MIN 4#define CPU_POWER_ENABLE_TURBO 5#define CPU_POWER_DISABLE_TURBO 6 + +/* Generic Power Command Response */ +#define CPU_POWER_CMD_ACK 1 +#define CPU_POWER_CMD_NAK 2 +#define HOURS 24#define MAX_VFS 10
lib/librte_power/guest_channel.c +57 -0
75 lines not on this page · raw message
lib/librte_power/guest_channel.h +35 -0
@@ -68,6 +68,41 @@ int guest_channel_send_msg(struct channel_packet *pkt, unsigned int lcore_id);int rte_power_guest_channel_send_msg (struct channel_packet *pkt,unsigned int lcore_id); +/** +* Read a message contained in pkt over the Virtio-Serial +* from the host endpoint. +* +* @param pkt +* Pointer to a populated struct channel_packet +* +* @param lcore_id +* lcore_id. +* +* @return +* - 0 on success. +* - Negative on error. +*/ +int power_guest_channel_read_msg (struct channel_packet *pkt, +unsigned int lcore_id); + +/** +* Receive a message contained in pkt over the Virtio-Serial +* from the host endpoint. +* +* @param pkt +* Pointer to a populated struct channel_packet +* +* @param lcore_id +* lcore_id. +* +* @return +* - 0 on success. +* - Negative on error. +*/ +int __rte_experimental +rte_power_guest_channel_receive_msg (struct channel_packet *pkt, +unsigned int lcore_id); + #ifdef __cplusplus }#endif
lib/librte_power/rte_power_version.map +1 -0
@@ -44,4 +44,5 @@ EXPERIMENTAL { rte_power_empty_poll_stat_update; rte_power_poll_stat_fetch; rte_power_poll_stat_update; + rte_power_guest_channel_receive_msg; };
Signature · 1 line
2.17.2
Re: [PATCH v2 2/4] power: extend guest channel api for reading
Review
Quoted 8 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Hajkowski
---(quoted diff) +1
-0+#define CPU_POWER_CMD_NAK 2
Instead of NAK , NACK would be better I guess.
lib/librte_power/guest_channel.c int rte_power_guest_channel_send_msg(struct channel_packet *pkt, · line 144
Quoted 1 line
lib/librte_power/guest_channel.c +1
-0+if (global_fds[lcore_id] ==0 ) {
Is this now < 0 ?
lib/librte_power/guest_channel.c int rte_power_guest_channel_send_msg(struct channel_packet *pkt, · line 152
Quoted 3 lines
lib/librte_power/guest_channel.c +3
-0+ ret =read (global_fds[lcore_id], + buffer, buffer_len); +if (ret <0 ) {
read() return value 0 also should be handled?
Quoted 18 lines
lib/librte_power/guest_channel.c +13
-0+ +int rte_power_guest_channel_receive_msg (struct channel_packet *pkt, +unsigned int lcore_id) +{ +int ret; + +struct pollfd fds; + fds.fd = global_fds[lcore_id]; + fds.events =POLLIN ; + + ret =poll (&fds,1 ,TIMEOUT ); +if (ret ==0 ) { + RTE_LOG(DEBUG, GUEST_CHANNEL, "Timeout occurs duringpoll function.\n");
lib/librte_power/guest_channel.c +3
-0+return -1 ; + }else if (ret <0 ) { + RTE_LOG(ERR, GUEST_CHANNEL, "Error occurred during pollfunction: %s\n",
lib/librte_power/guest_channel.c int rte_power_guest_channel_send_msg(struct channel_packet *pkt, · line 182
Quoted 4 lines
lib/librte_power/guest_channel.c +4
-0+ strerror(ret)); +return -1 ; + } +
You can keep this function simple by moving all the code above code to power_guest_channel_read_msg(), like the way done in rte_power_guest_channel_send_msg() and guest_channel_send_msg().
Thanks,
Reshma
PATCH v2 3/4 power: process incoming confirmation cmds
In reply to HajkowskiFrom: Marcin Hajkowski <[email protected]>
Extend vm_power_guest to check incoming confirmations of messages previously sent to host.
--- examples/vm_power_manager/guest_cli/Makefile | 1 + .../guest_cli/vm_power_cli_guest.c | 65 +++++++++++++++---- 2 files changed, 54 insertions(+), 12 deletions(-)
examples/vm_power_manager/guest_cli/Makefile +1 -0
@@ -18,6 +18,7 @@ SRCS-y := main.c vm_power_cli_guest.c parse.c CFLAGS += -O3 -I$(RTE_SDK)/lib/librte_power/ CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
examples/vm_power_manager/guest_cli/vm_power_cli_guest.c +53 -12
102 lines not on this page · raw message
Signature · 1 line
2.17.2
PATCH v2 4/4 power: send confirmation cmd to vm guest
In reply to HajkowskiFrom: Marcin Hajkowski <[email protected]>
Use new guest channel API to send confirmation
message for received power command.
--- examples/vm_power_manager/channel_monitor.c | 67 +++++++++++++++++++-- 1 file changed, 61 insertions(+), 6 deletions(-)
examples/vm_power_manager/channel_monitor.c +61 -6
@@ -627,6 +627,39 @@ apply_policy(struct policy *pol)apply_workload_profile (pol); } +static int +write_binary_packet (struct channel_packet *pkt,struct channel_info *chan_info) +{ +int ret, buffer_len =sizeof (*pkt); +void *buffer = pkt; + +if (chan_info->fd ==0 ) { +RTE_LOG (ERR ,CHANNEL_MONITOR ,"Channel is not connected\n" ); +return -1 ; + } + +while (buffer_len >0 ) { + ret =write (chan_info->fd, buffer, buffer_len); +if (ret ==-1 ) { +if (errno ==EINTR ) +continue ; +return -1 ; + } + buffer = (char *)buffer + ret; + buffer_len -= ret; + } +return 0 ; +} + +static int +send_ack_for_received_cmd (struct channel_packet *pkt, +struct channel_info *chan_info, +uint32_t command) +{ + pkt->command = command; +return write_binary_packet (pkt, chan_info); +} +static int process_request (struct channel_packet *pkt,struct channel_info *chan_info) {
@@ -645,33 +678,55 @@ process_request(struct channel_packet *pkt, struct channel_info *chan_info)else core_num = pkt->resource_id; +bool valid_unit = true; +int scale_res; +switch (pkt->unit) {case (CPU_POWER_SCALE_MIN ): -power_manager_scale_core_min (core_num); + scale_res =power_manager_scale_core_min (core_num);break ;case (CPU_POWER_SCALE_MAX ): -power_manager_scale_core_max (core_num); + scale_res =power_manager_scale_core_max (core_num);break ;case (CPU_POWER_SCALE_DOWN ): -power_manager_scale_core_down (core_num); + scale_res =power_manager_scale_core_down (core_num);break ;case (CPU_POWER_SCALE_UP ): -power_manager_scale_core_up (core_num); + scale_res =power_manager_scale_core_up (core_num);break ;case (CPU_POWER_ENABLE_TURBO ): -power_manager_enable_turbo_core (core_num); + scale_res =power_manager_enable_turbo_core (core_num);break ;case (CPU_POWER_DISABLE_TURBO ): -power_manager_disable_turbo_core (core_num); + scale_res =power_manager_disable_turbo_core (core_num);break ;default : + valid_unit = false;break ; } + +int ret =-1 ; +if (valid_unit) { + ret =send_ack_for_received_cmd (pkt, + chan_info, + scale_res >0 ? +CPU_POWER_CMD_ACK + :CPU_POWER_CMD_NAK ); +if (ret <0 ) +RTE_LOG (DEBUG ,CHANNEL_MONITOR ,"Error during sending ack command.\n" ); + }else +RTE_LOG (DEBUG ,CHANNEL_MONITOR ,"Unexpected unit type.\n" ); + }if (pkt->command ==PKT_POLICY ) {RTE_LOG (INFO ,CHANNEL_MONITOR ,"Processing policy request %s\n" , pkt->vm_name); +int ret =send_ack_for_received_cmd (pkt, + chan_info, +CPU_POWER_CMD_ACK ); +if (ret <0 ) +RTE_LOG (DEBUG ,CHANNEL_MONITOR ,"Error during sending ack command.\n" );update_policy (pkt); policy_is_set =1 ; }
Signature · 1 line
2.17.2