util: add sync_fence_info

This returns sync file info, including timestamps.
The caller is responsible for freeing the memory.

Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31548>
This commit is contained in:
Gurchetan Singh 2024-10-03 14:42:27 -07:00 committed by Marge Bot
parent 02b383fded
commit d7f264452e

View file

@ -36,6 +36,7 @@
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include "util/detect_os.h"
@ -85,6 +86,14 @@ struct sync_merge_data {
uint32_t pad;
};
struct sync_fence_info {
char obj_name[32];
char driver_name[32];
int32_t status;
uint32_t flags;
uint64_t timestamp_ns;
};
struct sync_file_info {
char name[32];
int32_t status;
@ -159,6 +168,34 @@ sync_valid_fd(int fd)
return ioctl(fd, SYNC_IOC_FILE_INFO, &info) >= 0;
}
static inline struct sync_file_info* sync_file_info(int32_t fd)
{
struct sync_file_info local_info;
struct sync_file_info *info;
int err;
memset(&local_info, 0, sizeof(local_info));
err = ioctl(fd, SYNC_IOC_FILE_INFO, &local_info);
if (err < 0)
return NULL;
info = (struct sync_file_info *)calloc(1, sizeof(struct sync_file_info) +
local_info.num_fences * sizeof(struct sync_fence_info));
if (!info)
return NULL;
info->num_fences = local_info.num_fences;
info->sync_fence_info = (uint64_t)(uintptr_t)(info + 1);
err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
if (err < 0) {
free(info);
return NULL;
}
return info;
}
#endif /* DETECT_OS_ANDROID */
/* accumulate fd2 into fd1. If *fd1 is not a valid fd then dup fd2,