Ejemplo n.º 1
0
static void cpu_desc_summary (struct cpu_desc *cpudesc)
{
  printf ("-= CPU Characteristics =-\n");

  print_s("Architecture:", cpu_desc_get_architecture (cpudesc));

  int cpu_mode = cpu_desc_get_mode (cpudesc);
  if (cpu_mode)
    {
      char mbuf[32], *p = mbuf;
      if (cpu_mode & MODE_32BIT)
        {
          strcpy (p, "32-bit, ");
          p += 8;
        }
      if (cpu_mode & MODE_64BIT)
        {
          strcpy (p, "64-bit, ");
          p += 8;
        }
      *(p - 2) = '\0';

      print_s("CPU op-mode(s):", mbuf);
    }

#if !defined(WORDS_BIGENDIAN)
  print_s("Byte Order:", "Little Endian");
#else
  print_s("Byte Order:", "Big Endian");
#endif

  int cpu, ncpus = cpu_desc_get_ncpus (cpudesc);

  print_d("CPU(s):", ncpus);

  unsigned int nsockets, ncores, nthreads;
  get_cputopology_read (&nsockets, &ncores, &nthreads);

  print_u("Thread(s) per core:", nthreads);
  print_u("Core(s) per socket:", ncores);
  print_u("Socket(s):", nsockets);

  print_s("Vendor ID:", cpu_desc_get_vendor (cpudesc));
  print_s("CPU Family:", cpu_desc_get_family (cpudesc));
  print_s("Model:", cpu_desc_get_model (cpudesc));
  print_s("Model name:", cpu_desc_get_model_name (cpudesc));

  for (cpu = 0; cpu < ncpus; cpu++)
    {
      printf ("-CPU%d-\n", cpu);

      bool cpu_hot_pluggable = get_processor_is_hot_pluggable (cpu);
      int cpu_online = get_processor_is_online (cpu);

      print_s ("CPU is Hot Pluggable:", cpu_hot_pluggable ?
		 (cpu_online ? "yes (online)" : "yes (offline)") : "no");

      unsigned long latency = cpufreq_get_transition_latency (cpu);
      if (latency)
	print_s("Maximum Transition Latency:",
		cpufreq_duration_to_string (latency));

      unsigned long freq_kernel = cpufreq_get_freq_kernel (cpu);
      if (freq_kernel > 0)
	print_s("Current CPU Frequency:", cpufreq_freq_to_string (freq_kernel));

      struct cpufreq_available_frequencies *cpufreqs, *curr;
      cpufreqs = curr = cpufreq_get_available_freqs (cpu);
      if (curr)
	{
	  print_key_s("Available CPU Frequencies:");
	  while (curr)
	    {
	      printf ("%s ",
		      cpufreq_freq_to_string
		      (cpufreq_get_available_freqs_value (curr)));
	      curr = cpufreq_get_available_freqs_next (curr);
	    }
	  printf ("\n");
	  cpufreq_available_frequencies_unref(cpufreqs);
	}

      unsigned long freq_min, freq_max;
      if (0 == cpufreq_get_hardware_limits (cpu, &freq_min, &freq_max))
	{
	  char *min_s = cpufreq_freq_to_string (freq_min),
	       *max_s = cpufreq_freq_to_string (freq_max);
	  print_range_s("Hardware Limits:", min_s, max_s);
	  free (min_s);
	  free (max_s);
	}

      char *freq_governor = cpufreq_get_governor (cpu);
      if (freq_governor)
	{
	  print_s ("CPU Freq Current Governor:", freq_governor);
	  free (freq_governor);
	}

      char *freq_governors = cpufreq_get_available_governors (cpu);
      if (freq_governors)
	{
	  print_s ("CPU Freq Available Governors:", freq_governors);
	  free (freq_governors);
	}

      char *freq_driver = cpufreq_get_driver (cpu);
      if (freq_driver)
	{
	  print_s ("CPU Freq Driver:", freq_driver);
	  free (freq_driver);
	}
    }

  char *cpu_virtflag = cpu_desc_get_virtualization_flag (cpudesc); 
  if (cpu_virtflag)
    print_s("Virtualization:", cpu_virtflag);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
   struct timespec ts,ts1;
   int i,ncpu;
   int idcpu;
   unsigned long freq[8];
   XEvent event;
   char gov[20];
   char drv[20],*ptr,*endptr;
   char prg[LN_PATH];
   ts.tv_sec=0;
   ts.tv_nsec=DELAY;
   prg[0]=0;
   idcpu=0;

   for(i=0;i<MAX_CPU;i++)
     freq[i]=0;
   if(argc >1)
     {
	for (i=1; i<=argc; i++)
	  {
	     if (!strcmp(argv[i], "-v"))
	       {
		  printf(WMCPUFREQ_VERSION);
		  exit(0);
	       }
	     if (!strcmp(argv[i], "-exe"))
	       {
		  if(strlen(argv[i+1]) < LN_PATH )
		    strcpy(prg,argv[i+1]);
		  break;
	       }
	     if (!strcmp(argv[i], "-cpuid"))
	       {
		 if(strlen(argv[i+1]) < LN_PATH )
		   idcpu=strtol(argv[i+1],&endptr,0);
		 printf("cpuid= %d \n",idcpu);
		 break;
	       }
	     printf("only -v, -exe, -cpuid supported \n");
	     exit(0);
	  }
     }

   /* basic checks */
   if ( idcpu < 0 )
     {
       printf("cpuid < 0 \n");
       exit(-1);
     }

   /* get driver name (guess all cpu have the same driver) */
   ptr=cpufreq_get_driver(cpu);
   if(!ptr)
     {
	printf("no driver found \n");
	exit(-1);
     }
   strcpy(drv,ptr);
   cpufreq_put_driver(ptr);


   /* get number of cpu (0=cpu0, 1=cpu1 ...) */

   ncpu=-1;

   for(i=0;i<MAX_CPU;i++)
     {
       if( cpufreq_cpu_exists(idcpu+i) ==0)
	 {
	   printf("cpuid %d found\n",idcpu+i);
	   ncpu=i;
	 }
     }

   switch ( ncpu ) {
   case -1:
     printf("no cpuid found \n");
     exit(-1);
   case 0:
     wm_xpm=wmcpufreq_master_xpm_1;
     wm_bits=wmcpufreq_mask_bits_1;
     break;
   case 1:
     wm_xpm=wmcpufreq_master_xpm_2;
     wm_bits=wmcpufreq_mask_bits_2;
     break;
   case 2:
     wm_xpm=wmcpufreq_master_3;
     wm_bits=wmcpufreq_mask_3_bits;
     break;
   case 3:
     wm_xpm=wmcpufreq_master_3;
     wm_bits=wmcpufreq_mask_3_bits;
     break;
   default:
     printf("no yet implemented: cpuid %d \n",ncpu);
     exit(-1);
     break;
   }

   /* guess every cpu has the same limits */
   if(cpufreq_get_hardware_limits(cpu, &f_min, &f_max))
     {
	printf("can't determine hardware limits \n");
	exit(-1);
     }
   openXwindow(argc,argv,
	       wm_xpm,
	       (char*)wm_bits,
	       wmcpufreq_mask_width,
               wmcpufreq_mask_height);
   while(1)
     {
	/* Process any pending X events */
	while(XPending(display))
	  {
	     XNextEvent(display, &event);
	     switch(event.type)
	       {
		case Expose:
		  RedrawWindow();
		  break;
		case ButtonPress:
		  if(strlen(prg))
		    execCommand(prg);
		  break;
		case ButtonRelease:
		  break;
	       }
	  }
	RedrawWindow();
	/* get info */
	for(i=0;i<=ncpu;i++)
	  freq[i]=cpufreq_get_freq_kernel(i+idcpu);
	policy=cpufreq_get_policy(cpu);
	strcpy(gov,policy->governor);
	max=policy->max;
	min=policy->min;
	cpufreq_put_policy(policy);
	/* show info */
	show_mhz(freq,ncpu);
	if (ncpu==0)
	  show_driver(drv);
	show_governor(gov);
	/* delay */
	nanosleep(&ts,&ts1);
     }
}