Skip to contentSkip to conversation

kernel: trace: pass export pointer as argument to ->write()

PATCH Superseded Felipe Balbi 4 participants 9 messages May 17, 2017 – Dec 8, 2017 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel: trace: pass export pointer as argument to ->write()

That way, users don't need to keep a global static pointer and can rely on container_of() to fetch their own structure.

---

I'm working on exposing this data over a USB peripheral controller and I really can't have a global pointer there.

 drivers/hwtracing/stm/ftrace.c | 6 ++++--
 include/linux/trace.h          | 2 +-
 kernel/trace/trace.c           | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/stm/ftrace.c +4 -2
index bd126a7c6da2..371b8333d9ae 100644
@@ -42,9 +42,11 @@ static struct stm_ftrace {
  * @len:	length of the data packet
  */
 static void notrace
-stm_ftrace_write(const void *buf, unsigned int len)
+stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
 {
-	stm_source_write(&stm_ftrace.data, STM_FTRACE_CHAN, buf, len);
+	struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
+
+	stm_source_write(stm->data, STM_FTRACE_CHAN, buf, len);
 }
 
 static int stm_ftrace_link(struct stm_source_data *data)
include/linux/trace.h +1 -1
index 9330a58e2651..477aed6f0caa 100644
@@ -17,7 +17,7 @@
  */
 struct trace_export {
 	struct trace_export __rcu	*next;
-	void (*write)(const void *, unsigned int);
+	void (*write)(struct trace_export *, const void *, unsigned int);
 };
 
 int register_ftrace_export(struct trace_export *export);
kernel/trace/trace.c +1 -1
index c4536c449021..6a96652a3b0f 100644
@@ -2317,7 +2317,7 @@ trace_process_export(struct trace_export *export,
 
 	entry = ring_buffer_event_data(event);
 	size = ring_buffer_event_length(event);
-	export->write(entry, size);
+	export->write(export, entry, size);
 }
 
 static DEFINE_MUTEX(ftrace_export_lock);
Signature · 1 line
2.11.0.295.gd7dffce1ce
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Wed, 17 May 2017 11:05:54 +0300 Felipe Balbi <[email protected]>…

That way, users don't need to keep a global static pointer and can rely on container_of() to fetch their own structure.

-- Steve

Quoted 54 lines

---

I'm working on exposing this data over a USB peripheral controller and I really can't have a global pointer there.

 drivers/hwtracing/stm/ftrace.c | 6 ++++--
 include/linux/trace.h          | 2 +-
 kernel/trace/trace.c           | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/stm/ftrace.c +4 -2
index bd126a7c6da2..371b8333d9ae 100644
@@ -42,9 +42,11 @@ static struct stm_ftrace {
  * @len:	length of the data packet
  */
 static void notrace
-stm_ftrace_write(const void *buf, unsigned int len)
+stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
 {
-	stm_source_write(&stm_ftrace.data, STM_FTRACE_CHAN, buf, len);
+	struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
+
+	stm_source_write(stm->data, STM_FTRACE_CHAN, buf, len);
 }
 
 static int stm_ftrace_link(struct stm_source_data *data)
include/linux/trace.h +1 -1
index 9330a58e2651..477aed6f0caa 100644
@@ -17,7 +17,7 @@
  */
 struct trace_export {
 	struct trace_export __rcu	*next;
-	void (*write)(const void *, unsigned int);
+	void (*write)(struct trace_export *, const void *, unsigned int);
 };
 
 int register_ftrace_export(struct trace_export *export);
kernel/trace/trace.c +1 -1
index c4536c449021..6a96652a3b0f 100644
@@ -2317,7 +2317,7 @@ trace_process_export(struct trace_export *export,
 
 	entry = ring_buffer_event_data(event);
 	size = ring_buffer_event_length(event);
-	export->write(entry, size);
+	export->write(export, entry, size);
 }
 
 static DEFINE_MUTEX(ftrace_export_lock);
Reviewed-by on v1 1/1
#2 lore raw
In reply to Felipe Balbi
Quoted 4 lines · Felipe Balbi

That way, users don't need to keep a global static pointer and can rely on container_of() to fetch their own structure.

Thanks,
Chunyan

Quoted 57 lines

---

I'm working on exposing this data over a USB peripheral controller and I really can't have a global pointer there.

 drivers/hwtracing/stm/ftrace.c | 6 ++++--
 include/linux/trace.h          | 2 +-
 kernel/trace/trace.c           | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/stm/ftrace.c +4 -2
index bd126a7c6da2..371b8333d9ae 100644
@@ -42,9 +42,11 @@ static struct stm_ftrace {
  * @len:       length of the data packet
  */
 static void notrace
-stm_ftrace_write(const void *buf, unsigned int len)
+stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
 {
-       stm_source_write(&stm_ftrace.data, STM_FTRACE_CHAN, buf, len);
+       struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
+
+       stm_source_write(stm->data, STM_FTRACE_CHAN, buf, len);
 }
 
 static int stm_ftrace_link(struct stm_source_data *data)
include/linux/trace.h +1 -1
index 9330a58e2651..477aed6f0caa 100644
@@ -17,7 +17,7 @@
  */
 struct trace_export {
        struct trace_export __rcu       *next;
-       void (*write)(const void *, unsigned int);
+       void (*write)(struct trace_export *, const void *, unsigned int);
 };
 
 int register_ftrace_export(struct trace_export *export);
kernel/trace/trace.c +1 -2
index c4536c449021..6a96652a3b0f 100644
@@ -2317,7 +2317,7 @@ trace_process_export(struct trace_export *export,
 
        entry = ring_buffer_event_data(event);
        size = ring_buffer_event_length(event);
-       export->write(entry, size);
+       export->write(export, entry, size);
 }
 
 static DEFINE_MUTEX(ftrace_export_lock);
--

2.11.0.295.gd7dffce1ce

maintainer
#4 lore raw
Quoted 7 lines · On Wed, 17 May 2017 22:52:28 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines · On Thu, 18 May 2017 10:26:59 +0800 Chunyan Zhang <[email protected]>…
Quoted 3 lines · Felipe Balbi

That way, users don't need to keep a global static pointer and can rely on container_of() to fetch their own structure.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

If someone wants to pull this through their tree, feel free to do so. I've already acked it.

I guess nobody pulled this in. Does it still need to go? I'll add it to my tree and start testing it, but I'll drop it if it's not needed (or I don't get a response to this email).

-- Steve

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Hi,

Quoted 19 lines · Alexander Shishkin
Quoted 18 lines · Steven Rostedt
Quoted 14 lines · On Wed, 17 May 2017 22:52:28 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 7 lines · On Thu, 18 May 2017 10:26:59 +0800 Chunyan Zhang <[email protected]>…
Quoted 4 lines · Felipe Balbi

That way, users don't need to keep a global static pointer and can rely on container_of() to fetch their own structure.

If someone wants to pull this through their tree, feel free to do so. I've already acked it.

Quoted 6 lines
Quoted 3 lines

I guess nobody pulled this in. Does it still need to go? I'll add it to my tree and start testing it, but I'll drop it if it's not needed (or I don't get a response to this email).

Ouch, it somehow got lost in my inbox. I don't mind taking it through my tree if there are no objections.

let me know if you guys need a rebase.

Signature · 1 line
balbi
#7 lore raw
In reply to Felipe Balbi
url: https://github.com/0day-ci/linux/commits/Felipe-Balbi/kernel-trace-pass-export-pointer-as-argument-to-write/20170518-135452 config: i386-allmodconfig (attached as .config) compiler: gcc-6…

Hi Felipe,

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.12-rc1 next-20170518]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Felipe-Balbi/kernel-trace-pass-export-pointer-as-argument-to-write/20170518-135452
config: i386-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/hwtracing/stm/ftrace.c: In function 'stm_ftrace_write':

>> drivers/hwtracing/stm/ftrace.c:49:19: error: incompatible type for argument 1 of 'stm_source_write'
     stm_source_write(stm->data, STM_FTRACE_CHAN, buf, len);
                      ^~~

In file included from drivers/hwtracing/stm/ftrace.c:18:0:
include/linux/stm.h:136:13: note: expected 'struct stm_source_data *' but argument is of type 'struct stm_source_data'
int notrace stm_source_write(struct stm_source_data *data, unsigned int chan,
^~~~~~~~~~~~~~~~

vim +/stm_source_write +49 drivers/hwtracing/stm/ftrace.c

    43	 */
    44	static void notrace
    45	stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
    46	{
    47		struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
    48	
  > 49		stm_source_write(stm->data, STM_FTRACE_CHAN, buf, len);
    50	}
    51	
    52	static int stm_ftrace_link(struct stm_source_data *data)

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#8 lore raw

Hi,

Quoted 24 lines · kbuild test robot

Hi Felipe,

[auto build test ERROR on tip/perf/core]
[also build test ERROR on v4.12-rc1 next-20170518]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Felipe-Balbi/kernel-trace-pass-export-pointer-as-argument-to-write/20170518-135452
config: i386-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/hwtracing/stm/ftrace.c: In function 'stm_ftrace_write':

Quoted 1 line
Quoted 1 line

drivers/hwtracing/stm/ftrace.c:49:19: error: incompatible type for argument 1 of 'stm_source_write'

     stm_source_write(stm->data, STM_FTRACE_CHAN, buf, len);
                      ^~~

In file included from drivers/hwtracing/stm/ftrace.c:18:0:
include/linux/stm.h:136:13: note: expected 'struct stm_source_data *' but argument is of type 'struct stm_source_data'
int notrace stm_source_write(struct stm_source_data *data, unsigned int chan,
^~~~~~~~~~~~~~~~

Quoted 9 lines

vim +/stm_source_write +49 drivers/hwtracing/stm/ftrace.c

    43	 */
    44	static void notrace
    45	stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
    46	{
    47		struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
    48	
Quoted 1 line

49 stm_source_write(stm->data, STM_FTRACE_CHAN, buf, len);

sorry, just came back from vacations and noticed this. I'll send a v2 shortly.

Signature · 1 line
balbi
#9 lore raw

PATCH v2 1/1 kernel: trace: pass export pointer as argument to ->write()

In reply to kbuild test robot

That way, users don't need to keep a global static pointer and can rely on container_of() to fetch their own structure.

---

Changes since v1:
- add missing & operator

 drivers/hwtracing/stm/ftrace.c | 6 ++++--
 include/linux/trace.h          | 2 +-
 kernel/trace/trace.c           | 2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
drivers/hwtracing/stm/ftrace.c +4 -2
index bd126a7c6da2..7da75644c750 100644
@@ -42,9 +42,11 @@ static struct stm_ftrace {
  * @len:	length of the data packet
  */
 static void notrace
-stm_ftrace_write(const void *buf, unsigned int len)
+stm_ftrace_write(struct trace_export *export, const void *buf, unsigned int len)
 {
-	stm_source_write(&stm_ftrace.data, STM_FTRACE_CHAN, buf, len);
+	struct stm_ftrace *stm = container_of(export, struct stm_ftrace, ftrace);
+
+	stm_source_write(&stm->data, STM_FTRACE_CHAN, buf, len);
 }
 
 static int stm_ftrace_link(struct stm_source_data *data)
include/linux/trace.h +1 -1
index 9330a58e2651..477aed6f0caa 100644
@@ -17,7 +17,7 @@
  */
 struct trace_export {
 	struct trace_export __rcu	*next;
-	void (*write)(const void *, unsigned int);
+	void (*write)(struct trace_export *, const void *, unsigned int);
 };
 
 int register_ftrace_export(struct trace_export *export);
kernel/trace/trace.c +1 -1
index 1122f151466f..d0b5e8baa858 100644
@@ -2317,7 +2317,7 @@ trace_process_export(struct trace_export *export,
 
 	entry = ring_buffer_event_data(event);
 	size = ring_buffer_event_length(event);
-	export->write(entry, size);
+	export->write(export, entry, size);
 }
 
 static DEFINE_MUTEX(ftrace_export_lock);
Signature · 1 line
2.11.0.295.gd7dffce1ce