int main( int argc, char *argv [ ] ) { time_t seconds; time( & seconds ) ; srand ( seconds ) ; int TAM_WIDTH_MAX = atoi (argv[1]); pareto_optimal(TAM_WIDTH_MAX); }
int machine_speed_init (actuator_t *act) { machine_state_data_t *data; unsigned long *states, *all_states; unsigned long *in_state, *out_state; int state_count, filtered_count; int core_count, i; freq_scaler_data_t *freq_data; act->data = data = malloc(sizeof(machine_state_data_t)); fail_if(!data, "cannot allocate powerstate data block"); get_actuators(&data->core_act, NULL, 16, &data->freq_acts[0], NULL); fail_if(data->core_act->max > 16, "too many cores lol"); freq_data = data->freq_acts[0]->data; core_count = get_core_count(); all_states = create_machine_states(&state_count, core_count, freq_data->freq_count, freq_data->freq_array); fail_if(!all_states, "cannot generate machine states"); qsort(all_states, state_count, STATE_SIZE(core_count), compare_states_on_speed); states = malloc(STATE_SIZE(core_count) * state_count); for (i = 0, in_state = all_states, out_state = states, filtered_count = 0; i < state_count; i++, in_state+=STATE_LEN(core_count)) { if (!redundant_state(in_state, core_count) && !drop_equivalent(in_state, i, all_states, state_count, core_count) && pareto_optimal(in_state, i, all_states, state_count, core_count) && in_state[SPEED_IDX] > 0) { #if DEBUG int j; printf("%lu\t%lu", in_state[SPEED_IDX], in_state[POWER_IDX]); for (j = 0; j < core_count; j++) printf("\t%lu", in_state[CORE_IDX(j)]); printf("\n"); #endif memmove (out_state, in_state, STATE_SIZE(core_count)); out_state += STATE_LEN(core_count); filtered_count++; } } data->state_count = state_count = filtered_count; data->states = states = realloc(states, STATE_SIZE(core_count) * state_count); free(all_states); act->min = STATE_I(states, core_count, 0)[SPEED_IDX]; act->max = STATE_I(states, core_count, state_count-1)[SPEED_IDX]; data->scratch_state = malloc(STATE_SIZE(core_count)); act->value = act->set_value = get_current_speed(act); return 0; fail: return -1; }
int main(int argc, char **argv) { struct cpufreq_available_frequencies *freq_list; int core_count; int i, j; unsigned long *states, *state; int state_count; int opt; int skip_redundant = 0; int skip_unoptimal = 0; char *state_file_name = NULL; int skip_equivalent = 0; while ((opt = getopt(argc, argv, "rpf:u")) != -1) switch (opt) { case 'r': skip_redundant = 1; break; case 'p': skip_unoptimal = 1; break; case 'f': state_file_name = optarg; break; case 'u': skip_equivalent = 1; break; default: fprintf(stderr, "Usage: %s [-r] [-p] [-f file] [-u]\n", argv[0]); exit(1); } if (state_file_name) { states = read_states_file(state_file_name, &state_count, &core_count); } else { int freq_count; unsigned long *freq_array; core_count = get_core_count(); freq_list = cpufreq_get_available_frequencies(0); freq_count = create_freq_array(freq_list, &freq_array); states = create_machine_states(&state_count, core_count, freq_count, freq_array); } qsort(states, state_count, STATE_SIZE(core_count), compare_states_on_speed); printf("speed\tpower"); for (j = 0; j < core_count; j++) printf("\tcore%d", j); printf("\n"); for (i = 0, state = states; i < state_count; i++, state+=STATE_LEN(core_count)) { if (skip_redundant && redundant_state(state, core_count)) continue; if (skip_equivalent && drop_equivalent(state, i, states, state_count, core_count)) continue; if (skip_unoptimal && !pareto_optimal(state, i, states, state_count, core_count)) continue; printf("%lu\t%lu", state[SPEED_IDX], state[POWER_IDX]); for (j = 0; j < core_count; j++) printf("\t%lu", state[CORE_IDX(j)]); printf("\n"); } return 0; }