All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Improve DIAG 9c observability
@ 2026-07-24 10:39 Ciunas Bennett
  2026-07-24 10:39 ` [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point Ciunas Bennett
  2026-07-24 10:39 ` [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations Ciunas Bennett
  0 siblings, 2 replies; 7+ messages in thread
From: Ciunas Bennett @ 2026-07-24 10:39 UTC (permalink / raw)
  To: linux-s390
  Cc: borntraeger, frankja, imbrenda, david, hca, gor, agordeev, svens,
	Ciunas Bennett

This series enhances observability for DIAG 9c directed yield operations
in s390 KVM by refactoring the handler and adding comprehensive tracing
support.

The first patch refactors __diag_time_slice_end_directed() to use a
single exit point with a result string variable. This consolidates the
control flow and eliminates code duplication in logging statements,
making the function more maintainable.

The second patch builds on this refactoring by adding a new tracepoint
kvm_s390_diag_9c that captures detailed information about directed yield
operations, including target vcpu, target physical CPU, and operation
results. This enables better analysis of VCPU scheduling
behaviour and helps diagnose performance issues in virtualised s390
environments.

Together, these changes provide kernel developers and system
administrators with better tools to understand and debug VCPU scheduling
patterns related to directed yields.

---
Changes in v3:
 - Patch 2: Remove duplicated target_cpu and target_vcpu fields

Changes in v2:
 - Add system maintainers to review mail

Ciunas Bennett (2):
  s390/kvm: Refactor __diag_time_slice_end_directed for single exit
    point
  s390/kvm: Add tracepoint for DIAG 9c directed yield operations

 arch/s390/kvm/diag.c  | 19 +++++++++++--------
 arch/s390/kvm/trace.h | 26 ++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 8 deletions(-)


base-commit: 1590cf0329716306e948a8fc29f1d3ee87d3989f
-- 
2.54.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point
  2026-07-24 10:39 [PATCH v3 0/2] Improve DIAG 9c observability Ciunas Bennett
@ 2026-07-24 10:39 ` Ciunas Bennett
  2026-07-24 11:07   ` sashiko-bot
  2026-07-24 12:10   ` Christian Borntraeger
  2026-07-24 10:39 ` [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations Ciunas Bennett
  1 sibling, 2 replies; 7+ messages in thread
From: Ciunas Bennett @ 2026-07-24 10:39 UTC (permalink / raw)
  To: linux-s390
  Cc: borntraeger, frankja, imbrenda, david, hca, gor, agordeev, svens,
	Ciunas Bennett

Refactor the DIAG 9c (directed yield) handler to use a unified exit path,
improving code maintainability and reducing duplication.
Changes:
 - Consolidate all exit paths to use a single 'out' label
 - Replace multiple VCPU_EVENT logging calls with one unified call
 - Introduce 'result' string variable to track operation outcome
 - Initialize tcpu_cpu to -1 for safe handling across all code paths
 - Ensure statistics updates occur before the common exit point

This refactoring maintains identical functionality while making the control
flow clearer and easier to maintain. All three possible outcomes (yield
forwarded, done, ignored) now converge at a single logging point

Signed-off-by: Ciunas Bennett <ciunas@linux.ibm.com>
---
 arch/s390/kvm/diag.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index d89d1c381522..85c84421b510 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -186,7 +186,8 @@ static int diag9c_forwarding_overrun(void)
 static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
 {
 	struct kvm_vcpu *tcpu;
-	int tcpu_cpu;
+	const char *result;
+	int tcpu_cpu = -1;
 	int tid;
 
 	tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
@@ -211,21 +212,22 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
 		if (!vcpu_is_preempted(tcpu_cpu))
 			goto no_yield;
 		smp_yield_cpu(tcpu_cpu);
-		VCPU_EVENT(vcpu, 5,
-			   "diag time slice end directed to %d: yield forwarded",
-			   tid);
 		vcpu->stat.diag_9c_forward++;
-		return 0;
+		result = "yield forwarded";
+		goto out;
 	}
 
 	if (kvm_vcpu_yield_to(tcpu) <= 0)
 		goto no_yield;
 
-	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: done", tid);
-	return 0;
+	result = "done";
+	goto out;
 no_yield:
-	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: ignored", tid);
 	vcpu->stat.diag_9c_ignored++;
+	result = "ignored";
+out:
+	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: %s", tid,
+		   result);
 	return 0;
 }
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations
  2026-07-24 10:39 [PATCH v3 0/2] Improve DIAG 9c observability Ciunas Bennett
  2026-07-24 10:39 ` [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point Ciunas Bennett
@ 2026-07-24 10:39 ` Ciunas Bennett
  2026-07-24 11:05   ` sashiko-bot
  2026-07-24 12:18   ` Christian Borntraeger
  1 sibling, 2 replies; 7+ messages in thread
From: Ciunas Bennett @ 2026-07-24 10:39 UTC (permalink / raw)
  To: linux-s390
  Cc: borntraeger, frankja, imbrenda, david, hca, gor, agordeev, svens,
	Ciunas Bennett

Add a new tracepoint, kvm_s390_diag_9c, to provide visibility into
directed yield operations. The tracepoint records:

  - Source vCPU context via the standard vCPU tracepoint fields
  - Target vCPU ID
  - Target physical CPU number
  - Operation result (done, ignored, or yield forwarded)

This improves observability of vCPU scheduling behaviour and helps
diagnose performance issues related to directed yields in virtualised
s390 environments.

Signed-off-by: Ciunas Bennett <ciunas@linux.ibm.com>
---
 arch/s390/kvm/diag.c  |  1 +
 arch/s390/kvm/trace.h | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index 85c84421b510..031ab6e5d6c4 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -228,6 +228,7 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
 out:
 	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: %s", tid,
 		   result);
+	trace_kvm_s390_diag_9c(vcpu, tid, tcpu_cpu, result);
 	return 0;
 }
 
diff --git a/arch/s390/kvm/trace.h b/arch/s390/kvm/trace.h
index aa419eb6a0c8..dd2685c7df5b 100644
--- a/arch/s390/kvm/trace.h
+++ b/arch/s390/kvm/trace.h
@@ -283,6 +283,32 @@ TRACE_EVENT(kvm_s390_handle_diag,
 			   __print_symbolic(__entry->code, diagnose_codes))
 	);
 
+TRACE_EVENT(kvm_s390_diag_9c,
+	    TP_PROTO(VCPU_PROTO_COMMON, int target_vcpu, int target_cpu,
+		     const char *result),
+	    TP_ARGS(VCPU_ARGS_COMMON, target_vcpu, target_cpu, result),
+
+	    TP_STRUCT__entry(
+		    VCPU_FIELD_COMMON
+		    __field(int, target_vcpu)
+		    __field(int, target_cpu)
+		    __string(result, result)
+		    ),
+
+	    TP_fast_assign(
+		    VCPU_ASSIGN_COMMON
+		    __entry->target_vcpu = target_vcpu;
+		    __entry->target_cpu = target_cpu;
+		    __assign_str(result);
+		    ),
+
+	    VCPU_TP_PRINTK(
+		       "diag=9c target_vcpu=%d target_pcpu=%d result=%s",
+		       __entry->target_vcpu,
+		       __entry->target_cpu,
+		       __get_str(result))
+	);
+
 TRACE_EVENT(kvm_s390_handle_lctl,
 	    TP_PROTO(VCPU_PROTO_COMMON, int g, int reg1, int reg3, u64 addr),
 	    TP_ARGS(VCPU_ARGS_COMMON, g, reg1, reg3, addr),
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations
  2026-07-24 10:39 ` [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations Ciunas Bennett
@ 2026-07-24 11:05   ` sashiko-bot
  2026-07-24 12:18   ` Christian Borntraeger
  1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-07-24 11:05 UTC (permalink / raw)
  To: Ciunas Bennett
  Cc: Vasily Gorbik, Alexander Gordeev, Heiko Carstens, linux-s390

> Add a new tracepoint, kvm_s390_diag_9c, to provide visibility into
> directed yield operations. The tracepoint records:
> 
>   - Source vCPU context via the standard vCPU tracepoint fields
>   - Target vCPU ID
>   - Target physical CPU number
>   - Operation result (done, ignored, or yield forwarded)
> 
> This improves observability of vCPU scheduling behaviour and helps
> diagnose performance issues related to directed yields in virtualised
> s390 environments.
> 
> Signed-off-by: Ciunas Bennett <ciunas@linux.ibm.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724103959.14861-1-ciunas@linux.ibm.com?part=2


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point
  2026-07-24 10:39 ` [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point Ciunas Bennett
@ 2026-07-24 11:07   ` sashiko-bot
  2026-07-24 12:10   ` Christian Borntraeger
  1 sibling, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-07-24 11:07 UTC (permalink / raw)
  To: Ciunas Bennett
  Cc: Heiko Carstens, linux-s390, Alexander Gordeev, Vasily Gorbik

> Refactor the DIAG 9c (directed yield) handler to use a unified exit path,
> improving code maintainability and reducing duplication.
> Changes:
>  - Consolidate all exit paths to use a single 'out' label
>  - Replace multiple VCPU_EVENT logging calls with one unified call
>  - Introduce 'result' string variable to track operation outcome
>  - Initialize tcpu_cpu to -1 for safe handling across all code paths
>  - Ensure statistics updates occur before the common exit point
> 
> This refactoring maintains identical functionality while making the control
> flow clearer and easier to maintain. All three possible outcomes (yield
> forwarded, done, ignored) now converge at a single logging point
> 
> Signed-off-by: Ciunas Bennett <ciunas@linux.ibm.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724103959.14861-1-ciunas@linux.ibm.com?part=1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point
  2026-07-24 10:39 ` [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point Ciunas Bennett
  2026-07-24 11:07   ` sashiko-bot
@ 2026-07-24 12:10   ` Christian Borntraeger
  1 sibling, 0 replies; 7+ messages in thread
From: Christian Borntraeger @ 2026-07-24 12:10 UTC (permalink / raw)
  To: Ciunas Bennett, linux-s390
  Cc: frankja, imbrenda, david, hca, gor, agordeev, svens



Am 24.07.26 um 12:39 schrieb Ciunas Bennett:
> Refactor the DIAG 9c (directed yield) handler to use a unified exit path,
> improving code maintainability and reducing duplication.
> Changes:
>   - Consolidate all exit paths to use a single 'out' label
>   - Replace multiple VCPU_EVENT logging calls with one unified call
>   - Introduce 'result' string variable to track operation outcome
>   - Initialize tcpu_cpu to -1 for safe handling across all code paths
>   - Ensure statistics updates occur before the common exit point
> 
> This refactoring maintains identical functionality while making the control
> flow clearer and easier to maintain. All three possible outcomes (yield
> forwarded, done, ignored) now converge at a single logging point
> 
> Signed-off-by: Ciunas Bennett <ciunas@linux.ibm.com>

Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>


> ---
>   arch/s390/kvm/diag.c | 18 ++++++++++--------
>   1 file changed, 10 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
> index d89d1c381522..85c84421b510 100644
> --- a/arch/s390/kvm/diag.c
> +++ b/arch/s390/kvm/diag.c
> @@ -186,7 +186,8 @@ static int diag9c_forwarding_overrun(void)
>   static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
>   {
>   	struct kvm_vcpu *tcpu;
> -	int tcpu_cpu;
> +	const char *result;
> +	int tcpu_cpu = -1;
>   	int tid;
>   
>   	tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
> @@ -211,21 +212,22 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
>   		if (!vcpu_is_preempted(tcpu_cpu))
>   			goto no_yield;
>   		smp_yield_cpu(tcpu_cpu);
> -		VCPU_EVENT(vcpu, 5,
> -			   "diag time slice end directed to %d: yield forwarded",
> -			   tid);
>   		vcpu->stat.diag_9c_forward++;
> -		return 0;
> +		result = "yield forwarded";
> +		goto out;
>   	}
>   
>   	if (kvm_vcpu_yield_to(tcpu) <= 0)
>   		goto no_yield;
>   
> -	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: done", tid);
> -	return 0;
> +	result = "done";
> +	goto out;
>   no_yield:
> -	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: ignored", tid);
>   	vcpu->stat.diag_9c_ignored++;
> +	result = "ignored";
> +out:
> +	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: %s", tid,
> +		   result);
>   	return 0;
>   }
>   


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations
  2026-07-24 10:39 ` [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations Ciunas Bennett
  2026-07-24 11:05   ` sashiko-bot
@ 2026-07-24 12:18   ` Christian Borntraeger
  1 sibling, 0 replies; 7+ messages in thread
From: Christian Borntraeger @ 2026-07-24 12:18 UTC (permalink / raw)
  To: Ciunas Bennett, linux-s390
  Cc: frankja, imbrenda, david, hca, gor, agordeev, svens

Am 24.07.26 um 12:39 schrieb Ciunas Bennett:
> Add a new tracepoint, kvm_s390_diag_9c, to provide visibility into
> directed yield operations. The tracepoint records:
> 
>    - Source vCPU context via the standard vCPU tracepoint fields
>    - Target vCPU ID
>    - Target physical CPU number
>    - Operation result (done, ignored, or yield forwarded)
> 
> This improves observability of vCPU scheduling behaviour and helps
> diagnose performance issues related to directed yields in virtualised
> s390 environments.
> 
> Signed-off-by: Ciunas Bennett <ciunas@linux.ibm.com>

Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>

> ---
>   arch/s390/kvm/diag.c  |  1 +
>   arch/s390/kvm/trace.h | 26 ++++++++++++++++++++++++++
>   2 files changed, 27 insertions(+)
> 
> diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
> index 85c84421b510..031ab6e5d6c4 100644
> --- a/arch/s390/kvm/diag.c
> +++ b/arch/s390/kvm/diag.c
> @@ -228,6 +228,7 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
>   out:
>   	VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: %s", tid,
>   		   result);
> +	trace_kvm_s390_diag_9c(vcpu, tid, tcpu_cpu, result);
>   	return 0;
>   }
>   
> diff --git a/arch/s390/kvm/trace.h b/arch/s390/kvm/trace.h
> index aa419eb6a0c8..dd2685c7df5b 100644
> --- a/arch/s390/kvm/trace.h
> +++ b/arch/s390/kvm/trace.h
> @@ -283,6 +283,32 @@ TRACE_EVENT(kvm_s390_handle_diag,
>   			   __print_symbolic(__entry->code, diagnose_codes))
>   	);
>   
> +TRACE_EVENT(kvm_s390_diag_9c,
> +	    TP_PROTO(VCPU_PROTO_COMMON, int target_vcpu, int target_cpu,
> +		     const char *result),
> +	    TP_ARGS(VCPU_ARGS_COMMON, target_vcpu, target_cpu, result),
> +
> +	    TP_STRUCT__entry(
> +		    VCPU_FIELD_COMMON
> +		    __field(int, target_vcpu)
> +		    __field(int, target_cpu)
> +		    __string(result, result)
> +		    ),
> +
> +	    TP_fast_assign(
> +		    VCPU_ASSIGN_COMMON
> +		    __entry->target_vcpu = target_vcpu;
> +		    __entry->target_cpu = target_cpu;
> +		    __assign_str(result);
> +		    ),
> +
> +	    VCPU_TP_PRINTK(
> +		       "diag=9c target_vcpu=%d target_pcpu=%d result=%s",
> +		       __entry->target_vcpu,
> +		       __entry->target_cpu,
> +		       __get_str(result))
> +	);
> +
>   TRACE_EVENT(kvm_s390_handle_lctl,
>   	    TP_PROTO(VCPU_PROTO_COMMON, int g, int reg1, int reg3, u64 addr),
>   	    TP_ARGS(VCPU_ARGS_COMMON, g, reg1, reg3, addr),


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-24 12:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24 10:39 [PATCH v3 0/2] Improve DIAG 9c observability Ciunas Bennett
2026-07-24 10:39 ` [PATCH v3 1/2] s390/kvm: Refactor __diag_time_slice_end_directed for single exit point Ciunas Bennett
2026-07-24 11:07   ` sashiko-bot
2026-07-24 12:10   ` Christian Borntraeger
2026-07-24 10:39 ` [PATCH v3 2/2] s390/kvm: Add tracepoint for DIAG 9c directed yield operations Ciunas Bennett
2026-07-24 11:05   ` sashiko-bot
2026-07-24 12:18   ` Christian Borntraeger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.