public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Binder: Add timestamp and async from to transaction record
@ 2023-04-24 11:05 Chuang Zhang
  2023-04-24 11:05 ` [PATCH v2 1/2] Binder: Add timestamp " Chuang Zhang
  2023-04-24 11:05 ` [PATCH v2 2/2] Binder: Add async from " Chuang Zhang
  0 siblings, 2 replies; 5+ messages in thread
From: Chuang Zhang @ 2023-04-24 11:05 UTC (permalink / raw)
  To: gregkh, cmllamas
  Cc: arve, tkjos, maco, joel, brauner, surenb, linux-kernel,
	Chuang Zhang

From: Chuang Zhang <zhangchuang3@xiaomi.com>

This path adds support for getting the pid, tid, and transfer duration
information of transfers in binderfs transfer records.
Previously, this information was not available in the transfer records,
which made it difficult to analyze certain issues in Android.

With this modification, Android engineers will be able to quickly identify
and diagnose problems in certain scenarios. We believe that this
improvement will be particularly useful for issue analysis and debugging
on Android.

This change does not affect existing functionality or performance and
is fully backward-compatible.

Chuang Zhang (2):
  Binder: Add timestamp to transaction record
  Binder: Add async from to transaction record

 drivers/android/binder.c          | 15 +++++++++++----
 drivers/android/binder_internal.h |  3 +++
 2 files changed, 14 insertions(+), 4 deletions(-)

-- 
2.34.1


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

* [PATCH v2 1/2] Binder: Add timestamp to transaction record
  2023-04-24 11:05 [PATCH v2 0/2] Binder: Add timestamp and async from to transaction record Chuang Zhang
@ 2023-04-24 11:05 ` Chuang Zhang
  2023-04-25 18:59   ` Carlos Llamas
  2023-04-24 11:05 ` [PATCH v2 2/2] Binder: Add async from " Chuang Zhang
  1 sibling, 1 reply; 5+ messages in thread
From: Chuang Zhang @ 2023-04-24 11:05 UTC (permalink / raw)
  To: gregkh, cmllamas
  Cc: arve, tkjos, maco, joel, brauner, surenb, linux-kernel,
	Chuang Zhang

From: Chuang Zhang <zhangchuang3@xiaomi.com>

This patch adds a timestamp field to the binder_transaction
structure to track the time consumed during transmission
when reading binder_transaction records.

Signed-off-by: Chuang Zhang <zhangchuang3@xiaomi.com>
---
 drivers/android/binder.c          | 9 +++++++--
 drivers/android/binder_internal.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index fb56bfc45096..b6413652906e 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -66,6 +66,7 @@
 #include <linux/syscalls.h>
 #include <linux/task_work.h>
 #include <linux/sizes.h>
+#include <linux/ktime.h>
 
 #include <uapi/linux/android/binder.h>
 
@@ -2904,6 +2905,7 @@ static void binder_transaction(struct binder_proc *proc,
 	binder_size_t last_fixup_min_off = 0;
 	struct binder_context *context = proc->context;
 	int t_debug_id = atomic_inc_return(&binder_last_id);
+	ktime_t t_start_time = ktime_get();
 	char *secctx = NULL;
 	u32 secctx_sz = 0;
 	struct list_head sgc_head;
@@ -3145,6 +3147,7 @@ static void binder_transaction(struct binder_proc *proc,
 	binder_stats_created(BINDER_STAT_TRANSACTION_COMPLETE);
 
 	t->debug_id = t_debug_id;
+	t->start_time = t_start_time;
 
 	if (reply)
 		binder_debug(BINDER_DEBUG_TRANSACTION,
@@ -5930,17 +5933,19 @@ static void print_binder_transaction_ilocked(struct seq_file *m,
 {
 	struct binder_proc *to_proc;
 	struct binder_buffer *buffer = t->buffer;
+	ktime_t current_time = ktime_get();
 
 	spin_lock(&t->lock);
 	to_proc = t->to_proc;
 	seq_printf(m,
-		   "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d",
+		   "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d elapsed %lldms",
 		   prefix, t->debug_id, t,
 		   t->from ? t->from->proc->pid : 0,
 		   t->from ? t->from->pid : 0,
 		   to_proc ? to_proc->pid : 0,
 		   t->to_thread ? t->to_thread->pid : 0,
-		   t->code, t->flags, t->priority, t->need_reply);
+		   t->code, t->flags, t->priority, t->need_reply,
+		   ktime_ms_delta(current_time, t->start_time));
 	spin_unlock(&t->lock);
 
 	if (proc != to_proc) {
diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h
index 28ef5b3704b1..92e64007f2b0 100644
--- a/drivers/android/binder_internal.h
+++ b/drivers/android/binder_internal.h
@@ -528,6 +528,7 @@ struct binder_transaction {
 	long    priority;
 	long    saved_priority;
 	kuid_t  sender_euid;
+	ktime_t start_time;
 	struct list_head fd_fixups;
 	binder_uintptr_t security_ctx;
 	/**
-- 
2.34.1


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

* [PATCH v2 2/2] Binder: Add async from to transaction record
  2023-04-24 11:05 [PATCH v2 0/2] Binder: Add timestamp and async from to transaction record Chuang Zhang
  2023-04-24 11:05 ` [PATCH v2 1/2] Binder: Add timestamp " Chuang Zhang
@ 2023-04-24 11:05 ` Chuang Zhang
  2023-04-25 18:59   ` Carlos Llamas
  1 sibling, 1 reply; 5+ messages in thread
From: Chuang Zhang @ 2023-04-24 11:05 UTC (permalink / raw)
  To: gregkh, cmllamas
  Cc: arve, tkjos, maco, joel, brauner, surenb, linux-kernel,
	Chuang Zhang

From: Chuang Zhang <zhangchuang3@xiaomi.com>

This commit adds support for getting the pid and tid information of
the sender for asynchronous transfers in binderfs transfer records.
In previous versions, it was not possible to obtain this information
from the transfer records. While this information may not be necessary
for all use cases, it can be useful in some scenarios.

Signed-off-by: Chuang Zhang <zhangchuang3@xiaomi.com>
---
 drivers/android/binder.c          | 6 ++++--
 drivers/android/binder_internal.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index b6413652906e..6674619845e0 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -3172,6 +3172,8 @@ static void binder_transaction(struct binder_proc *proc,
 		t->from = thread;
 	else
 		t->from = NULL;
+	t->from_pid = proc->pid;
+	t->from_tid = thread->pid;
 	t->sender_euid = task_euid(proc->tsk);
 	t->to_proc = target_proc;
 	t->to_thread = target_thread;
@@ -5940,8 +5942,8 @@ static void print_binder_transaction_ilocked(struct seq_file *m,
 	seq_printf(m,
 		   "%s %d: %pK from %d:%d to %d:%d code %x flags %x pri %ld r%d elapsed %lldms",
 		   prefix, t->debug_id, t,
-		   t->from ? t->from->proc->pid : 0,
-		   t->from ? t->from->pid : 0,
+		   t->from_pid,
+		   t->from_tid,
 		   to_proc ? to_proc->pid : 0,
 		   t->to_thread ? t->to_thread->pid : 0,
 		   t->code, t->flags, t->priority, t->need_reply,
diff --git a/drivers/android/binder_internal.h b/drivers/android/binder_internal.h
index 92e64007f2b0..7270d4d22207 100644
--- a/drivers/android/binder_internal.h
+++ b/drivers/android/binder_internal.h
@@ -515,6 +515,8 @@ struct binder_transaction {
 	int debug_id;
 	struct binder_work work;
 	struct binder_thread *from;
+	pid_t from_pid;
+	pid_t from_tid;
 	struct binder_transaction *from_parent;
 	struct binder_proc *to_proc;
 	struct binder_thread *to_thread;
-- 
2.34.1


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

* Re: [PATCH v2 1/2] Binder: Add timestamp to transaction record
  2023-04-24 11:05 ` [PATCH v2 1/2] Binder: Add timestamp " Chuang Zhang
@ 2023-04-25 18:59   ` Carlos Llamas
  0 siblings, 0 replies; 5+ messages in thread
From: Carlos Llamas @ 2023-04-25 18:59 UTC (permalink / raw)
  To: Chuang Zhang
  Cc: gregkh, arve, tkjos, maco, joel, brauner, surenb, linux-kernel,
	Chuang Zhang

On Mon, Apr 24, 2023 at 07:05:14PM +0800, Chuang Zhang wrote:
> From: Chuang Zhang <zhangchuang3@xiaomi.com>
> 
> This patch adds a timestamp field to the binder_transaction
> structure to track the time consumed during transmission
> when reading binder_transaction records.
> 
> Signed-off-by: Chuang Zhang <zhangchuang3@xiaomi.com>

Acked-by: Carlos Llamas <cmllamas@google.com>

Thanks

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

* Re: [PATCH v2 2/2] Binder: Add async from to transaction record
  2023-04-24 11:05 ` [PATCH v2 2/2] Binder: Add async from " Chuang Zhang
@ 2023-04-25 18:59   ` Carlos Llamas
  0 siblings, 0 replies; 5+ messages in thread
From: Carlos Llamas @ 2023-04-25 18:59 UTC (permalink / raw)
  To: Chuang Zhang
  Cc: gregkh, arve, tkjos, maco, joel, brauner, surenb, linux-kernel,
	Chuang Zhang

On Mon, Apr 24, 2023 at 07:05:15PM +0800, Chuang Zhang wrote:
> From: Chuang Zhang <zhangchuang3@xiaomi.com>
> 
> This commit adds support for getting the pid and tid information of
> the sender for asynchronous transfers in binderfs transfer records.
> In previous versions, it was not possible to obtain this information
> from the transfer records. While this information may not be necessary
> for all use cases, it can be useful in some scenarios.
> 
> Signed-off-by: Chuang Zhang <zhangchuang3@xiaomi.com>

Acked-by: Carlos Llamas <cmllamas@google.com>

Thanks

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

end of thread, other threads:[~2023-04-25 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-24 11:05 [PATCH v2 0/2] Binder: Add timestamp and async from to transaction record Chuang Zhang
2023-04-24 11:05 ` [PATCH v2 1/2] Binder: Add timestamp " Chuang Zhang
2023-04-25 18:59   ` Carlos Llamas
2023-04-24 11:05 ` [PATCH v2 2/2] Binder: Add async from " Chuang Zhang
2023-04-25 18:59   ` Carlos Llamas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox