linux - Problems setting CPU affinity in C -
I am trying to take the time to run the CPUID instruction.
Source:
#include & lt; Stdio.h & gt; # Include & lt; schedule.h & gt; Cpu_set_t mask; CPU_ZERO (& amp; mask); CPU_SET (0, and mask); Shade_setfinity (0, size, and mask); Static inline unsigned long tick () {unsigned long d; asm volatile ("rdtsc": "= a" (d)); Return D; } Zero cpuid (zero) {int i; For (i = 0; i! = 5; i ++) {ASM vapor ("CPUID"); }} Int main () {long long beef; Long back; Long time different; bef = tick (); CPUID (); Back = tick (); dif = back-bef; Printf ("% d \ n", beef); Printf ("% d \ n", behind); printF ("% d \ n", dif); Return 0; } I am now compiling using the following
GCC-D_GNUI-source -O test test.c Get errors on the code that is not a file! For example: test.c: 6: 1: error: expected identifier or '(' first 'to' test.c: 6: 1: error: expected identifier or '(' First 'while' test.c: 7: 1: error: before the expected identifier or '(' __extension__ 'test.c: 8: 1: Warning: there is no type or storage class in the data definition [enabled by def]. .. test c: 8: 1: error: the intializer element is not stable "Def ..." is not really the output because my terminal window is small.
Any help will be amazing!
For future readers Users @ EVILNETEXISTEDONOETEXIST use the following in full: Full x86 and x64 support Function for.
static __inline_ unsigned long rdtsc (zero) {unsigned hi, lo; __asm__ __volatile__ ("rdtsc": "= a" (lo), "=) (d ) (Back) (back to unsigned long)) | (((unsigned long time) hi) <32);}
The instructions should be in the main ():
cpu_set_t mask; CPU_ZERO (& amp; mask); CPU_SET (0, and mask); Shade_setfinity (0, size, and mask); This compile error should be corrected.
Then, there are fewer incentives for giving five iterations to meaningful results for cpuid () . You can test it but only use two scenes of two different series created with the CPUID instructions. You need a long cycle, but for a long time the lamb is not allowed to play.
I have run some tests with a defined test between 5 and 1000; CPU equality does not affect results on a quad-core:
#include & lt; Stdio.h & gt; # Include & lt; schedule.h & gt; Static inline unsigned long tick () {unsigned long d; asm volatile ("rdtsc": "= a" (d)); Return D; } Fixed inline void cpuid {zero} {int i; For (i = 0; i! = Test; i ++) {ASM vapor ("CPUID"); }} Int main () {long long beef, back, dif; bef = tick (); CPUID (); Back = tick (); Dif = (behind-bef) / test; Printf ("% lld \ n", dif); Return 0; } GCC-O0-DTET = 100-D_GNU-CWWall-O Time C & amp; Amp; ./time
Comments
Post a Comment