All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 05/39] blktrace: add trace note APIs
@ 2020-08-25 22:09 Chaitanya Kulkarni
  0 siblings, 0 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2020-08-25 22:09 UTC (permalink / raw)
  To: linux-btrace

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 kernel/trace/blktrace.c | 113 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 7857ac2b37c9..f739a1b73a47 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -114,6 +114,52 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
 	}
 }
 
+static void trace_note_ext(struct blk_trace_ext *bt, pid_t pid, u64 action,
+			   const void *data, size_t len, u64 cgid, u32 ioprio)
+{
+	struct blk_io_trace_ext *t;
+	struct ring_buffer_event *event = NULL;
+	struct trace_buffer *buffer = NULL;
+	int pc = 0;
+	int cpu = smp_processor_id();
+	bool blk_tracer = blk_tracer_enabled;
+	ssize_t cgid_len = cgid ? sizeof(cgid) : 0;
+
+	if (blk_tracer) {
+		buffer = blk_tr->array_buffer.buffer;
+		pc = preempt_count();
+		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
+						  sizeof(*t) + len + cgid_len,
+						  0, pc);
+		if (!event)
+			return;
+		t = ring_buffer_event_data(event);
+		goto record_it;
+	}
+
+	if (!bt->rchan)
+		return;
+
+	t = relay_reserve(bt->rchan, sizeof(*t) + len + cgid_len);
+	if (t) {
+		t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION_EXT;
+		t->time = ktime_to_ns(ktime_get());
+record_it:
+		t->device = bt->dev;
+		t->action = action | (cgid ? __BLK_TN_CGROUP : 0);
+		t->ioprio = ioprio;
+		t->pid = pid;
+		t->cpu = cpu;
+		t->pdu_len = len + cgid_len;
+		if (cgid_len)
+			memcpy((void *)t + sizeof(*t), &cgid, cgid_len);
+		memcpy((void *) t + sizeof(*t) + cgid_len, data, len);
+
+		if (blk_tracer)
+			trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
+	}
+}
+
 /*
  * Send out a notify for this process, if we haven't done so since a trace
  * started
@@ -132,6 +178,20 @@ static void trace_note_tsk(struct task_struct *tsk)
 	spin_unlock_irqrestore(&running_trace_lock, flags);
 }
 
+static void trace_note_tsk_ext(struct task_struct *tsk, u32 ioprio)
+{
+	unsigned long flags;
+	struct blk_trace_ext *bt;
+
+	tsk->btrace_seq = blktrace_seq;
+	spin_lock_irqsave(&running_trace_ext_lock, flags);
+	list_for_each_entry(bt, &running_trace_ext_list, running_ext_list) {
+		trace_note_ext(bt, tsk->pid, BLK_TN_PROCESS_EXT, tsk->comm,
+			   sizeof(tsk->comm), 0, ioprio);
+	}
+	spin_unlock_irqrestore(&running_trace_ext_lock, flags);
+}
+
 static void trace_note_time(struct blk_trace *bt)
 {
 	struct timespec64 now;
@@ -148,6 +208,22 @@ static void trace_note_time(struct blk_trace *bt)
 	local_irq_restore(flags);
 }
 
+static void trace_note_time_ext(struct blk_trace_ext *bt)
+{
+	struct timespec64 now;
+	unsigned long flags;
+	u32 words[2];
+
+	/* need to check user space to see if this breaks in y2038 or y2106 */
+	ktime_get_real_ts64(&now);
+	words[0] = (u32)now.tv_sec;
+	words[1] = now.tv_nsec;
+
+	local_irq_save(flags);
+	trace_note_ext(bt, 0, BLK_TN_TIMESTAMP, words, sizeof(words), 0, 0);
+	local_irq_restore(flags);
+}
+
 void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
 	const char *fmt, ...)
 {
@@ -185,6 +261,43 @@ void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
 }
 EXPORT_SYMBOL_GPL(__trace_note_message);
 
+void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
+	const char *fmt, ...)
+{
+	int n;
+	va_list args;
+	unsigned long flags;
+	char *buf;
+
+	if (unlikely(bt->trace_state != Blktrace_running &&
+		     !blk_tracer_enabled))
+		return;
+
+	/*
+	 * If the BLK_TC_NOTIFY action mask isn't set, don't send any note
+	 * message to the trace.
+	 */
+	if (!(bt->act_mask & BLK_TC_NOTIFY))
+		return;
+
+	local_irq_save(flags);
+	buf = this_cpu_ptr(bt->msg_data);
+	va_start(args, fmt);
+	n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
+	va_end(args);
+
+	if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
+		blkcg = NULL;
+#ifdef CONFIG_BLK_CGROUP
+	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n,
+		blkcg ? cgroup_id(blkcg->css.cgroup) : 1, 0);
+#else
+	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n, 0, 0);
+#endif
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL_GPL(__trace_note_message_ext);
+
 static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector,
 			 pid_t pid)
 {
-- 
2.22.1

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

* Re: [RFC PATCH 05/39] blktrace: add trace note APIs
  2021-02-25  7:01 ` [RFC PATCH 05/39] blktrace: add trace note APIs Chaitanya Kulkarni
  2021-02-25  9:07   ` kernel test robot
  2021-02-25 12:12   ` kernel test robot
@ 2021-02-26  4:39   ` Damien Le Moal
  2 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2021-02-26  4:39 UTC (permalink / raw)
  To: Chaitanya Kulkarni, axboe, viro, rostedt, mingo,
	Johannes Thumshirn, bvanassche, dongli.zhang, Aravind Ramesh,
	joshi.k, Niklas Cassel, hch, osandov, martin.petersen
  Cc: linux-block, linux-fsdevel

No commit message. Add one please.

On 2021/02/25 16:03, Chaitanya Kulkarni wrote:
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
>  kernel/trace/blktrace.c | 113 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 113 insertions(+)
> 
> diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
> index e45bbfcb5daf..4871934b9717 100644
> --- a/kernel/trace/blktrace.c
> +++ b/kernel/trace/blktrace.c
> @@ -114,6 +114,52 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
>  	}
>  }
>  
> +static void trace_note_ext(struct blk_trace_ext *bt, pid_t pid, u64 action,
> +			   const void *data, size_t len, u64 cgid, u32 ioprio)
> +{
> +	struct blk_io_trace_ext *t;
> +	struct ring_buffer_event *event = NULL;
> +	struct trace_buffer *buffer = NULL;
> +	int pc = 0;
> +	int cpu = smp_processor_id();
> +	bool blk_tracer = blk_tracer_enabled;
> +	ssize_t cgid_len = cgid ? sizeof(cgid) : 0;
> +
> +	if (blk_tracer) {
> +		buffer = blk_tr->array_buffer.buffer;
> +		pc = preempt_count();
> +		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
> +						  sizeof(*t) + len + cgid_len,
> +						  0, pc);
> +		if (!event)
> +			return;
> +		t = ring_buffer_event_data(event);
> +		goto record_it;
> +	}
> +
> +	if (!bt->rchan)
> +		return;
> +
> +	t = relay_reserve(bt->rchan, sizeof(*t) + len + cgid_len);
> +	if (t) {
> +		t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION_EXT;
> +		t->time = ktime_to_ns(ktime_get());
> +record_it:
> +		t->device = bt->dev;
> +		t->action = action | (cgid ? __BLK_TN_CGROUP : 0);
> +		t->ioprio = ioprio;
> +		t->pid = pid;
> +		t->cpu = cpu;
> +		t->pdu_len = len + cgid_len;
> +		if (cgid_len)
> +			memcpy((void *)t + sizeof(*t), &cgid, cgid_len);
> +		memcpy((void *) t + sizeof(*t) + cgid_len, data, len);
> +
> +		if (blk_tracer)
> +			trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
> +	}
> +}
> +
>  /*
>   * Send out a notify for this process, if we haven't done so since a trace
>   * started
> @@ -132,6 +178,20 @@ static void trace_note_tsk(struct task_struct *tsk)
>  	spin_unlock_irqrestore(&running_trace_lock, flags);
>  }
>  
> +static void trace_note_tsk_ext(struct task_struct *tsk, u32 ioprio)
> +{
> +	unsigned long flags;
> +	struct blk_trace_ext *bt;
> +
> +	tsk->btrace_seq = blktrace_seq;
> +	spin_lock_irqsave(&running_trace_ext_lock, flags);
> +	list_for_each_entry(bt, &running_trace_ext_list, running_ext_list) {
> +		trace_note_ext(bt, tsk->pid, BLK_TN_PROCESS_EXT, tsk->comm,
> +			   sizeof(tsk->comm), 0, ioprio);
> +	}
> +	spin_unlock_irqrestore(&running_trace_ext_lock, flags);
> +}
> +
>  static void trace_note_time(struct blk_trace *bt)
>  {
>  	struct timespec64 now;
> @@ -148,6 +208,22 @@ static void trace_note_time(struct blk_trace *bt)
>  	local_irq_restore(flags);
>  }
>  
> +static void trace_note_time_ext(struct blk_trace_ext *bt)
> +{
> +	struct timespec64 now;
> +	unsigned long flags;
> +	u32 words[2];
> +
> +	/* need to check user space to see if this breaks in y2038 or y2106 */
> +	ktime_get_real_ts64(&now);
> +	words[0] = (u32)now.tv_sec;
> +	words[1] = now.tv_nsec;
> +
> +	local_irq_save(flags);
> +	trace_note_ext(bt, 0, BLK_TN_TIMESTAMP, words, sizeof(words), 0, 0);
> +	local_irq_restore(flags);
> +}
> +
>  void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
>  	const char *fmt, ...)
>  {
> @@ -185,6 +261,43 @@ void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
>  }
>  EXPORT_SYMBOL_GPL(__trace_note_message);
>  
> +void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
> +	const char *fmt, ...)
> +{
> +	int n;
> +	va_list args;
> +	unsigned long flags;
> +	char *buf;
> +
> +	if (unlikely(bt->trace_state != Blktrace_running &&
> +		     !blk_tracer_enabled))
> +		return;
> +
> +	/*
> +	 * If the BLK_TC_NOTIFY action mask isn't set, don't send any note
> +	 * message to the trace.
> +	 */
> +	if (!(bt->act_mask & BLK_TC_NOTIFY))
> +		return;
> +
> +	local_irq_save(flags);
> +	buf = this_cpu_ptr(bt->msg_data);
> +	va_start(args, fmt);
> +	n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
> +	va_end(args);
> +
> +	if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
> +		blkcg = NULL;
> +#ifdef CONFIG_BLK_CGROUP
> +	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n,
> +		blkcg ? cgroup_id(blkcg->css.cgroup) : 1, 0);
> +#else
> +	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n, 0, 0);
> +#endif
> +	local_irq_restore(flags);
> +}
> +EXPORT_SYMBOL_GPL(__trace_note_message_ext);
> +
>  static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector,
>  			 pid_t pid)
>  {
> 

I fail to see why the xxx_ext functions need the different blk_trcae_ext
structure. It seems that everything should work with a modified blk_trace
structure. With such approach, a lot of the xxx_ext functions in here may not be
necessary at all. Simply change the interface of the existing note functions.
There are not that many call sites to change, right ?


-- 
Damien Le Moal
Western Digital Research

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

* Re: [RFC PATCH 05/39] blktrace: add trace note APIs
  2021-02-25  7:01 ` [RFC PATCH 05/39] blktrace: add trace note APIs Chaitanya Kulkarni
  2021-02-25  9:07   ` kernel test robot
@ 2021-02-25 12:12   ` kernel test robot
  2021-02-26  4:39   ` Damien Le Moal
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-02-25 12:12 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 3946 bytes --]

Hi Chaitanya,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on block/for-next]
[also build test WARNING on tip/perf/core linus/master v5.11 next-20210225]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Chaitanya-Kulkarni/blktrace-add-block-trace-extension-support/20210225-151637
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: x86_64-randconfig-a002-20210225 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project a921aaf789912d981cbb2036bdc91ad7289e1523)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/89334311842375e2921d0f281a39e5cc20a48a77
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Chaitanya-Kulkarni/blktrace-add-block-trace-extension-support/20210225-151637
        git checkout 89334311842375e2921d0f281a39e5cc20a48a77
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> kernel/trace/blktrace.c:264:6: warning: no previous prototype for function '__trace_note_message_ext' [-Wmissing-prototypes]
   void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
        ^
   kernel/trace/blktrace.c:264:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
   ^
   static 
   kernel/trace/blktrace.c:181:13: warning: unused function 'trace_note_tsk_ext' [-Wunused-function]
   static void trace_note_tsk_ext(struct task_struct *tsk, u32 ioprio)
               ^
   kernel/trace/blktrace.c:211:13: warning: unused function 'trace_note_time_ext' [-Wunused-function]
   static void trace_note_time_ext(struct blk_trace_ext *bt)
               ^
   3 warnings generated.


vim +/__trace_note_message_ext +264 kernel/trace/blktrace.c

   263	
 > 264	void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
   265		const char *fmt, ...)
   266	{
   267		int n;
   268		va_list args;
   269		unsigned long flags;
   270		char *buf;
   271	
   272		if (unlikely(bt->trace_state != Blktrace_running &&
   273			     !blk_tracer_enabled))
   274			return;
   275	
   276		/*
   277		 * If the BLK_TC_NOTIFY action mask isn't set, don't send any note
   278		 * message to the trace.
   279		 */
   280		if (!(bt->act_mask & BLK_TC_NOTIFY))
   281			return;
   282	
   283		local_irq_save(flags);
   284		buf = this_cpu_ptr(bt->msg_data);
   285		va_start(args, fmt);
   286		n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
   287		va_end(args);
   288	
   289		if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
   290			blkcg = NULL;
   291	#ifdef CONFIG_BLK_CGROUP
   292		trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n,
   293			blkcg ? cgroup_id(blkcg->css.cgroup) : 1, 0);
   294	#else
   295		trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n, 0, 0);
   296	#endif
   297		local_irq_restore(flags);
   298	}
   299	EXPORT_SYMBOL_GPL(__trace_note_message_ext);
   300	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 41963 bytes --]

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

* Re: [RFC PATCH 05/39] blktrace: add trace note APIs
  2021-02-25  7:01 ` [RFC PATCH 05/39] blktrace: add trace note APIs Chaitanya Kulkarni
@ 2021-02-25  9:07   ` kernel test robot
  2021-02-25 12:12   ` kernel test robot
  2021-02-26  4:39   ` Damien Le Moal
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2021-02-25  9:07 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6255 bytes --]

Hi Chaitanya,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on block/for-next]
[also build test WARNING on tip/perf/core linus/master hch-configfs/for-next v5.11 next-20210225]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Chaitanya-Kulkarni/blktrace-add-block-trace-extension-support/20210225-151637
base:   https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux-block.git for-next
config: sparc64-randconfig-s032-20210225 (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-229-g60c1f270-dirty
        # https://github.com/0day-ci/linux/commit/89334311842375e2921d0f281a39e5cc20a48a77
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Chaitanya-Kulkarni/blktrace-add-block-trace-extension-support/20210225-151637
        git checkout 89334311842375e2921d0f281a39e5cc20a48a77
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=sparc64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   kernel/trace/blktrace.c: In function '__trace_note_message':
   kernel/trace/blktrace.c:227:63: warning: parameter 'blkcg' set but not used [-Wunused-but-set-parameter]
     227 | void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
         |                                                 ~~~~~~~~~~~~~~^~~~~
   kernel/trace/blktrace.c: At top level:
>> kernel/trace/blktrace.c:264:6: warning: no previous prototype for '__trace_note_message_ext' [-Wmissing-prototypes]
     264 | void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
         |      ^~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/blktrace.c: In function '__trace_note_message_ext':
>> kernel/trace/blktrace.c:286:2: warning: function '__trace_note_message_ext' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
     286 |  n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
         |  ^
   kernel/trace/blktrace.c:264:71: warning: parameter 'blkcg' set but not used [-Wunused-but-set-parameter]
     264 | void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
         |                                                         ~~~~~~~~~~~~~~^~~~~
   At top level:
   kernel/trace/blktrace.c:211:13: warning: 'trace_note_time_ext' defined but not used [-Wunused-function]
     211 | static void trace_note_time_ext(struct blk_trace_ext *bt)
         |             ^~~~~~~~~~~~~~~~~~~
   kernel/trace/blktrace.c:181:13: warning: 'trace_note_tsk_ext' defined but not used [-Wunused-function]
     181 | static void trace_note_tsk_ext(struct task_struct *tsk, u32 ioprio)
         |             ^~~~~~~~~~~~~~~~~~

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for FRAME_POINTER
   Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS || MCOUNT
   Selected by
   - LOCKDEP && DEBUG_KERNEL && LOCK_DEBUGGING_SUPPORT && !MIPS && !PPC && !ARM && !S390 && !MICROBLAZE && !ARC && !X86


vim +/__trace_note_message_ext +264 kernel/trace/blktrace.c

   226	
 > 227	void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
   228		const char *fmt, ...)
   229	{
   230		int n;
   231		va_list args;
   232		unsigned long flags;
   233		char *buf;
   234	
   235		if (unlikely(bt->trace_state != Blktrace_running &&
   236			     !blk_tracer_enabled))
   237			return;
   238	
   239		/*
   240		 * If the BLK_TC_NOTIFY action mask isn't set, don't send any note
   241		 * message to the trace.
   242		 */
   243		if (!(bt->act_mask & BLK_TC_NOTIFY))
   244			return;
   245	
   246		local_irq_save(flags);
   247		buf = this_cpu_ptr(bt->msg_data);
   248		va_start(args, fmt);
   249		n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
   250		va_end(args);
   251	
   252		if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
   253			blkcg = NULL;
   254	#ifdef CONFIG_BLK_CGROUP
   255		trace_note(bt, current->pid, BLK_TN_MESSAGE, buf, n,
   256			   blkcg ? cgroup_id(blkcg->css.cgroup) : 1);
   257	#else
   258		trace_note(bt, current->pid, BLK_TN_MESSAGE, buf, n, 0);
   259	#endif
   260		local_irq_restore(flags);
   261	}
   262	EXPORT_SYMBOL_GPL(__trace_note_message);
   263	
 > 264	void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
   265		const char *fmt, ...)
   266	{
   267		int n;
   268		va_list args;
   269		unsigned long flags;
   270		char *buf;
   271	
   272		if (unlikely(bt->trace_state != Blktrace_running &&
   273			     !blk_tracer_enabled))
   274			return;
   275	
   276		/*
   277		 * If the BLK_TC_NOTIFY action mask isn't set, don't send any note
   278		 * message to the trace.
   279		 */
   280		if (!(bt->act_mask & BLK_TC_NOTIFY))
   281			return;
   282	
   283		local_irq_save(flags);
   284		buf = this_cpu_ptr(bt->msg_data);
   285		va_start(args, fmt);
 > 286		n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
   287		va_end(args);
   288	
   289		if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
   290			blkcg = NULL;
   291	#ifdef CONFIG_BLK_CGROUP
   292		trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n,
   293			blkcg ? cgroup_id(blkcg->css.cgroup) : 1, 0);
   294	#else
   295		trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n, 0, 0);
   296	#endif
   297		local_irq_restore(flags);
   298	}
   299	EXPORT_SYMBOL_GPL(__trace_note_message_ext);
   300	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 23719 bytes --]

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

* [RFC PATCH 05/39] blktrace: add trace note APIs
  2021-02-25  7:01 [RFC PATCH 00/39] blktrace: add block trace extension support Chaitanya Kulkarni
@ 2021-02-25  7:01 ` Chaitanya Kulkarni
  2021-02-25  9:07   ` kernel test robot
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2021-02-25  7:01 UTC (permalink / raw)
  To: axboe, viro, rostedt, mingo, chaitanya.kulkarni,
	johannes.thumshirn, damien.lemoal, bvanassche, dongli.zhang,
	aravind.ramesh, joshi.k, niklas.cassel, hch, osandov,
	martin.petersen
  Cc: linux-block, linux-fsdevel

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 kernel/trace/blktrace.c | 113 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index e45bbfcb5daf..4871934b9717 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -114,6 +114,52 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
 	}
 }
 
+static void trace_note_ext(struct blk_trace_ext *bt, pid_t pid, u64 action,
+			   const void *data, size_t len, u64 cgid, u32 ioprio)
+{
+	struct blk_io_trace_ext *t;
+	struct ring_buffer_event *event = NULL;
+	struct trace_buffer *buffer = NULL;
+	int pc = 0;
+	int cpu = smp_processor_id();
+	bool blk_tracer = blk_tracer_enabled;
+	ssize_t cgid_len = cgid ? sizeof(cgid) : 0;
+
+	if (blk_tracer) {
+		buffer = blk_tr->array_buffer.buffer;
+		pc = preempt_count();
+		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
+						  sizeof(*t) + len + cgid_len,
+						  0, pc);
+		if (!event)
+			return;
+		t = ring_buffer_event_data(event);
+		goto record_it;
+	}
+
+	if (!bt->rchan)
+		return;
+
+	t = relay_reserve(bt->rchan, sizeof(*t) + len + cgid_len);
+	if (t) {
+		t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION_EXT;
+		t->time = ktime_to_ns(ktime_get());
+record_it:
+		t->device = bt->dev;
+		t->action = action | (cgid ? __BLK_TN_CGROUP : 0);
+		t->ioprio = ioprio;
+		t->pid = pid;
+		t->cpu = cpu;
+		t->pdu_len = len + cgid_len;
+		if (cgid_len)
+			memcpy((void *)t + sizeof(*t), &cgid, cgid_len);
+		memcpy((void *) t + sizeof(*t) + cgid_len, data, len);
+
+		if (blk_tracer)
+			trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
+	}
+}
+
 /*
  * Send out a notify for this process, if we haven't done so since a trace
  * started
@@ -132,6 +178,20 @@ static void trace_note_tsk(struct task_struct *tsk)
 	spin_unlock_irqrestore(&running_trace_lock, flags);
 }
 
+static void trace_note_tsk_ext(struct task_struct *tsk, u32 ioprio)
+{
+	unsigned long flags;
+	struct blk_trace_ext *bt;
+
+	tsk->btrace_seq = blktrace_seq;
+	spin_lock_irqsave(&running_trace_ext_lock, flags);
+	list_for_each_entry(bt, &running_trace_ext_list, running_ext_list) {
+		trace_note_ext(bt, tsk->pid, BLK_TN_PROCESS_EXT, tsk->comm,
+			   sizeof(tsk->comm), 0, ioprio);
+	}
+	spin_unlock_irqrestore(&running_trace_ext_lock, flags);
+}
+
 static void trace_note_time(struct blk_trace *bt)
 {
 	struct timespec64 now;
@@ -148,6 +208,22 @@ static void trace_note_time(struct blk_trace *bt)
 	local_irq_restore(flags);
 }
 
+static void trace_note_time_ext(struct blk_trace_ext *bt)
+{
+	struct timespec64 now;
+	unsigned long flags;
+	u32 words[2];
+
+	/* need to check user space to see if this breaks in y2038 or y2106 */
+	ktime_get_real_ts64(&now);
+	words[0] = (u32)now.tv_sec;
+	words[1] = now.tv_nsec;
+
+	local_irq_save(flags);
+	trace_note_ext(bt, 0, BLK_TN_TIMESTAMP, words, sizeof(words), 0, 0);
+	local_irq_restore(flags);
+}
+
 void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
 	const char *fmt, ...)
 {
@@ -185,6 +261,43 @@ void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
 }
 EXPORT_SYMBOL_GPL(__trace_note_message);
 
+void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
+	const char *fmt, ...)
+{
+	int n;
+	va_list args;
+	unsigned long flags;
+	char *buf;
+
+	if (unlikely(bt->trace_state != Blktrace_running &&
+		     !blk_tracer_enabled))
+		return;
+
+	/*
+	 * If the BLK_TC_NOTIFY action mask isn't set, don't send any note
+	 * message to the trace.
+	 */
+	if (!(bt->act_mask & BLK_TC_NOTIFY))
+		return;
+
+	local_irq_save(flags);
+	buf = this_cpu_ptr(bt->msg_data);
+	va_start(args, fmt);
+	n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
+	va_end(args);
+
+	if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
+		blkcg = NULL;
+#ifdef CONFIG_BLK_CGROUP
+	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n,
+		blkcg ? cgroup_id(blkcg->css.cgroup) : 1, 0);
+#else
+	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n, 0, 0);
+#endif
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL_GPL(__trace_note_message_ext);
+
 static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector,
 			 pid_t pid)
 {
-- 
2.22.1


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

* [RFC PATCH 05/39] blktrace: add trace note APIs
@ 2020-11-05  2:40 Chaitanya Kulkarni
  0 siblings, 0 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2020-11-05  2:40 UTC (permalink / raw)
  To: linux-btrace

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 kernel/trace/blktrace.c | 113 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index e7fc8330b7bb..96c11bda8eef 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -114,6 +114,52 @@ static void trace_note(struct blk_trace *bt, pid_t pid, int action,
 	}
 }
 
+static void trace_note_ext(struct blk_trace_ext *bt, pid_t pid, u64 action,
+			   const void *data, size_t len, u64 cgid, u32 ioprio)
+{
+	struct blk_io_trace_ext *t;
+	struct ring_buffer_event *event = NULL;
+	struct trace_buffer *buffer = NULL;
+	int pc = 0;
+	int cpu = smp_processor_id();
+	bool blk_tracer = blk_tracer_enabled;
+	ssize_t cgid_len = cgid ? sizeof(cgid) : 0;
+
+	if (blk_tracer) {
+		buffer = blk_tr->array_buffer.buffer;
+		pc = preempt_count();
+		event = trace_buffer_lock_reserve(buffer, TRACE_BLK,
+						  sizeof(*t) + len + cgid_len,
+						  0, pc);
+		if (!event)
+			return;
+		t = ring_buffer_event_data(event);
+		goto record_it;
+	}
+
+	if (!bt->rchan)
+		return;
+
+	t = relay_reserve(bt->rchan, sizeof(*t) + len + cgid_len);
+	if (t) {
+		t->magic = BLK_IO_TRACE_MAGIC | BLK_IO_TRACE_VERSION_EXT;
+		t->time = ktime_to_ns(ktime_get());
+record_it:
+		t->device = bt->dev;
+		t->action = action | (cgid ? __BLK_TN_CGROUP : 0);
+		t->ioprio = ioprio;
+		t->pid = pid;
+		t->cpu = cpu;
+		t->pdu_len = len + cgid_len;
+		if (cgid_len)
+			memcpy((void *)t + sizeof(*t), &cgid, cgid_len);
+		memcpy((void *) t + sizeof(*t) + cgid_len, data, len);
+
+		if (blk_tracer)
+			trace_buffer_unlock_commit(blk_tr, buffer, event, 0, pc);
+	}
+}
+
 /*
  * Send out a notify for this process, if we haven't done so since a trace
  * started
@@ -132,6 +178,20 @@ static void trace_note_tsk(struct task_struct *tsk)
 	spin_unlock_irqrestore(&running_trace_lock, flags);
 }
 
+static void trace_note_tsk_ext(struct task_struct *tsk, u32 ioprio)
+{
+	unsigned long flags;
+	struct blk_trace_ext *bt;
+
+	tsk->btrace_seq = blktrace_seq;
+	spin_lock_irqsave(&running_trace_ext_lock, flags);
+	list_for_each_entry(bt, &running_trace_ext_list, running_ext_list) {
+		trace_note_ext(bt, tsk->pid, BLK_TN_PROCESS_EXT, tsk->comm,
+			   sizeof(tsk->comm), 0, ioprio);
+	}
+	spin_unlock_irqrestore(&running_trace_ext_lock, flags);
+}
+
 static void trace_note_time(struct blk_trace *bt)
 {
 	struct timespec64 now;
@@ -148,6 +208,22 @@ static void trace_note_time(struct blk_trace *bt)
 	local_irq_restore(flags);
 }
 
+static void trace_note_time_ext(struct blk_trace_ext *bt)
+{
+	struct timespec64 now;
+	unsigned long flags;
+	u32 words[2];
+
+	/* need to check user space to see if this breaks in y2038 or y2106 */
+	ktime_get_real_ts64(&now);
+	words[0] = (u32)now.tv_sec;
+	words[1] = now.tv_nsec;
+
+	local_irq_save(flags);
+	trace_note_ext(bt, 0, BLK_TN_TIMESTAMP, words, sizeof(words), 0, 0);
+	local_irq_restore(flags);
+}
+
 void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
 	const char *fmt, ...)
 {
@@ -185,6 +261,43 @@ void __trace_note_message(struct blk_trace *bt, struct blkcg *blkcg,
 }
 EXPORT_SYMBOL_GPL(__trace_note_message);
 
+void __trace_note_message_ext(struct blk_trace_ext *bt, struct blkcg *blkcg,
+	const char *fmt, ...)
+{
+	int n;
+	va_list args;
+	unsigned long flags;
+	char *buf;
+
+	if (unlikely(bt->trace_state != Blktrace_running &&
+		     !blk_tracer_enabled))
+		return;
+
+	/*
+	 * If the BLK_TC_NOTIFY action mask isn't set, don't send any note
+	 * message to the trace.
+	 */
+	if (!(bt->act_mask & BLK_TC_NOTIFY))
+		return;
+
+	local_irq_save(flags);
+	buf = this_cpu_ptr(bt->msg_data);
+	va_start(args, fmt);
+	n = vscnprintf(buf, BLK_TN_MAX_MSG, fmt, args);
+	va_end(args);
+
+	if (!(blk_tracer_flags.val & TRACE_BLK_OPT_CGROUP))
+		blkcg = NULL;
+#ifdef CONFIG_BLK_CGROUP
+	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n,
+		blkcg ? cgroup_id(blkcg->css.cgroup) : 1, 0);
+#else
+	trace_note_ext(bt, 0, BLK_TN_MESSAGE_EXT, buf, n, 0, 0);
+#endif
+	local_irq_restore(flags);
+}
+EXPORT_SYMBOL_GPL(__trace_note_message_ext);
+
 static int act_log_check(struct blk_trace *bt, u32 what, sector_t sector,
 			 pid_t pid)
 {
-- 
2.22.1

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

end of thread, other threads:[~2021-02-26  4:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 22:09 [RFC PATCH 05/39] blktrace: add trace note APIs Chaitanya Kulkarni
2020-11-05  2:40 Chaitanya Kulkarni
2021-02-25  7:01 [RFC PATCH 00/39] blktrace: add block trace extension support Chaitanya Kulkarni
2021-02-25  7:01 ` [RFC PATCH 05/39] blktrace: add trace note APIs Chaitanya Kulkarni
2021-02-25  9:07   ` kernel test robot
2021-02-25 12:12   ` kernel test robot
2021-02-26  4:39   ` Damien Le Moal

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.