Release 4.10 tools/testing/selftests/prctl/disable-tsc-on-off-stress-test.c
/*
* Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)
*
* Tests if the control register is updated correctly
* when set with prctl()
*
* Warning: this test will cause a very high load for a few seconds
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <inttypes.h>
#include <wait.h>
#include <sys/prctl.h>
#include <linux/prctl.h>
/* Get/set the process' ability to use the timestamp counter instruction */
#ifndef PR_GET_TSC
#define PR_GET_TSC 25
#define PR_SET_TSC 26
# define PR_TSC_ENABLE 1
/* allow the use of the timestamp counter */
# define PR_TSC_SIGSEGV 2
/* throw a SIGSEGV instead of reading the TSC */
#endif
/* snippet from wikipedia :-) */
static uint64_t rdtsc(void)
{
uint32_t lo, hi;
/* We cannot use "=A", since this would use %rax on x86_64 */
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
return (uint64_t)hi << 32 | lo;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
erik bosman | erik bosman | 23 | 85.19% | 1 | 50.00% |
peter foley | peter foley | 4 | 14.81% | 1 | 50.00% |
| Total | 27 | 100.00% | 2 | 100.00% |
int should_segv = 0;
static void sigsegv_cb(int sig)
{
if (!should_segv)
{
fprintf(stderr, "FATAL ERROR, rdtsc() failed while enabled\n");
exit(0);
}
if (prctl(PR_SET_TSC, PR_TSC_ENABLE) < 0)
{
perror("prctl");
exit(0);
}
should_segv = 0;
rdtsc();
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
erik bosman | erik bosman | 57 | 98.28% | 1 | 50.00% |
peter foley | peter foley | 1 | 1.72% | 1 | 50.00% |
| Total | 58 | 100.00% | 2 | 100.00% |
static void task(void)
{
signal(SIGSEGV, sigsegv_cb);
alarm(10);
for(;;)
{
rdtsc();
if (should_segv)
{
fprintf(stderr, "FATAL ERROR, rdtsc() succeeded while disabled\n");
exit(0);
}
if (prctl(PR_SET_TSC, PR_TSC_SIGSEGV) < 0)
{
perror("prctl");
exit(0);
}
should_segv = 1;
}
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
erik bosman | erik bosman | 74 | 98.67% | 1 | 50.00% |
peter foley | peter foley | 1 | 1.33% | 1 | 50.00% |
| Total | 75 | 100.00% | 2 | 100.00% |
int main(void)
{
int n_tasks = 100, i;
fprintf(stderr, "[No further output means we're allright]\n");
for (i=0; i<n_tasks; i++)
if (fork() == 0)
task();
for (i=0; i<n_tasks; i++)
wait(NULL);
exit(0);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
erik bosman | erik bosman | 66 | 98.51% | 1 | 50.00% |
mahesh khanwalkar | mahesh khanwalkar | 1 | 1.49% | 1 | 50.00% |
| Total | 67 | 100.00% | 2 | 100.00% |
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
erik bosman | erik bosman | 275 | 97.52% | 1 | 33.33% |
peter foley | peter foley | 6 | 2.13% | 1 | 33.33% |
mahesh khanwalkar | mahesh khanwalkar | 1 | 0.35% | 1 | 33.33% |
| Total | 282 | 100.00% | 3 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.