tools/testing/selftests/sync/sync_stress_consumer.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/sync/sync_stress_consumer.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/sync/sync_stress_consumer.c- Extension
.c- Size
- 5380 bytes
- Lines
- 186
- 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.
Dependency Surface
pthread.hsync.hsw_sync.hsynctest.h
Detected Declarations
function filesfunction mpsc_producer_threadfunction mpcs_consumer_threadfunction test_consumer_stress_multi_producer_single_consumer
Annotated Snippet
if ((iterations + id) % 8 != 0) {
ASSERT(sync_wait(fence, -1) > 0,
"Failure waiting on fence\n");
} else {
ASSERT(busy_wait_on_fence(fence) == 0,
"Failure waiting on fence\n");
}
/*
* Every producer increments the counter, the consumer
* checks and erases it
*/
pthread_mutex_lock(&test_data_mpsc.lock);
test_data_mpsc.counter++;
pthread_mutex_unlock(&test_data_mpsc.lock);
ASSERT(sw_sync_timeline_inc(producer_timelines[id], 1) == 0,
"Error advancing producer timeline\n");
sw_sync_fence_destroy(fence);
}
return 0;
}
static int mpcs_consumer_thread(void)
{
int fence, merged, tmp, valid, it, i;
int *producer_timelines = test_data_mpsc.producer_timelines;
int consumer_timeline = test_data_mpsc.consumer_timeline;
int iterations = test_data_mpsc.iterations;
int n = test_data_mpsc.threads;
for (it = 1; it <= iterations; it++) {
fence = sw_sync_fence_create(producer_timelines[0], "name", it);
for (i = 1; i < n; i++) {
tmp = sw_sync_fence_create(producer_timelines[i],
"name", it);
merged = sync_merge("name", tmp, fence);
sw_sync_fence_destroy(tmp);
sw_sync_fence_destroy(fence);
fence = merged;
}
valid = sw_sync_fence_is_valid(fence);
ASSERT(valid, "Failure merging fences\n");
/*
* Make sure we see an increment from every producer thread.
* Vary the means by which we wait.
*/
if (iterations % 8 != 0) {
ASSERT(sync_wait(fence, -1) > 0,
"Producers did not increment as expected\n");
} else {
ASSERT(busy_wait_on_fence(fence) == 0,
"Producers did not increment as expected\n");
}
ASSERT(test_data_mpsc.counter == n * it,
"Counter value mismatch!\n");
/* Release the producer threads */
ASSERT(sw_sync_timeline_inc(consumer_timeline, 1) == 0,
"Failure releasing producer threads\n");
sw_sync_fence_destroy(fence);
}
return 0;
}
int test_consumer_stress_multi_producer_single_consumer(void)
{
int iterations = 1 << 12;
int n = 5;
long i, ret;
int producer_timelines[n];
int consumer_timeline;
pthread_t threads[n];
consumer_timeline = sw_sync_timeline_create();
for (i = 0; i < n; i++)
producer_timelines[i] = sw_sync_timeline_create();
test_data_mpsc.producer_timelines = producer_timelines;
test_data_mpsc.consumer_timeline = consumer_timeline;
test_data_mpsc.iterations = iterations;
test_data_mpsc.threads = n;
test_data_mpsc.counter = 0;
Annotation
- Immediate include surface: `pthread.h`, `sync.h`, `sw_sync.h`, `synctest.h`.
- Detected declarations: `function files`, `function mpsc_producer_thread`, `function mpcs_consumer_thread`, `function test_consumer_stress_multi_producer_single_consumer`.
- 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.