[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] [PATCH] cpufreq module for >1CPU



To make the cpufreq module set the speed for both (or all?) CPUs, the
freqset utility has to be modified. This should do the job.

--- e17_orig/apps/e/src/modules/cpufreq/freqset.c	2006-08-21 17:59:07.000000000 +0200
+++ e17/apps/e/src/modules/cpufreq/freqset.c	2006-08-21 17:58:42.000000000 +0200
@@ -53,29 +53,21 @@
 #else   
    if (!strcmp(argv[1], "frequency"))
      {
-        new_frequency = atoi(argv[2]);
-	
-        f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", "w");
-        if (!f)
+	if(sys_cpu_setall("scaling_setspeed", argv[2]) == 0)
           {
              fprintf(stderr, "Unable to open frequency interface for writing.\n");
              return 1;
           }
-        fprintf(f, "%d\n", new_frequency);
-        fclose(f);
 	
         return 0;
      }
    else if (!strcmp(argv[1], "governor"))
      {
-        f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", "w");
-        if (!f)
+	if(sys_cpu_setall("scaling_governor", argv[2]) == 0)
           {
              fprintf(stderr, "Unable to open governor interface for writing.\n");
              return 1;
           }
-        fprintf(f, "%s\n", argv[2]);
-        fclose(f);
 	
         return 0;
      }
@@ -88,3 +80,23 @@
 
    seteuid(-1);
 }
+
+int sys_cpu_setall(const char *control, const char *value)
+{
+	int	num = 0;
+	char	filename[4096];
+	FILE	*f;
+	
+	while(1){
+		snprintf(filename, sizeof(filename), "/sys/devices/system/cpu/cpu%i/cpufreq/%s", num, control);
+		f = fopen(filename, "w");
+		
+		if(!f){
+			return(num);
+		}
+		fprintf(f, "%s\n", value);
+		fclose(f);
+		num++;
+	}
+	return -1;
+}