linux/Documentation/prctl/disable-tsc-ctxt-sw-stress-test.c
<<
.0.314./spa 14./form 14.a .0.314 href="../linux+v3 al1/Documenta > /prctl/disable-tsc-ctxt-sw-stress-test.c">.0.314.img src="../.sta c/gfx/right.png" alt=">>">.0./spa .0.spa class="lxr_search">.0.3 ="+search" method="post" onsubmit="return do_search(this);">.0.314.input typ hidden" nam navtarget" ion> ">.0.314.input typ text" nam search" id search">.0.314.buttopttyp submit">Search.0.314Prefs 14./a>.0./spa .314 4./div .314 4.form ac > ="ajax+*" method="post" onsubmit="return false;">.0.input typ hidden" nam ajax_lookup" id ajax_lookup" ion> ">..314 4./form ..314 4.div class="headingbottom">
4 41./a>.spa class="comment" /*./spa 4 42./a>.spa class="comment" * Tests for prctl(PR_GET_TSC, ...) / prctl(PR_SET_TSC, ...)./spa 4 43./a>.spa class="comment" *./spa 4 44./a>.spa class="comment" * Tests if the control register is updated correctly./spa 4 45./a>.spa class="comment" * at context switches./spa 4 46./a>.spa class="comment" *./spa 4 47./a>.spa class="comment" * Warning: this test will cause a very high load for a few seconds./spa 4 48./a>.spa class="comment" *./spa 4 49./a>.spa class="comment" */./spa 4 .17"a 4 11./a>#include <stdio.h./a>> 4 12./a>#include <stdlib.h./a>> 4 13./a>#include <unistd.h./a>> 4 14./a>#include <signal.h./a>> 4 15./a>#include <inttyp s.h./a>> 4 16./a>#include <wait.h./a>> 4 177"a 4 187"a 4 19./a>#include <sys/prctl.h./a>> 4 20./a>#include <linux/prctl.h./a>> 4 217"a 4 22./a>.spa class="comment" /* Get/set the process' ability to use the timestamp counter instruc > */./spa 4 23./a>#ifndef4.a href="+code=PR_GET_TSC" class="sref">PR_GET_TSC7"a 4 24./a>#define4.a href="+code=PR_GET_TSC" class="sref">PR_GET_TSC7"a 25 4 25./a>#define4.a href="+code=PR_SET_TSC" class="sref">PR_SET_TSC7"a 26 4 26./a># define4.a href="+code=PR_TSC_ENABLE" class="sref">PR_TSC_ENABLE7"a 14 4.spa class="comment" /* allow the use of the timestamp counter */./spa 4 27./a># define4.a href="+code=PR_TSC_SIGSEGV" class="sref">PR_TSC_SIGSEGV7"a 24 4.spa class="comment" /* throw a SIGSEGV instead of reading the TSC */./spa 4 287"a #endif 4 297"a 4 30./a>.a href="+code=uint64_t" class="sref">uint64_t7"a .a href="+code=rdtsc" class="sref">rdtsc7"a () { 4 31./a>.a href="+code=uint32_t" class="sref">uint32_t7"a .a href="+code=lo" class="sref">lo7"a , .a href="+code=hi" class="sref">hi7"a ; 4 32./a>.spa class="comment" /* We cannot use "=A", since this would use %rax > x86_64 */./spa 4 33./a>.a href="+code=__asm__" class="sref">__asm__7"a .a href="+code=__vola le__" class="sref">__vola le__7"a (.spa class="string">"rdtsc"./spa : .spa class="string">"=a"./spa (.a href="+code=lo" class="sref">lo7"a ), .spa class="string">"=d"./spa (.a href="+code=hi" class="sref">hi7"a )); 4 34./a>return (.a href="+code=uint64_t" class="sref">uint64_t7"a ).a href="+code=hi" class="sref">hi7"a << 32 | .a href="+code=lo" class="sref">lo7"a ; 4 35./a>} 4 367"a 4 37./a>void .a href="+code=sigsegv_expect" class="sref">sigsegv_expect7"a (int .a href="+code=sig" class="sref">sig7"a ) 4 387"a { 4 397"a .spa class="comment" /* */./spa 4 40./a>} 4 417"a 4 42./a>void .a href="+code=segvtask" class="sref">segvtask7"a (void) 4 437"a { 4 447"a if (.a href="+code=prctl" class="sref">prctl7"a (.a href="+code=PR_SET_TSC" class="sref">PR_SET_TSC7"a , .a href="+code=PR_TSC_SIGSEGV" class="sref">PR_TSC_SIGSEGV7"a ) < 0) 4 457"a { 4 467"a .a href="+code=perror" class="sref">perror7"a (.spa class="string">"prctl"./spa ); &0 > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSEGe" nam 4L38">4 387"a { /prctl/disable-tsc-ctxt-sw-stress-test.c#L41" id L41" class="line" nam 4L39">4 397"a .s4a cl4ss="comment" /ss="sref">sig7"a na"a (.a href="+co"a na"_SET_TSC" class="srePR_TSC_SIGSEGV7"a ) &la href="DocC_SIGSEGV" class="sref">sigsegv_expect7"a (int .a href="+code=si > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE5e" nam 5L40">4 40./a>} sig7alarm_expect7"a (intalarm_SET_10 > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE5e" nam 5L41">4 417"a sig7tsc7"a () { 4 42./a>void .a hr5f="+c52s="comment" /ss="sref">sig7fp;./tfa () { /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE5e" nam 5L43">4 437"a { sig7" iv_expect7"a (int" ivng">&0 > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE5e" nam 5L44">4 447"a if5(.a h54ta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L41" id L41" class="li5" nam LL5">4 45./a>.spa class=a hre55a > /prctl/disable-tsc-ctxt-sw-stress-test.c#L42" id L42" class="li5e" nam 5L46">4 467"a 5 5ta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L37" id L37" class="li5V" class5"srefw-stress-test.c#L35" 4re5de=sigsegv_expect" class="sref">sfai"a (.a href="+co"a ef">sfai"e=sig" class="sref">sig7"a ) 4 387"a { /prctl/disable-tsc-ctxt-sw-stress-test.c#L39" id L39" class="li5e" nam 5L39">4 397"a .s5a cl5ss="comment" /ss="sref">sig7fp;./tfa () { /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE6e" nam 6L40">4 40./a>} sig7" iv_expect7"a (int" ivng">&0 > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE6e" nam 6L41">4 417"a 4 42./a>void .a hr6f="+c62a > /prctl/disable-tsc-ctxt-sw-stress-test.c#L37" id L37" class="li6e" nam 6L43">4 437"a { /prctl/disable-tsc-ctxt-sw-stress-test.c#L43" id L43" class="li6e" nam 6L44">4 447"a if6(.a h64ta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L39" id L39" class="li6" nam 6L5">4 45./a>.spa class6a hre6="Documenta tl" class="sref">prctl7"a (.a href="+code=PR_SET_TSC" class="sref">PR_SET_TSC7"a , .a href="+code=PR_TSC_SIGSEGV" class="sref">R_TSC_ENABLE7"a 14 4.spa clumenta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L45" id L45" class="li6" nam LL6">4 46./a>.spa class= 6a href="+code> /prctl/disable-tsc-ctxt-sw-stress-test.c#L39" id L39" class="li6V" class6"srefw-stress-test.c#L36" 4re6s-tes4SC_SIGSET3-tsc-ctxt-sw-l1al2 9error7"a (.spa class="string">"prctl"./spa ); 4 387"a { &0 > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE6e" nam 6L39">4 397"a .s6a cl6ss="comment" > /prctl/disable-tsc-ctxt-sw-stress-test.c#L41" id L41" class="li7e" nam 7L40">4 40./a>} sig7"a na"a (.a href="+co"a na"_SET_TSC" class="srePR_TSC_SIGSEGV7"a ) &la href="DocC_SIGSEGV" class="sref">sfai"a (.a href="+co"a ef">sfai"e=si > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE7e" nam 7L41">4 417"a sig7alarm_expect7"a (intalarm_SET_10 > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE7e" nam 7L42">4 42./a>void .a hr7f="+c72s="comment" for(;;) /ss="sref">sig7tsc7"a () { 4 437"a { /prctl/disable-tsc-ctxt-sw-stress-test.c#L41" id L41" class="li7e" nam 7L44">4 447"a if7(.a h74a > /prctl/disable-tsc-ctxt-sw-stress-test.c#L37" id L37" class="li7" nam 7L5">4 45./a>.spa class7a hre75a > /prctl/disable-tsc-ctxt-sw-stress-test.c#L42" id L42" class="li7" nam 7L6">4 46./a>.spa class7 7a hre" class="sref">sig7maina () { sig7arg"a () { sig7argva () { /prctl/disable-tsc-ctxt-sw-stress-test.c#L38" id L38" class="li7" nam LL7">4 47./a>.spa class=" 4re77ta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L39" id L39" class="li7e" nam 7L38">4 387"a { sig7n_vtassa () { /prctl/disable-tsc-ctxt-sw-stress-test.c#L32" id L32" class="li7e" nam 7L39">4 397"a .s7a cl7ta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L30" id L30" class="li8e" nam 8L40">4 40./a>} sig7fp;./tfa () { <]\nf="Documenta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE8e" nam 8L41">4 417"a 4 42./a>void .a hr8f="+c82s="comment" for" class="sref">pr << 32 | .nta =0;_SIGSEGV" class= << 32 | .nta inux/prctl.h"">sig7n_vtassa () { /prctl/disable-tsc-ctxt-sw-stress-test.c#L38" id L38" class="li8e" nam 8L43">4 437"a { prforsk7"a (void) /prctl/disable-tsc-ctxt-sw-stress-test.c#L45" id L45" class="li8e" nam 8L44">4 447"a if8(.a h84-tes4SC_SIGSET3-tsc-> /prctl/disable-tsc-ctxt-sw-stress-test.c#L39" id L39" class="li8" nam 8L5">4 45./a>.spa class8a hre85-tes4SC_SIGSET3-tsc-ET3-tsc-tl" class="sref">pr << 32 | .nta & 1> /prctl/disable-tsc-ctxt-sw-stress-test.c#L45" id L45" class="li8" nam 8L6">4 46./a>.spa class8 8a href="+code=perror"4SC_SIGSET3-tsc-ctxt-sw-l1al2 9>segvtask7"a (void) 4 47./a>.spa class8" 4re8s-tes4SC_SIGSET3-tsc---------else /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE8" nam LL8">4 48./a>.spa class=Docum88-tes4SC_SIGSET3-tsc-4SC_SIGSET3-tsc-ctxt-sw-l1al2 9"Docuvtask7"a (void) /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE8e" nam 8L39">4 397"a .s8a cl89-tes4SC_SIGSET3-tsc-> /prctl/disable-tsc-ctxt-sw-stress-test.c#L41" id L41" class="li9e" nam 9L40">4 40./a>} /prctl/disable-tsc-ctxt-sw-stress-test.c#L11" id L11" class="li9e" nam 9L41">4 417"a pr << 32 | .nta =0;_SIGSEGV" class= << 32 | .nta inux/prctl.h"">sig7n_vtassa () { /prctl/disable-tsc-ctxt-sw-stress-test.c#L38" id L38" class="li9e" nam 9L42">4 42./a>void .a hr9f="+c92-tes4SC_SIGSET3-tsc-SIGSEGV" class=="Do<< 32 | .="Do_SET_TSC" class="sreNULL<< 32 | .NULLe=si > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE9e" nam 9L43">4 437"a { /prctl/disable-tsc-ctxt-sw-stress-test.c#L11" id L11" class="li9e" nam 9L44">4 447"a if9(.a h94s="comment" /ss="sref">sig7" iv_expect7"a (int" ivng">&0 > /prctl/disable-tsc-ctxt-sw-stress-test.c#L34" 4ress-tes4SC_SIGSE9" nam 9L5">4 45./a>.spa class9a hre9nta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L36" id L36" class="li9" nam 9L6">4 46./a>.spa class9 9ta > /prctl/disable-tsc-ctxt-sw-stress-test.c#L37" id L37" class="li9" nam 9L7">4 47./a>.spa class9" 4re9ent" t-se4 14 4.d nt" .div id>4 47./footer"> The ot;"inal LXR softwaretbyhref=/prctl/dihttp://sourceforge.nett-sojects/lxr">LXR ="+crie-tsclfew s"Docbyh/prctl/dimailto:lxr@lxr@4 47./subfooter"> lxr.Redpill La -so AS"DocC_-sovider of La ux < .