tools/testing/selftests/timers/threadtest.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/threadtest.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/timers/threadtest.c- Extension
.c- Size
- 4368 bytes
- Lines
- 194
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hunistd.hstdlib.hsys/time.hpthread.hkselftest.h
Detected Declarations
function checklistfunction main
Annotated Snippet
if (listcount >= LISTSIZE) {
checklist(global_list, LISTSIZE);
listcount = 0;
}
clock_gettime(CLOCK_MONOTONIC, &global_list[listcount++]);
pthread_mutex_unlock(&list_lock);
}
return NULL;
}
/* Each independent thread fills in its own
* list. This stresses clock_gettime() lock contention.
*/
void *independent_thread(void *arg)
{
struct timespec my_list[LISTSIZE];
int count;
while (!done) {
/* fill the list */
for (count = 0; count < LISTSIZE; count++)
clock_gettime(CLOCK_MONOTONIC, &my_list[count]);
checklist(my_list, LISTSIZE);
}
return NULL;
}
#define DEFAULT_THREAD_COUNT 8
#define DEFAULT_RUNTIME 30
int main(int argc, char **argv)
{
int thread_count, i;
time_t start, now, runtime;
char buf[255];
pthread_t pth[MAX_THREADS];
int opt;
void *tret;
int ret = 0;
void *(*thread)(void *) = shared_thread;
thread_count = DEFAULT_THREAD_COUNT;
runtime = DEFAULT_RUNTIME;
/* Process arguments */
while ((opt = getopt(argc, argv, "t:n:i")) != -1) {
switch (opt) {
case 't':
runtime = atoi(optarg);
break;
case 'n':
thread_count = atoi(optarg);
break;
case 'i':
thread = independent_thread;
printf("using independent threads\n");
break;
default:
printf("Usage: %s [-t <secs>] [-n <numthreads>] [-i]\n", argv[0]);
printf(" -t: time to run\n");
printf(" -n: number of threads\n");
printf(" -i: use independent threads\n");
return -1;
}
}
if (thread_count > MAX_THREADS)
thread_count = MAX_THREADS;
setbuf(stdout, NULL);
start = time(0);
strftime(buf, 255, "%a, %d %b %Y %T %z", localtime(&start));
printf("%s\n", buf);
printf("Testing consistency with %i threads for %ld seconds: ", thread_count, runtime);
fflush(stdout);
/* spawn */
for (i = 0; i < thread_count; i++)
pthread_create(&pth[i], 0, thread, 0);
while (time(&now) < start + runtime) {
sleep(1);
if (done) {
ret = 1;
strftime(buf, 255, "%a, %d %b %Y %T %z", localtime(&now));
printf("%s\n", buf);
Annotation
- Immediate include surface: `stdio.h`, `unistd.h`, `stdlib.h`, `sys/time.h`, `pthread.h`, `kselftest.h`.
- Detected declarations: `function checklist`, `function main`.
- 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.