ret = frsh_battery_get_expiration(&exp_time);
if (ret) goto err;
- if (fosa_abs_time_smaller(req_time, exp_time))
+ if (fosa_abs_time_smaller(exp_time, req_time))
ret = FRSH_ERR_CONTRACT_REJECTED;
}
return FRSH_NO_ERROR;
}
+int frsh_resource_get_speed
+ (frsh_resource_type_t resource_type,
+ frsh_resource_id_t resource_id,
+ frsh_power_level_t power_level,
+ double *speed_ratio)
+{
+ switch(resource_type)
+ {
+#ifdef CONFIG_ACPI_CPU
+ case FRSH_RT_PROCESSOR:
+ {
+ int ret;
+
+ ret = fra_CPU_power_init(resource_id);
+ if (ret) return FRSH_ERR_INTERNAL_ERROR;
+ ret = fra_CPU_get_speed(resource_id,
+ (int) power_level,
+ speed_ratio);
+ if (ret) return FRSH_ERR_INTERNAL_ERROR;
+
+ break;
+ }
+#endif
+#ifdef CONFIG_ACPI_LCD
+ case FRSH_RT_LCD:
+ {
+ int ret;
+
+ ret = fra_LCD_power_init(resource_id);
+ if (ret) return FRSH_ERR_INTERNAL_ERROR;
+ ret = fra_LCD_get_speed(resource_id,
+ (int) power_level,
+ speed_ratio);
+ if (ret) return FRSH_ERR_INTERNAL_ERROR;
+
+ break;
+ }
+#endif
+ default:
+ return FRSH_ERR_NOT_IMPLEMENTED;
+ }
+
+ return FRSH_NO_ERROR;
+}
+
int frsh_resource_get_num_power_levels
(frsh_resource_type_t resource_type,
frsh_resource_id_t resource_id,
if (ret) return FRSH_ERR_INTERNAL_ERROR;
ret = fra_battery_expiration(&interval);
- if (ret == EAGAIN) {
- *expiration = fosa_msec_to_abs_time(0);
- goto out;
- }
- if (ret)
- return FRSH_ERR_INTERNAL_ERROR;
+ if (ret == EAGAIN) return ret;
+ if (ret) return FRSH_ERR_INTERNAL_ERROR;
fosa_clock_get_time(FOSA_CLOCK_REALTIME, expiration);
*expiration = fosa_abs_time_incr(*expiration, interval);
-out:
return FRSH_NO_ERROR;
#else
return FRSH_ERR_NOT_IMPLEMENTED;
#include <frsh.h>
-#include <aqcpu_res.h>
-#include <error.h>
int main()
{
- int ret;
+ int terror;
frsh_vres_id_t vres;
frsh_contract_t contract;
frsh_rel_time_t budget, period;
- frsh_rel_time_t duration, expiration;
- unsigned long long duration_msec = 10000;
+ frsh_rel_time_t current, duration, expiration;
+ unsigned long duration_msec, duration_step;
- if (frsh_init())
- error(1, 0, "FRSH initialization failed\n");
+ PXW(frsh_init());
+
+ PXW(frsh_contract_init(&contract));
+
+ duration_msec = duration_step = 1000UL * 60UL * 10UL;
- /* Contract negotiation for CPU */
- ret = frsh_contract_init(&contract);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
-
budget = fosa_msec_to_rel_time(10);
period = fosa_msec_to_rel_time(100);
- ret = frsh_contract_set_basic_params(&contract,
- &budget,
- &period,
- FRSH_WT_BOUNDED,
- FRSH_CT_REGULAR);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+ PXW(frsh_contract_set_basic_params(&contract,
+ &budget,
+ &period,
+ FRSH_WT_BOUNDED,
+ FRSH_CT_REGULAR));
+
+ PXW(frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR, 0,"TEST_VRES"));
+
+ PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_HIGH, &budget));
- ret = frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR,
- 0,"TEST_VRES");
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+ PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_MEDIUM, &budget));
- ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_HIGH, &budget);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_HIGH)");
+ PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_LOW, &budget));
- ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_MEDIUM, &budget);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_MEDIUM)");
+ terror = frsh_battery_get_expiration(&expiration);
+ if (terror == EAGAIN)
+ PERROR_AND_EXIT(terror, "frsh_battery_get_expiration: system running on AC");
+ if (terror)
+ PERROR_AND_EXIT(terror, "frsh_battery_get_expiration");
- ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_LOW, &budget);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_LOW)");
+ fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t);
+ printf("System battery wil expire in %lu seconds\n",
+ fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
+
+ printf("Starting with minumum diration = %lu seconds\n"
+ " ans stepping by %lu seconds.\n",
+ duration_msec / 1000UL,
+ duration_step / 1000UL);
duration = fosa_msec_to_rel_time(duration_msec);
- ret = frsh_contract_set_min_expiration(&contract, duration);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_expiration");
+ PXW(frsh_contract_set_min_expiration(&contract, duration));
- ret = frsh_contract_get_min_expiration(&contract, &duration);
- if (ret || fosa_rel_time_to_msec(duration) != duration_msec)
- PERROR_AND_EXIT(ret, "frsh_contract_get_min_expiration");
- printf("Minimum duration correctly set to: %lu\n", fosa_rel_time_to_msec(duration));
+ PXW(frsh_contract_get_min_expiration(&contract, &duration));
- ret = frsh_contract_negotiate(&contract, &vres);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+ PXW(frsh_contract_negotiate(&contract, &vres));
printf("Aqcpu vres negotiated, vres-ID: %d\n", (int) vres);
while (1) {
- duration_msec += duration_msec;
+ duration_msec += duration_step;
duration = fosa_msec_to_rel_time(duration_msec);
- ret = frsh_contract_set_min_expiration(&contract, duration);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_expiration");
-
- ret = frsh_contract_get_min_expiration(&contract, &duration);
- if (ret || fosa_rel_time_to_msec(duration) != duration_msec) {
- //PERROR_AND_EXIT(ret, "frsh_contract_get_duration");
- printf("%lu %lu\n", fosa_rel_time_to_msec(duration), duration_msec);
- break;
- }
- printf("Minimum duration correctly set to: %lu\n",
- fosa_rel_time_to_msec(duration));
+ fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t);
+ printf(" Renegotiating the contract with minimum expiration %lu sec.\n"
+ " System expiration time: %lu seconds\n",
+ fosa_rel_time_to_msec(duration) / 1000UL,
+ fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
- ret = frsh_battery_get_expiration(&expiration);
- if (ret) PERROR_AND_EXIT(ret, "frsh_battery_get_expiration");
+ PXW(frsh_contract_set_min_expiration(&contract, duration));
- ret = frsh_contract_renegotiate_sync(&contract, vres);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_renegotiate_sync");
-
- printf("Contract with minimum expiration %lu renegotiated."
- "System expiration time: %lu\n",
- fosa_rel_time_to_msec(duration),
- fosa_abs_time_to_msec(expiration));
+ PXW(frsh_battery_get_expiration(&expiration));
+ terror = frsh_contract_renegotiate_sync(&contract, vres);
+ if (terror == FRSH_ERR_CONTRACT_REJECTED) {
+ PERROR_FRESCOR(terror, "frsh_contract_renegotiate_sync");
+ goto out;
+ }
+ if (terror) PERROR_AND_EXIT(terror, "frsh_contract_renegotiate_sync");
sleep(3);
}
- ret = frsh_contract_cancel(vres);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");
+out:
+ PXW(frsh_contract_cancel(vres));
printf("Test PASSED!\n");
return cpufreq_set_frequency(cpu, freqs[level]);
}
+int fra_CPU_get_speed(int cpu, int level, double *ratio)
+{
+ if (!frequency_initialized || level >= 3)
+ return EINVAL;
+
+ *ratio = (double) freqs[level] / freqs[0];
+
+ return 0;
+}
+
int fra_CPU_set_power(int cpu, int level);
+int fra_CPU_get_speed(int cpu, int level, double *ratio);
+
#endif
#include <frsh.h>
-#include <error.h>
int main()
{
+ frsh_power_level_t level;
int power_levels;
- int ret;
+ double speed;
+ int terror;
- if (frsh_init())
- error(1, 0, "FRSH initialization failed\n");
+ PXW(frsh_init());
- ret = frsh_resource_get_num_power_levels(FRSH_RT_PROCESSOR,
- 0, &power_levels);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_get_num_power_levels");
+ PXW(frsh_resource_get_num_power_levels(FRSH_RT_PROCESSOR, 0, &power_levels));
printf("Number of power levels suppoerted: %d\n", power_levels);
if (power_levels == 1)
PERROR_AND_EXIT(EINVAL, "Different power levels not supported");
-
- printf("Starting...\n");
+
+ PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+ printf("Starting with power level %d, speed = %f\n", level, speed);
sleep(3);
- ret = frsh_resource_set_power_level(FRSH_RT_PROCESSOR,
- 0, FRSH_PLT_HIGH);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
- printf("FRSH_PLT_MEDIUM correctly set\n");
+ PXW(frsh_resource_set_power_level(FRSH_RT_PROCESSOR, 0, FRSH_PLT_HIGH));
+ PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+ printf("%d (FRSH_PLT_HIGH) correctly set, speed = %f\n", level, speed);
sleep(3);
- ret = frsh_resource_set_power_level(FRSH_RT_PROCESSOR,
- 0, FRSH_PLT_MEDIUM);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
- printf("FRSH_PLT_MEDIUM correctly set\n");
+ PXW(frsh_resource_set_power_level(FRSH_RT_PROCESSOR, 0, FRSH_PLT_MEDIUM));
+ PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+ printf("%d (FRSH_PLT_MEDIUM) correctly set, speed = %f\n", level, speed);
sleep(3);
- ret = frsh_resource_set_power_level(FRSH_RT_PROCESSOR,
- 0, FRSH_PLT_LOW);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
- printf("FRSH_PLT_LOW correctly set\n");
+ PXW(frsh_resource_set_power_level(FRSH_RT_PROCESSOR, 0, FRSH_PLT_LOW));
+ PXW(frsh_resource_get_power_level(FRSH_RT_PROCESSOR, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_PROCESSOR, 0, level, &speed));
+ printf("%d (FRSH_PLT_LOW) correctly set, speed = %f\n", level, speed);
- return 0;
+ return 0;
}
return __set_lcd_brightness(level);
}
+int fra_LCD_get_speed(int lcd, int level, double *ratio)
+{
+ if (lcd_initialized == NONE || level >= 3)
+ return EINVAL;
+
+ *ratio = bright[level]/bright[0];
+
+ return 0;
+}
+
int fra_LCD_set_power(int lcd, int level);
+int fra_LCD_get_speed(int lcd, int level, double *ratio);
+
#endif
#include <frsh.h>
-#include <error.h>
int main()
{
+ frsh_power_level_t level;
int power_levels;
- int ret;
+ double speed;
+ int terror;
- if (frsh_init())
- error(1, 0, "FRSH initialization failed\n");
+ PXW(frsh_init());
- ret = frsh_resource_get_num_power_levels(FRSH_RT_LCD,
- 0, &power_levels);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_get_num_power_levels");
+ PXW(frsh_resource_get_num_power_levels(FRSH_RT_LCD, 0, &power_levels));
printf("Number of power levels suppoerted: %d\n", power_levels);
if (power_levels == 1)
PERROR_AND_EXIT(EINVAL, "Different power levels not supported");
-
- printf("Starting...\n");
-
- sleep(5);
- ret = frsh_resource_set_power_level(FRSH_RT_LCD,
- 0, FRSH_PLT_HIGH);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
- printf("FRSH_PLT_MEDIUM correctly set\n");
-
- sleep(5);
- ret = frsh_resource_set_power_level(FRSH_RT_LCD,
- 0, FRSH_PLT_MEDIUM);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
- printf("FRSH_PLT_MEDIUM correctly set\n");
-
- sleep(5);
- ret = frsh_resource_set_power_level(FRSH_RT_LCD,
- 0, FRSH_PLT_LOW);
- if (ret) PERROR_AND_EXIT(ret, "frsh_resource_set_power_level");
- printf("FRSH_PLT_LOW correctly set\n");
-
- return 0;
+
+ PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+ printf("Starting with power level %d, speed = %f\n", level, speed);
+
+ sleep(3);
+ PXW(frsh_resource_set_power_level(FRSH_RT_LCD, 0, FRSH_PLT_HIGH));
+ PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+ printf("%d (FRSH_PLT_HIGH) correctly set, speed = %f\n", level, speed);
+
+ sleep(3);
+ PXW(frsh_resource_set_power_level(FRSH_RT_LCD, 0, FRSH_PLT_MEDIUM));
+ PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+ printf("%d (FRSH_PLT_MEDIUM) correctly set, speed = %f\n", level, speed);
+
+ sleep(3);
+ PXW(frsh_resource_set_power_level(FRSH_RT_LCD, 0, FRSH_PLT_LOW));
+ PXW(frsh_resource_get_power_level(FRSH_RT_LCD, 0, &level));
+ PXW(frsh_resource_get_speed(FRSH_RT_LCD, 0, level, &speed));
+ printf("%d (FRSH_PLT_LOW) correctly set, speed = %f\n", level, speed);
+
+ return 0;
}