mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
plugins/amdgpu: Add socket operations
When enabling parallel restore, the target process and the main CRIU process need an IPC interface to communicate and transfer restore commands. This patch adds a Unix domain TCP socket and stores this socket in `fdstore`. Signed-off-by: Yanning Yang <yangyanning@sjtu.edu.cn>
This commit is contained in:
parent
e257d04974
commit
1fd1b670c4
2 changed files with 65 additions and 0 deletions
59
plugins/amdgpu/amdgpu_socket_utils.c
Normal file
59
plugins/amdgpu/amdgpu_socket_utils.c
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "amdgpu_socket_utils.h"
|
||||
#include "criu-log.h"
|
||||
#include "common/scm.h"
|
||||
#include "fdstore.h"
|
||||
#include "util-pie.h"
|
||||
#include "util.h"
|
||||
|
||||
int parallel_socket_addr_len;
|
||||
struct sockaddr_un parallel_socket_addr;
|
||||
int parallel_socket_id = 0;
|
||||
|
||||
static void amdgpu_socket_name_gen(struct sockaddr_un *addr, int *len)
|
||||
{
|
||||
addr->sun_family = AF_UNIX;
|
||||
snprintf(addr->sun_path, UNIX_PATH_MAX, "x/criu-amdgpu-parallel-%s", criu_run_id);
|
||||
*len = SUN_LEN(addr);
|
||||
*addr->sun_path = '\0';
|
||||
}
|
||||
|
||||
int install_parallel_sock(void)
|
||||
{
|
||||
int ret = 0;
|
||||
int sock_fd;
|
||||
|
||||
sock_fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
if (sock_fd < 0) {
|
||||
pr_perror("socket creation failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
amdgpu_socket_name_gen(¶llel_socket_addr, ¶llel_socket_addr_len);
|
||||
ret = bind(sock_fd, (struct sockaddr *)¶llel_socket_addr, parallel_socket_addr_len);
|
||||
if (ret < 0) {
|
||||
pr_perror("bind failed");
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = listen(sock_fd, SOMAXCONN);
|
||||
if (ret < 0) {
|
||||
pr_perror("listen failed");
|
||||
goto err;
|
||||
}
|
||||
|
||||
parallel_socket_id = fdstore_add(sock_fd);
|
||||
if (parallel_socket_id < 0) {
|
||||
ret = -1;
|
||||
goto err;
|
||||
}
|
||||
err:
|
||||
close(sock_fd);
|
||||
return ret;
|
||||
}
|
||||
6
plugins/amdgpu/amdgpu_socket_utils.h
Normal file
6
plugins/amdgpu/amdgpu_socket_utils.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef __KFD_PLUGIN_AMDGPU_SOCKET_UTILS_H__
|
||||
#define __KFD_PLUGIN_AMDGPU_SOCKET_UTILS_H__
|
||||
|
||||
int install_parallel_sock(void);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue