[BACK]Return to cpuctl.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / usr.sbin / cpuctl

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/usr.sbin/cpuctl/cpuctl.c between version 1.19.2.3 and 1.20

version 1.19.2.3, 2014/05/22 11:43:02 version 1.20, 2012/01/13 16:05:16
Line 82  static struct cmdtab {
Line 82  static struct cmdtab {
 };  };
   
 static int      fd;  static int      fd;
 int             verbose;  
   
 int  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         const struct cmdtab *ct;          const struct cmdtab *ct;
         int ch;  
   
         while ((ch = getopt(argc, argv, "v")) != -1)          if (argc < 2)
                 switch (ch) {  
                 case 'v':  
                         verbose = 1;  
                         break;  
                 default:  
                         usage();  
                 }  
         argc -= optind;  
         argv += optind;  
         if (argc < 1)  
                 usage();                  usage();
   
         if ((fd = open(_PATH_CPUCTL, O_RDWR)) < 0)          if ((fd = open(_PATH_CPUCTL, O_RDWR)) < 0)
                 err(EXIT_FAILURE, _PATH_CPUCTL);                  err(EXIT_FAILURE, _PATH_CPUCTL);
   
         for (ct = cpu_cmdtab; ct->label != NULL; ct++) {          for (ct = cpu_cmdtab; ct->label != NULL; ct++) {
                 if (strcmp(argv[0], ct->label) == 0) {                  if (strcmp(argv[1], ct->label) == 0) {
                         if (!ct->argsoptional &&                          if (!ct->argsoptional &&
                             ((ct->takesargs == 0) ^ (argv[1] == NULL)))                              ((ct->takesargs == 0) ^ (argv[2] == NULL)))
                         {                          {
                                 usage();                                  usage();
                         }                          }
                         (*ct->func)(argv + 1);                          (*ct->func)(argv + 2);
                         break;                          break;
                 }                  }
         }          }
Line 204  cpu_ucode(char **argv)
Line 192  cpu_ucode(char **argv)
 {  {
         int error;          int error;
         struct cpu_ucode uc;          struct cpu_ucode uc;
         unsigned long id = 0; /* gcc */  
         char *ep;  
         cpuset_t *cpuset;  
   
         uc.cpu_nr = -1;  
         if (argv[0] != NULL) {  
                 id = strtoul(argv[0], &ep, 0);  
                 if (id != ULONG_MAX && *ep == '\0') {  
                         uc.cpu_nr = id;  
                         argv++;  
                 }  
         }  
         if (argv[0] != NULL)          if (argv[0] != NULL)
                 strlcpy(uc.fwname, argv[0], sizeof(uc.fwname));                  strlcpy(uc.fwname, argv[0], sizeof(uc.fwname));
         else          else
                 memset(uc.fwname, '\0', sizeof(uc.fwname));                  memset(uc.fwname, '\0', sizeof(uc.fwname));
   
         error = ucodeupdate_check(fd, &uc);  
         if (error)  
                 errx(EXIT_FAILURE, "unsupported");  
   
         if (uc.cpu_nr == CPU_UCODE_CURRENT_CPU) {  
                 cpuset = cpuset_create();  
                 if (cpuset == NULL)  
                         err(EXIT_FAILURE, "cpuset_create");  
                 cpuset_zero(cpuset);  
                 cpuset_set(id, cpuset);  
                 if (_sched_setaffinity(0, 0, cpuset_size(cpuset), cpuset) < 0) {  
                         err(EXIT_FAILURE, "_sched_setaffinity");  
                 }  
                 cpuset_destroy(cpuset);  
         }  
         error = ioctl(fd, IOC_CPU_UCODE_APPLY, &uc);          error = ioctl(fd, IOC_CPU_UCODE_APPLY, &uc);
         if (error < 0) {          if (error < 0) {
                 if (uc.fwname[0])                  if (uc.fwname[0])
Line 252  cpu_identify(char **argv)
Line 214  cpu_identify(char **argv)
         char name[32];          char name[32];
         unsigned int id, np;          unsigned int id, np;
         cpuset_t *cpuset;          cpuset_t *cpuset;
           struct cpu_ucode ucode;
           char ucbuf[16];
   
         np = sysconf(_SC_NPROCESSORS_CONF);          np = sysconf(_SC_NPROCESSORS_CONF);
         id = getcpuid(argv);          id = getcpuid(argv);
         snprintf(name, sizeof(name), "cpu%u", id);          snprintf(name, sizeof(name), "cpu%u", id);
   
         if (np != 1) {          if (np != 0) {
                 cpuset = cpuset_create();                  cpuset = cpuset_create();
                 if (cpuset == NULL)                  if (cpuset == NULL)
                         err(EXIT_FAILURE, "cpuset_create");                          err(EXIT_FAILURE, "cpuset_create");
Line 274  cpu_identify(char **argv)
Line 238  cpu_identify(char **argv)
                 }                  }
                 cpuset_destroy(cpuset);                  cpuset_destroy(cpuset);
         }          }
         identifycpu(fd, name);          identifycpu(name);
   
           if (ioctl(fd, IOC_CPU_UCODE_GET_VERSION, &ucode) < 0)
                   ucode.version = (uint64_t)-1;
           if (ucode.version == (uint64_t)-1)
                   strcpy(ucbuf, "?");
           else
                   snprintf(ucbuf, sizeof(ucbuf), "0x%"PRIx64,
                       ucode.version);
   
           printf("%s: UCode version: %s\n", name, ucbuf);
 }  }
   
 static u_int  static u_int

Legend:
Removed from v.1.19.2.3  
changed lines
  Added in v.1.20

CVSweb <webmaster@jp.NetBSD.org>