[BACK]Return to pctr.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / pctr

Diff for /src/usr.bin/pctr/pctr.c between version 1.11 and 1.12

version 1.11, 2003/08/04 17:06:44 version 1.12, 2004/12/19 13:26:48
Line 128 
Line 128 
          "Number of modified lines removed from the L2 for any reason."},           "Number of modified lines removed from the L2 for any reason."},
         {0x28, CFL_MESI, "L2_IFETCH",          {0x28, CFL_MESI, "L2_IFETCH",
          "Number of L2 instruction fetches."},           "Number of L2 instruction fetches."},
         {0x29, CFL_MESI, "L2_LD",          {0x29, CFL_MESI, "L2_LD",
          "Number of L2 data loads."},           "Number of L2 data loads."},
         {0x2a, CFL_MESI, "L2_ST",          {0x2a, CFL_MESI, "L2_ST",
          "Number of L2 data stores."},           "Number of L2 data stores."},
Line 161 
Line 161 
          "Number of burst read transactions."},           "Number of burst read transactions."},
         {0x66, CFL_SA, "BUS_TRAN_RFO",          {0x66, CFL_SA, "BUS_TRAN_RFO",
          "Number of read for ownership transactions."},           "Number of read for ownership transactions."},
         {0x67, CFL_SA, "BUS_TRANS_WB",          {0x67, CFL_SA, "BUS_TRANS_WB",
          "Number of write back transactions."},           "Number of write back transactions."},
         {0x68, CFL_SA, "BUS_TRAN_IFETCH",          {0x68, CFL_SA, "BUS_TRAN_IFETCH",
          "Number of instruction fetch transactions."},           "Number of instruction fetch transactions."},
Line 277 
Line 277 
                 cfnp = p6fn;                  cfnp = p6fn;
         else {          else {
                 fprintf(stderr, "Unknown CPU family %d\n", fam);                  fprintf(stderr, "Unknown CPU family %d\n", fam);
                 exit (1);                  exit(1);
         }          }
         printf("Hardware counter functions for the %s:\n\n",          printf("Hardware counter functions for the %s:\n\n",
         fam == 5 ? "Pentium" : "Pentium Pro");          fam == 5 ? "Pentium" : "Pentium Pro");
Line 326 
Line 326 
   
         if (family == 5) {          if (family == 5) {
                 fn = sel & 0x3f;                  fn = sel & 0x3f;
                 cfnp = fn2cfnp (family, fn);                  cfnp = fn2cfnp(family, fn);
                 snprintf(buf, sizeof buf, "%c%c%c %02x %s",                  snprintf(buf, sizeof buf, "%c%c%c %02x %s",
                     sel & P5CTR_C ? 'c' : '-',                      sel & P5CTR_C ? 'c' : '-',
                     sel & P5CTR_U ? 'u' : '-',                      sel & P5CTR_U ? 'u' : '-',
Line 334 
Line 334 
                     fn, cfnp ? cfnp->name : "unknown function");                      fn, cfnp ? cfnp->name : "unknown function");
         } else if (family == 6) {          } else if (family == 6) {
                 fn = sel & 0xff;                  fn = sel & 0xff;
                 cfnp = fn2cfnp (family, fn);                  cfnp = fn2cfnp(family, fn);
                 if (cfnp && cfnp->flags & CFL_MESI)                  if (cfnp && cfnp->flags & CFL_MESI)
                         snprintf(um, sizeof um, "/%c%c%c%c",                          snprintf(um, sizeof um, "/%c%c%c%c",
                             sel & P6CTR_UM_M ? 'm' : '-',                              sel & P6CTR_UM_M ? 'm' : '-',
Line 351 
Line 351 
                     sel & P6CTR_E ? 'e' : '-',                      sel & P6CTR_E ? 'e' : '-',
                     sel & P6CTR_K ? 'k' : '-',                      sel & P6CTR_K ? 'k' : '-',
                     sel & P6CTR_U ? 'u' : '-',                      sel & P6CTR_U ? 'u' : '-',
                     fn, cm, um, 7 - (strlen (cm) + strlen (um)), "",                      fn, cm, um, 7 - (strlen(cm) + strlen(um)), "",
                     cfnp ? cfnp->name : "unknown function");                      cfnp ? cfnp->name : "unknown function");
         } else          } else
                 return (NULL);                  return (NULL);
Line 365 
Line 365 
         int fd, i;          int fd, i;
         struct pctrst st;          struct pctrst st;
   
         fd = open (_PATH_PCTR, O_RDONLY);          fd = open(_PATH_PCTR, O_RDONLY);
         if (fd < 0)          if (fd < 0)
                 err (1, _PATH_PCTR);                  err(1, _PATH_PCTR);
         if (ioctl (fd, PCIOCRD, &st) < 0)          if (ioctl(fd, PCIOCRD, &st) < 0)
                 err (1, "PCIOCRD");                  err(1, "PCIOCRD");
         close (fd);          close(fd);
   
         if (usep5ctr || usep6ctr) {          if (usep5ctr || usep6ctr) {
                 for (i = 0; i < PCTR_NUM; i++)                  for (i = 0; i < PCTR_NUM; i++)
                         printf(" ctr%d = %16qd  [%s]\n", i, st.pctr_hwc[i],                          printf(" ctr%d = %16qd  [%s]\n", i, st.pctr_hwc[i],
                             fn2str (cpufamily, st.pctr_fn[i]));                              fn2str(cpufamily, st.pctr_fn[i]));
         }          }
         printf("  tsc = %16qd\n  idl = %16qd\n", st.pctr_tsc, st.pctr_idl);          printf("  tsc = %16qd\n  idl = %16qd\n", st.pctr_tsc, st.pctr_idl);
 }  }
Line 385 
Line 385 
 {  {
         int fd;          int fd;
   
         fd = open (_PATH_PCTR, O_WRONLY);          fd = open(_PATH_PCTR, O_WRONLY);
         if (fd < 0)          if (fd < 0)
                 err (1, _PATH_PCTR);                  err(1, _PATH_PCTR);
         if (ioctl (fd, PCIOCS0 + ctr, &val) < 0)          if (ioctl(fd, PCIOCS0 + ctr, &val) < 0)
                 err (1, "PCIOCSn");                  err(1, "PCIOCSn");
         close (fd);          close(fd);
 }  }
   
 static void  static void
 usage(void)  usage(void)
 {  {
         fprintf(stderr,          fprintf(stderr,
            "usage:\n"              "usage:\n"
            "  %s\n"              "  %s\n"
            "    Read the counters.\n"              "    Read the counters.\n"
            "  %s -l [5|6]\n"              "  %s -l [5|6]\n"
            "    List all possible counter functions for P5/P6.\n",              "    List all possible counter functions for P5/P6.\n",
            __progname, __progname);              __progname, __progname);
         if (usep5ctr)          if (usep5ctr)
                 fprintf(stderr,                  fprintf(stderr,
              "  %s -s {0|1} [-[c][u][k]] function\n"                      "  %s -s {0|1} [-[c][u][k]] function\n"
              "    Configure counter.\n"                      "    Configure counter.\n"
              "      0/1 - counter to configure\n"                      "      0/1 - counter to configure\n"
              "        c - count cycles not events\n"                      "        c - count cycles not events\n"
              "        u - count events in user mode (ring 3)\n"                      "        u - count events in user mode (ring 3)\n"
              "        k - count events in kernel mode (rings 0-2)\n",                      "        k - count events in kernel mode (rings 0-2)\n",
              __progname);                      __progname);
         else if (usep6ctr)          else if (usep6ctr)
                 fprintf(stderr,                  fprintf(stderr,
              "  %s -s {0|1} [-[i][e][k][u]] "                      "  %s -s {0|1} [-[i][e][k][u]] "
              "function[+cm][/{[m][e][s][i]|[a]}]\n"                      "function[+cm][/{[m][e][s][i]|[a]}]\n"
              "    Configure counter.\n"                      "    Configure counter.\n"
              "       0/1 - counter number to configure\n"                      "       0/1 - counter number to configure\n"
              "         i - invert cm\n"                      "         i - invert cm\n"
              "         e - edge detect\n"                      "         e - edge detect\n"
              "         k - count events in kernel mode (rings 0-2)\n"                      "         k - count events in kernel mode (rings 0-2)\n"
              "         u - count events in user mode (ring 3)\n"                      "         u - count events in user mode (ring 3)\n"
              "        cm - # events/cycle required to bump ctr\n"                      "        cm - # events/cycle required to bump ctr\n"
              "      mesi - Modified/Exclusive/Shared/Invalid in cache\n"                      "      mesi - Modified/Exclusive/Shared/Invalid in cache\n"
              "       s/a - self generated/all events\n", __progname);                      "       s/a - self generated/all events\n", __progname);
         exit (1);          exit(1);
 }  }
   
 int  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         u_int ctr;          char *cp, **ap;
         char *cp;          u_int ctr, fn, fl = 0;
         u_int fn, fl = 0;  
         char **ap;  
         int ac;  
         struct ctrfn *cfnp;          struct ctrfn *cfnp;
         int mib[2];          int mib[2], ac;
         size_t len;          size_t len;
   
         /* Get the kernel cpuid return values. */          /* Get the kernel cpuid return values. */
Line 463 
Line 460 
         pctr_isintel = (strcmp(cpu_vendor, "GenuineIntel") == 0);          pctr_isintel = (strcmp(cpu_vendor, "GenuineIntel") == 0);
   
         if (argc <= 1)          if (argc <= 1)
                 readst ();                  readst();
         else if (argc == 2 && !strcmp (argv[1], "-l"))          else if (argc == 2 && !strcmp(argv[1], "-l"))
                 list (cpufamily);                  list(cpufamily);
         else if (argc == 3 && !strcmp (argv[1], "-l"))          else if (argc == 3 && !strcmp(argv[1], "-l"))
                 list (atoi (argv[2]));                  list(atoi(argv[2]));
         else if (!strcmp (argv[1], "-s") && argc >= 4) {          else if (!strcmp(argv[1], "-s") && argc >= 4) {
                 ctr = atoi (argv[2]);                  ctr = atoi(argv[2]);
                 if (ctr >= PCTR_NUM)                  if (ctr >= PCTR_NUM)
                         usage ();                          usage();
                 ap = &argv[3];                  ap = &argv[3];
                 ac = argc - 3;                  ac = argc - 3;
   
                 if (usep6ctr)                  if (usep6ctr)
                 fl |= P6CTR_EN;                          fl |= P6CTR_EN;
                 if (**ap == '-') {                  if (**ap == '-') {
                         cp = *ap;                          cp = *ap;
                         if (usep6ctr) {                          if (usep6ctr) {
Line 495 
Line 492 
                                                 fl |= P6CTR_U;                                                  fl |= P6CTR_U;
                                                 break;                                                  break;
                                         default:                                          default:
                                                 usage ();                                                  usage();
                                         }                                          }
                         } else if(usep5ctr) {                          } else if (usep5ctr) {
                                 while (*++cp)                                  while (*++cp)
                                         switch (*cp) {                                          switch (*cp) {
                                         case 'c':                                          case 'c':
Line 510 
Line 507 
                                                 fl |= P5CTR_U;                                                  fl |= P5CTR_U;
                                                 break;                                                  break;
                                         default:                                          default:
                                                 usage ();                                                  usage();
                                         }                                          }
                         }                          }
                         ap++;                          ap++;
Line 523 
Line 520 
                 }                  }
   
                 if (!ac)                  if (!ac)
                         usage ();                          usage();
   
                 fn = strtoul (*ap, NULL, 16);                  fn = strtoul(*ap, NULL, 16);
                 if ((usep6ctr && (fn & ~0xff)) || (!usep6ctr && (fn & ~0x3f)))                  if ((usep6ctr && (fn & ~0xff)) || (!usep6ctr && (fn & ~0x3f)))
                         usage ();                          usage();
                 fl |= fn;                  fl |= fn;
                 if (usep6ctr && (cp = strchr (*ap, '+'))) {                  if (usep6ctr && (cp = strchr(*ap, '+'))) {
                         cp++;                          cp++;
                         fn = strtol (cp, NULL, 0);                          fn = strtol(cp, NULL, 0);
                         if (fn & ~0xff)                          if (fn & ~0xff)
                                 usage ();                                  usage();
                         fl |= (fn << 24);                          fl |= (fn << 24);
                 }                  }
                 cfnp = fn2cfnp (6, fl);                  cfnp = fn2cfnp(6, fl);
                 if (usep6ctr && cfnp && (cp = strchr (*ap, '/'))) {                  if (usep6ctr && cfnp && (cp = strchr(*ap, '/'))) {
                         if (cfnp->flags & CFL_MESI) {                          if (cfnp->flags & CFL_MESI) {
                                 while (*++cp)                                  while (*++cp)
                                         switch (*cp) {                                          switch (*cp) {
Line 554 
Line 551 
                                                 fl |= P6CTR_UM_I;                                                  fl |= P6CTR_UM_I;
                                                 break;                                                  break;
                                         default:                                          default:
                                                 usage ();                                                  usage();
                                         }                                          }
                         } else if (cfnp->flags & CFL_SA) {                          } else if (cfnp->flags & CFL_SA) {
                                 while (*++cp)                                  while (*++cp)
Line 563 
Line 560 
                                                 fl |= P6CTR_UM_A;                                                  fl |= P6CTR_UM_A;
                                                 break;                                                  break;
                                         default:                                          default:
                                                 usage ();                                                  usage();
                                         }                                          }
                         } else                          } else
                                 usage ();                                  usage();
                 } else if (cfnp && (cfnp->flags & CFL_MESI))                  } else if (cfnp && (cfnp->flags & CFL_MESI))
                         fl |= P6CTR_UM_MESI;                          fl |= P6CTR_UM_MESI;
                 ap++;                  ap++;
                 ac--;                  ac--;
   
                 if (ac)                  if (ac)
                         usage ();                          usage();
   
                 if (usep6ctr && ! (fl & 0xff))                  if (usep6ctr && ! (fl & 0xff))
                         fl = 0;                          fl = 0;
                 setctr (ctr, fl);                  setctr(ctr, fl);
         } else          } else
                 usage ();                  usage();
   
         return 0;          return 0;
 }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12