~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/perf/arch/x86/util/header.c

Version: ~ [ linux-5.3-rc4 ] ~ [ linux-5.2.8 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.66 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.138 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.71 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <sys/types.h>
  2 #include <unistd.h>
  3 #include <stdio.h>
  4 #include <stdlib.h>
  5 #include <string.h>
  6 
  7 #include "../../util/header.h"
  8 
  9 static inline void
 10 cpuid(unsigned int op, unsigned int *a, unsigned int *b, unsigned int *c,
 11       unsigned int *d)
 12 {
 13         __asm__ __volatile__ (".byte 0x53\n\tcpuid\n\t"
 14                               "movl %%ebx, %%esi\n\t.byte 0x5b"
 15                         : "=a" (*a),
 16                         "=S" (*b),
 17                         "=c" (*c),
 18                         "=d" (*d)
 19                         : "a" (op));
 20 }
 21 
 22 int
 23 get_cpuid(char *buffer, size_t sz)
 24 {
 25         unsigned int a, b, c, d, lvl;
 26         int family = -1, model = -1, step = -1;
 27         int nb;
 28         char vendor[16];
 29 
 30         cpuid(0, &lvl, &b, &c, &d);
 31         strncpy(&vendor[0], (char *)(&b), 4);
 32         strncpy(&vendor[4], (char *)(&d), 4);
 33         strncpy(&vendor[8], (char *)(&c), 4);
 34         vendor[12] = '\0';
 35 
 36         if (lvl >= 1) {
 37                 cpuid(1, &a, &b, &c, &d);
 38 
 39                 family = (a >> 8) & 0xf;  /* bits 11 - 8 */
 40                 model  = (a >> 4) & 0xf;  /* Bits  7 - 4 */
 41                 step   = a & 0xf;
 42 
 43                 /* extended family */
 44                 if (family == 0xf)
 45                         family += (a >> 20) & 0xff;
 46 
 47                 /* extended model */
 48                 if (family >= 0x6)
 49                         model += ((a >> 16) & 0xf) << 4;
 50         }
 51         nb = scnprintf(buffer, sz, "%s,%u,%u,%u$", vendor, family, model, step);
 52 
 53         /* look for end marker to ensure the entire data fit */
 54         if (strchr(buffer, '$')) {
 55                 buffer[nb-1] = '\0';
 56                 return 0;
 57         }
 58         return -1;
 59 }
 60 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp