]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Added speed reading functions.
authorDario Faggioli <faggioli@gandalf.sssup.it>
Wed, 13 May 2009 09:58:22 +0000 (11:58 +0200)
committerDario Faggioli <faggioli@gandalf.sssup.it>
Wed, 13 May 2009 09:58:22 +0000 (11:58 +0200)
frsh_resource_get_speed() function (and their implementations for CPU and
LCD) are added by this commit.
They can be used to retreive the ratio between the speed of a power level
and the maximum achievable speed for that resource.

Test cases are added and updated accordingly.

frsh_api/frsh_contract.c
frsh_api/frsh_power.c
resources/acpi_battery/tests/acpi_battery_test.c
resources/acpi_cpu/fra_acpi_cpu.c
resources/acpi_cpu/fra_acpi_cpu.h
resources/acpi_cpu/tests/acpi_cpu_test.c
resources/acpi_lcd/fra_acpi_lcd.c
resources/acpi_lcd/fra_acpi_lcd.h
resources/acpi_lcd/tests/acpi_lcd_test.c

index b726217175005547ad6740c85c6524d787bd7e86..b2317cb5860f71a07273557d8aec124755fd9921 100644 (file)
@@ -337,7 +337,7 @@ int __contract_check_min_expiration(const frsh_contract_t *contract)
                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;
        }
 
index ee7ed864f0fad420ca48e2b4452a326cf04fe604..c304a8ddc2e5291f90e31d13620b08ea0ae3be65 100644 (file)
@@ -306,6 +306,51 @@ int frsh_resource_get_power_level
        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,
@@ -356,17 +401,12 @@ int frsh_battery_get_expiration(frsh_abs_time_t *expiration)
        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;        
index 09c84dffa9b6b73376345d454e2ddb76645523db..fe18b6df1b2c7689ad17fdf2945d1626e56b11aa 100644 (file)
@@ -1,90 +1,84 @@
 #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, &current);
+       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, &current);
+               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");
                
index b7bc9bbe328d0590e262df6327075288108768ce..8a1131bec08cb8387bdb537c9510b3fcf4c6e38a 100644 (file)
@@ -88,3 +88,13 @@ int fra_CPU_set_power(int cpu, int level)
        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;
+}
+
index 4264455ee791dd7fa6712b5d565b315c0e12b184..1d5d51db79951efae09f106ab210041a171c347f 100644 (file)
@@ -13,5 +13,7 @@ int fra_CPU_get_power(int cpu, int *level);
 
 int fra_CPU_set_power(int cpu, int level);
 
+int fra_CPU_get_speed(int cpu, int level, double *ratio);
+
 #endif
 
index 2dd9f4506f63849e9fb3b7f64deaa87aa46542bf..2f77b06cc1359e5f2bc7a29973cfad8c75620022 100644 (file)
@@ -1,42 +1,42 @@
 #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;
 }
 
index 827b9e22b5b89ad383af68ff7b34b3c5bc3a0f78..4cf8de7c0a814d743678fe710ab4e47f69f4a66f 100644 (file)
@@ -173,3 +173,13 @@ int fra_LCD_set_power(int lcd, int level)
        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;
+}
+
index bbe79e4f57500ed9e5547ca914efcfbd1583099b..cb89f87b6271dfa439764226ea383cb0ea5597da 100644 (file)
@@ -29,5 +29,7 @@ int fra_LCD_get_power(int lcd, int *level);
 
 int fra_LCD_set_power(int lcd, int level);
 
+int fra_LCD_get_speed(int lcd, int level, double *ratio);
+
 #endif
 
index add72a28ffe5ad4927c09920187e8f725e093246..7b6942e9ee55c12415d1684587be6edcede9e93d 100644 (file)
@@ -1,42 +1,42 @@
 #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;
 }