diff mbox

[4/7] arm: remove muldiv64()

Message ID 1440535491-4511-5-git-send-email-lvivier@redhat.com
State New
Headers show

Commit Message

Laurent Vivier Aug. 25, 2015, 8:44 p.m. UTC
muldiv64() is used to convert microseconds to nanoseconds.

Use qemu_clock_get_ns() instead of qemu_clock_get_us()
to avoid this operation.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 target-arm/helper.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Peter Crosthwaite Aug. 25, 2015, 9:11 p.m. UTC | #1
On Tue, Aug 25, 2015 at 1:44 PM, Laurent Vivier <lvivier@redhat.com> wrote:
> muldiv64() is used to convert microseconds to nanoseconds.
>
> Use qemu_clock_get_ns() instead of qemu_clock_get_us()
> to avoid this operation.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
>  target-arm/helper.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/target-arm/helper.c b/target-arm/helper.c
> index 1568aa6..f5e8fd8 100644
> --- a/target-arm/helper.c
> +++ b/target-arm/helper.c
> @@ -678,8 +678,7 @@ void pmccntr_sync(CPUARMState *env)
>  {
>      uint64_t temp_ticks;
>
> -    temp_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
> -                          get_ticks_per_sec(), 1000000);
> +    temp_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>
>      if (env->cp15.c9_pmcr & PMCRD) {
>          /* Increment once every 64 processor clock cycles */
> @@ -717,8 +716,7 @@ static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri)
>          return env->cp15.c15_ccnt;
>      }
>
> -    total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
> -                           get_ticks_per_sec(), 1000000);
> +    total_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>

The long term goal here was to replace get_ticks_per_sec with a
parameterizable CPU frequency so ideally the math should remain. The
ARM CPU frequency == get_ticks_per_sec is the bigger issue.

Regards,
Peter

>      if (env->cp15.c9_pmcr & PMCRD) {
>          /* Increment once every 64 processor clock cycles */
> @@ -738,8 +736,7 @@ static void pmccntr_write(CPUARMState *env, const ARMCPRegInfo *ri,
>          return;
>      }
>
> -    total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
> -                           get_ticks_per_sec(), 1000000);
> +    total_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>
>      if (env->cp15.c9_pmcr & PMCRD) {
>          /* Increment once every 64 processor clock cycles */
> --
> 2.1.0
>
>
Laurent Vivier Aug. 25, 2015, 9:36 p.m. UTC | #2
On 25/08/2015 23:11, Peter Crosthwaite wrote:
> On Tue, Aug 25, 2015 at 1:44 PM, Laurent Vivier <lvivier@redhat.com> wrote:
>> muldiv64() is used to convert microseconds to nanoseconds.
>>
>> Use qemu_clock_get_ns() instead of qemu_clock_get_us()
>> to avoid this operation.
>>
>> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
>> ---
>>  target-arm/helper.c | 9 +++------
>>  1 file changed, 3 insertions(+), 6 deletions(-)
>>
>> diff --git a/target-arm/helper.c b/target-arm/helper.c
>> index 1568aa6..f5e8fd8 100644
>> --- a/target-arm/helper.c
>> +++ b/target-arm/helper.c
>> @@ -678,8 +678,7 @@ void pmccntr_sync(CPUARMState *env)
>>  {
>>      uint64_t temp_ticks;
>>
>> -    temp_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
>> -                          get_ticks_per_sec(), 1000000);
>> +    temp_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>>
>>      if (env->cp15.c9_pmcr & PMCRD) {
>>          /* Increment once every 64 processor clock cycles */
>> @@ -717,8 +716,7 @@ static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri)
>>          return env->cp15.c15_ccnt;
>>      }
>>
>> -    total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
>> -                           get_ticks_per_sec(), 1000000);
>> +    total_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>>
> 
> The long term goal here was to replace get_ticks_per_sec with a
> parameterizable CPU frequency so ideally the math should remain. The
> ARM CPU frequency == get_ticks_per_sec is the bigger issue.

OK, I will remove this one from the series.

Perhaps a comment in the original functions would help to understand
what we are doing here...

or something like that:

#define ARM_CPU_FREQ 1000000000 /* FIXME: should be parameterizable */
#define NSEC_PER_SEC 1000000000

total_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
ARM_CPU_FREQ, NSEC_PER_SEC);

Laurent
> Regards,
> Peter
> 
>>      if (env->cp15.c9_pmcr & PMCRD) {
>>          /* Increment once every 64 processor clock cycles */
>> @@ -738,8 +736,7 @@ static void pmccntr_write(CPUARMState *env, const ARMCPRegInfo *ri,
>>          return;
>>      }
>>
>> -    total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
>> -                           get_ticks_per_sec(), 1000000);
>> +    total_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>>
>>      if (env->cp15.c9_pmcr & PMCRD) {
>>          /* Increment once every 64 processor clock cycles */
>> --
>> 2.1.0
>>
>>
diff mbox

Patch

diff --git a/target-arm/helper.c b/target-arm/helper.c
index 1568aa6..f5e8fd8 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -678,8 +678,7 @@  void pmccntr_sync(CPUARMState *env)
 {
     uint64_t temp_ticks;
 
-    temp_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
-                          get_ticks_per_sec(), 1000000);
+    temp_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
     if (env->cp15.c9_pmcr & PMCRD) {
         /* Increment once every 64 processor clock cycles */
@@ -717,8 +716,7 @@  static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri)
         return env->cp15.c15_ccnt;
     }
 
-    total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
-                           get_ticks_per_sec(), 1000000);
+    total_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
     if (env->cp15.c9_pmcr & PMCRD) {
         /* Increment once every 64 processor clock cycles */
@@ -738,8 +736,7 @@  static void pmccntr_write(CPUARMState *env, const ARMCPRegInfo *ri,
         return;
     }
 
-    total_ticks = muldiv64(qemu_clock_get_us(QEMU_CLOCK_VIRTUAL),
-                           get_ticks_per_sec(), 1000000);
+    total_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 
     if (env->cp15.c9_pmcr & PMCRD) {
         /* Increment once every 64 processor clock cycles */