void scaling_governor_func(int argc, char *argv[]) { int cpuid = -1; char *name; if ( argc >= 2 ) { parse_cpuid(argv[0], &cpuid); name = argv[1]; } else if ( argc > 0 ) name = argv[0]; else { fprintf(stderr, "Missing argument(s)\n"); exit(EINVAL); } if ( cpuid < 0 ) { int i; for ( i = 0; i < max_cpu_nr; i++ ) if ( xc_set_cpufreq_gov(xc_handle, i, name) ) fprintf(stderr, "[CPU%d] failed to set governor name (%d - %s)\n", i, errno, strerror(errno)); } else { if ( xc_set_cpufreq_gov(xc_handle, cpuid, name) ) fprintf(stderr, "failed to set governor name (%d - %s)\n", errno, strerror(errno)); } }
void scaling_governor_func(int argc, char *argv[]) { int cpuid = -1; char *name = NULL; if ( argc >= 2 ) { name = strdup(argv[1]); if ( name == NULL ) goto out; if ( sscanf(argv[0], "%d", &cpuid) != 1 ) { free(name); goto out; } } else if ( argc > 0 ) { name = strdup(argv[0]); if ( name == NULL ) goto out; } else goto out; if ( cpuid < 0 ) { int i; for ( i = 0; i < max_cpu_nr; i++ ) if ( xc_set_cpufreq_gov(xc_handle, i, name) ) fprintf(stderr, "[CPU%d] failed to set governor name\n", i); } else { if ( xc_set_cpufreq_gov(xc_handle, cpuid, name) ) fprintf(stderr, "failed to set governor name\n"); } free(name); return ; out: fprintf(stderr, "failed to set governor name\n"); }