tools/testing/selftests/sync/sync.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sync/sync.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sync/sync.c- Extension
.c- Size
- 4739 bytes
- Lines
- 222
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hmalloc.hpoll.hstdint.hstring.hunistd.hsys/ioctl.hsys/stat.hsys/types.hsync.hsw_sync.hlinux/sync_file.h
Detected Declarations
struct sw_sync_create_fence_datafunction sync_waitfunction sync_mergefunction sync_file_info_freefunction sync_fence_sizefunction sync_fence_count_with_statusfunction sw_sync_timeline_createfunction sw_sync_timeline_incfunction sw_sync_timeline_is_validfunction sw_sync_timeline_destroyfunction sw_sync_fence_createfunction sw_sync_fence_is_validfunction sw_sync_fence_destroy
Annotated Snippet
struct sw_sync_create_fence_data {
__u32 value;
char name[32];
__s32 fence;
};
#define SW_SYNC_IOC_MAGIC 'W'
#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0,\
struct sw_sync_create_fence_data)
#define SW_SYNC_IOC_INC _IOW(SW_SYNC_IOC_MAGIC, 1, __u32)
int sync_wait(int fd, int timeout)
{
struct pollfd fds;
fds.fd = fd;
fds.events = POLLIN | POLLERR;
return poll(&fds, 1, timeout);
}
int sync_merge(const char *name, int fd1, int fd2)
{
struct sync_merge_data data = {};
int err;
data.fd2 = fd2;
strncpy(data.name, name, sizeof(data.name) - 1);
data.name[sizeof(data.name) - 1] = '\0';
err = ioctl(fd1, SYNC_IOC_MERGE, &data);
if (err < 0)
return err;
return data.fence;
}
static struct sync_file_info *sync_file_info(int fd)
{
struct sync_file_info *info;
struct sync_fence_info *fence_info;
int err, num_fences;
info = calloc(1, sizeof(*info));
if (info == NULL)
return NULL;
err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
if (err < 0) {
free(info);
return NULL;
}
num_fences = info->num_fences;
if (num_fences) {
info->flags = 0;
info->num_fences = num_fences;
fence_info = calloc(num_fences, sizeof(*fence_info));
if (!fence_info) {
free(info);
return NULL;
}
info->sync_fence_info = (uint64_t)(unsigned long)fence_info;
err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
if (err < 0) {
free(fence_info);
free(info);
return NULL;
}
}
return info;
}
static void sync_file_info_free(struct sync_file_info *info)
{
free((void *)(unsigned long)info->sync_fence_info);
free(info);
}
int sync_fence_size(int fd)
{
int count;
struct sync_file_info *info = sync_file_info(fd);
Annotation
- Immediate include surface: `fcntl.h`, `malloc.h`, `poll.h`, `stdint.h`, `string.h`, `unistd.h`, `sys/ioctl.h`, `sys/stat.h`.
- Detected declarations: `struct sw_sync_create_fence_data`, `function sync_wait`, `function sync_merge`, `function sync_file_info_free`, `function sync_fence_size`, `function sync_fence_count_with_status`, `function sw_sync_timeline_create`, `function sw_sync_timeline_inc`, `function sw_sync_timeline_is_valid`, `function sw_sync_timeline_destroy`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.