Measuring CPU frequency in *nix
From a "How to get the right answer" point of view, David's comment which explains why asking the OS is the only trustworthy solution best answers the question.

But this is Code Review, not Stack Overflow.  From that point of view:

The cpuid instruction returns different data depending on the input value of eax.  Since you never set it before executing your asm, (conceivably) the length of the operation could vary between calls, mucking up your calculation.

Also, the mov statements are unnecessary:

asm ("cpuid\n\t"
     "rdtsc"
     : "=d"(my_edx), "=a"(my_eax)
     : "a"(0) 
     : "%ebx", "%ecx");


It might also be worth looking at rdtscp as a replacement for cpuid + rdtsc.