Re: [PATCH] arm-common: account for SMC exits

2018-10-18 Thread Jan Kiszka

On 18.10.18 16:03, Ralf Ramsauer wrote:



On 10/18/18 3:59 PM, Jan Kiszka wrote:

On 18.10.18 15:50, Ralf Ramsauer wrote:

From: Ralf Ramsauer 


From: Ralf Ramsauer 

wrote that patch on my private machine and forgot to set the correct
email...



Statistics on ARM currently has some imbalances: the total number of
exits doesn't equal the sum of the fine granular exit counters: we
aren't accounting for SMCCC exits.

Fix this by adding a new statistic counter for SMCCC.

PSCI exits are already accounted inside psci_dispatch(), move SMCCC
accounting to the dispatcher routine handle_smc().



I suppose that is a fix for 7688e96c815ba2f7c713228ecdd75241bcb8102a -
or something around that?


Fixes: 7688e96c815b ("arm-common: Rework handling of SMC")

By the way, we currently use 32 bit types for statistics. We might want
to think of 64 bit types.

Let's say we have 100kexits/s, then we'll overflow in under 12 hours.


Well, we currently piggy-back on the hypercall return value for transporting the 
counter (which is actually 31 bit only). Would require "some" change to the 
JAILHOUSE_HC_CPU_GET_INFO ABI - or more frequent checks of the user how the 
counters behave.


Jan

--
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux

--
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [PATCH] arm-common: account for SMC exits

2018-10-18 Thread Ralf Ramsauer



On 10/18/18 3:59 PM, Jan Kiszka wrote:
> On 18.10.18 15:50, Ralf Ramsauer wrote:
>> From: Ralf Ramsauer 

From: Ralf Ramsauer 

wrote that patch on my private machine and forgot to set the correct
email...

>>
>> Statistics on ARM currently has some imbalances: the total number of
>> exits doesn't equal the sum of the fine granular exit counters: we
>> aren't accounting for SMCCC exits.
>>
>> Fix this by adding a new statistic counter for SMCCC.
>>
>> PSCI exits are already accounted inside psci_dispatch(), move SMCCC
>> accounting to the dispatcher routine handle_smc().
>>
> 
> I suppose that is a fix for 7688e96c815ba2f7c713228ecdd75241bcb8102a -
> or something around that?

Fixes: 7688e96c815b ("arm-common: Rework handling of SMC")

By the way, we currently use 32 bit types for statistics. We might want
to think of 64 bit types.

Let's say we have 100kexits/s, then we'll overflow in under 12 hours.

  Ralf

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [PATCH] arm-common: account for SMC exits

2018-10-18 Thread Jan Kiszka

On 18.10.18 15:50, Ralf Ramsauer wrote:

From: Ralf Ramsauer 

Statistics on ARM currently has some imbalances: the total number of
exits doesn't equal the sum of the fine granular exit counters: we
aren't accounting for SMCCC exits.

Fix this by adding a new statistic counter for SMCCC.

PSCI exits are already accounted inside psci_dispatch(), move SMCCC
accounting to the dispatcher routine handle_smc().



I suppose that is a fix for 7688e96c815ba2f7c713228ecdd75241bcb8102a - or 
something around that?



Signed-off-by: Ralf Ramsauer 
---
  driver/sysfs.c   | 3 +++
  hypervisor/arch/arm-common/smccc.c   | 4 
  include/arch/arm/asm/jailhouse_hypercall.h   | 5 +++--
  include/arch/arm64/asm/jailhouse_hypercall.h | 3 ++-
  4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/driver/sysfs.c b/driver/sysfs.c
index 8648cfeb..a272ef4c 100644
--- a/driver/sysfs.c
+++ b/driver/sysfs.c
@@ -148,6 +148,7 @@ JAILHOUSE_CPU_STATS_ATTR(vmexits_maintenance,
  JAILHOUSE_CPU_STATS_ATTR(vmexits_virt_irq, JAILHOUSE_CPU_STAT_VMEXITS_VIRQ);
  JAILHOUSE_CPU_STATS_ATTR(vmexits_virt_sgi, JAILHOUSE_CPU_STAT_VMEXITS_VSGI);
  JAILHOUSE_CPU_STATS_ATTR(vmexits_psci, JAILHOUSE_CPU_STAT_VMEXITS_PSCI);
+JAILHOUSE_CPU_STATS_ATTR(vmexits_smccc, JAILHOUSE_CPU_STAT_VMEXITS_SMCCC);
  #ifdef CONFIG_ARM
  JAILHOUSE_CPU_STATS_ATTR(vmexits_cp15, JAILHOUSE_CPU_STAT_VMEXITS_CP15);
  #endif
@@ -172,6 +173,7 @@ static struct attribute *cell_stats_attrs[] = {
_virt_irq_cell_attr.kattr.attr,
_virt_sgi_cell_attr.kattr.attr,
_psci_cell_attr.kattr.attr,
+   _smccc_cell_attr.kattr.attr,
  #ifdef CONFIG_ARM
_cp15_cell_attr.kattr.attr,
  #endif
@@ -203,6 +205,7 @@ static struct attribute *cpu_stats_attrs[] = {
_virt_irq_cpu_attr.kattr.attr,
_virt_sgi_cpu_attr.kattr.attr,
_psci_cpu_attr.kattr.attr,
+   _smccc_cpu_attr.kattr.attr,
  #ifdef CONFIG_ARM
_cp15_cpu_attr.kattr.attr,
  #endif
diff --git a/hypervisor/arch/arm-common/smccc.c 
b/hypervisor/arch/arm-common/smccc.c
index b525ef25..095d14e1 100644
--- a/hypervisor/arch/arm-common/smccc.c
+++ b/hypervisor/arch/arm-common/smccc.c
@@ -33,13 +33,16 @@ static long handle_arch(struct trap_context *ctx)
  int handle_smc(struct trap_context *ctx)
  {
unsigned long *regs = ctx->regs;
+   u32 *stats = this_cpu_public()->stats;
  
  	switch (SMCCC_GET_OWNER(regs[0])) {

case ARM_SMCCC_OWNER_ARCH:
+   stats[JAILHOUSE_CPU_STAT_VMEXITS_SMCCC]++;
regs[0] = handle_arch(ctx);
break;
  
  	case ARM_SMCCC_OWNER_SIP:

+   stats[JAILHOUSE_CPU_STAT_VMEXITS_SMCCC]++;
regs[0] = ARM_SMCCC_NOT_SUPPORTED;
break;
  
@@ -48,6 +51,7 @@ int handle_smc(struct trap_context *ctx)

break;
  
  	default:

+   stats[JAILHOUSE_CPU_STAT_VMEXITS_SMCCC]++;


Unhandled exits will panic - we generally do not account for them. And such an 
exit here may not even be SMCCC-conforming.


Jan


return TRAP_UNHANDLED;
  
  	}

diff --git a/include/arch/arm/asm/jailhouse_hypercall.h 
b/include/arch/arm/asm/jailhouse_hypercall.h
index 7b00f873..c5c1d45a 100644
--- a/include/arch/arm/asm/jailhouse_hypercall.h
+++ b/include/arch/arm/asm/jailhouse_hypercall.h
@@ -51,8 +51,9 @@
  #define JAILHOUSE_CPU_STAT_VMEXITS_VIRQ   
JAILHOUSE_GENERIC_CPU_STATS + 1
  #define JAILHOUSE_CPU_STAT_VMEXITS_VSGI   
JAILHOUSE_GENERIC_CPU_STATS + 2
  #define JAILHOUSE_CPU_STAT_VMEXITS_PSCI   
JAILHOUSE_GENERIC_CPU_STATS + 3
-#define JAILHOUSE_CPU_STAT_VMEXITS_CP15
JAILHOUSE_GENERIC_CPU_STATS + 4
-#define JAILHOUSE_NUM_CPU_STATS
JAILHOUSE_GENERIC_CPU_STATS + 5
+#define JAILHOUSE_CPU_STAT_VMEXITS_SMCCC   JAILHOUSE_GENERIC_CPU_STATS + 4
+#define JAILHOUSE_CPU_STAT_VMEXITS_CP15
JAILHOUSE_GENERIC_CPU_STATS + 5
+#define JAILHOUSE_NUM_CPU_STATS
JAILHOUSE_GENERIC_CPU_STATS + 6
  
  #ifndef __ASSEMBLY__
  
diff --git a/include/arch/arm64/asm/jailhouse_hypercall.h b/include/arch/arm64/asm/jailhouse_hypercall.h

index 5994e1a0..497ba504 100644
--- a/include/arch/arm64/asm/jailhouse_hypercall.h
+++ b/include/arch/arm64/asm/jailhouse_hypercall.h
@@ -50,7 +50,8 @@
  #define JAILHOUSE_CPU_STAT_VMEXITS_VIRQ   
JAILHOUSE_GENERIC_CPU_STATS + 1
  #define JAILHOUSE_CPU_STAT_VMEXITS_VSGI   
JAILHOUSE_GENERIC_CPU_STATS + 2
  #define JAILHOUSE_CPU_STAT_VMEXITS_PSCI   
JAILHOUSE_GENERIC_CPU_STATS + 3
-#define JAILHOUSE_NUM_CPU_STATS
JAILHOUSE_GENERIC_CPU_STATS + 4
+#define JAILHOUSE_CPU_STAT_VMEXITS_SMCCC   JAILHOUSE_GENERIC_CPU_STATS + 4
+#define JAILHOUSE_NUM_CPU_STATS
JAILHOUSE_GENERIC_CPU_STATS + 5
  
  #ifndef __ASSEMBLY__
  



--
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded