tools/virtio/ringtest/ptr_ring.c
Source file repositories/reference/linux-study-clean/tools/virtio/ringtest/ptr_ring.c
File Facts
- System
- Linux kernel
- Corpus path
tools/virtio/ringtest/ptr_ring.c- Extension
.c- Size
- 3601 bytes
- Lines
- 210
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
main.hstdlib.hstdio.hstring.hpthread.hmalloc.hassert.herrno.hlimits.h../../../include/linux/ptr_ring.h
Detected Declarations
function kfreefunction spin_lock_initfunction spin_lockfunction spin_unlockfunction spin_lock_bhfunction spin_unlock_bhfunction spin_lock_irqfunction spin_unlock_irqfunction spin_lock_irqsavefunction spin_unlock_irqrestorefunction alloc_ringfunction add_inbuffunction used_emptyfunction disable_callfunction enable_callfunction kick_availablefunction disable_kickfunction enable_kickfunction avail_emptyfunction use_buffunction call_used
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#include "main.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <malloc.h>
#include <assert.h>
#include <errno.h>
#include <limits.h>
#define SMP_CACHE_BYTES 64
#define cache_line_size() SMP_CACHE_BYTES
#define ____cacheline_aligned_in_smp __attribute__ ((aligned (SMP_CACHE_BYTES)))
#define unlikely(x) (__builtin_expect(!!(x), 0))
#define likely(x) (__builtin_expect(!!(x), 1))
#define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a))
#define SIZE_MAX (~(size_t)0)
#define KMALLOC_MAX_SIZE SIZE_MAX
typedef pthread_spinlock_t spinlock_t;
typedef int gfp_t;
#define __GFP_ZERO 0x1
static void *kmalloc(unsigned size, gfp_t gfp)
{
void *p = memalign(64, size);
if (!p)
return p;
if (gfp & __GFP_ZERO)
memset(p, 0, size);
return p;
}
static inline void *kzalloc(unsigned size, gfp_t flags)
{
return kmalloc(size, flags | __GFP_ZERO);
}
static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
if (size != 0 && n > SIZE_MAX / size)
return NULL;
return kmalloc(n * size, flags);
}
static inline void *kcalloc(size_t n, size_t size, gfp_t flags)
{
return kmalloc_array(n, size, flags | __GFP_ZERO);
}
static void kfree(void *p)
{
if (p)
free(p);
}
#define kvmalloc_array kmalloc_array
#define kvfree kfree
static void spin_lock_init(spinlock_t *lock)
{
int r = pthread_spin_init(lock, 0);
assert(!r);
}
static void spin_lock(spinlock_t *lock)
{
int ret = pthread_spin_lock(lock);
assert(!ret);
}
static void spin_unlock(spinlock_t *lock)
{
int ret = pthread_spin_unlock(lock);
assert(!ret);
}
static void spin_lock_bh(spinlock_t *lock)
{
spin_lock(lock);
}
static void spin_unlock_bh(spinlock_t *lock)
{
spin_unlock(lock);
}
Annotation
- Immediate include surface: `main.h`, `stdlib.h`, `stdio.h`, `string.h`, `pthread.h`, `malloc.h`, `assert.h`, `errno.h`.
- Detected declarations: `function kfree`, `function spin_lock_init`, `function spin_lock`, `function spin_unlock`, `function spin_lock_bh`, `function spin_unlock_bh`, `function spin_lock_irq`, `function spin_unlock_irq`, `function spin_lock_irqsave`, `function spin_unlock_irqrestore`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.