static GObject *
cpufreq_monitor_libcpufreq_constructor (GType                  type,
                                        guint                  n_construct_properties,
                                        GObjectConstructParam *construct_params)
{
    GObject *object;
    gulong   max_freq, min_freq;
    guint    cpu;

    object = G_OBJECT_CLASS (
                 cpufreq_monitor_libcpufreq_parent_class)->constructor (type,
                         n_construct_properties,
                         construct_params);
    g_object_get (G_OBJECT (object),
                  "cpu", &cpu,
                  NULL);

    if (cpufreq_get_hardware_limits (cpu, &min_freq, &max_freq) != 0) {
        g_warning ("Error getting CPUINFO_MAX\n");
        max_freq = -1;
    }

    g_object_set (G_OBJECT (object),
                  "max-frequency", max_freq,
                  NULL);

    return object;
}
Пример #2
0
int set_process_cpu_and_freq(const unsigned int cpu_index) {
    // set the core-affinity
    cpu_set_t cpu_set;
    CPU_ZERO(&cpu_set);
    CPU_SET(cpu_index, &cpu_set);
    sched_setaffinity(0, sizeof(cpu_set), &cpu_set);

    // set CPU governor
    unsigned long cpu_max = 0;
    unsigned long cpu_min = 0;
    unsigned long cpu_cur = 0;

    if (cpufreq_cpu_exists(cpu_index) != 0) {
        printf("Invalid CPU index!\n");
        return -1;
    }

    if (cpufreq_get_hardware_limits(cpu_index, &cpu_min, &cpu_max) != 0) {
        printf("Unable to get hardware limits!\n");
        return -1;
    }

    if (cpufreq_set_frequency(cpu_index, cpu_max) != 0) {
        printf("Unable to set frequency(%luMHz) Are u root?\n", cpu_max / 1000);
        return -1;
    }

    cpu_cur = (cpufreq_get_freq_kernel(cpu_index) / 1000);

    printf("Current CPU %u Frequency: %lu MHz\n\n", cpu_index, cpu_cur);

    return 0;
}
Пример #3
0
int single_freq_init (actuator_t *act)
{
	int err;
	struct cpufreq_policy *policy;
	struct cpufreq_available_frequencies *freq_list;
	freq_scaler_data_t *data;
	unsigned long freq_min, freq_max;
	
	act->data = data = malloc(sizeof(freq_scaler_data_t));
	fail_if(!data, "cannot allocate freq data block");
	
	err = cpufreq_get_hardware_limits(act->core, &freq_min, &freq_max);
	fail_if(err, "cannot get cpufreq hardware limits");
	act->min = freq_min;
	act->max = freq_max;
	
	policy = cpufreq_get_policy(act->core);
	fail_if(!policy, "cannot get cpufreq policy");
	if (strcmp(policy->governor, "userspace") != 0) {
		err = cpufreq_modify_policy_governor(act->core, "userspace");
		policy = cpufreq_get_policy(act->core);
		fail_if (strcmp(policy->governor, "userspace") != 0, "cannot set cpufreq policy to userspace");
	}
	
	freq_list = cpufreq_get_available_frequencies(act->core);
	data->freq_count = create_freq_array(freq_list, &data->freq_array);
	fail_if(data->freq_count < 1, "cannot get frequency list");
	
	act->value = act->set_value = cpufreq_get_freq_kernel(act->core);
	data->cur_index = get_freq_index(data, act->value);
	
	return 0;
fail:
	return -1;
}
Пример #4
0
static int get_hardware_limits(unsigned int cpu) {
	
	if (cpufreq_get_hardware_limits(cpu, &min, &max))
	  return -EINVAL;

        printf("Your frequency limits is:\n");
        printf("MIN: %luMHZ and MAX:%luMHZ\n", min,max);
	return 0;
}
Пример #5
0
GkrellmMonitor* gkrellm_init_plugin(void)

{
  /* If this next call is made, the background and krell images for this
     plugin can be custom themed by putting bg_meter.png or krell.png in the
     subdirectory STYLE_NAME of the theme directory.  Text colors (and
     other things) can also be specified for the plugin with gkrellmrc
     lines like:  StyleMeter  STYLE_NAME.textcolor orange black shadow
     If no custom theming has been done, then all above calls using
     style_id will be equivalent to style_id = DEFAULT_STYLE_ID.
  */
  pGK = gkrellm_ticks();
  style_id = gkrellm_add_meter_style(&plugin_mon, STYLE_NAME);
  monitor = &plugin_mon;

  /* determine number of cpus */
  for( ncpu = 0; cpufreq_get_freq_kernel(ncpu)>0; ++ncpu )
    ;
  ncpu = ncpu > NCPU_MAX ? NCPU_MAX : ncpu;

  /* determine maximal frequency */
  unsigned int cpu;
  for ( cpu = 0; cpu<ncpu; ++cpu) {
    unsigned long khz_min = 0;
    unsigned long khz_max_i = 0;
    cpufreq_get_hardware_limits( cpu, &khz_min, &khz_max_i );
    khz_max = khz_max < khz_max_i ? khz_max_i : khz_max;
  }

  read_khz();

  strcpy(empty, "");
  if (gov_enable_current) {
    read_governors();
  } else {
    for ( cpu=0; cpu<ncpu; ++cpu ) {
      strcpy(governor[cpu], "");
    }
  }
  return &plugin_mon;
}
Пример #6
0
JNIEXPORT jint JNICALL Java_platforms_x86_X86_1DVFS_getHardwareLimits
  (JNIEnv *env, jobject obj, jint cpu)
{
	unsigned long min, max;
	jclass cls;
	jfieldID fid;
	int ret;

	ret = cpufreq_get_hardware_limits((unsigned int)cpu, &min, &max);

	if (ret < 0)
		return ret;

	cls = (*env)->GetObjectClass(env, obj);

	fid = (*env)->GetFieldID(env, cls, "minFreq", "J");
	(*env)->SetLongField(env, obj, fid, min);
	fid = (*env)->GetFieldID(env, cls, "maxFreq", "J");
	(*env)->SetLongField(env, obj, fid, max);

	(*env)->DeleteLocalRef(env, cls);
	return ret;
}
Пример #7
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);
}
Пример #8
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);
     }
}