Skip to contentSkip to conversation

tracing: Fix document and blktrace

PATCH In review Masami Hiramatsu 3 participants 9 messages Aug 16, 2018 – Aug 31, 2018

Subsystems (4)
lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

cover tracing: Fix document and blktrace

Hi,

Here are 2 small fixes for ftrace, one is documentation fix to add stacktrace action and another is blktrace fix so that user can set the current enablement parameter without an error.

Thank you,

---

Masami Hiramatsu (2):
docs: tracing: Add stacktrace filter command tracing/blktrace: Fix to allow setting same value

 Documentation/trace/ftrace.rst |    3 +++
 kernel/trace/blktrace.c        |   11 +++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/2 docs: tracing: Add stacktrace filter command

Add a description of stacktrace filter command.

---
 Documentation/trace/ftrace.rst |    3 +++
 1 file changed, 3 insertions(+)
Documentation/trace/ftrace.rst +3 -0
index a20d34955333..81378a8b631e 100644
@@ -2987,6 +2987,9 @@ The following commands are supported:
   command, it only prints out the contents of the ring buffer for the
   CPU that executed the function that triggered the dump.
 
+- stacktrace:
+  When the function is hit, a stack trace is recorded.
+
 trace_pipe
 ----------
 
author maintainer
#4 lore raw

PATCH 2/2 tracing/blktrace: Fix to allow setting same value

In reply to Masami Hiramatsu

Current trace-enable attribute in sysfs returns an error if user writes the same setting value as current one, e.g.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  bash: echo: write error: Invalid argument
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  bash: echo: write error: Device or resource busy

But this is not a preferred behavior, it should ignore if new setting is same as current one. This fixes the problem as below.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
---
 kernel/trace/blktrace.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
kernel/trace/blktrace.c +7 -4
index 987d9a9ae283..e67db1e8a000 100644
@@ -1602,11 +1602,11 @@ static int blk_trace_remove_queue(struct request_queue *q)
 	struct blk_trace *bt;
 
 	bt = xchg(&q->blk_trace, NULL);
-	if (bt == NULL)
-		return -EINVAL;
+	if (bt != NULL) {
+		put_probe_ref();
+		blk_trace_free(bt);
+	}
 
-	put_probe_ref();
-	blk_trace_free(bt);
 	return 0;
 }
 
@@ -1619,6 +1619,9 @@ static int blk_trace_setup_queue(struct request_queue *q,
 	struct blk_trace *bt = NULL;
 	int ret = -ENOMEM;
 
+	if (q->blk_trace)
+		return 0;
+
 	bt = kzalloc(sizeof(*bt), GFP_KERNEL);
 	if (!bt)
 		return -ENOMEM;
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] docs: tracing: Add stacktrace filter command

In reply to Masami Hiramatsu
Quoted 5 lines · On Thu, 16 Aug 2018 18:50:47 +0900 Masami Hiramatsu <[email protected]> wrote:

Add a description of stacktrace filter command.

Jon, want to pull this patch into your tree?

-- Steve

Quoted 18 lines
---
 Documentation/trace/ftrace.rst |    3 +++
 1 file changed, 3 insertions(+)
Documentation/trace/ftrace.rst +3 -0
index a20d34955333..81378a8b631e 100644
@@ -2987,6 +2987,9 @@ The following commands are supported:
   command, it only prints out the contents of the ring buffer for the
   CPU that executed the function that triggered the dump.
 
+- stacktrace:
+  When the function is hit, a stack trace is recorded.
+
 trace_pipe
 ----------
 
maintainer
#5 lore raw

Re: [PATCH 2/2] tracing/blktrace: Fix to allow setting same value

In reply to Masami Hiramatsu
Quoted 50 lines · On Thu, 16 Aug 2018 18:51:15 +0900 Masami Hiramatsu <[email protected]> wrote:

Current trace-enable attribute in sysfs returns an error if user writes the same setting value as current one, e.g.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  bash: echo: write error: Invalid argument
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  bash: echo: write error: Device or resource busy

But this is not a preferred behavior, it should ignore if new setting is same as current one. This fixes the problem as below.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
---
 kernel/trace/blktrace.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
kernel/trace/blktrace.c +4 -4
index 987d9a9ae283..e67db1e8a000 100644
@@ -1602,11 +1602,11 @@ static int blk_trace_remove_queue(struct request_queue *q)
 	struct blk_trace *bt;
 
 	bt = xchg(&q->blk_trace, NULL);
-	if (bt == NULL)
-		return -EINVAL;
+	if (bt != NULL) {
+		put_probe_ref();
+		blk_trace_free(bt);
+	}
 
-	put_probe_ref();
-	blk_trace_free(bt);
 	return 0;
 }
 

kernel/trace/blktrace.c static int blk_trace_setup_queue(struct request_queue *q, · line 1627

Quoted 9 lines
kernel/trace/blktrace.c +3 -0
@@ -1619,6 +1619,9 @@ static int blk_trace_setup_queue(struct request_queue *q,
 	struct blk_trace *bt = NULL;
 	int ret = -ENOMEM;
 
+	if (q->blk_trace)
+		return 0;
+
 	bt = kzalloc(sizeof(*bt), GFP_KERNEL);
 	if (!bt)
 		return -ENOMEM;

Hmm, why not just do this? Does this fix it too?

kernel/trace/blktrace.c +2 -0
index 987d9a9ae283..10b2b9c5fd25 100644
@@ -1841,6 +1841,8 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
 	mutex_lock(&q->blk_trace_mutex);
 
 	if (attr == &dev_attr_enable) {
+		if (!!value == !!q->blk_trace)
+			goto out_unlock_bdev;
 		if (value)
 			ret = blk_trace_setup_queue(q, bdev);
 		else

-- Steve

author maintainer
#6 lore raw

Re: [PATCH 2/2] tracing/blktrace: Fix to allow setting same value

Quoted 56 lines · On Thu, 16 Aug 2018 10:38:02 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 53 lines · On Thu, 16 Aug 2018 18:51:15 +0900 Masami Hiramatsu <[email protected]> wrote:

Current trace-enable attribute in sysfs returns an error if user writes the same setting value as current one, e.g.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  bash: echo: write error: Invalid argument
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  bash: echo: write error: Device or resource busy

But this is not a preferred behavior, it should ignore if new setting is same as current one. This fixes the problem as below.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
---
 kernel/trace/blktrace.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
kernel/trace/blktrace.c +4 -4
index 987d9a9ae283..e67db1e8a000 100644
@@ -1602,11 +1602,11 @@ static int blk_trace_remove_queue(struct request_queue *q)
 	struct blk_trace *bt;
 
 	bt = xchg(&q->blk_trace, NULL);
-	if (bt == NULL)
-		return -EINVAL;
+	if (bt != NULL) {
+		put_probe_ref();
+		blk_trace_free(bt);
+	}
 
-	put_probe_ref();
-	blk_trace_free(bt);
 	return 0;
 }
 
@@ -1619,6 +1619,9 @@ static int blk_trace_setup_queue(struct request_queue *q,
 	struct blk_trace *bt = NULL;
 	int ret = -ENOMEM;
 
Quoted 8 lines

kernel/trace/blktrace.c static int blk_trace_setup_queue(struct request_queue *q, · line 1627

Quoted 6 lines
kernel/trace/blktrace.c +3 -0
+	if (q->blk_trace)
+		return 0;
+
 	bt = kzalloc(sizeof(*bt), GFP_KERNEL);
 	if (!bt)
 		return -ENOMEM;

Hmm, why not just do this? Does this fix it too?

Ah, yes, but we need to clear "ret" in that case.

Thanks!

Quoted 16 lines
kernel/trace/blktrace.c +2 -1
index 987d9a9ae283..10b2b9c5fd25 100644
@@ -1841,6 +1841,8 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
 	mutex_lock(&q->blk_trace_mutex);
 
 	if (attr == &dev_attr_enable) {
+		if (!!value == !!q->blk_trace)
+			goto out_unlock_bdev;
 		if (value)
 			ret = blk_trace_setup_queue(q, bdev);
 		else
 
-- Steve
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#7 lore raw

Re: [PATCH 2/2] tracing/blktrace: Fix to allow setting same value

Quoted 68 lines · On Fri, 17 Aug 2018 01:38:47 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 56 lines · On Thu, 16 Aug 2018 10:38:02 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 53 lines · On Thu, 16 Aug 2018 18:51:15 +0900 Masami Hiramatsu <[email protected]> wrote:

Current trace-enable attribute in sysfs returns an error if user writes the same setting value as current one, e.g.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  bash: echo: write error: Invalid argument
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  bash: echo: write error: Device or resource busy

But this is not a preferred behavior, it should ignore if new setting is same as current one. This fixes the problem as below.

  # cat /sys/block/sda/trace/enable
  0
  # echo 0 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
  # echo 1 > /sys/block/sda/trace/enable
---
 kernel/trace/blktrace.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
kernel/trace/blktrace.c +4 -4
index 987d9a9ae283..e67db1e8a000 100644
@@ -1602,11 +1602,11 @@ static int blk_trace_remove_queue(struct request_queue *q)
 	struct blk_trace *bt;
 
 	bt = xchg(&q->blk_trace, NULL);
-	if (bt == NULL)
-		return -EINVAL;
+	if (bt != NULL) {
+		put_probe_ref();
+		blk_trace_free(bt);
+	}
 
-	put_probe_ref();
-	blk_trace_free(bt);
 	return 0;
 }
 
@@ -1619,6 +1619,9 @@ static int blk_trace_setup_queue(struct request_queue *q,
 	struct blk_trace *bt = NULL;
 	int ret = -ENOMEM;
 
Quoted 8 lines

kernel/trace/blktrace.c static int blk_trace_setup_queue(struct request_queue *q, · line 1627

Quoted 6 lines
kernel/trace/blktrace.c +3 -0
+	if (q->blk_trace)
+		return 0;
+
 	bt = kzalloc(sizeof(*bt), GFP_KERNEL);
 	if (!bt)
 		return -ENOMEM;  

Hmm, why not just do this? Does this fix it too?

Quoted 1 line

Ah, yes, but we need to clear "ret" in that case.

Sure.

Quoted 12 lines

Thanks!

Quoted 8 lines
kernel/trace/blktrace.c +0 -0
index 987d9a9ae283..10b2b9c5fd25 100644
@@ -1841,6 +1841,8 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
 	mutex_lock(&q->blk_trace_mutex);
 
Quoted 2 lines

kernel/trace/blktrace.c static ssize_t sysfs_blk_trace_attr_store(struct device *dev, · line 1844

Quoted 2 lines
kernel/trace/blktrace.c +1 -0
 	if (attr == &dev_attr_enable) {
+		if (!!value == !!q->blk_trace) {

+ ret = 0;

Quoted 1 line

kernel/trace/blktrace.c static ssize_t sysfs_blk_trace_attr_store(struct device *dev, · line 1845

Quoted 1 line
kernel/trace/blktrace.c +1 -0
+			goto out_unlock_bdev;
    +		}

-- Steve

Quoted 7 lines
Quoted 5 lines
kernel/trace/blktrace.c +0 -1
 		if (value)
 			ret = blk_trace_setup_queue(q, bdev);
 		else
 
-- Steve  
author maintainer Tested-by
#8 lore raw

Re: [PATCH 2/2] tracing/blktrace: Fix to allow setting same value

Quoted 19 lines · On Thu, 16 Aug 2018 12:49:17 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines
Quoted 2 lines

Hmm, why not just do this? Does this fix it too?

Ah, yes, but we need to clear "ret" in that case.

Sure.

Quoted 11 lines

Thanks!

Quoted 8 lines
kernel/trace/blktrace.c +0 -0
index 987d9a9ae283..10b2b9c5fd25 100644
@@ -1841,6 +1841,8 @@ static ssize_t sysfs_blk_trace_attr_store(struct device *dev,
 	mutex_lock(&q->blk_trace_mutex);
 
Quoted 6 lines
Quoted 2 lines

kernel/trace/blktrace.c static ssize_t sysfs_blk_trace_attr_store(struct device *dev, · line 1844

Quoted 2 lines
kernel/trace/blktrace.c +1 -0
 	if (attr == &dev_attr_enable) {
+		if (!!value == !!q->blk_trace) {

+ ret = 0;

Quoted 1 line

kernel/trace/blktrace.c static ssize_t sysfs_blk_trace_attr_store(struct device *dev, · line 1845

Quoted 1 line
kernel/trace/blktrace.c +1 -0
+			goto out_unlock_bdev;
    +		}

OK, I tested and ensured that this works.

Thanks!

Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#3 lore raw

Re: [PATCH 1/2] docs: tracing: Add stacktrace filter command

In reply to Steven Rostedt
Quoted 5 lines · On Thu, 16 Aug 2018 08:50:31 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 2 lines · On Thu, 16 Aug 2018 18:50:47 +0900 Masami Hiramatsu <[email protected]> wrote:

Add a description of stacktrace filter command.

Quoted 7 lines
Quoted 3 lines

Jon, want to pull this patch into your tree?

Applied (finally), thanks.

jon