[Qemu-devel] [PATCH v2 01/12] cacheinfo: add i/d cache_linesize_log

Emilio G. Cota posted 12 patches 7 years, 1 month ago
There is a newer version of this series
[Qemu-devel] [PATCH v2 01/12] cacheinfo: add i/d cache_linesize_log
Posted by Emilio G. Cota 7 years, 1 month ago
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
 include/qemu/osdep.h | 2 ++
 util/cacheinfo.c     | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index a91068df0e..a746a5e531 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -570,6 +570,8 @@ extern uintptr_t qemu_real_host_page_size;
 extern intptr_t qemu_real_host_page_mask;
 
 extern int qemu_icache_linesize;
+extern int qemu_icache_linesize_log;
 extern int qemu_dcache_linesize;
+extern int qemu_dcache_linesize_log;
 
 #endif
diff --git a/util/cacheinfo.c b/util/cacheinfo.c
index db5172d07c..57c7d58159 100644
--- a/util/cacheinfo.c
+++ b/util/cacheinfo.c
@@ -7,9 +7,12 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/host-utils.h"
 
 int qemu_icache_linesize = 0;
+int qemu_icache_linesize_log;
 int qemu_dcache_linesize = 0;
+int qemu_dcache_linesize_log;
 
 /*
  * Operating system specific detection mechanisms.
@@ -173,5 +176,7 @@ static void __attribute__((constructor)) init_cache_info(void)
     fallback_cache_info(&isize, &dsize);
 
     qemu_icache_linesize = isize;
+    qemu_icache_linesize_log = 31 - clz32(isize);
     qemu_dcache_linesize = dsize;
+    qemu_dcache_linesize_log = 31 - clz32(dsize);
 }
-- 
2.17.1


Re: [Qemu-devel] [PATCH v2 01/12] cacheinfo: add i/d cache_linesize_log
Posted by Richard Henderson 7 years, 1 month ago
On 09/10/2018 04:27 PM, Emilio G. Cota wrote:
> @@ -173,5 +176,7 @@ static void __attribute__((constructor)) init_cache_info(void)
>      fallback_cache_info(&isize, &dsize);
>  
>      qemu_icache_linesize = isize;
> +    qemu_icache_linesize_log = 31 - clz32(isize);
>      qemu_dcache_linesize = dsize;
> +    qemu_dcache_linesize_log = 31 - clz32(dsize);

Either pow2ceil or realize that linesize is already a power of 2 and use ctz32.


r~

Re: [Qemu-devel] [PATCH v2 01/12] cacheinfo: add i/d cache_linesize_log
Posted by Paolo Bonzini 7 years, 1 month ago
On 11/09/2018 14:16, Richard Henderson wrote:
> On 09/10/2018 04:27 PM, Emilio G. Cota wrote:
>> @@ -173,5 +176,7 @@ static void __attribute__((constructor)) init_cache_info(void)
>>      fallback_cache_info(&isize, &dsize);
>>  
>>      qemu_icache_linesize = isize;
>> +    qemu_icache_linesize_log = 31 - clz32(isize);
>>      qemu_dcache_linesize = dsize;
>> +    qemu_dcache_linesize_log = 31 - clz32(dsize);
> 
> Either pow2ceil or realize that linesize is already a power of 2 and use ctz32.

Changed to ctz32.

Paolo