/* riempe la struttura cpuState tenendo anche conto * degli argomenti passati da linea di comando */ void init_cpuState ( ) { #ifndef LONGRUN FILE * fp; char red[10]; char * paths[4][3] = { /* sys proc user */ /* min */ { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq", "/proc/sys/cpu/0/speed-min", args_useFileMin }, /* max */ { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "/proc/sys/cpu/0/speed-max", args_useFileMax }, /* set */ { "/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", "/proc/sys/cpu/0/speed", args_useFileSet }, /* read */ { "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "/proc/sys/cpu/0/speed", args_useFileSet } }; u_int8 idx[3] = { /* the second index */ args_useFileMin ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ), args_useFileMax ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ), args_useFileSet ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ) }; /* auto_freq_state */ cpuState.auto_freq_state = ( args_autoFreq == AUTOFREQ_ON ); /* will be checked later */ cpuState.userspace = false; /* min freq */ if( (fp = fopen( paths[0][idx[0]], "r" )) == NULL ) { fprintf( stderr, "Error reading the info file (%s):\n%s\n", paths[0][idx[0]], strerror(errno) ); free_and_exit( ERROR ); } fgets ( red, 10, fp ); cpuState.minFreq = atoi ( red ); fclose ( fp ); /* max freq */ if( (fp = fopen( paths[1][idx[1]], "r" )) == NULL ) { fprintf( stderr, "Error reading the info file (%s):\n%s\n", paths[1][idx[1]], strerror(errno) ); free_and_exit( ERROR ); } fgets ( red, 10, fp ); cpuState.maxFreq = atoi ( red ); fclose ( fp ); /* set freq file */ cpuState.setFreqFile = paths[2][idx[2]]; /* read freq file */ cpuState.readFreqFile = paths[3][idx[2]]; /* if we have to use the SYS's way to set cpufreq, then ensure that in * scaling_governor there has been put 'userspace'; otherwise let's try * to put it by ourself */ if( idx[2] == 0 ) scalingGovernorHelper( ); cpuReadFreq( ); /* set freq */ cpuState.setFreq = cpuState.actualFreq; /* step freq */ cpuState.stepFreq = args_incrementalStep; #else /* init and get first actual frequency */ /* PENDING: get these files from config */ longrun_init("/dev/cpu/0/cpuid","/dev/cpu/0/msr"); cpuReadFreq( ); cpuState.setLevelIdx = cpuState.actualLevelIdx; cpuState.auto_freq_state = ( args_autoFreq == AUTOFREQ_ON ); cpuState.stepLevelIdx = 1; /* did user set a valid value here? */ if (args_incrementalStep < 10 && args_incrementalStep > 0) cpuState.stepLevelIdx = args_incrementalStep; #endif /* ok, if we are in ttyMode we don't need to modify values.. we just want to read them */ if( args_ttyMode ) return; #ifndef LONGRUN /* other options */ if( args_maxFreq != ARGSDEF_LEAVE ) { if( args_maxFreq > cpuState.maxFreq ) { PRINTQ( stderr, "Error: args_maxFreq > maxFreq possible (using %d as max)\n", cpuState.maxFreq ); args_maxFreq = cpuState.maxFreq; } cpuState.maxFreq = args_maxFreq; } if( args_minFreq != ARGSDEF_LEAVE ) { if( args_minFreq < cpuState.minFreq ) { PRINTQ( stderr, "Error: args_minFreq < minFreq possible (using %d as min)\n", cpuState.minFreq ); args_minFreq = cpuState.minFreq; } cpuState.minFreq = args_minFreq; } /* little control.. */ if( cpuState.minFreq > cpuState.maxFreq ) { fprintf( stderr, "Error: minFreq > maxFreq\n" ); free_and_exit( ERROR ); } #endif switch( args_startingFreq ) { case STARTINGFREQ_MIN: #ifndef LONGRUN /* frequence at min */ while( cpuState.actualFreq != cpuState.minFreq ) cpuSetFreq( FREQ_DECREMENT, FREQ_NEXT ); #else cpuState.setLevelIdx = 0; #endif break; case STARTINGFREQ_MAX: /* frequence at max */ #ifndef LONGRUN while( cpuState.actualFreq != cpuState.maxFreq ) cpuSetFreq( FREQ_INCREMENT, FREQ_NEXT ); #else cpuState.setLevelIdx = cpuState.nLongRunLevels-1; #endif } #ifndef LONGRUN #ifdef DEBUG fprintf ( stderr, "min freq: %d\nmax freq: %d\nactual freq: %d\n", cpuState.minFreq, cpuState.maxFreq, cpuState.actualFreq ); #endif #else fprintf ( stderr, "LongRun CPU starts at %d, with autoadjust = %d\n\n", cpuState.setLevelIdx, cpuState.auto_freq_state ); cpuEchoFreq(); /* set initial range */ #endif return; }
int main(int argc, char **argv) { XEvent event; XpmColorSymbol colors[2] = { {"Back0", NULL, 0}, {"Back1", NULL, 0} }; int ncolor = 0; /* Parse CommandLine */ parse_arguments(argc, argv); /* Initialize Application */ dockapp_open_window(display_name, PACKAGE, SIZE, SIZE, argc, argv); dockapp_set_eventmask(ButtonPressMask); if (light_color) { colors[0].pixel = dockapp_getcolor(light_color); colors[1].pixel = dockapp_blendedcolor(light_color, -24, -24, -24, 1.0); ncolor = 2; } /* change raw xpm data to pixmap */ if (dockapp_iswindowed) backdrop_on_xpm[1] = backdrop_off_xpm[1] = WINDOWED_BG; if (!is_led_style) { dockapp_xpm2pixmap(backdrop_on_xpm, &backdrop_on, &mask, colors,ncolor); dockapp_xpm2pixmap(backdrop_off_xpm, &backdrop_off, NULL, NULL, 0); } else { dockapp_xpm2pixmap(backdrop_led_xpm, &backdrop_led, &mask, colors, ncolor); } dockapp_xpm2pixmap(parts_xpm, &parts, NULL, colors, ncolor); /* shape window */ if (!dockapp_iswindowed) dockapp_setshape(mask, 0, 0); if (mask) XFreePixmap(display, mask); /* pixmap: draw area */ pixmap = dockapp_XCreatePixmap(SIZE, SIZE); /* Initialize pixmap */ longrun_init(cpuid_dev, msr_dev); update(); dockapp_set_background(pixmap); dockapp_show(); /* Main loop */ for (;;) { if (dockapp_nextevent_or_timeout(&event, update_interval)) { /* Next Event */ switch(event.type) { case ButtonPress: if (!is_led_style) { /* led does not have back-light */ switch_light(); update(); } break; default: /* make gcc happy */ break; } } else { /* Time Out */ update(); } } return 0; }