Re: [PATCH RT 0/1] Linux v4.19.312-rt134-rc3

2024-05-13 Thread Daniel Wagner
On Mon, May 13, 2024 at 08:59:35AM GMT, Sebastian Andrzej Siewior wrote:
> On 2024-05-07 17:16:47 [+0200], Daniel Wagner wrote:
> > Dear RT Folks,
> > 
> > This is the RT stable review cycle of patch 4.19.312-rt134-rc3.
> > 
> > Please scream at me if I messed something up. Please test the patches
> > too.
> >
> > The -rc release is also available on kernel.org
> 
> I do have to complain a bit. The whole diff contains only a diff against
> localversion while the content of interest not here. But but I guess it
> is what we talked about so... but for everyone else it looks like
> version increment.

Sure, the merge diff should also be included. This feature missing in
the tooling. I'll add it, so next time it should also contain also the
merge diff.



[PATCH RT 0/1] Linux v4.19.312-rt134-rc3

2024-05-07 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.312-rt134-rc3.

Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2024-05-14.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.307-rt133:


Daniel Wagner (1):
  Linux 4.19.312-rt134

 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.44.0




[PATCH RT 1/1] Linux 4.19.312-rt134

2024-05-07 Thread Daniel Wagner
v4.19.312-rt134-rc3 stable review patch.
If anyone has any objections, please let me know.

---


Signed-off-by: Daniel Wagner 
---
 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localversion-rt b/localversion-rt
index c2c7e0fb6685..6067da4c8c99 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt133
+-rt134
-- 
2.44.0




Re: [PATCH RT 0/1] Linux v4.19.312-rt134-rc2

2024-05-07 Thread Daniel Wagner
Hi Sebastian,

On Tue, May 07, 2024 at 11:54:07AM GMT, Sebastian Andrzej Siewior wrote:
> I compared mine outcome vs v4.19-rt-next and the diff at the bottom came
> out:
> 
> - timer_delete_sync() used to have "#if 0" block around
>   lockdep_assert_preemption_enabled() because the function is not part
>   of v4.19. You ended up with might_sleep() which is a minor change.
>   Your queue as of a previous release had the if0 block (in
>   __del_timer_sync()).
>   I would say this is minor but looks like a miss-merge. Therefore I
>   would say it should go back for consistency vs previous release and
>   not change it due to conflicts.

Makes sense.

> - The timer_delete_sync() is structured differently with
>   __del_timer_sync(). That function invokes timer_sync_wait_running()
>   which drops two locks which are not acquired. That is wrong. It should
>   have been del_timer_wait_running().

Understood. I was a bit strungling here. Glad you caught this error.

> I suggest you apply the diff below to align it with later versions. It
> also gets rid of the basep argument in __try_to_del_timer_sync() which
> is not really used.

Will do.

> As an alternative I can send you my rebased queue if this makes it
> easier for you.

Yes please, this makes it easy to sync the rebase branch.

Thanks a lot!

Cheers,
Daniel



Re: [PATCH RT 0/1] Linux v4.19.312-rt134-rc2

2024-05-06 Thread Daniel Wagner

Hi Sebastian,

On 06.05.24 12:46, Daniel Wagner wrote:

Dear RT Folks,

This is the RT stable review cycle of patch 4.19.312-rt134-rc2.

Please scream at me if I messed something up. Please test the patches
too.


My announce script is not attaching any conflict resolve diffs
(eventually, I'll fix this). Could have a look if I got the
kernel/time/timer.c upddate right? This was caused by stable
including the 030dcdd197d7 ("timers: Prepare support for
PREEMPT_RT") patch.

commit 2c1a32c5e05fd75885186793bc0d26e0a65b473d
Merge: 4790d0210f19 3d86e7f5bdf3
Author: Daniel Wagner 
Date:   Wed Apr 17 16:31:21 2024 +0200

Merge tag 'v4.19.312' into v4.19-rt-next

This is the 4.19.312 stable release

Conflicts:
include/linux/timer.h
kernel/time/timer.c

diff --git a/include/linux/timer.h b/include/linux/timer.h
remerge CONFLICT (content): Merge conflict in include/linux/timer.h
index b70c5168a346..aef40cac2add 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -173,13 +173,6 @@ extern void add_timer(struct timer_list *timer);
 extern int try_to_del_timer_sync(struct timer_list *timer);
 extern int timer_delete_sync(struct timer_list *timer);

-<<<<<<< 4790d0210f19 (Linux 4.19.307-rt133)
-#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
-  extern int del_timer_sync(struct timer_list *timer);
-#else
-# define del_timer_sync(t) del_timer(t)
-#endif
-===
 /**
  * del_timer_sync - Delete a pending timer and wait for a running callback
  * @timer: The timer to be deleted
@@ -192,7 +185,6 @@ static inline int del_timer_sync(struct timer_list 
*timer)

 {
return timer_delete_sync(timer);
 }
->>>>>>> 3d86e7f5bdf3 (Linux 4.19.312)

 #define del_singleshot_timer_sync(t) del_timer_sync(t)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
remerge CONFLICT (content): Merge conflict in kernel/time/timer.c
index 911191916df1..bc5ce0cf9488 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1250,6 +1250,25 @@ int del_timer(struct timer_list *timer)
 }
 EXPORT_SYMBOL(del_timer);

+static int __try_to_del_timer_sync(struct timer_list *timer,
+  struct timer_base **basep)
+{
+   struct timer_base *base;
+   unsigned long flags;
+   int ret = -1;
+
+   debug_assert_init(timer);
+
+   *basep = base = lock_timer_base(timer, );
+
+   if (base->running_timer != timer)
+   ret = detach_if_pending(timer, base, true);
+
+   raw_spin_unlock_irqrestore(>lock, flags);
+
+   return ret;
+}
+
 /**
  * try_to_del_timer_sync - Try to deactivate a timer
  * @timer: Timer to deactivate
@@ -1269,19 +1288,8 @@ EXPORT_SYMBOL(del_timer);
 int try_to_del_timer_sync(struct timer_list *timer)
 {
struct timer_base *base;
-   unsigned long flags;
-   int ret = -1;
-
-   debug_assert_init(timer);
-
-   base = lock_timer_base(timer, );
-
-   if (base->running_timer != timer)
-   ret = detach_if_pending(timer, base, true);
-
-   raw_spin_unlock_irqrestore(>lock, flags);

-   return ret;
+   return __try_to_del_timer_sync(timer, );
 }
 EXPORT_SYMBOL(try_to_del_timer_sync);

@@ -1303,7 +1311,6 @@ static inline void timer_base_unlock_expiry(struct 
timer_base *base)


 /*
  * The counterpart to del_timer_wait_running().
-<<<<<<< 4790d0210f19 (Linux 4.19.307-rt133)
  *
  * If there is a waiter for base->expiry_lock, then it was waiting for the
  * timer callback to finish. Drop expiry_lock and reaquire it. That allows
@@ -1359,64 +1366,35 @@ static inline void 
timer_sync_wait_running(struct timer_base *base) { }

 static inline void del_timer_wait_running(struct timer_list *timer) { }
 #endif

-#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
-/**
- * del_timer_sync - deactivate a timer and wait for the handler to finish.
- * @timer: the timer to be deactivated
-===
->>>>>>> 3d86e7f5bdf3 (Linux 4.19.312)
- *
- * If there is a waiter for base->expiry_lock, then it was waiting for the
- * timer callback to finish. Drop expiry_lock and reaquire it. That allows
- * the waiter to acquire the lock and make progress.
- */
-static void timer_sync_wait_running(struct timer_base *base)
+static int __del_timer_sync(struct timer_list *timer)
 {
-   if (atomic_read(>timer_waiters)) {
-   spin_unlock(>expiry_lock);
-   spin_lock(>expiry_lock);
-   }
-}
+   struct timer_base *base;
+   int ret;

-/*
- * This function is called on PREEMPT_RT kernels when the fast path
- * deletion of a timer failed because the timer callback function was
- * running.
- *
- * This prevents priority inversion, if the softirq thread on a remote CPU
- * got preempted, and it prevents a life lock when the task which tries to
- * delete a timer preempted the softirq thread runn

[PATCH RT 1/1] Linux 4.19.312-rt134

2024-05-06 Thread Daniel Wagner
v4.19.312-rt134-rc2 stable review patch.
If anyone has any objections, please let me know.

---


Signed-off-by: Daniel Wagner 
---
 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localversion-rt b/localversion-rt
index c2c7e0fb6685..6067da4c8c99 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt133
+-rt134
-- 
2.44.0




[PATCH RT 0/1] Linux v4.19.312-rt134-rc2

2024-05-06 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.312-rt134-rc2.

Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2024-05-13.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.307-rt133:


Daniel Wagner (1):
  Linux 4.19.312-rt134

 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.44.0




[PATCH RT 0/1] Linux v4.19.312-rt134-rc1

2024-04-17 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.312-rt134-rc1.

Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2024-04-24.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.307-rt133:


Daniel Wagner (1):
  Linux 4.19.312-rt134

 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.44.0




[PATCH RT 1/1] Linux 4.19.312-rt134

2024-04-17 Thread Daniel Wagner
v4.19.312-rt134-rc1 stable review patch.
If anyone has any objections, please let me know.

---


Signed-off-by: Daniel Wagner 
---
 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localversion-rt b/localversion-rt
index c2c7e0fb6685..6067da4c8c99 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt133
+-rt134
-- 
2.44.0




Re: [PATCH bpf-next] rethook: Remove warning messages printed for finding return address of a frame.

2024-04-03 Thread Daniel Borkmann

On 4/2/24 6:58 PM, Andrii Nakryiko wrote:

On Mon, Apr 1, 2024 at 12:16 PM Kui-Feng Lee  wrote:


rethook_find_ret_addr() prints a warning message and returns 0 when the
target task is running and not the "current" task to prevent returning an
incorrect return address. However, this check is incomplete as the target
task can still transition to the running state when finding the return
address, although it is safe with RCU.

The issue we encounter is that the kernel frequently prints warning
messages when BPF profiling programs call to bpf_get_task_stack() on
running tasks.

The callers should be aware and willing to take the risk of receiving an
incorrect return address from a task that is currently running other than
the "current" one. A warning is not needed here as the callers are intent
on it.

Signed-off-by: Kui-Feng Lee 
---
  kernel/trace/rethook.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c
index fa03094e9e69..4297a132a7ae 100644
--- a/kernel/trace/rethook.c
+++ b/kernel/trace/rethook.c
@@ -248,7 +248,7 @@ unsigned long rethook_find_ret_addr(struct task_struct 
*tsk, unsigned long frame
 if (WARN_ON_ONCE(!cur))
 return 0;

-   if (WARN_ON_ONCE(tsk != current && task_is_running(tsk)))
+   if (tsk != current && task_is_running(tsk))
 return 0;



This should probably go through Masami's tree, but the change makes
sense to me, given this is an expected condition.

Acked-by: Andrii Nakryiko 


Masami, I assume you'll pick this up?

Thanks,
Daniel



[GIT PULL V2] tracing/tools: Updates for 6.9

2024-03-20 Thread Daniel Bristot de Oliveira
Steven,

[
   I rebased my queue on top of the v6.8 tag.
]

Tracing:
- Update makefiles for latency-collector and RTLA,
  using tools/build/ makefiles like perf does, inheriting
  its benefits. For example, having a proper way to
  handle dependencies.

- The timerlat tracer has an interface for any tool to use.
  rtla timerlat tool uses this interface dispatching its
  own threads as workload. But, rtla timerlat could also be
  used for any other process. So, add 'rtla timerlat -U'
  option, allowing the timerlat tool to measure the latency of
  any task using the timerlat tracer interface.

Verification:
- Update makefiles for verification/rv, using tools/build/
  makefiles like perf does, inheriting its benefits.
  For example, having a proper way to handle dependencies.


Please pull the latest trace-tools-v6.9-2 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/bristot/linux.git
trace-tools-v6.9-2

Tag SHA1: e8d5e0f38601c3718874d95db2a0020ab1c454df
Head SHA1: a23c05fd76cf4ad27e0c74f7a93e7b089e94a55c


Daniel Bristot de Oliveira (4):
  tools/tracing: Use tools/build makefiles on latency-collector
  tools/rtla: Use tools/build makefiles to build rtla
  tools/verification: Use tools/build makefiles on rv
  tools/rtla: Add -U/--user-load option to timerlat


 .../tools/rtla/common_timerlat_options.rst |   6 +
 tools/tracing/latency/.gitignore   |   5 +-
 tools/tracing/latency/Build|   1 +
 tools/tracing/latency/Makefile | 105 --
 tools/tracing/latency/Makefile.config  |  30 +++
 tools/tracing/rtla/.gitignore  |   7 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 217 +++--
 tools/tracing/rtla/Makefile.config |  47 +
 tools/tracing/rtla/Makefile.rtla   |  80 
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/sample/timerlat_load.py |  74 +++
 tools/tracing/rtla/src/Build   |  11 ++
 tools/tracing/rtla/src/timerlat_hist.c |  16 +-
 tools/tracing/rtla/src/timerlat_top.c  |  14 +-
 tools/verification/rv/.gitignore   |   6 +
 tools/verification/rv/Build|   1 +
 tools/verification/rv/Makefile | 207 +++-
 tools/verification/rv/Makefile.config  |  47 +
 tools/verification/rv/Makefile.rv  |  51 +
 tools/verification/rv/src/Build|   4 +
 21 files changed, 650 insertions(+), 306 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/sample/timerlat_load.py
 create mode 100644 tools/tracing/rtla/src/Build
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build
---



Re: [GIT PULL] tracing/tools: Updates for 6.9

2024-03-20 Thread Daniel Bristot de Oliveira
On 3/20/24 00:02, Steven Rostedt wrote:
> On Mon, 18 Mar 2024 18:41:13 +0100
> Daniel Bristot de Oliveira  wrote:
> 
>> Steven,
>>
>> Tracing tooling updates for 6.9
>>
>> Tracing:
>> - Update makefiles for latency-collector and RTLA,
>>   using tools/build/ makefiles like perf does, inheriting
>>   its benefits. For example, having a proper way to
>>   handle dependencies.
>>
>> - The timerlat tracer has an interface for any tool to use.
>>   rtla timerlat tool uses this interface dispatching its
>>   own threads as workload. But, rtla timerlat could also be
>>   used for any other process. So, add 'rtla timerlat -U'
>>   option, allowing the timerlat tool to measure the latency of
>>   any task using the timerlat tracer interface.
>>
>> Verification:
>> - Update makefiles for verification/rv, using tools/build/
>>   makefiles like perf does, inheriting its benefits.
>>   For example, having a proper way to handle dependencies.
>>
>>
>> Please pull the latest trace-tools-v6.9 tree, which can be found at:
>>
>>
>>   git://git.kernel.org/pub/scm/linux/kernel/git/bristot/linux.git
>> trace-tools-v6.9
> 
> Looks like you just built on top of a random commit from Linus's tree:

yeah :-/

> commit f6cef5f8c37f58a3bc95b3754c3ae98e086631ca
> Merge: 906a93befec8 8f06fb458539
> Author: Linus Torvalds 
> Date:   Sun Mar 17 16:59:33 2024 -0700
> 
> Merge tag 'i3c/for-6.9' of 
> git://git.kernel.org/pub/scm/linux/kernel/git/i3c/linux
> 
> Linus prefers basing off of real tags or previous pulls from us.

Ack, took note. I will do on top v6.8 tag.

> Can you rebase your changes on v6.8 and resend?
> 
>   $ git checkout v6.8
>   $ git cherry-pick f6cef5f8c37f58a3bc95b3754c3ae98e086631ca..trace-tools-v6.9
> 
> Appears to work fine.

questions: when something go wrong in a pull request

- Should I keep the old tag, and then do another one with -2
  (it seems you do like this), or delete the old tag and send it again
  with the same name?

- Should I resend the PULL request with something in the log or
  at the Subject saying it is a v2 of the pull request?

I could ask via chat, but I think it is good for the community to
have access to these info.

Thanks!
-- Daniel

> Thanks!
> 
> -- Steve



[GIT PULL] tracing/tools: Updates for 6.9

2024-03-18 Thread Daniel Bristot de Oliveira
Steven,

Tracing tooling updates for 6.9

Tracing:
- Update makefiles for latency-collector and RTLA,
  using tools/build/ makefiles like perf does, inheriting
  its benefits. For example, having a proper way to
  handle dependencies.

- The timerlat tracer has an interface for any tool to use.
  rtla timerlat tool uses this interface dispatching its
  own threads as workload. But, rtla timerlat could also be
  used for any other process. So, add 'rtla timerlat -U'
  option, allowing the timerlat tool to measure the latency of
  any task using the timerlat tracer interface.

Verification:
- Update makefiles for verification/rv, using tools/build/
  makefiles like perf does, inheriting its benefits.
  For example, having a proper way to handle dependencies.


Please pull the latest trace-tools-v6.9 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/bristot/linux.git
trace-tools-v6.9

Tag SHA1: 2eb09a97c56af3c27bd9dcebccb495f70d56d5c0
Head SHA1: 9c63d9f58a42b979a42bcaed534d9246996ac0d9


Daniel Bristot de Oliveira (4):
  tools/tracing: Use tools/build makefiles on latency-collector
  tools/rtla: Use tools/build makefiles to build rtla
  tools/verification: Use tools/build makefiles on rv
  tools/rtla: Add -U/--user-load option to timerlat


 .../tools/rtla/common_timerlat_options.rst |   6 +
 tools/tracing/latency/.gitignore   |   5 +-
 tools/tracing/latency/Build|   1 +
 tools/tracing/latency/Makefile | 105 --
 tools/tracing/latency/Makefile.config  |  30 +++
 tools/tracing/rtla/.gitignore  |   7 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 217 +++--
 tools/tracing/rtla/Makefile.config |  47 +
 tools/tracing/rtla/Makefile.rtla   |  80 
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/sample/timerlat_load.py |  74 +++
 tools/tracing/rtla/src/Build   |  11 ++
 tools/tracing/rtla/src/timerlat_hist.c |  16 +-
 tools/tracing/rtla/src/timerlat_top.c  |  14 +-
 tools/verification/rv/.gitignore   |   6 +
 tools/verification/rv/Build|   1 +
 tools/verification/rv/Makefile | 207 +++-
 tools/verification/rv/Makefile.config  |  47 +
 tools/verification/rv/Makefile.rv  |  51 +
 tools/verification/rv/src/Build|   4 +
 21 files changed, 650 insertions(+), 306 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/sample/timerlat_load.py
 create mode 100644 tools/tracing/rtla/src/Build
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build
---



[PATCH V3 3/3] tools/verification: Use tools/build makefiles on rv

2024-03-15 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build rv, inheriting the benefits of
it. For example, having a proper way to handle dependencies.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/verification/rv/.gitignore  |   6 +
 tools/verification/rv/Build   |   1 +
 tools/verification/rv/Makefile| 207 +-
 tools/verification/rv/Makefile.config |  47 ++
 tools/verification/rv/Makefile.rv |  51 +++
 tools/verification/rv/src/Build   |   4 +
 6 files changed, 183 insertions(+), 133 deletions(-)
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build

diff --git a/tools/verification/rv/.gitignore b/tools/verification/rv/.gitignore
new file mode 100644
index ..34a486585a34
--- /dev/null
+++ b/tools/verification/rv/.gitignore
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+rv
+rv-static
+fixdep
+feature
+FEATURE-DUMP
diff --git a/tools/verification/rv/Build b/tools/verification/rv/Build
new file mode 100644
index ..a44c22349d4b
--- /dev/null
+++ b/tools/verification/rv/Build
@@ -0,0 +1 @@
+rv-y += src/
diff --git a/tools/verification/rv/Makefile b/tools/verification/rv/Makefile
index 485f8aeddbe0..411d62b3d8eb 100644
--- a/tools/verification/rv/Makefile
+++ b/tools/verification/rv/Makefile
@@ -1,146 +1,87 @@
-NAME   :=  rv
-# Follow the kernel version
-VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. 
kernelversion | grep -v make)
-
-# From libtracefs:
-# Makefiles suck: This macro sets a default value of $(2) for the
-# variable named by $(1), unless the variable has been set by
-# environment or command line. This is necessary for CC and AR
-# because make sets default values, so the simpler ?= approach
-# won't work as expected.
-define allow-override
-  $(if $(or $(findstring environment,$(origin $(1))),\
-$(findstring command line,$(origin $(1,,\
-$(eval $(1) = $(2)))
-endef
-
-# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
-$(call allow-override,CC,$(CROSS_COMPILE)gcc)
-$(call allow-override,AR,$(CROSS_COMPILE)ar)
-$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
-$(call allow-override,PKG_CONFIG,pkg-config)
-$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
-$(call allow-override,LDCONFIG,ldconfig)
-
-INSTALL=   install
-MKDIR  =   mkdir
-FOPTS  :=  -flto=auto -ffat-lto-objects -fexceptions 
-fstack-protector-strong \
-   -fasynchronous-unwind-tables -fstack-clash-protection
-WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
-
-ifeq ($(CC),clang)
-  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
-  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+# SPDX-License-Identifier: GPL-2.0-only
+
+ifeq ($(srctree),)
+  srctree  := $(patsubst %/,%,$(dir $(CURDIR)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
-TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
-
-CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS) -I include
-LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
-LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
-
-SRC:=  $(wildcard src/*.c)
-HDR:=  $(wildcard src/*.h)
-OBJ:=  $(SRC:.c=.o)
-DIRS   :=  src
-FILES  :=  Makefile README.txt
-CEXT   :=  bz2
-TARBALL:=  $(NAME)-$(VERSION).tar.$(CEXT)
-TAROPTS:=  -cvjf $(TARBALL)
-BINDIR :=  /usr/bin
-DATADIR:=  /usr/share
-DOCDIR :=  $(DATADIR)/doc
-MANDIR :=  $(DATADIR)/man
-LICDIR :=  $(DATADIR)/licenses
-SRCTREE:=  $(or $(BUILD_SRC),$(CURDIR))
-
-# If running from the tarball, man pages are stored in the Documentation
-# dir. If running from the kernel source, man pages are stored in
-# Documentation/tools/rv/.
-ifneq ($(wildcard Documentation/.*),)
-DOCSRC =   Documentation/
+include $(srctree)/tools/scripts/Makefile.include
+
+# O is an alias for OUTPUT
+OUTPUT  := $(O)
+
+ifeq ($(OUTPUT),)
+  OUTPUT   := $(CURDIR)/
 else
-DOCSRC =   $(SRCTREE)/../../../Documentation/tools/rv/
+  # subdir is used by the ../Makefile in $(call descend,)
+  ifneq ($(subdir),)
+OUTPUT:= $(OUTPUT)/$(subdir)
+  endif
+endif
+
+ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),)
+  OUTPUT := $(OUTPUT)/
 endif
 
-LIBTRACEEVENT_MIN_VERSION = 1.5
-LIBTRACEFS_MIN_VERSION = 1.3
+RV := $(OUTPUT)rv
+RV_IN  := $(RV)-in.o
 
-.PHONY:all warnings show_warnings
-all:   warnings rv
+VERSION:= $(shell sh -c "make -sC ../../.. kernelversion | 
grep

[PATCH V3 2/3] tools/rtla: Use tools/build makefiles to build rtla

2024-03-15 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build rtla, inheriting the benefits of
it. For example, having a proper way to handle dependencies.

rtla is built using perf infra-structure when building inside the
kernel tree.

At this point, rtla diverges from perf in two points: Documentation
and tarball generation/build.

At the documentation level, rtla is one step ahead, placing the
documentation at Documentation/tools/rtla/, using the same build
tools as kernel documentation. The idea is to move perf
documentation to the same scheme and then share the same makefiles.

rtla has a tarball target that the (old) RHEL8 uses. The tarball was
kept using a simple standalone makefile for compatibility. The
standalone makefile shares most of the code, e.g., flags, with
regular buildings.

The tarball method was set as deprecated. If necessary, we can make
a rtla tarball like perf, which includes the entire tools/build.
But this would also require changes in the user side (the directory
structure changes, and probably the deps to build the package).

Inspired on perf and objtool.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/.gitignore  |   7 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 217 +
 tools/tracing/rtla/Makefile.config |  47 ++
 tools/tracing/rtla/Makefile.rtla   |  80 +
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/src/Build   |  11 ++
 7 files changed, 244 insertions(+), 145 deletions(-)
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build

diff --git a/tools/tracing/rtla/.gitignore b/tools/tracing/rtla/.gitignore
index e9df32419b2b..293f0dbb0ca2 100644
--- a/tools/tracing/rtla/.gitignore
+++ b/tools/tracing/rtla/.gitignore
@@ -1 +1,6 @@
-/rtla
+# SPDX-License-Identifier: GPL-2.0-only
+rtla
+rtla-static
+fixdep
+feature
+FEATURE-DUMP
diff --git a/tools/tracing/rtla/Build b/tools/tracing/rtla/Build
new file mode 100644
index ..6c9d5b36a315
--- /dev/null
+++ b/tools/tracing/rtla/Build
@@ -0,0 +1 @@
+rtla-y += src/
diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
index afd18c678ff5..b5878be36125 100644
--- a/tools/tracing/rtla/Makefile
+++ b/tools/tracing/rtla/Makefile
@@ -1,157 +1,86 @@
-NAME   :=  rtla
-# Follow the kernel version
-VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. 
kernelversion | grep -v make)
-
-# From libtracefs:
-# Makefiles suck: This macro sets a default value of $(2) for the
-# variable named by $(1), unless the variable has been set by
-# environment or command line. This is necessary for CC and AR
-# because make sets default values, so the simpler ?= approach
-# won't work as expected.
-define allow-override
-  $(if $(or $(findstring environment,$(origin $(1))),\
-$(findstring command line,$(origin $(1,,\
-$(eval $(1) = $(2)))
-endef
-
-# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
-$(call allow-override,CC,$(CROSS_COMPILE)gcc)
-$(call allow-override,AR,$(CROSS_COMPILE)ar)
-$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
-$(call allow-override,PKG_CONFIG,pkg-config)
-$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
-$(call allow-override,LDCONFIG,ldconfig)
-
-INSTALL=   install
-MKDIR  =   mkdir
-FOPTS  :=  -flto=auto -ffat-lto-objects -fexceptions 
-fstack-protector-strong \
-   -fasynchronous-unwind-tables -fstack-clash-protection
-WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
-
-ifeq ($(CC),clang)
-  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
-  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+# SPDX-License-Identifier: GPL-2.0-only
+
+ifeq ($(srctree),)
+  srctree  := $(patsubst %/,%,$(dir $(CURDIR)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
-TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
-
-CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
-LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
-LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
-
-SRC:=  $(wildcard src/*.c)
-HDR:=  $(wildcard src/*.h)
-OBJ:=  $(SRC:.c=.o)
-DIRS   :=  src
-FILES  :=  Makefile README.txt
-CEXT   :=  bz2
-TARBALL:=  $(NAME)-$(VERSION).tar.$(CEXT)
-TAROPTS:=  -cvjf $(TARBALL)
-BINDIR :=  /usr/bin
-DATADIR:=  /usr/share
-DOCDIR :=  $(DATADIR)/doc
-MANDIR :=  $(DATADIR)/man
-LICDIR :=  $(DATADIR)/licenses
-SRCTREE:=  $(o

[PATCH V3 1/3] tools/tracing: Use tools/build makefiles on latency-collector

2024-03-15 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build latency-collector, inheriting
the benefits of it. For example: Before this patch, a missing
tracefs/traceevents headers will result in fail like this:

  ~/linux/tools/tracing/latency $ make
  cc -Wall -Wextra -g -O2  -o latency-collector latency-collector.c -lpthread
  latency-collector.c:26:10: fatal error: tracefs.h: No such file or directory
 26 | #include 
|  ^~~
  compilation terminated.
  make: *** [Makefile:14: latency-collector] Error 1

Which is not that helpful. After this change it reports:

  ~/linux/tools/tracing/latency# make

  Auto-detecting system features:
  ...   libtraceevent: [ OFF ]
  ...  libtracefs: [ OFF ]

  libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel
  libtracefs is missing. Please install libtracefs-dev/libtracefs-devel
  Makefile.config:29: *** Please, check the errors above..  Stop.

This type of output is common across other tools in tools/ like perf
and objtool.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/latency/.gitignore  |   5 +-
 tools/tracing/latency/Build   |   1 +
 tools/tracing/latency/Makefile| 105 +-
 tools/tracing/latency/Makefile.config |  30 
 4 files changed, 122 insertions(+), 19 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config

diff --git a/tools/tracing/latency/.gitignore b/tools/tracing/latency/.gitignore
index 0863960761e7..2bb8e60f7fdd 100644
--- a/tools/tracing/latency/.gitignore
+++ b/tools/tracing/latency/.gitignore
@@ -1,2 +1,5 @@
-# SPDX-License-Identifier: GPL-2.0
+# SPDX-License-Identifier: GPL-2.0-only
 latency-collector
+fixdep
+feature
+FEATURE-DUMP
diff --git a/tools/tracing/latency/Build b/tools/tracing/latency/Build
new file mode 100644
index ..0ce65ea72bf9
--- /dev/null
+++ b/tools/tracing/latency/Build
@@ -0,0 +1 @@
+latency-collector-y += latency-collector.o
diff --git a/tools/tracing/latency/Makefile b/tools/tracing/latency/Makefile
index 40c4ddaf8be1..6518b03e05c7 100644
--- a/tools/tracing/latency/Makefile
+++ b/tools/tracing/latency/Makefile
@@ -1,24 +1,93 @@
-# SPDX-License-Identifier: GPL-2.0
-# Makefile for vm tools
-#
-VAR_CFLAGS := $(shell pkg-config --cflags libtracefs 2>/dev/null)
-VAR_LDLIBS := $(shell pkg-config --libs libtracefs 2>/dev/null)
+# SPDX-License-Identifier: GPL-2.0-only
 
-TARGETS = latency-collector
-CFLAGS = -Wall -Wextra -g -O2 $(VAR_CFLAGS)
-LDFLAGS = -lpthread $(VAR_LDLIBS)
+ifeq ($(srctree),)
+  srctree  := $(patsubst %/,%,$(dir $(CURDIR)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+endif
 
-all: $(TARGETS)
+include $(srctree)/tools/scripts/Makefile.include
 
-%: %.c
-   $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+# O is an alias for OUTPUT
+OUTPUT := $(O)
 
-clean:
-   $(RM) latency-collector
+ifeq ($(OUTPUT),)
+  OUTPUT   := $(CURDIR)
+else
+  # subdir is used by the ../Makefile in $(call descend,)
+  ifneq ($(subdir),)
+OUTPUT := $(OUTPUT)/$(subdir)
+  endif
+endif
+
+ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),)
+  OUTPUT   := $(OUTPUT)/
+endif
+
+LATENCY-COLLECTOR  := $(OUTPUT)latency-collector
+LATENCY-COLLECTOR_IN   := $(LATENCY-COLLECTOR)-in.o
+
+export CC  := gcc
+export LD  := ld
+export AR  := ar
+export PKG_CONFIG := pkg-config
+
+FEATURE_TESTS  := libtraceevent
+FEATURE_TESTS  += libtracefs
+FEATURE_DISPLAY:= libtraceevent
+FEATURE_DISPLAY+= libtracefs
+
+ifeq ($(V),1)
+  Q=
+else
+  Q= @
+endif
+
+all: $(LATENCY-COLLECTOR)
+
+include $(srctree)/tools/build/Makefile.include
+
+# check for dependencies only on required targets
+NON_CONFIG_TARGETS := clean install
 
-prefix ?= /usr/local
-sbindir ?= ${prefix}/sbin
+config := 1
+ifdef MAKECMDGOALS
+ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
+ config:= 0
+endif
+endif
 
-install: all
-   install -d $(DESTDIR)$(sbindir)
-   install -m 755 -p $(TARGETS) $(DESTDIR)$(sbindir)
+ifeq ($(config),1)
+  include $(srctree)/tools/build/Makefile.feature
+  include Makefile.config
+endif
+
+CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
+
+export CFLAGS OUTPUT srctree
+
+$(LATENCY-COLLECTOR): $(LATENCY-COLLECTOR_IN)
+   $(QUIET_LINK)$(CC) $(LDFLAGS) -o $(LATENCY-COLLECTOR) 
$(LATENCY-COLLECTOR_IN) $(EXTLIBS)
+
+latency-collector.%: fixdep FORCE
+   make -f $(srctree)/tools/build/Makefile.build dir=. $@
+
+$(LATENCY-COLLECTOR_IN): fixdep FORCE
+   make $(build)=latency-collector
+
+INSTALL:= install
+MKDIR  := mkdir
+STRIP  := strip
+BINDIR := /usr/bin
+
+install:
+   @$(MKDIR) -p $(DESTDIR)$(BINDIR)
+   $(call QUIET_INSTALL,latency-collector)$(INSTALL) $(LATENCY-COLLE

[PATCH V3 0/3] tools/tracing: Use tools/build makefiles like perf

2024-03-15 Thread Daniel Bristot de Oliveira
tools/tracing and tools/verification/rv are using standalone Makefiles
and this approach has some drawbacks. For example, code duplication
and lack of proper dependency handling, making things harder for
users. 

Linus suggested using perf's build system, and it is indeed the best way to go.

This series replaces tools/tracing and tools/verification/rv makefiles
with makefiles inspired by perf and objtool that use tools/build/
infrastructure.

Thanks, Arnaldo, for the pointers via chat.

Link: 
https://lore.kernel.org/lkml/CAHk-=wjq9bjkbpi3sjn2dy5jvwpo03u9aoc6-g8anlcgq-e...@mail.gmail.com/

Changes from V2:
  - Link: https://lore.kernel.org/lkml/cover.1710512430.git.bris...@kernel.org/
  - Fix the log of the first patch, removing the '- %< ' because
some scripts interpret them as the '---' patch separator, truncating
the log.

Changes from V1:
  - Link: https://lore.kernel.org/lkml/cover.1709914259.git.bris...@kernel.org/
  - Proper handle O= and OUTPUT= flags fixing "make tools/tracing"
  - Cleanups

Daniel Bristot de Oliveira (3):
  tools/tracing: Use tools/build makefiles on latency-collector
  tools/rtla: Use tools/build makefiles to build rtla
  tools/verification: Use tools/build makefiles on rv

 tools/tracing/latency/.gitignore   |   5 +-
 tools/tracing/latency/Build|   1 +
 tools/tracing/latency/Makefile | 105 ++--
 tools/tracing/latency/Makefile.config  |  30 
 tools/tracing/rtla/.gitignore  |   7 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 217 +
 tools/tracing/rtla/Makefile.config |  47 ++
 tools/tracing/rtla/Makefile.rtla   |  80 +
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/src/Build   |  11 ++
 tools/verification/rv/.gitignore   |   6 +
 tools/verification/rv/Build|   1 +
 tools/verification/rv/Makefile | 207 +--
 tools/verification/rv/Makefile.config  |  47 ++
 tools/verification/rv/Makefile.rv  |  51 ++
 tools/verification/rv/src/Build|   4 +
 17 files changed, 549 insertions(+), 297 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build

-- 
2.44.0




Re: [PATCH V2 1/3] tools/tracing: Use tools/build makefiles on latency-collector

2024-03-15 Thread Daniel Bristot de Oliveira
On 3/15/24 15:53, Arnaldo Carvalho de Melo wrote:
> On Fri, Mar 15, 2024 at 03:48:58PM +0100, Daniel Bristot de Oliveira wrote:
>> On 3/15/24 15:24, Daniel Bristot de Oliveira wrote:
>>> Use tools/build/ makefiles to build latency-collector, inheriting
>>> the benefits of it. For example: Before this patch, a missing
>>> tracefs/traceevents headers will result in fail like this:
>>>
>>>  %< ---
>>
>> Oops, b4 is interpreting these -- as the '---' separator, and is 
>> truncating
>> the message. I will fix this in a v3.
>>
>> sorry.
> 
> Yeah, that confuses scripts, that separator.

checkpatch did not point that as an error, and git am works as well but it
indeed confuses other scripts...

Thanks, Arnaldo.
-- Daniel



Re: [PATCH V2 1/3] tools/tracing: Use tools/build makefiles on latency-collector

2024-03-15 Thread Daniel Bristot de Oliveira
On 3/15/24 15:24, Daniel Bristot de Oliveira wrote:
> Use tools/build/ makefiles to build latency-collector, inheriting
> the benefits of it. For example: Before this patch, a missing
> tracefs/traceevents headers will result in fail like this:
> 
>  %< ---

Oops, b4 is interpreting these -- as the '---' separator, and is truncating
the message. I will fix this in a v3.

sorry.

-- Daniel



[PATCH V2 3/3] tools/verification: Use tools/build makefiles on rv

2024-03-15 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build rv, inheriting the benefits of
it. For example, having a proper way to handle dependencies.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/verification/rv/.gitignore  |   6 +
 tools/verification/rv/Build   |   1 +
 tools/verification/rv/Makefile| 207 +-
 tools/verification/rv/Makefile.config |  47 ++
 tools/verification/rv/Makefile.rv |  51 +++
 tools/verification/rv/src/Build   |   4 +
 6 files changed, 183 insertions(+), 133 deletions(-)
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build

diff --git a/tools/verification/rv/.gitignore b/tools/verification/rv/.gitignore
new file mode 100644
index ..34a486585a34
--- /dev/null
+++ b/tools/verification/rv/.gitignore
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+rv
+rv-static
+fixdep
+feature
+FEATURE-DUMP
diff --git a/tools/verification/rv/Build b/tools/verification/rv/Build
new file mode 100644
index ..a44c22349d4b
--- /dev/null
+++ b/tools/verification/rv/Build
@@ -0,0 +1 @@
+rv-y += src/
diff --git a/tools/verification/rv/Makefile b/tools/verification/rv/Makefile
index 485f8aeddbe0..411d62b3d8eb 100644
--- a/tools/verification/rv/Makefile
+++ b/tools/verification/rv/Makefile
@@ -1,146 +1,87 @@
-NAME   :=  rv
-# Follow the kernel version
-VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. 
kernelversion | grep -v make)
-
-# From libtracefs:
-# Makefiles suck: This macro sets a default value of $(2) for the
-# variable named by $(1), unless the variable has been set by
-# environment or command line. This is necessary for CC and AR
-# because make sets default values, so the simpler ?= approach
-# won't work as expected.
-define allow-override
-  $(if $(or $(findstring environment,$(origin $(1))),\
-$(findstring command line,$(origin $(1,,\
-$(eval $(1) = $(2)))
-endef
-
-# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
-$(call allow-override,CC,$(CROSS_COMPILE)gcc)
-$(call allow-override,AR,$(CROSS_COMPILE)ar)
-$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
-$(call allow-override,PKG_CONFIG,pkg-config)
-$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
-$(call allow-override,LDCONFIG,ldconfig)
-
-INSTALL=   install
-MKDIR  =   mkdir
-FOPTS  :=  -flto=auto -ffat-lto-objects -fexceptions 
-fstack-protector-strong \
-   -fasynchronous-unwind-tables -fstack-clash-protection
-WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
-
-ifeq ($(CC),clang)
-  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
-  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+# SPDX-License-Identifier: GPL-2.0-only
+
+ifeq ($(srctree),)
+  srctree  := $(patsubst %/,%,$(dir $(CURDIR)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
-TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
-
-CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS) -I include
-LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
-LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
-
-SRC:=  $(wildcard src/*.c)
-HDR:=  $(wildcard src/*.h)
-OBJ:=  $(SRC:.c=.o)
-DIRS   :=  src
-FILES  :=  Makefile README.txt
-CEXT   :=  bz2
-TARBALL:=  $(NAME)-$(VERSION).tar.$(CEXT)
-TAROPTS:=  -cvjf $(TARBALL)
-BINDIR :=  /usr/bin
-DATADIR:=  /usr/share
-DOCDIR :=  $(DATADIR)/doc
-MANDIR :=  $(DATADIR)/man
-LICDIR :=  $(DATADIR)/licenses
-SRCTREE:=  $(or $(BUILD_SRC),$(CURDIR))
-
-# If running from the tarball, man pages are stored in the Documentation
-# dir. If running from the kernel source, man pages are stored in
-# Documentation/tools/rv/.
-ifneq ($(wildcard Documentation/.*),)
-DOCSRC =   Documentation/
+include $(srctree)/tools/scripts/Makefile.include
+
+# O is an alias for OUTPUT
+OUTPUT  := $(O)
+
+ifeq ($(OUTPUT),)
+  OUTPUT   := $(CURDIR)/
 else
-DOCSRC =   $(SRCTREE)/../../../Documentation/tools/rv/
+  # subdir is used by the ../Makefile in $(call descend,)
+  ifneq ($(subdir),)
+OUTPUT:= $(OUTPUT)/$(subdir)
+  endif
+endif
+
+ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),)
+  OUTPUT := $(OUTPUT)/
 endif
 
-LIBTRACEEVENT_MIN_VERSION = 1.5
-LIBTRACEFS_MIN_VERSION = 1.3
+RV := $(OUTPUT)rv
+RV_IN  := $(RV)-in.o
 
-.PHONY:all warnings show_warnings
-all:   warnings rv
+VERSION:= $(shell sh -c "make -sC ../../.. kernelversion | 
grep

[PATCH V2 2/3] tools/rtla: Use tools/build makefiles to build rtla

2024-03-15 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build rtla, inheriting the benefits of
it. For example, having a proper way to handle dependencies.

rtla is built using perf infra-structure when building inside the
kernel tree.

At this point, rtla diverges from perf in two points: Documentation
and tarball generation/build.

At the documentation level, rtla is one step ahead, placing the
documentation at Documentation/tools/rtla/, using the same build
tools as kernel documentation. The idea is to move perf
documentation to the same scheme and then share the same makefiles.

rtla has a tarball target that the (old) RHEL8 uses. The tarball was
kept using a simple standalone makefile for compatibility. The
standalone makefile shares most of the code, e.g., flags, with
regular buildings.

The tarball method was set as deprecated. If necessary, we can make
a rtla tarball like perf, which includes the entire tools/build.
But this would also require changes in the user side (the directory
structure changes, and probably the deps to build the package).

Inspired on perf and objtool.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/.gitignore  |   7 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 217 +
 tools/tracing/rtla/Makefile.config |  47 ++
 tools/tracing/rtla/Makefile.rtla   |  80 +
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/src/Build   |  11 ++
 7 files changed, 244 insertions(+), 145 deletions(-)
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build

diff --git a/tools/tracing/rtla/.gitignore b/tools/tracing/rtla/.gitignore
index e9df32419b2b..293f0dbb0ca2 100644
--- a/tools/tracing/rtla/.gitignore
+++ b/tools/tracing/rtla/.gitignore
@@ -1 +1,6 @@
-/rtla
+# SPDX-License-Identifier: GPL-2.0-only
+rtla
+rtla-static
+fixdep
+feature
+FEATURE-DUMP
diff --git a/tools/tracing/rtla/Build b/tools/tracing/rtla/Build
new file mode 100644
index ..6c9d5b36a315
--- /dev/null
+++ b/tools/tracing/rtla/Build
@@ -0,0 +1 @@
+rtla-y += src/
diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
index afd18c678ff5..b5878be36125 100644
--- a/tools/tracing/rtla/Makefile
+++ b/tools/tracing/rtla/Makefile
@@ -1,157 +1,86 @@
-NAME   :=  rtla
-# Follow the kernel version
-VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. 
kernelversion | grep -v make)
-
-# From libtracefs:
-# Makefiles suck: This macro sets a default value of $(2) for the
-# variable named by $(1), unless the variable has been set by
-# environment or command line. This is necessary for CC and AR
-# because make sets default values, so the simpler ?= approach
-# won't work as expected.
-define allow-override
-  $(if $(or $(findstring environment,$(origin $(1))),\
-$(findstring command line,$(origin $(1,,\
-$(eval $(1) = $(2)))
-endef
-
-# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
-$(call allow-override,CC,$(CROSS_COMPILE)gcc)
-$(call allow-override,AR,$(CROSS_COMPILE)ar)
-$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
-$(call allow-override,PKG_CONFIG,pkg-config)
-$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
-$(call allow-override,LDCONFIG,ldconfig)
-
-INSTALL=   install
-MKDIR  =   mkdir
-FOPTS  :=  -flto=auto -ffat-lto-objects -fexceptions 
-fstack-protector-strong \
-   -fasynchronous-unwind-tables -fstack-clash-protection
-WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
-
-ifeq ($(CC),clang)
-  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
-  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+# SPDX-License-Identifier: GPL-2.0-only
+
+ifeq ($(srctree),)
+  srctree  := $(patsubst %/,%,$(dir $(CURDIR)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
 endif
 
-TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
-
-CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
-LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
-LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
-
-SRC:=  $(wildcard src/*.c)
-HDR:=  $(wildcard src/*.h)
-OBJ:=  $(SRC:.c=.o)
-DIRS   :=  src
-FILES  :=  Makefile README.txt
-CEXT   :=  bz2
-TARBALL:=  $(NAME)-$(VERSION).tar.$(CEXT)
-TAROPTS:=  -cvjf $(TARBALL)
-BINDIR :=  /usr/bin
-DATADIR:=  /usr/share
-DOCDIR :=  $(DATADIR)/doc
-MANDIR :=  $(DATADIR)/man
-LICDIR :=  $(DATADIR)/licenses
-SRCTREE:=  $(o

[PATCH V2 1/3] tools/tracing: Use tools/build makefiles on latency-collector

2024-03-15 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build latency-collector, inheriting
the benefits of it. For example: Before this patch, a missing
tracefs/traceevents headers will result in fail like this:

 %< ---
~/linux/tools/tracing/latency $ make
cc -Wall -Wextra -g -O2  -o latency-collector latency-collector.c -lpthread
latency-collector.c:26:10: fatal error: tracefs.h: No such file or directory
   26 | #include 
  |  ^~~
compilation terminated.
make: *** [Makefile:14: latency-collector] Error 1
 %< ---

Which is not that helpful. After this change it reports:

 %< ---
~/linux/tools/tracing/latency# make

Auto-detecting system features:
...   libtraceevent: [ OFF ]
...  libtracefs: [ OFF ]

libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel
libtracefs is missing. Please install libtracefs-dev/libtracefs-devel
Makefile.config:29: *** Please, check the errors above..  Stop.
 %< ---

This type of output is common across other tools in tools/ like perf
and objtool.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/latency/.gitignore  |   5 +-
 tools/tracing/latency/Build   |   1 +
 tools/tracing/latency/Makefile| 105 +-
 tools/tracing/latency/Makefile.config |  30 
 4 files changed, 122 insertions(+), 19 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config

diff --git a/tools/tracing/latency/.gitignore b/tools/tracing/latency/.gitignore
index 0863960761e7..2bb8e60f7fdd 100644
--- a/tools/tracing/latency/.gitignore
+++ b/tools/tracing/latency/.gitignore
@@ -1,2 +1,5 @@
-# SPDX-License-Identifier: GPL-2.0
+# SPDX-License-Identifier: GPL-2.0-only
 latency-collector
+fixdep
+feature
+FEATURE-DUMP
diff --git a/tools/tracing/latency/Build b/tools/tracing/latency/Build
new file mode 100644
index ..0ce65ea72bf9
--- /dev/null
+++ b/tools/tracing/latency/Build
@@ -0,0 +1 @@
+latency-collector-y += latency-collector.o
diff --git a/tools/tracing/latency/Makefile b/tools/tracing/latency/Makefile
index 40c4ddaf8be1..6518b03e05c7 100644
--- a/tools/tracing/latency/Makefile
+++ b/tools/tracing/latency/Makefile
@@ -1,24 +1,93 @@
-# SPDX-License-Identifier: GPL-2.0
-# Makefile for vm tools
-#
-VAR_CFLAGS := $(shell pkg-config --cflags libtracefs 2>/dev/null)
-VAR_LDLIBS := $(shell pkg-config --libs libtracefs 2>/dev/null)
+# SPDX-License-Identifier: GPL-2.0-only
 
-TARGETS = latency-collector
-CFLAGS = -Wall -Wextra -g -O2 $(VAR_CFLAGS)
-LDFLAGS = -lpthread $(VAR_LDLIBS)
+ifeq ($(srctree),)
+  srctree  := $(patsubst %/,%,$(dir $(CURDIR)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+  srctree  := $(patsubst %/,%,$(dir $(srctree)))
+endif
 
-all: $(TARGETS)
+include $(srctree)/tools/scripts/Makefile.include
 
-%: %.c
-   $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+# O is an alias for OUTPUT
+OUTPUT := $(O)
 
-clean:
-   $(RM) latency-collector
+ifeq ($(OUTPUT),)
+  OUTPUT   := $(CURDIR)
+else
+  # subdir is used by the ../Makefile in $(call descend,)
+  ifneq ($(subdir),)
+OUTPUT := $(OUTPUT)/$(subdir)
+  endif
+endif
+
+ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),)
+  OUTPUT   := $(OUTPUT)/
+endif
+
+LATENCY-COLLECTOR  := $(OUTPUT)latency-collector
+LATENCY-COLLECTOR_IN   := $(LATENCY-COLLECTOR)-in.o
+
+export CC  := gcc
+export LD  := ld
+export AR  := ar
+export PKG_CONFIG := pkg-config
+
+FEATURE_TESTS  := libtraceevent
+FEATURE_TESTS  += libtracefs
+FEATURE_DISPLAY:= libtraceevent
+FEATURE_DISPLAY+= libtracefs
+
+ifeq ($(V),1)
+  Q=
+else
+  Q= @
+endif
+
+all: $(LATENCY-COLLECTOR)
+
+include $(srctree)/tools/build/Makefile.include
+
+# check for dependencies only on required targets
+NON_CONFIG_TARGETS := clean install
 
-prefix ?= /usr/local
-sbindir ?= ${prefix}/sbin
+config := 1
+ifdef MAKECMDGOALS
+ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
+ config:= 0
+endif
+endif
 
-install: all
-   install -d $(DESTDIR)$(sbindir)
-   install -m 755 -p $(TARGETS) $(DESTDIR)$(sbindir)
+ifeq ($(config),1)
+  include $(srctree)/tools/build/Makefile.feature
+  include Makefile.config
+endif
+
+CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
+
+export CFLAGS OUTPUT srctree
+
+$(LATENCY-COLLECTOR): $(LATENCY-COLLECTOR_IN)
+   $(QUIET_LINK)$(CC) $(LDFLAGS) -o $(LATENCY-COLLECTOR) 
$(LATENCY-COLLECTOR_IN) $(EXTLIBS)
+
+latency-collector.%: fixdep FORCE
+   make -f $(srctree)/tools/build/Makefile.build dir=. $@
+
+$(LATENCY-COLLECTOR_IN): fixdep FORCE
+   make $(bui

[PATCH V2 0/3] tools/tracing: Use tools/build makefiles like perf

2024-03-15 Thread Daniel Bristot de Oliveira
tools/tracing and tools/verification/rv are using standalone Makefiles
and this approach has some drawbacks. For example, code duplication
and lack of proper dependency handling, making things harder for
users. 

Linus suggested using perf's build system, and it is indeed the best way to go.

This series replaces tools/tracing and tools/verification/rv makefiles
with makefiles inspired by perf and objtool that use tools/build/
infrastructure.

Thanks, Arnaldo, for the pointers via chat.

Link: 
https://lore.kernel.org/lkml/CAHk-=wjq9bjkbpi3sjn2dy5jvwpo03u9aoc6-g8anlcgq-e...@mail.gmail.com/

Changes from V1:
  - Link: https://lore.kernel.org/lkml/cover.1709914259.git.bris...@kernel.org/
  - Proper handle O= and OUTPUT= flags fixing "make tools/tracing"
  - Cleanups

Daniel Bristot de Oliveira (3):
  tools/tracing: Use tools/build makefiles on latency-collector
  tools/rtla: Use tools/build makefiles to build rtla
  tools/verification: Use tools/build makefiles on rv

 tools/tracing/latency/.gitignore   |   5 +-
 tools/tracing/latency/Build|   1 +
 tools/tracing/latency/Makefile | 105 ++--
 tools/tracing/latency/Makefile.config  |  30 
 tools/tracing/rtla/.gitignore  |   7 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 217 +
 tools/tracing/rtla/Makefile.config |  47 ++
 tools/tracing/rtla/Makefile.rtla   |  80 +
 tools/tracing/rtla/Makefile.standalone |  26 +++
 tools/tracing/rtla/src/Build   |  11 ++
 tools/verification/rv/.gitignore   |   6 +
 tools/verification/rv/Build|   1 +
 tools/verification/rv/Makefile | 207 +--
 tools/verification/rv/Makefile.config  |  47 ++
 tools/verification/rv/Makefile.rv  |  51 ++
 tools/verification/rv/src/Build|   4 +
 17 files changed, 549 insertions(+), 297 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build

-- 
2.44.0




[PATCH 3/3] tools/rtla: Use tools/build makefiles to build rtla

2024-03-08 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build rtla, inheriting the benefits of
it. For example, having a proper way to handle dependencies.

rtla is built using perf infra-structure when building inside the
kernel tree.

At this point, rtla diverges from perf in two points: Documentation
and tarball generation/build.

At the documentation level, rtla is one step ahead, placing the
documentation at Documentation/tools/rtla/, using the same build
tools as kernel documentation. The idea is to move perf
documentation to the same scheme and then share the same makefiles.

rtla has a tarball target that the (old) RHEL8 uses. The tarball was
kept using a simple standalone makefile for compatibility. The
standalone makefile shares most of the code, e.g., flags, with
regular buildings.

The tarball method was set as deprecated. If necessary, we can make
a rtla tarball like perf, which includes the entire tools/build.
But this would also require changes in the user side (the directory
structure changes, and probably the deps to build the package).

Inspired on perf and objtool.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/.gitignore  |   4 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 177 +
 tools/tracing/rtla/Makefile.config |  44 ++
 tools/tracing/rtla/Makefile.rtla   |  77 +++
 tools/tracing/rtla/Makefile.standalone |  24 
 tools/tracing/rtla/src/Build   |  11 ++
 7 files changed, 193 insertions(+), 145 deletions(-)
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build

diff --git a/tools/tracing/rtla/.gitignore b/tools/tracing/rtla/.gitignore
index e9df32419b2b..9ec8a142e157 100644
--- a/tools/tracing/rtla/.gitignore
+++ b/tools/tracing/rtla/.gitignore
@@ -1 +1,3 @@
-/rtla
+rtla
+rtla-static
+FEATURE-DUMP
diff --git a/tools/tracing/rtla/Build b/tools/tracing/rtla/Build
new file mode 100644
index ..6c9d5b36a315
--- /dev/null
+++ b/tools/tracing/rtla/Build
@@ -0,0 +1 @@
+rtla-y += src/
diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
index afd18c678ff5..1064b02bd735 100644
--- a/tools/tracing/rtla/Makefile
+++ b/tools/tracing/rtla/Makefile
@@ -1,157 +1,46 @@
-NAME   :=  rtla
-# Follow the kernel version
-VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. 
kernelversion | grep -v make)
+# SPDX-License-Identifier: GPL-2.0
+export srctree := $(abspath ../../..)
 
-# From libtracefs:
-# Makefiles suck: This macro sets a default value of $(2) for the
-# variable named by $(1), unless the variable has been set by
-# environment or command line. This is necessary for CC and AR
-# because make sets default values, so the simpler ?= approach
-# won't work as expected.
-define allow-override
-  $(if $(or $(findstring environment,$(origin $(1))),\
-$(findstring command line,$(origin $(1,,\
-$(eval $(1) = $(2)))
-endef
+VERSION:= $(shell sh -c "make -sC ../../.. kernelversion | 
grep -v make")
+DOCSRC := ../../../Documentation/tools/rtla/
 
-# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
-$(call allow-override,CC,$(CROSS_COMPILE)gcc)
-$(call allow-override,AR,$(CROSS_COMPILE)ar)
-$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
-$(call allow-override,PKG_CONFIG,pkg-config)
-$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
-$(call allow-override,LDCONFIG,ldconfig)
+FEATURE_TESTS  := libtraceevent
+FEATURE_TESTS  += libtracefs
+FEATURE_DISPLAY:= libtraceevent
+FEATURE_DISPLAY+= libtracefs
 
-INSTALL=   install
-MKDIR  =   mkdir
-FOPTS  :=  -flto=auto -ffat-lto-objects -fexceptions 
-fstack-protector-strong \
-   -fasynchronous-unwind-tables -fstack-clash-protection
-WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
-
-ifeq ($(CC),clang)
-  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
-  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
-endif
-
-TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
-
-CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
-LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
-LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
-
-SRC:=  $(wildcard src/*.c)
-HDR:=  $(wildcard src/*.h)
-OBJ:=  $(SRC:.c=.o)
-DIRS   :=  src
-FILES  :=  Makefile README.txt
-CEXT   :=  bz2
-TARBALL:=  $(NAME)-$(VERSION).tar.$(CEXT)
-TAROPTS:=  -cvjf $(TARBALL)
-BINDIR :=  /usr/bin
-DATADIR:=  /usr/share
-DOCDIR :=  $(DATADIR)/doc
-MANDIR

[PATCH 2/3] tools/verification: Use tools/build makefiles on rv

2024-03-08 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build rv, inheriting the benefits of
it. For example, having a proper way to handle dependencies.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/verification/rv/.gitignore  |   2 +
 tools/verification/rv/Build   |   1 +
 tools/verification/rv/Makefile| 166 +-
 tools/verification/rv/Makefile.config |  44 +++
 tools/verification/rv/Makefile.rv |  49 
 tools/verification/rv/src/Build   |   4 +
 6 files changed, 133 insertions(+), 133 deletions(-)
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build

diff --git a/tools/verification/rv/.gitignore b/tools/verification/rv/.gitignore
new file mode 100644
index ..a446aca35eb2
--- /dev/null
+++ b/tools/verification/rv/.gitignore
@@ -0,0 +1,2 @@
+rv
+FEATURE-DUMP
diff --git a/tools/verification/rv/Build b/tools/verification/rv/Build
new file mode 100644
index ..a44c22349d4b
--- /dev/null
+++ b/tools/verification/rv/Build
@@ -0,0 +1 @@
+rv-y += src/
diff --git a/tools/verification/rv/Makefile b/tools/verification/rv/Makefile
index 485f8aeddbe0..da16b7c4db0f 100644
--- a/tools/verification/rv/Makefile
+++ b/tools/verification/rv/Makefile
@@ -1,146 +1,46 @@
-NAME   :=  rv
-# Follow the kernel version
-VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. 
kernelversion | grep -v make)
+# SPDX-License-Identifier: GPL-2.0
+export srctree := $(abspath ../../..)
 
-# From libtracefs:
-# Makefiles suck: This macro sets a default value of $(2) for the
-# variable named by $(1), unless the variable has been set by
-# environment or command line. This is necessary for CC and AR
-# because make sets default values, so the simpler ?= approach
-# won't work as expected.
-define allow-override
-  $(if $(or $(findstring environment,$(origin $(1))),\
-$(findstring command line,$(origin $(1,,\
-$(eval $(1) = $(2)))
-endef
+VERSION:= $(shell sh -c "make -sC ../../.. kernelversion | 
grep -v make")
+DOCSRC := ../../../Documentation/tools/rv/
 
-# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
-$(call allow-override,CC,$(CROSS_COMPILE)gcc)
-$(call allow-override,AR,$(CROSS_COMPILE)ar)
-$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
-$(call allow-override,PKG_CONFIG,pkg-config)
-$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
-$(call allow-override,LDCONFIG,ldconfig)
+FEATURE_TESTS  := libtraceevent
+FEATURE_TESTS  += libtracefs
+FEATURE_DISPLAY:= libtraceevent
+FEATURE_DISPLAY+= libtracefs
 
-INSTALL=   install
-MKDIR  =   mkdir
-FOPTS  :=  -flto=auto -ffat-lto-objects -fexceptions 
-fstack-protector-strong \
-   -fasynchronous-unwind-tables -fstack-clash-protection
-WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
-
-ifeq ($(CC),clang)
-  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
-  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
-endif
-
-TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
-
-CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS) -I include
-LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
-LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
-
-SRC:=  $(wildcard src/*.c)
-HDR:=  $(wildcard src/*.h)
-OBJ:=  $(SRC:.c=.o)
-DIRS   :=  src
-FILES  :=  Makefile README.txt
-CEXT   :=  bz2
-TARBALL:=  $(NAME)-$(VERSION).tar.$(CEXT)
-TAROPTS:=  -cvjf $(TARBALL)
-BINDIR :=  /usr/bin
-DATADIR:=  /usr/share
-DOCDIR :=  $(DATADIR)/doc
-MANDIR :=  $(DATADIR)/man
-LICDIR :=  $(DATADIR)/licenses
-SRCTREE:=  $(or $(BUILD_SRC),$(CURDIR))
-
-# If running from the tarball, man pages are stored in the Documentation
-# dir. If running from the kernel source, man pages are stored in
-# Documentation/tools/rv/.
-ifneq ($(wildcard Documentation/.*),)
-DOCSRC =   Documentation/
+ifeq ($(V),1)
+  Q =
 else
-DOCSRC =   $(SRCTREE)/../../../Documentation/tools/rv/
-endif
-
-LIBTRACEEVENT_MIN_VERSION = 1.5
-LIBTRACEFS_MIN_VERSION = 1.3
-
-.PHONY:all warnings show_warnings
-all:   warnings rv
-
-TEST_LIBTRACEEVENT = $(shell sh -c "$(PKG_CONFIG) --atleast-version 
$(LIBTRACEEVENT_MIN_VERSION) libtraceevent > /dev/null 2>&1 || echo n")
-ifeq ("$(TEST_LIBTRACEEVENT)", "n")
-WARNINGS = show_warnings
-MISSING_LIBS += echo "**   libtraceevent version $(LIBTRACEEVENT_MIN_VERSION) 
or higher";
-MISSING_PACKAGES += "libtraceevent-devel"
-MISSING_

[PATCH 1/3] tools/tracing: Use tools/build makefiles on latency-collector

2024-03-08 Thread Daniel Bristot de Oliveira
Use tools/build/ makefiles to build latency-collector, inheriting
the benefits of it. For example, having a proper way to
handle dependencies.

Inspired on perf and objtool.

Suggested-by: Linus Torvalds 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/latency/.gitignore  |  1 +
 tools/tracing/latency/Build   |  1 +
 tools/tracing/latency/Makefile| 48 +--
 tools/tracing/latency/Makefile.config | 28 
 4 files changed, 61 insertions(+), 17 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config

diff --git a/tools/tracing/latency/.gitignore b/tools/tracing/latency/.gitignore
index 0863960761e7..11490d9da0b3 100644
--- a/tools/tracing/latency/.gitignore
+++ b/tools/tracing/latency/.gitignore
@@ -1,2 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 latency-collector
+FEATURE-DUMP
diff --git a/tools/tracing/latency/Build b/tools/tracing/latency/Build
new file mode 100644
index ..0ce65ea72bf9
--- /dev/null
+++ b/tools/tracing/latency/Build
@@ -0,0 +1 @@
+latency-collector-y += latency-collector.o
diff --git a/tools/tracing/latency/Makefile b/tools/tracing/latency/Makefile
index 40c4ddaf8be1..3a2b5e8f5997 100644
--- a/tools/tracing/latency/Makefile
+++ b/tools/tracing/latency/Makefile
@@ -1,24 +1,38 @@
 # SPDX-License-Identifier: GPL-2.0
-# Makefile for vm tools
-#
-VAR_CFLAGS := $(shell pkg-config --cflags libtracefs 2>/dev/null)
-VAR_LDLIBS := $(shell pkg-config --libs libtracefs 2>/dev/null)
+export srctree := $(abspath ../../..)
+export CC  := gcc
+export LD  := ld
+export AR  := ar
+export PKG_CONFIG := pkg-config
 
-TARGETS = latency-collector
-CFLAGS = -Wall -Wextra -g -O2 $(VAR_CFLAGS)
-LDFLAGS = -lpthread $(VAR_LDLIBS)
+FEATURE_TESTS := libtraceevent
+FEATURE_TESTS += libtracefs
+FEATURE_DISPLAY := libtraceevent
+FEATURE_DISPLAY += libtracefs
 
-all: $(TARGETS)
+latency-collector:
 
-%: %.c
-   $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+include $(srctree)/tools/build/Makefile.include
+include $(srctree)/tools/build/Makefile.feature
+include $(srctree)/tools/scripts/Makefile.include
+include Makefile.config
 
-clean:
-   $(RM) latency-collector
+CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
+
+export CFLAGS := $(CFLAGS)
+
+latency-collector: latency-collector-in.o
+   $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $(EXTLIBS)
 
-prefix ?= /usr/local
-sbindir ?= ${prefix}/sbin
+latency-collector.%: fixdep FORCE
+   make -f $(srctree)/tools/build/Makefile.build dir=. $@
+
+latency-collector-in.o: fixdep FORCE
+   make $(build)=latency-collector
+
+clean:
+   $(call QUIET_CLEAN, latency-collector)
+   @find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' 
-delete
+   @rm -f latency-collector FEATURE-DUMP
 
-install: all
-   install -d $(DESTDIR)$(sbindir)
-   install -m 755 -p $(TARGETS) $(DESTDIR)$(sbindir)
+.PHONY: FORCE clean
diff --git a/tools/tracing/latency/Makefile.config 
b/tools/tracing/latency/Makefile.config
new file mode 100644
index ..5100d89346ab
--- /dev/null
+++ b/tools/tracing/latency/Makefile.config
@@ -0,0 +1,28 @@
+STOP_ERROR :=
+
+define lib_setup
+  $(eval EXTLIBS += -l$(1))
+  $(eval LIB_INCLUDES += $(shell sh -c "$(PKG_CONFIG) --cflags lib$(1)"))
+endef
+
+$(call feature_check,libtraceevent)
+ifeq ($(feature-libtraceevent), 1)
+  $(call detected,CONFIG_LIBTRACEEVENT)
+  $(call lib_setup,traceevent)
+else
+  STOP_ERROR := 1
+  $(info libtraceevent is missing. Please install 
libtraceevent-dev/libtraceevent-devel)
+endif
+
+$(call feature_check,libtracefs)
+ifeq ($(feature-libtracefs), 1)
+  $(call detected,CONFIG_LIBTRACEFS)
+  $(call lib_setup,tracefs)
+else
+  STOP_ERROR := 1
+  $(info libtracefs is missing. Please install libtracefs-dev/libtracefs-devel)
+endif
+
+ifeq ($(STOP_ERROR),1)
+  $(error Please, check the errors above.)
+endif
-- 
2.44.0




[PATCH 0/3] tools/tracing: Use tools/build makefiles like perf

2024-03-08 Thread Daniel Bristot de Oliveira
tools/tracing and tools/verification/rv are using standalone Makefiles.
However, This approach has some drawbacks. For example, code
duplication and lack of proper dependency handling, making things
harder for users. 

Linus suggested using perf's build system, and it is indeed the best way to go.

This series replaces tools/tracing and tools/verification/rv makefiles
with makefiles inspired by perf and objtool that use tools/build/
infrastructure.

Thanks, Arnaldo, for the pointers via chat.

Link: 
https://lore.kernel.org/lkml/CAHk-=wjq9bjkbpi3sjn2dy5jvwpo03u9aoc6-g8anlcgq-e...@mail.gmail.com/

Daniel Bristot de Oliveira (3):
  tools/tracing: Use tools/build makefiles on latency-collector
  tools/verification: Use tools/build makefiles on rv
  tools/rtla: Use tools/build makefiles to build rtla

 tools/tracing/latency/.gitignore   |   1 +
 tools/tracing/latency/Build|   1 +
 tools/tracing/latency/Makefile |  48 ---
 tools/tracing/latency/Makefile.config  |  28 
 tools/tracing/rtla/.gitignore  |   4 +-
 tools/tracing/rtla/Build   |   1 +
 tools/tracing/rtla/Makefile| 177 +
 tools/tracing/rtla/Makefile.config |  44 ++
 tools/tracing/rtla/Makefile.rtla   |  77 +++
 tools/tracing/rtla/Makefile.standalone |  24 
 tools/tracing/rtla/src/Build   |  11 ++
 tools/verification/rv/.gitignore   |   2 +
 tools/verification/rv/Build|   1 +
 tools/verification/rv/Makefile | 166 +--
 tools/verification/rv/Makefile.config  |  44 ++
 tools/verification/rv/Makefile.rv  |  49 +++
 tools/verification/rv/src/Build|   4 +
 17 files changed, 387 insertions(+), 295 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config
 create mode 100644 tools/tracing/rtla/Build
 create mode 100644 tools/tracing/rtla/Makefile.config
 create mode 100644 tools/tracing/rtla/Makefile.rtla
 create mode 100644 tools/tracing/rtla/Makefile.standalone
 create mode 100644 tools/tracing/rtla/src/Build
 create mode 100644 tools/verification/rv/.gitignore
 create mode 100644 tools/verification/rv/Build
 create mode 100644 tools/verification/rv/Makefile.config
 create mode 100644 tools/verification/rv/Makefile.rv
 create mode 100644 tools/verification/rv/src/Build

-- 
2.44.0




[ANNOUNCE] 4.19.307-rt133

2024-03-03 Thread Daniel Wagner
Hello RT-list!

I'm pleased to announce the 4.19.307-rt133 stable release. This is
just an update to the stable release 4.19.307. No RT specific changes.

You can get this release via the git tree at:

  git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

  branch: v4.19-rt
  Head SHA1: 4790d0210f1929d981659cd4e7ecfb34e0a6889c

Or to build 4.19.307-rt133 directly, the following patches should be applied:

  https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.xz

  https://www.kernel.org/pub/linux/kernel/v4.x/patch-4.19.307.xz

  
https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.307-rt133.patch.xz

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel



[PATCH RT 0/1] Linux v4.19.307-rt133-rc1

2024-02-27 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.307-rt133-rc1.

Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2024-03-05.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.306-rt132:


Daniel Wagner (1):
  Linux 4.19.307-rt133

 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.43.2




[PATCH RT 1/1] Linux 4.19.307-rt133

2024-02-27 Thread Daniel Wagner
v4.19.307-rt133-rc1 stable review patch.
If anyone has any objections, please let me know.

---


Signed-off-by: Daniel Wagner 
---
 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localversion-rt b/localversion-rt
index ecff281e807f..c2c7e0fb6685 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt132
+-rt133
-- 
2.43.2




[GIT PULL] tracing/tools: Fixes for 6.8-rc4

2024-02-12 Thread Daniel Bristot de Oliveira
Steven,

Tracing tooling updates for 6.8-rc4

RTLA:
- rtla tools are exiting with a positive value  when usage()
  is called. Make them return 0 if the usage was called via
  -h/--help.

- the -P priority sets the sched priority for rtla workload.
  When the SCHED_OTHER scheduler is selected, it sets
  the rt_priority instead of the nice parameter. Setting
  the nice value is the correct thing, so fix it.

- rtla is failing to compile with clang due to unsupported
  options from gcc. Adjusting the compiler/linker options
  makes clang work properly.

- Remove the sched_getattr() unused function on utils.c.

- Fixes on variable initialization and size, reported by
  clang.

Verification:
- rv is failing to compile with clang due to unsupported
  options from gcc. Adjusting the compiler/linker options
  makes clang work properly.

- Fix an uninitialized variable on in_kernel.c reported by
  clang.


Please pull the latest trace-tools-fixes-v6.8-rc4 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/bristot/linux.git
trace-tools-fixes-v6.8-rc4

Tag SHA1: 63f0522db203c7d138595e760b9a237bc02990fa
Head SHA1: b5f319360371087d52070d8f3fc7789e80ce69a6

Daniel Bristot de Oliveira (6):
  tools/rtla: Fix Makefile compiler options for clang
  tools/rtla: Fix uninitialized bucket/data->bucket_size warning
  tools/rtla: Fix clang warning about mount_point var size
  tools/rtla: Remove unused sched_getattr() function
  tools/rv: Fix Makefile compiler options for clang
  tools/rv: Fix curr_reactor uninitialized variable

John Kacur (1):
  tools/rtla: Exit with EXIT_SUCCESS when help is invoked

limingming3 (1):
  tools/rtla: Replace setting prio with nice for SCHED_OTHER


 tools/tracing/rtla/Makefile|  7 ++-
 tools/tracing/rtla/src/osnoise_hist.c  |  9 ++---
 tools/tracing/rtla/src/osnoise_top.c   |  6 +-
 tools/tracing/rtla/src/timerlat_hist.c |  9 ++---
 tools/tracing/rtla/src/timerlat_top.c  |  6 +-
 tools/tracing/rtla/src/utils.c | 14 --
 tools/tracing/rtla/src/utils.h |  2 ++
 tools/verification/rv/Makefile |  7 ++-
 tools/verification/rv/src/in_kernel.c  |  2 +-
 9 files changed, 41 insertions(+), 21 deletions(-)
---
diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
index 2456a399eb9a..afd18c678ff5 100644
--- a/tools/tracing/rtla/Makefile
+++ b/tools/tracing/rtla/Makefile
@@ -28,10 +28,15 @@ FOPTS   :=  -flto=auto -ffat-lto-objects 
-fexceptions -fstack-protector-strong \
-fasynchronous-unwind-tables -fstack-clash-protection
 WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
 
+ifeq ($(CC),clang)
+  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
+  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+endif
+
 TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
 
 CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
-LDFLAGS:=  -ggdb $(EXTRA_LDFLAGS)
+LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
 LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
 
 SRC:=  $(wildcard src/*.c)
diff --git a/tools/tracing/rtla/src/osnoise_hist.c 
b/tools/tracing/rtla/src/osnoise_hist.c
index 8f81fa007364..01870d50942a 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -135,8 +135,7 @@ static void osnoise_hist_update_multiple(struct 
osnoise_tool *tool, int cpu,
if (params->output_divisor)
duration = duration / params->output_divisor;
 
-   if (data->bucket_size)
-   bucket = duration / data->bucket_size;
+   bucket = duration / data->bucket_size;
 
total_duration = duration * count;
 
@@ -480,7 +479,11 @@ static void osnoise_hist_usage(char *usage)
 
for (i = 0; msg[i]; i++)
fprintf(stderr, "%s\n", msg[i]);
-   exit(1);
+
+   if (usage)
+   exit(EXIT_FAILURE);
+
+   exit(EXIT_SUCCESS);
 }
 
 /*
diff --git a/tools/tracing/rtla/src/osnoise_top.c 
b/tools/tracing/rtla/src/osnoise_top.c
index f7c959be8677..457360db0767 100644
--- a/tools/tracing/rtla/src/osnoise_top.c
+++ b/tools/tracing/rtla/src/osnoise_top.c
@@ -331,7 +331,11 @@ static void osnoise_top_usage(struct osnoise_top_params 
*params, char *usage)
 
for (i = 0; msg[i]; i++)
fprintf(stderr, "%s\n", msg[i]);
-   exit(1);
+
+   if (usage)
+   exit(EXIT_FAILURE);
+
+   exit(EXIT_SUCCESS);
 }
 
 /*
diff --git a/tools/tracing/rtla/src/timerlat_hist.c 
b/tools/tracing/rtla/src/timerlat_hist.c
index 47d3d8b53cb2..

[ANNOUNCE] 4.19.306-rt132

2024-02-12 Thread Daniel Wagner
Hello RT-list!

I'm pleased to announce the 4.19.306-rt132 stable release.

This is an update to the v4.19.306 stable release. There is a small RT
related changed due to the backport of

  f8f261f9ade2 ("crypto: scompress - Use per-CPU struct instead multiple 
variables")

I had to drop a downstream version of this patch

  "crypto: scompress - serialize RT percpu scratch buffer access with a local 
lock"

You can get this release via the git tree at:

  git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

  branch: v4.19-rt
  Head SHA1: 138ebc1820d1462c623c367c4d243855d8956bf6

Or to build 4.19.306-rt132 directly, the following patches should be applied:

  https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.xz

  https://www.kernel.org/pub/linux/kernel/v4.x/patch-4.19.306.xz

  
https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.306-rt132.patch.xz

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.302-rt131:
---

Daniel Wagner (1):
  Linux 4.19.306-rt132
---
localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/localversion-rt b/localversion-rt
index a328b97369c2..ecff281e807f 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt131
+-rt132



Re: [PATCH] tools/rtla: Replace setting prio with nice for SCHED_OTHER

2024-02-08 Thread Daniel Bristot de Oliveira
On 2/7/24 07:51, limingming3 wrote:
> Since the sched_priority for SCHED_OTHER is always 0, it makes no
> sence to set it.
> Setting nice for SCHED_OTHER seems more meaningful.

Thanks!

This is actually a fix, I meant to set nice since the beginning.

-- Daniel



Re: [PATCH 1/6] tools/rtla: Fix Makefile compiler options for clang

2024-02-08 Thread Daniel Bristot de Oliveira
On 2/6/24 16:48, Nathan Chancellor wrote:
> On Tue, Feb 06, 2024 at 12:05:29PM +0100, Daniel Bristot de Oliveira wrote:
>> The following errors are showing up when compiling rtla with clang:
>>
>>  $ make HOSTCC=clang CC=clang LLVM_IAS=1
>>  [...]
>>
>>   clang -O -g -DVERSION=\"6.8.0-rc1\" -flto=auto -ffat-lto-objects
>>  -fexceptions -fstack-protector-strong
>>  -fasynchronous-unwind-tables -fstack-clash-protection  -Wall
>>  -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
>>  -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
>>  $(pkg-config --cflags libtracefs)-c -o src/utils.o src/utils.c
>>
>>   clang: warning: optimization flag '-ffat-lto-objects' is not supported 
>> [-Wignored-optimization-argument]
> 
> For what it's worth, this flag is supported in clang 17.0.0 and newer:
> 
> https://github.com/llvm/llvm-project/commit/610fc5cbcc8b68879c562f6458608afe2473ab7f

Good! still, I am getting this error on fedora, with this clang version:

bristot@x1:~/src/git/linux/tools/tracing/rtla$ clang --version
clang version 17.0.6 (Fedora 17.0.6-1.fc39)
Target: x86_64-redhat-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

:-(

> But if it is not critical, just dropping the flag like you have done
> here rather than conditionally supporting it is probably easier.

Yeah, I will drop it for now, and keep monitoring.

Thanks Natan!
-- Daniel



[PATCH 6/6] tools/rv: Fix curr_reactor uninitialized variable

2024-02-06 Thread Daniel Bristot de Oliveira
clang is reporting:

$ make HOSTCC=clang CC=clang LLVM_IAS=1

clang -O -g -DVERSION=\"6.8.0-rc3\" -flto=auto -fexceptions
-fstack-protector-strong -fasynchronous-unwind-tables
-fstack-clash-protection  -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
$(pkg-config --cflags libtracefs)  -I include
-c -o src/in_kernel.o src/in_kernel.c
[...]

src/in_kernel.c:227:6: warning: variable 'curr_reactor' is used uninitialized 
whenever 'if' condition is true [-Wsometimes-uninitialized]
  227 | if (!end)
  | ^~~~
src/in_kernel.c:242:9: note: uninitialized use occurs here
  242 | return curr_reactor;
  |^~~~
src/in_kernel.c:227:2: note: remove the 'if' if its condition is always false
  227 | if (!end)
  | ^
  228 | goto out_free;
  | ~
src/in_kernel.c:221:6: warning: variable 'curr_reactor' is used uninitialized 
whenever 'if' condition is true [-Wsometimes-uninitialized]
  221 | if (!start)
  | ^~
src/in_kernel.c:242:9: note: uninitialized use occurs here
  242 | return curr_reactor;
  |^~~~
src/in_kernel.c:221:2: note: remove the 'if' if its condition is always false
  221 | if (!start)
  | ^~~
  222 | goto out_free;
  | ~
src/in_kernel.c:215:20: note: initialize the variable 'curr_reactor' to silence 
this warning
  215 | char *curr_reactor;
  |   ^
  |= NULL
2 warnings generated.

Which is correct. Setting curr_reactor to NULL avoids the problem.

Cc: sta...@vger.kernel.org
Fixes: 6d60f89691fc ("tools/rv: Add in-kernel monitor interface")
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/verification/rv/src/in_kernel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/verification/rv/src/in_kernel.c 
b/tools/verification/rv/src/in_kernel.c
index ad28582bcf2b..f04479ecc96c 100644
--- a/tools/verification/rv/src/in_kernel.c
+++ b/tools/verification/rv/src/in_kernel.c
@@ -210,9 +210,9 @@ static char *ikm_read_reactor(char *monitor_name)
 static char *ikm_get_current_reactor(char *monitor_name)
 {
char *reactors = ikm_read_reactor(monitor_name);
+   char *curr_reactor = NULL;
char *start;
char *end;
-   char *curr_reactor;
 
if (!reactors)
return NULL;
-- 
2.43.0




[PATCH 5/6] tools/rv: Fix Makefile compiler options for clang

2024-02-06 Thread Daniel Bristot de Oliveira
The following errors are showing up when compiling rv with clang:

 $ make HOSTCC=clang CC=clang LLVM_IAS=1
 [...]
  clang -O -g -DVERSION=\"6.8.0-rc1\" -flto=auto -ffat-lto-objects
  -fexceptions -fstack-protector-strong -fasynchronous-unwind-tables
  -fstack-clash-protection  -Wall -Werror=format-security
  -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
  -Wno-maybe-uninitialized $(pkg-config --cflags libtracefs)
  -I include   -c -o src/utils.o src/utils.c
  clang: warning: optimization flag '-ffat-lto-objects' is not supported 
[-Wignored-optimization-argument]
  warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean 
'-Wno-uninitialized'? [-Wunknown-warning-option]
  1 warning generated.

  clang -o rv -ggdb  src/in_kernel.o src/rv.o src/trace.o src/utils.o 
$(pkg-config --libs libtracefs)
  src/in_kernel.o: file not recognized: file format not recognized
  clang: error: linker command failed with exit code 1 (use -v to see 
invocation)
  make: *** [Makefile:110: rv] Error 1

Solve these issues by:
  - removing -ffat-lto-objects and -Wno-maybe-uninitialized if using clang
  - informing the linker about -flto=auto

Cc: sta...@vger.kernel.org
Fixes: 4bc4b131d44c ("rv: Add rv tool")
Suggested-by: Donald Zickus 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/verification/rv/Makefile | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/verification/rv/Makefile b/tools/verification/rv/Makefile
index 3d0f3888a58c..485f8aeddbe0 100644
--- a/tools/verification/rv/Makefile
+++ b/tools/verification/rv/Makefile
@@ -28,10 +28,15 @@ FOPTS   :=  -flto=auto -ffat-lto-objects 
-fexceptions -fstack-protector-strong \
-fasynchronous-unwind-tables -fstack-clash-protection
 WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
 
+ifeq ($(CC),clang)
+  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
+  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+endif
+
 TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
 
 CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS) -I include
-LDFLAGS:=  -ggdb $(EXTRA_LDFLAGS)
+LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
 LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
 
 SRC:=  $(wildcard src/*.c)
-- 
2.43.0




[PATCH 4/6] tools/rtla: Remove unused sched_getattr() function

2024-02-06 Thread Daniel Bristot de Oliveira
Clang is reporting:

$ make HOSTCC=clang CC=clang LLVM_IAS=1
[...]
clang -O -g -DVERSION=\"6.8.0-rc3\" -flto=auto -fexceptions 
-fstack-protector-strong -fasynchronous-unwind-tables -fstack-clash-protection  
-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS 
$(pkg-config --cflags libtracefs)-c -o src/utils.o src/utils.c
src/utils.c:241:19: warning: unused function 'sched_getattr' [-Wunused-function]
  241 | static inline int sched_getattr(pid_t pid, struct sched_attr *attr,
  |   ^
1 warning generated.

Which is correct, so remove the unused function.

Cc: sta...@vger.kernel.org
Fixes: b1696371d865 ("rtla: Helper functions for rtla")
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/src/utils.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index b998b24edf1e..5fcd6495ff05 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -238,12 +238,6 @@ static inline int sched_setattr(pid_t pid, const struct 
sched_attr *attr,
return syscall(__NR_sched_setattr, pid, attr, flags);
 }
 
-static inline int sched_getattr(pid_t pid, struct sched_attr *attr,
-   unsigned int size, unsigned int flags)
-{
-   return syscall(__NR_sched_getattr, pid, attr, size, flags);
-}
-
 int __set_sched_attr(int pid, struct sched_attr *attr)
 {
int flags = 0;
-- 
2.43.0




[PATCH 3/6] tools/rtla: Fix clang warning about mount_point var size

2024-02-06 Thread Daniel Bristot de Oliveira
clang is reporting this warning:

$ make HOSTCC=clang CC=clang LLVM_IAS=1
[...]
clang -O -g -DVERSION=\"6.8.0-rc3\" -flto=auto -fexceptions
-fstack-protector-strong -fasynchronous-unwind-tables
-fstack-clash-protection  -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
$(pkg-config --cflags libtracefs)-c -o src/utils.o src/utils.c

src/utils.c:548:66: warning: 'fscanf' may overflow; destination buffer in 
argument 3 has size 1024, but the corresponding specifier may require size 1025 
[-Wfortify-source]
  548 | while (fscanf(fp, "%*s %" STR(MAX_PATH) "s %99s %*s %*d %*d\n", 
mount_point, type) == 2) {
  | 
^

Increase mount_point variable size to MAX_PATH+1 to avoid the overflow.

Cc: sta...@vger.kernel.org
Fixes: a957cbc02531 ("rtla: Add -C cgroup support")
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/src/utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index c769d7b3842c..b998b24edf1e 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -536,7 +536,7 @@ int set_cpu_dma_latency(int32_t latency)
  */
 static const int find_mount(const char *fs, char *mp, int sizeof_mp)
 {
-   char mount_point[MAX_PATH];
+   char mount_point[MAX_PATH+1];
char type[100];
int found = 0;
FILE *fp;
-- 
2.43.0




[PATCH 2/6] tools/rtla: Fix uninitialized bucket/data->bucket_size warning

2024-02-06 Thread Daniel Bristot de Oliveira
When compiling rtla with clang, I am getting the following warnings:

$ make HOSTCC=clang CC=clang LLVM_IAS=1

[..]
clang -O -g -DVERSION=\"6.8.0-rc3\" -flto=auto -fexceptions
-fstack-protector-strong -fasynchronous-unwind-tables
-fstack-clash-protection  -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
$(pkg-config --cflags libtracefs)
-c -o src/osnoise_hist.o src/osnoise_hist.c
src/osnoise_hist.c:138:6: warning: variable 'bucket' is used uninitialized 
whenever 'if' condition is false [-Wsometimes-uninitialized]
  138 | if (data->bucket_size)
  | ^
src/osnoise_hist.c:149:6: note: uninitialized use occurs here
  149 | if (bucket < entries)
  | ^~
src/osnoise_hist.c:138:2: note: remove the 'if' if its condition is always true
  138 | if (data->bucket_size)
  | ^~
  139 | bucket = duration / data->bucket_size;
src/osnoise_hist.c:132:12: note: initialize the variable 'bucket' to silence 
this warning
  132 | int bucket;
  |   ^
  |= 0
1 warning generated.

[...]

clang -O -g -DVERSION=\"6.8.0-rc3\" -flto=auto -fexceptions
-fstack-protector-strong -fasynchronous-unwind-tables
-fstack-clash-protection  -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
$(pkg-config --cflags libtracefs)
-c -o src/timerlat_hist.o src/timerlat_hist.c
src/timerlat_hist.c:181:6: warning: variable 'bucket' is used uninitialized 
whenever 'if' condition is false [-Wsometimes-uninitialized]
  181 | if (data->bucket_size)
  | ^
src/timerlat_hist.c:204:6: note: uninitialized use occurs here
  204 | if (bucket < entries)
  | ^~
src/timerlat_hist.c:181:2: note: remove the 'if' if its condition is always true
  181 | if (data->bucket_size)
  | ^~
  182 | bucket = latency / data->bucket_size;
src/timerlat_hist.c:175:12: note: initialize the variable 'bucket' to silence 
this warning
  175 | int bucket;
  |   ^
  |= 0
1 warning generated.

This is a legit warning, but data->bucket_size is always > 0 (see
timerlat_hist_parse_args()), so the if is not necessary.

Remove the unneeded if (data->bucket_size) to avoid the warning.

Cc: sta...@vger.kernel.org
Fixes: 1eeb6328e8b3 ("rtla/timerlat: Add timerlat hist mode")
Fixes: 829a6c0b5698 ("rtla/osnoise: Add the hist mode")
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/src/osnoise_hist.c  | 3 +--
 tools/tracing/rtla/src/timerlat_hist.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/tracing/rtla/src/osnoise_hist.c 
b/tools/tracing/rtla/src/osnoise_hist.c
index 8f81fa007364..67128171c29d 100644
--- a/tools/tracing/rtla/src/osnoise_hist.c
+++ b/tools/tracing/rtla/src/osnoise_hist.c
@@ -135,8 +135,7 @@ static void osnoise_hist_update_multiple(struct 
osnoise_tool *tool, int cpu,
if (params->output_divisor)
duration = duration / params->output_divisor;
 
-   if (data->bucket_size)
-   bucket = duration / data->bucket_size;
+   bucket = duration / data->bucket_size;
 
total_duration = duration * count;
 
diff --git a/tools/tracing/rtla/src/timerlat_hist.c 
b/tools/tracing/rtla/src/timerlat_hist.c
index 47d3d8b53cb2..3a5b8c409e7d 100644
--- a/tools/tracing/rtla/src/timerlat_hist.c
+++ b/tools/tracing/rtla/src/timerlat_hist.c
@@ -178,8 +178,7 @@ timerlat_hist_update(struct osnoise_tool *tool, int cpu,
if (params->output_divisor)
latency = latency / params->output_divisor;
 
-   if (data->bucket_size)
-   bucket = latency / data->bucket_size;
+   bucket = latency / data->bucket_size;
 
if (!context) {
hist = data->hist[cpu].irq;
-- 
2.43.0




[PATCH 1/6] tools/rtla: Fix Makefile compiler options for clang

2024-02-06 Thread Daniel Bristot de Oliveira
The following errors are showing up when compiling rtla with clang:

 $ make HOSTCC=clang CC=clang LLVM_IAS=1
 [...]

  clang -O -g -DVERSION=\"6.8.0-rc1\" -flto=auto -ffat-lto-objects
-fexceptions -fstack-protector-strong
-fasynchronous-unwind-tables -fstack-clash-protection  -Wall
-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
$(pkg-config --cflags libtracefs)-c -o src/utils.o src/utils.c

  clang: warning: optimization flag '-ffat-lto-objects' is not supported 
[-Wignored-optimization-argument]
  warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean 
'-Wno-uninitialized'? [-Wunknown-warning-option]
  1 warning generated.

  clang -o rtla -ggdb  src/osnoise.o src/osnoise_hist.o src/osnoise_top.o
  src/rtla.o src/timerlat_aa.o src/timerlat.o src/timerlat_hist.o
  src/timerlat_top.o src/timerlat_u.o src/trace.o src/utils.o $(pkg-config 
--libs libtracefs)

  src/osnoise.o: file not recognized: file format not recognized
  clang: error: linker command failed with exit code 1 (use -v to see 
invocation)
  make: *** [Makefile:110: rtla] Error 1

Solve these issues by:
  - removing -ffat-lto-objects and -Wno-maybe-uninitialized if using clang
  - informing the linker about -flto=auto

Cc: sta...@vger.kernel.org
Fixes: 1a7b22ab15eb ("tools/rtla: Build with EXTRA_{C,LD}FLAGS")
Suggested-by: Donald Zickus 
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/Makefile | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/tracing/rtla/Makefile b/tools/tracing/rtla/Makefile
index 2456a399eb9a..afd18c678ff5 100644
--- a/tools/tracing/rtla/Makefile
+++ b/tools/tracing/rtla/Makefile
@@ -28,10 +28,15 @@ FOPTS   :=  -flto=auto -ffat-lto-objects 
-fexceptions -fstack-protector-strong \
-fasynchronous-unwind-tables -fstack-clash-protection
 WOPTS  :=  -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 
-Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
 
+ifeq ($(CC),clang)
+  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
+  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
+endif
+
 TRACEFS_HEADERS:= $$($(PKG_CONFIG) --cflags libtracefs)
 
 CFLAGS :=  -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) 
$(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
-LDFLAGS:=  -ggdb $(EXTRA_LDFLAGS)
+LDFLAGS:=  -flto=auto -ggdb $(EXTRA_LDFLAGS)
 LIBS   :=  $$($(PKG_CONFIG) --libs libtracefs)
 
 SRC:=  $(wildcard src/*.c)
-- 
2.43.0




[PATCH 0/6] tools: Fix rtla and rv problems (found) with clang

2024-02-06 Thread Daniel Bristot de Oliveira
RHEL people reported some errors when compiling rtla and rv with
clang. The command line used to compile the tools is:

$ make HOSTCC=clang CC=clang LLVM_IAS=1

The first problem is two unsupported flags passed to the compiler:
-ffat-lto-objects and -Wno-maybe-uninitialized. They will be
removed if the compile is clang.

Also, the clang linker does not automatically recognize the
-flto=auto option used at compilation time, so it is explicitly
set.

With the compiler working, it starts pointing to some warnings
and errors about uninitialized variables, variable size, and an
unused function. These problems are also fixed.


Daniel Bristot de Oliveira (6):
  tools/rtla: Fix Makefile compiler options for clang
  tools/rtla: Fix uninitialized bucket/data->bucket_size warning
  tools/rtla: Fix clang warning about mount_point var size
  tools/rtla: Remove unused sched_getattr() function
  tools/rv: Fix Makefile compiler options for clang
  tools/rv: Fix curr_reactor uninitialized variable

 tools/tracing/rtla/Makefile| 7 ++-
 tools/tracing/rtla/src/osnoise_hist.c  | 3 +--
 tools/tracing/rtla/src/timerlat_hist.c | 3 +--
 tools/tracing/rtla/src/utils.c | 8 +---
 tools/verification/rv/Makefile | 7 ++-
 tools/verification/rv/src/in_kernel.c  | 2 +-
 6 files changed, 16 insertions(+), 14 deletions(-)

-- 
2.43.0




[PATCH RT 0/1] Linux v4.19.306-rt132-rc1

2024-02-02 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.306-rt132-rc1.

I reverted one -rt specific commit to be able to merge the 4.19.306
release:

  0cb152421350 ("crypto: scompress - serialize RT percpu scratch buffer access 
with a local lock")

because the stable backport

  f8f261f9ade2 ("crypto: scompress - Use per-CPU struct instead multiple 
variables")

seems to make the downstream -rt fix unnecessary.


Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2024-02-09.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel



[PATCH] Revert "crypto: scompress - serialize RT percpu scratch buffer access with a local lock"

2024-02-02 Thread Daniel Wagner
This reverts commit 0cb152421350004d4dcf3a4523d88c002d0a7973.

The stable backport f8f261f9ade2 ("crypto: scompress - Use per-CPU
struct instead multiple variables") replaces this downstream workaround.

Signed-off-by: Daniel Wagner 
---
 crypto/scompress.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/crypto/scompress.c b/crypto/scompress.c
index c2f0077e0801..968bbcf65c94 100644
--- a/crypto/scompress.c
+++ b/crypto/scompress.c
@@ -24,7 +24,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -35,7 +34,6 @@ static void * __percpu *scomp_src_scratches;
 static void * __percpu *scomp_dst_scratches;
 static int scomp_scratch_users;
 static DEFINE_MUTEX(scomp_lock);
-static DEFINE_LOCAL_IRQ_LOCK(scomp_scratches_lock);
 
 #ifdef CONFIG_NET
 static int crypto_scomp_report(struct sk_buff *skb, struct crypto_alg *alg)
@@ -148,7 +146,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, 
int dir)
void **tfm_ctx = acomp_tfm_ctx(tfm);
struct crypto_scomp *scomp = *tfm_ctx;
void **ctx = acomp_request_ctx(req);
-   const int cpu = local_lock_cpu(scomp_scratches_lock);
+   const int cpu = get_cpu();
u8 *scratch_src = *per_cpu_ptr(scomp_src_scratches, cpu);
u8 *scratch_dst = *per_cpu_ptr(scomp_dst_scratches, cpu);
int ret;
@@ -183,7 +181,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, 
int dir)
 1);
}
 out:
-   local_unlock_cpu(scomp_scratches_lock);
+   put_cpu();
return ret;
 }
 
-- 
2.43.0




Re: [PATCH] tracing/timerlat: Move hrtimer_init to timerlat_fd open()

2024-02-01 Thread Daniel Bristot de Oliveira
On 2/1/24 16:44, Greg KH wrote:
> On Thu, Feb 01, 2024 at 04:13:39PM +0100, Daniel Bristot de Oliveira wrote:
>> Currently, the timerlat's hrtimer is initialized at the first read of
>> timerlat_fd, and destroyed at close(). It works, but it causes an error
>> if the user program open() and close() the file without reading.
> 
> What error exactly happens?  Userspace, or the kernel crashes?

sorry, kernel crash:

# echo NO_OSNOISE_WORKLOAD > /sys/kernel/debug/tracing/osnoise/options
# echo timerlat > /sys/kernel/debug/tracing/current_tracer

# cat ./timerlat_load.py
#!/usr/bin/env python3

timerlat_fd = open("/sys/kernel/tracing/osnoise/per_cpu/cpu0/timerlat_fd", 'r')
timerlat_fd.close();

# ./taskset -c 0 ./timerlat_load.py


[ 6401.611374] BUG: kernel NULL pointer dereference, address: 0010
[ 6401.611786] #PF: supervisor read access in kernel mode
[ 6401.612081] #PF: error_code(0x) - not-present page
[ 6401.612376] PGD 0 P4D 0
[ 6401.612495] Oops:  [#1] PREEMPT SMP NOPTI
[ 6401.612690] CPU: 1 PID: 2673 Comm: python3 Not tainted 
6.6.13-200.fc39.x86_64 #1
[ 6401.613011] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 
1.16.3-1.fc39 04/01/2014
[ 6401.613379] RIP: 0010:hrtimer_active+0xd/0x50
[ 6401.613577] Code: 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 90 90 90 90 90 90 
90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 0f 1f 44 00 00 48 8b 57 30 <8b> 42 10 
a8 01 74 09 f3 90 8b 42 10 a8 01 75 f7 80 7f 38 00 75 1d
[ 6401.614374] RSP: 0018:b031009b7e10 EFLAGS: 00010286
[ 6401.614604] RAX: 0002db00 RBX: 9118f786db08 RCX: 
[ 6401.614914] RDX:  RSI: 9117a0e64400 RDI: 9118f786db08
[ 6401.615225] RBP: 9118f786db80 R08: 9117a0ddd420 R09: 9117804d4f70
[ 6401.615534] R10:  R11:  R12: 9118f786db08
[ 6401.615846] R13: 91178fdd5e20 R14: 9117840978c0 R15: 
[ 6401.616157] FS:  7f2ffbab1740() GS:9118f784() 
knlGS:
[ 6401.616508] CS:  0010 DS:  ES:  CR0: 80050033
[ 6401.616765] CR2: 0010 CR3: 0001b402e000 CR4: 00750ee0
[ 6401.617075] PKRU: 5554
[ 6401.617197] Call Trace:
[ 6401.617309]  
[ 6401.617407]  ? __die+0x23/0x70
[ 6401.617548]  ? page_fault_oops+0x171/0x4e0
[ 6401.617983]  ? srso_alias_return_thunk+0x5/0x7f
[ 6401.618389]  ? avc_has_extended_perms+0x237/0x520
[ 6401.618800]  ? exc_page_fault+0x7f/0x180
[ 6401.619176]  ? asm_exc_page_fault+0x26/0x30
[ 6401.619563]  ? hrtimer_active+0xd/0x50
[ 6401.619926]  hrtimer_cancel+0x15/0x40
[ 6401.620286]  timerlat_fd_release+0x48/0xe0
[ 6401.620666]  __fput+0xf5/0x290
[ 6401.621004]  __x64_sys_close+0x3d/0x80
[ 6401.621370]  do_syscall_64+0x60/0x90
[ 6401.621730]  ? srso_alias_return_thunk+0x5/0x7f
[ 6401.622129]  ? __x64_sys_ioctl+0x72/0xd0
[ 6401.622503]  ? srso_alias_return_thunk+0x5/0x7f
[ 6401.622902]  ? syscall_exit_to_user_mode+0x2b/0x40
[ 6401.623309]  ? srso_alias_return_thunk+0x5/0x7f
[ 6401.623703]  ? do_syscall_64+0x6c/0x90
[ 6401.624063]  ? srso_alias_return_thunk+0x5/0x7f
[ 6401.624457]  ? exit_to_user_mode_prepare+0x142/0x1f0
[ 6401.624868]  ? srso_alias_return_thunk+0x5/0x7f
[ 6401.625262]  ? syscall_exit_to_user_mode+0x2b/0x40
[ 6401.625663]  ? srso_alias_return_thunk+0x5/0x7f
[ 6401.626051]  ? do_syscall_64+0x6c/0x90
[ 6401.626404]  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
[ 6401.626810] RIP: 0033:0x7f2ffb321594
[ 6401.627164] Code: 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 
00 00 90 f3 0f 1e fa 80 3d d5 cd 0d 00 00 74 13 b8 03 00 00 00 0f 05 <48> 3d 00 
f0 ff ff 77 3c c3 0f 1f 00 55 48 89 e5 48 83 ec 10 89 7d
[ 6401.628345] RSP: 002b:7ffe8d8eef18 EFLAGS: 0202 ORIG_RAX: 
0003
[ 6401.628867] RAX: ffda RBX: 7f2ffba4e668 RCX: 7f2ffb321594
[ 6401.629372] RDX:  RSI:  RDI: 0003
[ 6401.629879] RBP: 7ffe8d8eef40 R08:  R09: 
[ 6401.630384] R10: 55c926e3167eae79 R11: 0202 R12: 0003
[ 6401.630889] R13: 7ffe8d8ef030 R14:  R15: 7f2ffba4e668
[ 6401.631394]  
[ 6401.631691] Modules linked in: tls nft_fib_inet nft_fib_ipv4 nft_fib_ipv6 
nft_fib nft_reject_inet nf_reject_ipv4 nf_reject_ipv6 nft_reject nft_ct 
nft_chain_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 rfkill ip_set 
nf_tables nfnetlink qrtr sunrpc pktcdvd intel_rapl_msr snd_hda_codec_generic 
intel_rapl_common ledtrig_audio snd_hda_intel snd_intel_dspcfg 
snd_intel_sdw_acpi snd_hda_codec snd_hda_core snd_hwdep snd_pcm kvm_amd 
iTCO_wdt snd_timer intel_pmc_bxt ccp joydev iTCO_vendor_support kvm irqbypass 
i2c_i801 snd i2c_smbus soundcore lpc_ich virtio_balloon loop zram 
crct10dif_pclmul crc32_pclmul crc32c_intel polyval_clmulni polyval_generic 
ghash_clmulni_intel sha512_ssse3 sha256_ssse3 sha1_ssse3 virtio_net virtio_gpu 
virtio_console vi

Re: [PATCH] tracing/timerlat: Move hrtimer_init to timerlat_fd open()

2024-02-01 Thread Daniel Bristot de Oliveira
On 2/1/24 16:25, Steven Rostedt wrote:
> On Thu,  1 Feb 2024 16:13:39 +0100
> Daniel Bristot de Oliveira  wrote:
> 
>> Currently, the timerlat's hrtimer is initialized at the first read of
>> timerlat_fd, and destroyed at close(). It works, but it causes an error
>> if the user program open() and close() the file without reading.
>>
>> Move hrtimer_init to timerlat_fd open() to avoid this problem.
>>
>> No functional changes.
> 
> It can't be fixing something and not have any functional changes.
> 
> No functional changes means the code is restructured but the resulting
> assembly would be the same.
> 
> Like moving functions around in a file so that you don't need extra
> prototype declarations.
> 
> Please only add "No functional changes" if the function's assembly would be
> the same.

ok

>>
>> Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface")
> 
> With a fixes tag, I'm assuming his should go into v6.8 with a Cc stable?

right, I added it on Cc, but did not include the Cc:.. tag. It seems that I 
should have.

-- Daniel

> -- Steve
> 
> 
>> Signed-off-by: Daniel Bristot de Oliveira 
>> ---
>>  kernel/trace/trace_osnoise.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
>> index bd0d01d00fb9..a8e28f9b9271 100644
>> --- a/kernel/trace/trace_osnoise.c
>> +++ b/kernel/trace/trace_osnoise.c
>> @@ -2444,6 +2444,9 @@ static int timerlat_fd_open(struct inode *inode, 
>> struct file *file)
>>  tlat = this_cpu_tmr_var();
>>  tlat->count = 0;
>>  
>> +hrtimer_init(>timer, CLOCK_MONOTONIC, 
>> HRTIMER_MODE_ABS_PINNED_HARD);
>> +tlat->timer.function = timerlat_irq;
>> +
>>  migrate_enable();
>>  return 0;
>>  };
>> @@ -2526,9 +2529,6 @@ timerlat_fd_read(struct file *file, char __user *ubuf, 
>> size_t count,
>>  tlat->tracing_thread = false;
>>  tlat->kthread = current;
>>  
>> -hrtimer_init(>timer, CLOCK_MONOTONIC, 
>> HRTIMER_MODE_ABS_PINNED_HARD);
>> -tlat->timer.function = timerlat_irq;
>> -
>>  /* Annotate now to drift new period */
>>  tlat->abs_period = hrtimer_cb_get_time(>timer);
>>  
> 




[PATCH] tracing/timerlat: Move hrtimer_init to timerlat_fd open()

2024-02-01 Thread Daniel Bristot de Oliveira
Currently, the timerlat's hrtimer is initialized at the first read of
timerlat_fd, and destroyed at close(). It works, but it causes an error
if the user program open() and close() the file without reading.

Move hrtimer_init to timerlat_fd open() to avoid this problem.

No functional changes.

Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface")
Signed-off-by: Daniel Bristot de Oliveira 
---
 kernel/trace/trace_osnoise.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index bd0d01d00fb9..a8e28f9b9271 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -2444,6 +2444,9 @@ static int timerlat_fd_open(struct inode *inode, struct 
file *file)
tlat = this_cpu_tmr_var();
tlat->count = 0;
 
+   hrtimer_init(>timer, CLOCK_MONOTONIC, 
HRTIMER_MODE_ABS_PINNED_HARD);
+   tlat->timer.function = timerlat_irq;
+
migrate_enable();
return 0;
 };
@@ -2526,9 +2529,6 @@ timerlat_fd_read(struct file *file, char __user *ubuf, 
size_t count,
tlat->tracing_thread = false;
tlat->kthread = current;
 
-   hrtimer_init(>timer, CLOCK_MONOTONIC, 
HRTIMER_MODE_ABS_PINNED_HARD);
-   tlat->timer.function = timerlat_irq;
-
/* Annotate now to drift new period */
tlat->abs_period = hrtimer_cb_get_time(>timer);
 
-- 
2.43.0




Re: [PATCH v2 0/5] PM: domains: Add helpers for multi PM domains to avoid open-coding

2024-01-08 Thread Daniel Baluta
On Fri, Jan 5, 2024 at 6:02 PM Ulf Hansson  wrote:
>
> Updates in v2:
> - Ccing Daniel Baluta and Iuliana Prodan the NXP remoteproc patches to
> requests help with testing.
> - Fixed NULL pointer bug in patch1, pointed out by Nikunj.
> - Added some tested/reviewed-by tags.

Thanks for doing this Ulf. I remember that I've tried introducing the
helpers some time ago
but got side tracked by other tasks.

https://lore.kernel.org/linux-pm/20200624103247.7115-1-daniel.bal...@oss.nxp.com/t/

Will review the series and test the remoteproc part this week.

Daniel.



[ANNOUNCE] 4.19.302-rt131

2023-12-20 Thread Daniel Wagner
Hello RT-list!

I'm pleased to announce the 4.19.302-rt131 stable release.

This is just an update to the v4.19.302 stable release. No RT specific
changes.

You can get this release via the git tree at:

  git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

  branch: v4.19-rt
  Head SHA1: 5cb4bf59d366acdf4ba96cb0d98962379bd9645d

Or to build 4.19.302-rt131 directly, the following patches should be applied:

  https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.xz

  https://www.kernel.org/pub/linux/kernel/v4.x/patch-4.19.302.xz

  
https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.302-rt131.patch.xz

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.299-rt130:



Re: [PATCH net-next 16/24] net: netkit, veth, tun, virt*: Use nested-BH locking for XDP redirect.

2023-12-18 Thread Daniel Borkmann

Hi Sebastian,

On 12/15/23 6:07 PM, Sebastian Andrzej Siewior wrote:

The per-CPU variables used during bpf_prog_run_xdp() invocation and
later during xdp_do_redirect() rely on disabled BH for their protection.
Without locking in local_bh_disable() on PREEMPT_RT these data structure
require explicit locking.

This is a follow-up on the previous change which introduced
bpf_run_lock.redirect_lock and uses it now within drivers.

The simple way is to acquire the lock before bpf_prog_run_xdp() is
invoked and hold it until the end of function.
This does not always work because some drivers (cpsw, atlantic) invoke
xdp_do_flush() in the same context.
Acquiring the lock in bpf_prog_run_xdp() and dropping in
xdp_do_redirect() (without touching drivers) does not work because not
all driver, which use bpf_prog_run_xdp(), do support XDP_REDIRECT (and
invoke xdp_do_redirect()).

Ideally the minimal locking scope would be bpf_prog_run_xdp() +
xdp_do_redirect() and everything else (error recovery, DMA unmapping,
free/ alloc of memory, …) would happen outside of the locked section.

[...]


  drivers/net/hyperv/netvsc_bpf.c |  1 +
  drivers/net/netkit.c| 13 +++
  drivers/net/tun.c   | 28 +--
  drivers/net/veth.c  | 40 -
  drivers/net/virtio_net.c|  1 +
  drivers/net/xen-netfront.c  |  1 +
  6 files changed, 52 insertions(+), 32 deletions(-)

[...]

Please exclude netkit from this set given it does not support XDP, but
instead only accepts tc BPF typed programs.

Thanks,
Daniel


diff --git a/drivers/net/netkit.c b/drivers/net/netkit.c
index 39171380ccf29..fbcf78477bda8 100644
--- a/drivers/net/netkit.c
+++ b/drivers/net/netkit.c
@@ -80,8 +80,15 @@ static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct 
net_device *dev)
netkit_prep_forward(skb, !net_eq(dev_net(dev), dev_net(peer)));
skb->dev = peer;
entry = rcu_dereference(nk->active);
-   if (entry)
-   ret = netkit_run(entry, skb, ret);
+   if (entry) {
+   scoped_guard(local_lock_nested_bh, _run_lock.redirect_lock) 
{
+   ret = netkit_run(entry, skb, ret);
+   if (ret == NETKIT_REDIRECT) {
+   dev_sw_netstats_tx_add(dev, 1, len);
+   skb_do_redirect(skb);
+   }
+   }
+   }
switch (ret) {
case NETKIT_NEXT:
case NETKIT_PASS:
@@ -95,8 +102,6 @@ static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct 
net_device *dev)
}
break;
case NETKIT_REDIRECT:
-   dev_sw_netstats_tx_add(dev, 1, len);
-   skb_do_redirect(skb);
break;
case NETKIT_DROP:
default:




[PATCH RT 1/1] Linux 4.19.302-rt131

2023-12-14 Thread Daniel Wagner
v4.19.302-rt131-rc1 stable review patch.
If anyone has any objections, please let me know.

---


Signed-off-by: Daniel Wagner 
---
 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localversion-rt b/localversion-rt
index 6fa797e5b850..a328b97369c2 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt130
+-rt131
-- 
2.43.0




[PATCH RT 0/1] Linux v4.19.302-rt131-rc1

2023-12-14 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.302-rt131-rc1.

Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2023-12-21.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.299-rt130:


Daniel Wagner (1):
  Linux 4.19.302-rt131

 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.43.0




[ANNOUNCE] 4.19.299-rt130

2023-12-14 Thread Daniel Wagner
Hello RT-list!

I'm pleased to announce the 4.19.299-rt130 stable release. This
is just updating the stable release 4.19.299. No RT specific changes.

There was a conflict due to the backport of 56e894982522 ("sched/rt:
Provide migrate_disable/enable() inlines") to stable. Thus I dropped the
backport because v4.19-rt already provides these two functions.

You can get this release via the git tree at:

  git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

  branch: v4.19-rt
  Head SHA1: a279ca52df99df429ac873bcd8cf7df8569758ae

Or to build 4.19.299-rt130 directly, the following patches should be applied:

  https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.xz

  https://www.kernel.org/pub/linux/kernel/v4.x/patch-4.19.299.xz

  
https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.299-rt130.patch.xz

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.295-rt129:
---

Daniel Wagner (2):
  Revert "sched/rt: Provide migrate_disable/enable() inlines"
  Linux 4.19.299-rt130
---
include/linux/preempt.h | 30 --
 localversion-rt |  2 +-
 2 files changed, 1 insertion(+), 31 deletions(-)
---
diff --git a/include/linux/preempt.h b/include/linux/preempt.h
index 29ecd13afdda..9c74a019bf57 100644
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -422,34 +422,4 @@ static inline void preempt_notifier_init(struct 
preempt_notifier *notifier,
 
 #endif
 
-/**
- * migrate_disable - Prevent migration of the current task
- *
- * Maps to preempt_disable() which also disables preemption. Use
- * migrate_disable() to annotate that the intent is to prevent migration,
- * but not necessarily preemption.
- *
- * Can be invoked nested like preempt_disable() and needs the corresponding
- * number of migrate_enable() invocations.
- */
-static __always_inline void migrate_disable(void)
-{
-   preempt_disable();
-}
-
-/**
- * migrate_enable - Allow migration of the current task
- *
- * Counterpart to migrate_disable().
- *
- * As migrate_disable() can be invoked nested, only the outermost invocation
- * reenables migration.
- *
- * Currently mapped to preempt_enable().
- */
-static __always_inline void migrate_enable(void)
-{
-   preempt_enable();
-}
-
 #endif /* __LINUX_PREEMPT_H */
diff --git a/localversion-rt b/localversion-rt
index 90303f5aabcf..6fa797e5b850 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt129
+-rt130



[PATCH RT 1/2] Revert "sched/rt: Provide migrate_disable/enable() inlines"

2023-12-07 Thread Daniel Wagner
v4.19.299-rt130-rc1 stable review patch.
If anyone has any objections, please let me know.

---


This reverts commit 56e8949825226341d28dd5156b3d0057684ff669.

The tree contains already the migrate_disable/enable() helpers thus this
stable backport conflicts (b) with the existing definition (compiler
complains with conflicting definition). Thus we don't need this
backported functions and can avoid the conflict by just dropping the
backport.

Signed-off-by: Daniel Wagner 
---
 include/linux/preempt.h | 30 --
 1 file changed, 30 deletions(-)

diff --git a/include/linux/preempt.h b/include/linux/preempt.h
index 29ecd13afdda..9c74a019bf57 100644
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -422,34 +422,4 @@ static inline void preempt_notifier_init(struct 
preempt_notifier *notifier,
 
 #endif
 
-/**
- * migrate_disable - Prevent migration of the current task
- *
- * Maps to preempt_disable() which also disables preemption. Use
- * migrate_disable() to annotate that the intent is to prevent migration,
- * but not necessarily preemption.
- *
- * Can be invoked nested like preempt_disable() and needs the corresponding
- * number of migrate_enable() invocations.
- */
-static __always_inline void migrate_disable(void)
-{
-   preempt_disable();
-}
-
-/**
- * migrate_enable - Allow migration of the current task
- *
- * Counterpart to migrate_disable().
- *
- * As migrate_disable() can be invoked nested, only the outermost invocation
- * reenables migration.
- *
- * Currently mapped to preempt_enable().
- */
-static __always_inline void migrate_enable(void)
-{
-   preempt_enable();
-}
-
 #endif /* __LINUX_PREEMPT_H */
-- 
2.42.0




[PATCH RT 0/2] Linux v4.19.299-rt130-rc1

2023-12-07 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.299-rt130-rc1.

Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2023-12-14.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.295-rt129:


Daniel Wagner (2):
  Revert "sched/rt: Provide migrate_disable/enable() inlines"
  Linux 4.19.299-rt130

 include/linux/preempt.h | 30 --
 localversion-rt |  2 +-
 2 files changed, 1 insertion(+), 31 deletions(-)

-- 
2.42.0




[PATCH RT 2/2] Linux 4.19.299-rt130

2023-12-07 Thread Daniel Wagner
v4.19.299-rt130-rc1 stable review patch.
If anyone has any objections, please let me know.

---


Signed-off-by: Daniel Wagner 
---
 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localversion-rt b/localversion-rt
index 90303f5aabcf..6fa797e5b850 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt129
+-rt130
-- 
2.42.0




Re: [RFC][PATCH] tracing: Allow creating instances with specified system events

2023-11-28 Thread Daniel Wagner
On Mon, Nov 27, 2023 at 05:50:21PM -0500, Steven Rostedt wrote:
> On Mon, 27 Nov 2023 17:41:08 -0500
> Steven Rostedt  wrote:
> 
> > From: "Steven Rostedt (Google)" 
> > 
> > A trace instance may only need to enable specific events. As the eventfs
> > directory of an instance currently creates all events which adds overhead,
> > allow internal instances to be created with just the events in systems
> > that they care about. This currently only deals with systems and not
> > individual events, but this should bring down the overhead of creating
> > instances for specific use cases quite bit.
> 
> This change log is not very good. I didn't actually state what was done :-p
> 
> Anyway, function trace_array_get_by_name() has an added parameter "systems"
> (and I forgot to update its kerneldoc). This parameter is a string of
> comma, or space, or commas and spaces deliminators of event system names.
> If it's not NULL, then it will only create the event system directories of
> those event systems that match the systems parameter.
> 
> That is:
> 
>  trace_array_get_by_name("qla2xxx", "qla");
> 
> Will create an instance called "qla2xxx" and only have "qla" system events
> in it.

Makes sense to me. The qla2xxx driver is interested only in its own
trace events. This should be fine, at least as far I understand it.



Re: [PATCH net] bpf: test_run: fix WARNING in format_decode

2023-11-27 Thread Daniel Borkmann

On 11/22/23 6:28 AM, Yonghong Song wrote:

On 11/21/23 7:50 PM, Edward Adam Davis wrote:

Confirm that skb->len is not 0 to ensure that skb length is valid.

Fixes: 114039b34201 ("bpf: Move skb->len == 0 checks into __bpf_redirect")
Reported-by: syzbot+e2c932aec5c8a6e1d...@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis 


Stan, Could you take a look at this patch?


I think this only papers over the bug.. also BPF selftests seem to break
with this change.

Looking again at the syzkaller trace :

  [...]
  Please remove unsupported %\0 in format string
  WARNING: CPU: 0 PID: 5068 at lib/vsprintf.c:2675 format_decode+0xa03/0xba0 
lib/vsprintf.c:2675
  [...]

We need to fix bpf_bprintf_prepare() instead to reject invalid fmts such
as %0 and similar.


  net/bpf/test_run.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index c9fdcc5cdce1..78258a822a5c 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -845,6 +845,9 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct 
__sk_buff *__skb)
  {
  struct qdisc_skb_cb *cb = (struct qdisc_skb_cb *)skb->cb;
+    if (!skb->len)
+    return -EINVAL;
+
  if (!__skb)
  return 0;





[GIT PULL] tracing/tools: Updates for 6.7

2023-10-30 Thread Daniel Bristot de Oliveira
Steven,

Tracing tools changes for 6.7:

RTLA:
  - On rtla/utils.c, initialize the 'found' variable to avoid garbage
when a mount point is not found.

Verification:
  - Remove duplicated imports on dot2k python script


Please pull the latest tracing-tools-v6.7 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/bristot/linux.git
tracing-tools-v6.7

Tag SHA1: eadb7e76bc7ce4174d4905a29a4a07cd835508fe
Head SHA1: 696444a544ecd6d62c1edc89516b376cefb28929


Alessandro Carminati (Red Hat) (1):
  verification/dot2k: Delete duplicate imports

Colin Ian King (1):
  rtla: Fix uninitialized variable found


 tools/tracing/rtla/src/utils.c | 2 +-
 tools/verification/dot2/dot2k  | 2 --
 2 files changed, 1 insertion(+), 3 deletions(-)
---
diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c
index 623a38908ed5..c769d7b3842c 100644
--- a/tools/tracing/rtla/src/utils.c
+++ b/tools/tracing/rtla/src/utils.c
@@ -538,7 +538,7 @@ static const int find_mount(const char *fs, char *mp, int 
sizeof_mp)
 {
char mount_point[MAX_PATH];
char type[100];
-   int found;
+   int found = 0;
FILE *fp;
 
fp = fopen("/proc/mounts", "r");
diff --git a/tools/verification/dot2/dot2k b/tools/verification/dot2/dot2k
index 9dcd38abe20a..d4d7e52d549e 100644
--- a/tools/verification/dot2/dot2k
+++ b/tools/verification/dot2/dot2k
@@ -15,8 +15,6 @@ if __name__ == '__main__':
 import os
 import platform
 import sys
-import sys
-import argparse
 
 parser = argparse.ArgumentParser(description='transform .dot file into 
kernel rv monitor')
 parser.add_argument('-d', "--dot", dest="dot_file", required=True)



Re: [PATCH v5] scripts/link-vmlinux.sh: Add alias to duplicate symbols for kallsyms

2023-10-16 Thread Daniel Bristot de Oliveira


>> In any case, as you've pointed out, duplicates can arise from names in code
>> that is not intended to be a module.
>> Therefore, relying solely on the module name would not fully address the
>> problem you initially aimed to solve.
> 
> From my POV:
> 
> The source path and the line number is enough to distinguish duplicate
> symbols even in modules.
> 
> The added module name would just add extra complexity into the kernel
> and tools parsing and using the alias. The tracing tools would need to
> handle the source path and line number anyway for symbols duplicated
> within same module/vmlinux.
> 
> Adding module name for builtin modules might be misleading. It won't
> be clear which symbols are in vmlinux binary and which are in
> real modules.

+1

-- Daniel



Re: [PATCH v1] Ftrace: make sched_wakeup can focus on the target process

2023-10-10 Thread Daniel Bristot de Oliveira
On 10/9/23 17:37, Jinyu Tang wrote:
> $ cyclictest --mlockall --smp --priority=99 &

rtla timerlat -a 

will give you an structured analysis of your latency...

https://bristot.me/linux-scheduling-latency-debug-and-analysis/

-- Daniel



Re: [PATCH V3] tracing/timerlat: Hotplug support for the user-space interface

2023-10-04 Thread Daniel Bristot de Oliveira
On 10/4/23 03:03, Steven Rostedt wrote:
> On Fri, 29 Sep 2023 17:02:46 +0200
> Daniel Bristot de Oliveira  wrote:
> 
>> The osnoise/per_cpu/CPU$/timerlat_fd is create for each possible
>> CPU, but it might create confusion if the CPU is not online.
>>
>> Create the file only for online CPUs, also follow hotplug by
>> creating and deleting as CPUs come and go.
>>
>> Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface")
> 
> Is this a fix that needs to go in now and Cc'd to stable? Or is this
> something that can wait till the next merge window?

We can wait for the next merge window... it is a non-trivial fix.

-- Daniel
> -- Steve




[GIT PULL] rtla: Fixes for 6.6

2023-10-04 Thread Daniel Bristot de Oliveira
Steven,

Timerlat auto-analysis:

  - Timerlat is reporting thread interference time without thread noise
events occurrence. It was caused because the thread interference variable
was not reset after the analysis of a timerlat activation that did not
hit the threshold.

  - The IRQ handler delay is estimated from the delta of the IRQ latency
reported by timerlat, and the timestamp from IRQ handler start event.
If the delta is near-zero, the drift from the external clock and the
trace event and/or the overhead can cause the value to be negative.
If the value is negative, print a zero-delay.

  - IRQ handlers happening after the timerlat thread event but before
the stop tracing were being reported as IRQ that happened before the
*current* IRQ occurrence. Ignore Previous IRQ noise in this condition
because they are valid only for the *next* timerlat activation.

Timerlat user-space:

  - Timerlat is stopping all user-space thread if a CPU becomes
offline. Do not stop the entire tool if a CPU is/become offline,
but only the thread of the unavailable CPU. Stop the tool only,
if all threads leave because the CPUs become/are offline.

man-pages:

  - Fix command line example in timerlat hist man page.


Please pull the latest rtla-v6.6-fixes tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/bristot/linux.git
rtla-v6.6-fixes

Tag SHA1: 6a0df51b5c0a075a553a5ad73b1fd421f559eb6b
Head SHA1: 81ec384b80ffbda752c230778d39ea620c7e3bcf


Daniel Bristot de Oliveira (4):
  rtla/timerlat_aa: Zero thread sum after every sample analysis
  rtla/timerlat_aa: Fix negative IRQ delay
  rtla/timerlat_aa: Fix previous IRQ delay for IRQs that happens after 
thread sample
  rtla/timerlat: Do not stop user-space if a cpu is offline

Xie XiuQi (1):
  rtla: fix a example in rtla-timerlat-hist.rst


 Documentation/tools/rtla/rtla-timerlat-hist.rst |  4 ++--
 tools/tracing/rtla/src/timerlat_aa.c| 32 -
 tools/tracing/rtla/src/timerlat_u.c |  6 +++--
 3 files changed, 32 insertions(+), 10 deletions(-)
---
diff --git a/Documentation/tools/rtla/rtla-timerlat-hist.rst 
b/Documentation/tools/rtla/rtla-timerlat-hist.rst
index 057db78d4095..03b7f3deb069 100644
--- a/Documentation/tools/rtla/rtla-timerlat-hist.rst
+++ b/Documentation/tools/rtla/rtla-timerlat-hist.rst
@@ -36,11 +36,11 @@ EXAMPLE
 In the example below, **rtla timerlat hist** is set to run for *10* minutes,
 in the cpus *0-4*, *skipping zero* only lines. Moreover, **rtla timerlat
 hist** will change the priority of the *timerlat* threads to run under
-*SCHED_DEADLINE* priority, with a *10us* runtime every *1ms* period. The
+*SCHED_DEADLINE* priority, with a *100us* runtime every *1ms* period. The
 *1ms* period is also passed to the *timerlat* tracer. Auto-analysis is disabled
 to reduce overhead ::
 
-  [root@alien ~]# timerlat hist -d 10m -c 0-4 -P d:100us:1ms -p 1ms --no-aa
+  [root@alien ~]# timerlat hist -d 10m -c 0-4 -P d:100us:1ms -p 1000 --no-aa
   # RTLA timerlat histogram
   # Time unit is microseconds (us)
   # Duration:   0 00:10:00
diff --git a/tools/tracing/rtla/src/timerlat_aa.c 
b/tools/tracing/rtla/src/timerlat_aa.c
index e0ffe69c271c..7093fd5333be 100644
--- a/tools/tracing/rtla/src/timerlat_aa.c
+++ b/tools/tracing/rtla/src/timerlat_aa.c
@@ -159,6 +159,7 @@ static int timerlat_aa_irq_latency(struct timerlat_aa_data 
*taa_data,
taa_data->thread_nmi_sum = 0;
taa_data->thread_irq_sum = 0;
taa_data->thread_softirq_sum = 0;
+   taa_data->thread_thread_sum = 0;
taa_data->thread_blocking_duration = 0;
taa_data->timer_irq_start_time = 0;
taa_data->timer_irq_duration = 0;
@@ -337,7 +338,23 @@ static int timerlat_aa_irq_handler(struct trace_seq *s, 
struct tep_record *recor
taa_data->timer_irq_start_time = start;
taa_data->timer_irq_duration = duration;
 
-   taa_data->timer_irq_start_delay = 
taa_data->timer_irq_start_time - expected_start;
+   /*
+* We are dealing with two different clock sources: the
+* external clock source that timerlat uses as a reference
+* and the clock used by the tracer. There are also two
+* moments: the time reading the clock and the timer in
+* which the event is placed in the buffer (the trace
+* event timestamp). If the processor is slow or there
+* is some hardware noise, the difference between the
+* timestamp and the external clock read can be longer
+* than the IRQ handler delay, resulting in a negative
+* time. If so, set IRQ start delay as 0. In the end,
+* it is less relevant than the noise.
+*/
+   if (expected_start

[ANNOUNCE] 4.19.295-rt129

2023-09-30 Thread Daniel Wagner
Hello RT-list!

I'm pleased to announce the 4.19.295-rt129 stable release.

This is just an update to the v4.19.295 stable release. No RT
specific changes.

You can get this release via the git tree at:

  git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

  branch: v4.19-rt
  Head SHA1: b285af6da7f3b111dd0c285492defb01a4dc91ad

Or to build 4.19.295-rt129 directly, the following patches should be applied:

  https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.19.tar.xz

  https://www.kernel.org/pub/linux/kernel/v4.x/patch-4.19.295.xz

  
https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.295-rt129.patch.xz

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel


[PATCH V3] tracing/timerlat: Hotplug support for the user-space interface

2023-09-29 Thread Daniel Bristot de Oliveira
The osnoise/per_cpu/CPU$/timerlat_fd is create for each possible
CPU, but it might create confusion if the CPU is not online.

Create the file only for online CPUs, also follow hotplug by
creating and deleting as CPUs come and go.

Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface")
Signed-off-by: Daniel Bristot de Oliveira 
---

Changes from V2:
  - Better split the code into the generic (per_cpu/cpu$)
and timerlat (/timerlat_fd) specific function (Daniel)
  - Fixed a cpus_read_lock/unlock() usage (kbuild test)
  Link: 
https://lore.kernel.org/lkml/6b9a5f306e488bc77bf8521faeade420a0adf3e4.1695224204.git.bris...@kernel.org/

Changes from V1:
  - Fix compilation issue when !HOTPLUG
  - Fix init interface | hotplug race
  Link: 
https://lore.kernel.org/lkml/b619d9fd08a3bb47018cf40afa95783844a3c1fd.1694789910.git.bris...@kernel.org/

 kernel/trace/trace_osnoise.c | 149 ---
 1 file changed, 121 insertions(+), 28 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index bd0d01d00fb9..f375fb1e721d 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -229,6 +229,19 @@ static inline struct osnoise_variables 
*this_cpu_osn_var(void)
 }
 
 #ifdef CONFIG_TIMERLAT_TRACER
+
+/*
+ * osnoise/per_cpu dir
+ */
+static struct dentry   *osnoise_per_cpu_fd;
+
+struct osnoise_per_cpu_dir {
+   struct dentry *root;
+   struct dentry *timerlat_fd;
+};
+
+static DEFINE_PER_CPU(struct osnoise_per_cpu_dir, osnoise_per_cpu_dir);
+
 /*
  * Runtime information for the timer mode.
  */
@@ -2000,6 +2013,9 @@ static int start_kthread(unsigned int cpu)
char comm[24];
 
if (timerlat_enabled()) {
+   if (!test_bit(OSN_WORKLOAD, _options))
+   return 0;
+
snprintf(comm, 24, "timerlat/%d", cpu);
main = timerlat_main;
} else {
@@ -2065,19 +2081,99 @@ static int start_per_cpu_kthreads(void)
return retval;
 }
 
+#ifdef CONFIG_TIMERLAT_TRACER
+static struct dentry *osnoise_get_per_cpu_dir(long cpu)
+{
+   struct dentry *cpu_dir_entry = per_cpu_ptr(_per_cpu_dir, 
cpu)->root;
+   char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */
+
+   if (cpu_dir_entry)
+   return cpu_dir_entry;
+
+   if (!osnoise_per_cpu_fd)
+   return NULL;
+
+   snprintf(cpu_str, 30, "cpu%ld", cpu);
+   cpu_dir_entry = tracefs_create_dir(cpu_str, osnoise_per_cpu_fd);
+   if (!cpu_dir_entry)
+   return NULL;
+
+   per_cpu_ptr(_per_cpu_dir, cpu)->root = cpu_dir_entry;
+
+   return cpu_dir_entry;
+}
+
+static void osnoise_put_per_cpu_dir(long cpu)
+{
+   struct dentry *cpu_dir_entry = per_cpu_ptr(_per_cpu_dir, 
cpu)->root;
+
+   if (!cpu_dir_entry)
+   return;
+
+   tracefs_remove(cpu_dir_entry);
+
+   per_cpu_ptr(_per_cpu_dir, cpu)->root = NULL;
+}
+
+static const struct file_operations timerlat_fd_fops;
+
+static int timerlat_add_per_cpu_interface(long cpu)
+{
+   struct dentry *cpu_dir_entry = osnoise_get_per_cpu_dir(cpu);
+   struct dentry *timerlat_fd;
+
+   lockdep_assert_cpus_held();
+
+   if (!cpu_dir_entry)
+   return -ENOMEM;
+
+   timerlat_fd = trace_create_file("timerlat_fd", TRACE_MODE_READ, 
cpu_dir_entry, NULL,
+   _fd_fops);
+   if (!timerlat_fd)
+   goto out_put;
+
+   per_cpu_ptr(_per_cpu_dir, cpu)->timerlat_fd = timerlat_fd;
+
+   /* Record the CPU */
+   d_inode(timerlat_fd)->i_cdev = (void *)(cpu);
+
+   return 0;
+
+out_put:
+   osnoise_put_per_cpu_dir(cpu);
+   return -ENOMEM;
+}
+
+static void timerlat_rm_per_cpu_interface(long cpu)
+{
+   struct dentry *timerlat_fd = per_cpu_ptr(_per_cpu_dir, 
cpu)->timerlat_fd;
+
+   if (timerlat_fd) {
+   tracefs_remove(timerlat_fd);
+   per_cpu_ptr(_per_cpu_dir, cpu)->timerlat_fd = NULL;
+   }
+
+   osnoise_put_per_cpu_dir(cpu);
+}
+#elif defined(CONFIG_HOTPLUG_CPU)
+static int timerlat_add_per_cpu_interface(long cpu) { return 0; };
+static void timerlat_rm_per_cpu_interface(long cpu) {};
+#endif
+
 #ifdef CONFIG_HOTPLUG_CPU
 static void osnoise_hotplug_workfn(struct work_struct *dummy)
 {
unsigned int cpu = smp_processor_id();
 
mutex_lock(_types_lock);
-
-   if (!osnoise_has_registered_instances())
-   goto out_unlock_trace;
-
mutex_lock(_lock);
cpus_read_lock();
 
+   timerlat_add_per_cpu_interface(cpu);
+
+   if (!osnoise_has_registered_instances())
+   goto out_unlock;
+
if (!cpumask_test_cpu(cpu, _cpumask))
goto out_unlock;
 
@@ -2086,7 +2182,6 @@ static void osnoise_hotplug_workfn(struct work_struct 
*dummy)
 out_unlock:
cpus_read_unlock();
mutex_un

[PATCH RT 0/1] Linux v4.19.295-rt129-rc1

2023-09-25 Thread Daniel Wagner
Dear RT Folks,

This is the RT stable review cycle of patch 4.19.295-rt129-rc1.

Please scream at me if I messed something up. Please test the patches
too.

The -rc release is also available on kernel.org

  https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

on the v4.19-rt-next branch.

If all goes well, this patch will be converted to the next main
release on 2023-10-02.

Signing key fingerprint:

  5BF6 7BC5 0826 72CA BB45  ACAE 587C 5ECA 5D0A 306C

All keys used for the above files and repositories can be found on the
following git repository:

   git://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git

Enjoy!
Daniel

Changes from v4.19.292-rt128:


Daniel Wagner (1):
  Linux 4.19.295-rt129

 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.41.0



[PATCH RT 1/1] Linux 4.19.295-rt129

2023-09-25 Thread Daniel Wagner
v4.19.295-rt129-rc1 stable review patch.
If anyone has any objections, please let me know.

---


Signed-off-by: Daniel Wagner 
---
 localversion-rt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/localversion-rt b/localversion-rt
index 6d2a676e2033..90303f5aabcf 100644
--- a/localversion-rt
+++ b/localversion-rt
@@ -1 +1 @@
--rt128
+-rt129
-- 
2.41.0



[PATCH V2] tracing/timerlat: Hotplug support for the user-space interface

2023-09-20 Thread Daniel Bristot de Oliveira
The osnoise/per_cpu/CPU$/timerlat_fd is create for each possible
CPU, but it might create confusion if the CPU is not online.

Create the file only for online CPUs, also follow hotplug by
creating and deleting as CPUs come and go.

Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface")
Signed-off-by: Daniel Bristot de Oliveira 
---
  Changes from V1:
- Fix compilation issue when !HOTPLUG
- Fix init interface | hotplug race
Link: 
https://lore.kernel.org/lkml/b619d9fd08a3bb47018cf40afa95783844a3c1fd.1694789910.git.bris...@kernel.org/

 kernel/trace/trace_osnoise.c | 112 +++
 1 file changed, 86 insertions(+), 26 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index bd0d01d00fb9..8422562d9864 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -229,6 +229,19 @@ static inline struct osnoise_variables 
*this_cpu_osn_var(void)
 }
 
 #ifdef CONFIG_TIMERLAT_TRACER
+
+/*
+ * osnoise/per_cpu dir
+ */
+static struct dentry   *osnoise_per_cpu_fd;
+
+struct osnoise_per_cpu_dir {
+   struct dentry *root;
+   struct dentry *timerlat_fd;
+};
+
+static DEFINE_PER_CPU(struct osnoise_per_cpu_dir, osnoise_per_cpu_dir);
+
 /*
  * Runtime information for the timer mode.
  */
@@ -2000,6 +2013,9 @@ static int start_kthread(unsigned int cpu)
char comm[24];
 
if (timerlat_enabled()) {
+   if (!test_bit(OSN_WORKLOAD, _options))
+   return 0;
+
snprintf(comm, 24, "timerlat/%d", cpu);
main = timerlat_main;
} else {
@@ -2065,19 +2081,64 @@ static int start_per_cpu_kthreads(void)
return retval;
 }
 
+#ifdef CONFIG_TIMERLAT_TRACER
+static const struct file_operations timerlat_fd_fops;
+static int timerlat_add_per_cpu_interface(long cpu)
+{
+   struct dentry *timerlat_fd, *cpu_dir_fd;
+   char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */
+
+   if (!osnoise_per_cpu_fd)
+   return 0;
+
+   snprintf(cpu_str, 30, "cpu%ld", cpu);
+   cpu_dir_fd = tracefs_create_dir(cpu_str, osnoise_per_cpu_fd);
+
+   if (cpu_dir_fd) {
+   timerlat_fd = trace_create_file("timerlat_fd", TRACE_MODE_READ,
+  cpu_dir_fd, NULL, 
_fd_fops);
+   WARN_ON_ONCE(!timerlat_fd);
+   per_cpu_ptr(_per_cpu_dir, cpu)->root = cpu_dir_fd;
+   per_cpu_ptr(_per_cpu_dir, cpu)->timerlat_fd = 
timerlat_fd;
+
+   /* Record the CPU */
+   d_inode(timerlat_fd)->i_cdev = (void *)(cpu);
+
+   return 0;
+   }
+
+   return -ENOMEM;
+}
+
+static void timerlat_rm_per_cpu_interface(long cpu)
+{
+   struct dentry *cpu_dir = per_cpu_ptr(_per_cpu_dir, cpu)->root;
+
+   if (cpu_dir) {
+   tracefs_remove(cpu_dir);
+   per_cpu_ptr(_per_cpu_dir, cpu)->root = NULL;
+   per_cpu_ptr(_per_cpu_dir, cpu)->timerlat_fd = NULL;
+   }
+}
+#elif defined(CONFIG_HOTPLUG_CPU)
+static int timerlat_add_per_cpu_interface(long cpu) { return 0; };
+static void timerlat_rm_per_cpu_interface(long cpu) {};
+#endif
+
 #ifdef CONFIG_HOTPLUG_CPU
 static void osnoise_hotplug_workfn(struct work_struct *dummy)
 {
unsigned int cpu = smp_processor_id();
 
mutex_lock(_types_lock);
-
-   if (!osnoise_has_registered_instances())
-   goto out_unlock_trace;
-
mutex_lock(_lock);
cpus_read_lock();
 
+   timerlat_add_per_cpu_interface(cpu);
+
+   if (!osnoise_has_registered_instances())
+   goto out_unlock;
+
if (!cpumask_test_cpu(cpu, _cpumask))
goto out_unlock;
 
@@ -2086,7 +2147,6 @@ static void osnoise_hotplug_workfn(struct work_struct 
*dummy)
 out_unlock:
cpus_read_unlock();
mutex_unlock(_lock);
-out_unlock_trace:
mutex_unlock(_types_lock);
 }
 
@@ -2106,6 +2166,7 @@ static int osnoise_cpu_init(unsigned int cpu)
  */
 static int osnoise_cpu_die(unsigned int cpu)
 {
+   timerlat_rm_per_cpu_interface(cpu);
stop_kthread(cpu);
return 0;
 }
@@ -2708,10 +2769,7 @@ static int init_timerlat_stack_tracefs(struct dentry 
*top_dir)
 
 static int osnoise_create_cpu_timerlat_fd(struct dentry *top_dir)
 {
-   struct dentry *timerlat_fd;
-   struct dentry *per_cpu;
-   struct dentry *cpu_dir;
-   char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */
+   int retval;
long cpu;
 
/*
@@ -2720,29 +2778,24 @@ static int osnoise_create_cpu_timerlat_fd(struct dentry 
*top_dir)
 * Because osnoise/timerlat have a single workload, having
 * multiple files like these are wast of memory.
 */
-   per_cpu = tracefs_create_dir("per_cpu", top_dir);
-   if (!per_cpu)
+   osnoise_per_cpu_fd = tra

Re: [PATCH] tracing/timerlat: Hotplug support for the user-space interface

2023-09-18 Thread Daniel Bristot de Oliveira
On 9/16/23 02:21, kernel test robot wrote:
> Hi Daniel,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on linus/master]
> [also build test WARNING on v6.6-rc1 next-20230915]
> [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#_base_tree_information]
> 
> url:
> https://github.com/intel-lab-lkp/linux/commits/Daniel-Bristot-de-Oliveira/tracing-timerlat-Hotplug-support-for-the-user-space-interface/20230915-230157
> base:   linus/master
> patch link:
> https://lore.kernel.org/r/b619d9fd08a3bb47018cf40afa95783844a3c1fd.1694789910.git.bristot%40kernel.org
> patch subject: [PATCH] tracing/timerlat: Hotplug support for the user-space 
> interface
> config: um-randconfig-002-20230916 
> (https://download.01.org/0day-ci/archive/20230916/202309160854.saw0rium-...@intel.com/config)
> 

^^ The config has no timerlat and no hotplug...

compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
> reproduce (this is a W=1 build): 
> (https://download.01.org/0day-ci/archive/20230916/202309160854.saw0rium-...@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version 
> of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot 
> | Closes: 
> https://lore.kernel.org/oe-kbuild-all/202309160854.saw0rium-...@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>>> kernel/trace/trace_osnoise.c:2125:13: warning: 
>>> 'timerlat_rm_per_cpu_interface' defined but not used [-Wunused-function]
> 2125 | static void timerlat_rm_per_cpu_interface(long cpu) {};
>  | ^
>>> kernel/trace/trace_osnoise.c:2124:12: warning: 
>>> 'timerlat_add_per_cpu_interface' defined but not used [-Wunused-function]
> 2124 | static int timerlat_add_per_cpu_interface(long cpu) { return 0; };
>  |^~

These functions are called when hotplug but no timerlat when no hotplug: 
defined but not used.

> 
> vim +/timerlat_rm_per_cpu_interface +2125 kernel/trace/trace_osnoise.c
> 
>   2112
>   2113static void timerlat_rm_per_cpu_interface(long cpu)
>   2114{
>   2115struct dentry *cpu_dir = 
> per_cpu_ptr(_per_cpu_dir, cpu)->root;
>   2116
>   2117if (cpu_dir) {
>   2118tracefs_remove(cpu_dir);
>   2119per_cpu_ptr(_per_cpu_dir, cpu)->root = 
> NULL;
>   2120per_cpu_ptr(_per_cpu_dir, 
> cpu)->timerlat_fd = NULL;
>   2121}
>   2122}
>   2123    #else
>> 2124 static int timerlat_add_per_cpu_interface(long cpu) { return 0; };
>> 2125 static void timerlat_rm_per_cpu_interface(long cpu) {};
>   2126#endif
>   2127
> 

Fixing it.

-- Daniel


[PATCH] tracing/timerlat: Hotplug support for the user-space interface

2023-09-15 Thread Daniel Bristot de Oliveira
The osnoise/per_cpu/CPU$/timerlat_fd is create for each possible
CPU, but it might create confusion if the CPU is not online.

Create the file only for online CPUs, also follow hotplug by
creating and deleting as CPUs come and go.

Fixes: e88ed227f639 ("tracing/timerlat: Add user-space interface")
Signed-off-by: Daniel Bristot de Oliveira 
---
 kernel/trace/trace_osnoise.c | 101 ++-
 1 file changed, 77 insertions(+), 24 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index bd0d01d00fb9..1af01eec3e36 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -229,6 +229,19 @@ static inline struct osnoise_variables 
*this_cpu_osn_var(void)
 }
 
 #ifdef CONFIG_TIMERLAT_TRACER
+
+/*
+ * osnoise/per_cpu dir
+ */
+static struct dentry   *osnoise_per_cpu_fd;
+
+struct osnoise_per_cpu_dir {
+   struct dentry *root;
+   struct dentry *timerlat_fd;
+};
+
+static DEFINE_PER_CPU(struct osnoise_per_cpu_dir, osnoise_per_cpu_dir);
+
 /*
  * Runtime information for the timer mode.
  */
@@ -2000,6 +2013,9 @@ static int start_kthread(unsigned int cpu)
char comm[24];
 
if (timerlat_enabled()) {
+   if (!test_bit(OSN_WORKLOAD, _options))
+   return 0;
+
snprintf(comm, 24, "timerlat/%d", cpu);
main = timerlat_main;
} else {
@@ -2065,19 +2081,64 @@ static int start_per_cpu_kthreads(void)
return retval;
 }
 
+#ifdef CONFIG_TIMERLAT_TRACER
+static const struct file_operations timerlat_fd_fops;
+static int timerlat_add_per_cpu_interface(long cpu)
+{
+   struct dentry *timerlat_fd, *cpu_dir_fd;
+   char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */
+
+   if (!osnoise_per_cpu_fd)
+   return 0;
+
+   snprintf(cpu_str, 30, "cpu%ld", cpu);
+   cpu_dir_fd = tracefs_create_dir(cpu_str, osnoise_per_cpu_fd);
+
+   if (cpu_dir_fd) {
+   timerlat_fd = trace_create_file("timerlat_fd", TRACE_MODE_READ,
+  cpu_dir_fd, NULL, 
_fd_fops);
+   WARN_ON_ONCE(!timerlat_fd);
+   per_cpu_ptr(_per_cpu_dir, cpu)->root = cpu_dir_fd;
+   per_cpu_ptr(_per_cpu_dir, cpu)->timerlat_fd = 
timerlat_fd;
+
+   /* Record the CPU */
+   d_inode(timerlat_fd)->i_cdev = (void *)(cpu);
+
+   return 0;
+   }
+
+   return -ENOMEM;
+}
+
+static void timerlat_rm_per_cpu_interface(long cpu)
+{
+   struct dentry *cpu_dir = per_cpu_ptr(_per_cpu_dir, cpu)->root;
+
+   if (cpu_dir) {
+   tracefs_remove(cpu_dir);
+   per_cpu_ptr(_per_cpu_dir, cpu)->root = NULL;
+   per_cpu_ptr(_per_cpu_dir, cpu)->timerlat_fd = NULL;
+   }
+}
+#else
+static int timerlat_add_per_cpu_interface(long cpu) { return 0; };
+static void timerlat_rm_per_cpu_interface(long cpu) {};
+#endif
+
 #ifdef CONFIG_HOTPLUG_CPU
 static void osnoise_hotplug_workfn(struct work_struct *dummy)
 {
unsigned int cpu = smp_processor_id();
 
mutex_lock(_types_lock);
-
-   if (!osnoise_has_registered_instances())
-   goto out_unlock_trace;
-
mutex_lock(_lock);
cpus_read_lock();
 
+   timerlat_add_per_cpu_interface(cpu);
+
+   if (!osnoise_has_registered_instances())
+   goto out_unlock;
+
if (!cpumask_test_cpu(cpu, _cpumask))
goto out_unlock;
 
@@ -2086,7 +2147,6 @@ static void osnoise_hotplug_workfn(struct work_struct 
*dummy)
 out_unlock:
cpus_read_unlock();
mutex_unlock(_lock);
-out_unlock_trace:
mutex_unlock(_types_lock);
 }
 
@@ -2106,6 +2166,7 @@ static int osnoise_cpu_init(unsigned int cpu)
  */
 static int osnoise_cpu_die(unsigned int cpu)
 {
+   timerlat_rm_per_cpu_interface(cpu);
stop_kthread(cpu);
return 0;
 }
@@ -2708,10 +2769,7 @@ static int init_timerlat_stack_tracefs(struct dentry 
*top_dir)
 
 static int osnoise_create_cpu_timerlat_fd(struct dentry *top_dir)
 {
-   struct dentry *timerlat_fd;
-   struct dentry *per_cpu;
-   struct dentry *cpu_dir;
-   char cpu_str[30]; /* see trace.c: tracing_init_tracefs_percpu() */
+   int retval;
long cpu;
 
/*
@@ -2720,29 +2778,24 @@ static int osnoise_create_cpu_timerlat_fd(struct dentry 
*top_dir)
 * Because osnoise/timerlat have a single workload, having
 * multiple files like these are wast of memory.
 */
-   per_cpu = tracefs_create_dir("per_cpu", top_dir);
-   if (!per_cpu)
+   osnoise_per_cpu_fd = tracefs_create_dir("per_cpu", top_dir);
+   if (!osnoise_per_cpu_fd)
return -ENOMEM;
 
-   for_each_possible_cpu(cpu) {
-   snprintf(cpu_str, 30, "cpu%ld", cpu);
-   cpu_dir = tracefs_cre

[PATCH] tools/rtla: Do not stop user-space if a cpu is offline

2023-09-15 Thread Daniel Bristot de Oliveira
If no CPU list is passed, timerlat in user-space will dispatch
one thread per sysconf(_SC_NPROCESSORS_CONF). However, not all
CPU might be available, for instance, if HT is disabled.

Currently, rtla timerlat is stopping the session if an user-space
thread cannot set affinity to a CPU, or if a running user-space
thread is killed. However, this is too restrictive.

So, reduce the error to a debug message, and rtla timerlat run as
long as there is at least one user-space thread alive.

Fixes: cdca4f4e5e8e ("rtla/timerlat_top: Add timerlat user-space support")
Signed-off-by: Daniel Bristot de Oliveira 
---
 tools/tracing/rtla/src/timerlat_u.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/tracing/rtla/src/timerlat_u.c 
b/tools/tracing/rtla/src/timerlat_u.c
index 05e310696dd5..01dbf9a6b5a5 100644
--- a/tools/tracing/rtla/src/timerlat_u.c
+++ b/tools/tracing/rtla/src/timerlat_u.c
@@ -45,7 +45,7 @@ static int timerlat_u_main(int cpu, struct timerlat_u_params 
*params)
 
retval = sched_setaffinity(gettid(), sizeof(set), );
if (retval == -1) {
-   err_msg("Error setting user thread affinity\n");
+   debug_msg("Error setting user thread affinity %d, is the CPU 
online?\n", cpu);
exit(1);
}
 
@@ -193,7 +193,9 @@ void *timerlat_u_dispatcher(void *data)
procs_count--;
}
}
-   break;
+
+   if (!procs_count)
+   break;
}
 
sleep(1);
-- 
2.38.1



Re: [PATCH v2] verification/dot2k: Delete duplicate imports

2023-09-14 Thread Daniel Bristot de Oliveira
On 9/6/23 17:57, Alessandro Carminati (Red Hat) wrote:
> The presence of duplicate import lines appears to be a typo.
> Removing them.
> 
> Fixes: 24bce201d798 ("tools/rv: Add dot2k")
> Signed-off-by: Alessandro Carminati (Red Hat) 

Queued, thanks!

https://git.kernel.org/pub/scm/linux/kernel/git/bristot/linux.git/commit/?h=tools/verification=5a9587fea055163026b6d22d593fc64ed04de3a6

-- Daniel



Re: [PATCH 2/2] arm64: dts: imx8mp: add reserve-memory nodes for DSP

2023-09-12 Thread Daniel Baluta
On Tue, Sep 12, 2023 at 12:54 PM Iuliana Prodan  wrote:
>
> On 9/12/2023 11:26 AM, Krzysztof Kozlowski wrote:
> > On 12/09/2023 10:13, Iuliana Prodan wrote:
> >> On 9/12/2023 10:07 AM, Krzysztof Kozlowski wrote:
> >>> On 12/09/2023 00:44, Iuliana Prodan (OSS) wrote:
>  From: Iuliana Prodan 
> 
>  Add the reserve-memory nodes used by DSP when the rpmsg
>  feature is enabled.
>  These can be later used in a dsp node, like:
>  dsp: dsp@3b6e8000 {
> compatible = "fsl,imx8mp-dsp";
> reg = <0x3b6e8000 0x88000>;
> mbox-names = "tx0", "rx0", "rxdb0";
> mboxes = < 2 0>, < 2 1>,
> < 3 0>, < 3 1>;
> memory-region = <_vdev0buffer>, <_vdev0vring0>,
> <_vdev0vring1>, <_reserved>;
> status = "okay";
> >>> Drop this example from commit msg, useless and not really correct.
> >> Ok, will drop it. But this is a correct example, is just incomplete.
> > No, status=okay is redundant, thus it is not a correct example.
> ok
>  };
> 
>  Signed-off-by: Iuliana Prodan 
>  ---
> arch/arm64/boot/dts/freescale/imx8mp.dtsi | 12 
> 1 file changed, 12 insertions(+)
> 
>  diff --git a/arch/arm64/boot/dts/freescale/imx8mp.dtsi 
>  b/arch/arm64/boot/dts/freescale/imx8mp.dtsi
>  index cc406bb338fe..eedc1921af62 100644
>  --- a/arch/arm64/boot/dts/freescale/imx8mp.dtsi
>  +++ b/arch/arm64/boot/dts/freescale/imx8mp.dtsi
>  @@ -210,6 +210,18 @@
> dsp_reserved: dsp@9240 {
> reg = <0 0x9240 0 0x200>;
> no-map;
> >>> Please test the patches before sending. This does not build.
> >> I've tested on remoteproc tree, but it seems I missed a bracket when
> >> sending upstream. Sorry abut this, will fix it in v2.
> > No, this is not how testing works. You must test this patch. This means
> > you tested something, then ported patch to entirely different tree,
> > resolved conflicts in buggy way and send it without testing. Nope.
> >
> >> Should I test this on other tree(s)?
> > You test the patch on the tree you send it. What is the point to test it
> > on some old code, cherry-pick with bugs and then send?
> >
> > If you have cross-tree dependencies between subsystem, isn't linux-next
> > for this?

linux-next tree is the tree we want.


Re: [v3,1/3] thermal: mediatek: Relocate driver to mediatek folder

2021-04-20 Thread Daniel Lezcano
On 12/03/2021 04:40, Michael Kao wrote:
> Add Mediatek proprietary folder to upstream more thermal zone and cooler
> drivers. Relocate the original thermal controller driver to it and rename
> as soc_temp.c to show its purpose more clearly.

We already know the purpose :)

soc_temp gives no additional information.

Either keep the name or give the hardware sensor name. It is a driver
directory.

> Signed-off-by: Michael Kao 
> ---
>  drivers/thermal/Kconfig   | 14 ---
>  drivers/thermal/Makefile  |  2 +-
>  drivers/thermal/mediatek/Kconfig  | 23 +++
>  drivers/thermal/mediatek/Makefile |  1 +
>  .../{mtk_thermal.c => mediatek/soc_temp.c}|  0

[ ... ]

vv


> +config MTK_THERMAL
> + tristate "Mediatek thermal drivers"
> + depends on THERMAL_OF
> + help
> +   This is the option for Mediatek thermal software
> +   solutions. Please enable corresponding options to
> +   get temperature information from thermal sensors or
> +   turn on throttle mechaisms for thermal mitigation.
> +
> +if MTK_THERMAL


^^

All the above not needed.

> +config MTK_SOC_THERMAL
> + tristate "Temperature sensor driver for mediatek SoCs"
> + depends on HAS_IOMEM
> + depends on NVMEM
> + depends on RESET_CONTROLLER
> + help
> +   Enable this option if you want to get SoC temperature
> +   information for Mediatek platforms. This driver
> +   configures thermal controllers to collect temperature
> +   via AUXADC interface.
> +
> +endif
> diff --git a/drivers/thermal/mediatek/Makefile 
> b/drivers/thermal/mediatek/Makefile
> new file mode 100644
> index ..f75313ddce5e
> --- /dev/null
> +++ b/drivers/thermal/mediatek/Makefile
> @@ -0,0 +1 @@
> +obj-$(CONFIG_MTK_SOC_THERMAL)+= soc_temp.o
> diff --git a/drivers/thermal/mtk_thermal.c 
> b/drivers/thermal/mediatek/soc_temp.c
> similarity index 100%
> rename from drivers/thermal/mtk_thermal.c
> rename to drivers/thermal/mediatek/soc_temp.c



-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


Re: [PATCH v2 2/2] thermal: power_allocator: update once cooling devices when temp is low

2021-04-20 Thread Daniel Lezcano
On 20/04/2021 22:01, Lukasz Luba wrote:
> 
> 
> On 4/20/21 4:24 PM, Daniel Lezcano wrote:
>> On 20/04/2021 16:21, Lukasz Luba wrote:
>>> Hi Daniel,
>>>
>>> On 4/20/21 2:30 PM, Daniel Lezcano wrote:
>>>> On 19/04/2021 10:45, Lukasz Luba wrote:
>>>
>>> [snip]

[ ... ]

> 
> That new approach should work. I can test your patch with this new
> functions and re-base my work on top of it.
> Or you like me to write such patch and send it?

At your convenience. I'm pretty busy ATM with more patches to review, so
if you can handle that change that will be nice. Otherwise, I can take
care of it but later.

Thanks

  -- Daniel

-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


Re: [PATCH v2] thermal: mediatek: add sensors-support

2021-04-20 Thread Daniel Lezcano
On 20/04/2021 17:54, Frank Wunderlich wrote:
> From: Frank Wunderlich 
> 
> add HWMON-support to mediateks thermal driver to allow lm-sensors
> userspace tools read soc temperature
> 
> Signed-off-by: Frank Wunderlich 
> ---
> v2: drop ifdef and used devm_thermal_add_hwmon_sysfs
> ---
>  drivers/thermal/mtk_thermal.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> index 149c6d7fd5a0..32be8a715c7d 100644
> --- a/drivers/thermal/mtk_thermal.c
> +++ b/drivers/thermal/mtk_thermal.c
> @@ -23,6 +23,8 @@
>  #include 
>  #include 
>  
> +#include "thermal_hwmon.h"
> +
>  /* AUXADC Registers */
>  #define AUXADC_CON1_SET_V0x008
>  #define AUXADC_CON1_CLR_V0x00c
> @@ -1087,6 +1089,11 @@ static int mtk_thermal_probe(struct platform_device 
> *pdev)
>   goto err_disable_clk_peri_therm;
>   }
>  
> + tzdev->tzp->no_hwmon = false;

^^ you can drop this line

> + ret = devm_thermal_add_hwmon_sysfs(tzdev);
> + if (ret)
> + dev_err(>dev, "error in thermal_add_hwmon_sysfs");
> +
>   return 0;
>  
>  err_disable_clk_peri_therm:
> 


-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


Re: [PATCH v2 1/1] thermal: ti-soc-thermal: Remove duplicated header file inclusion

2021-04-20 Thread Daniel Lezcano
On 06/04/2021 11:19, Zhen Lei wrote:
> Delete one of the header files  that are included
> twice, all included header files are then rearranged alphabetically.

The duplicate header file inclusion has been already fixed in a previous
patch.

Applied this patch by massaging the changelog accordingly and fixing the
conflict.

Thanks

  -- Daniel

-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


Re: Aw: Re: [PATCH] thermal: mediatek: add sensors-support

2021-04-20 Thread Daniel Lezcano
On 20/04/2021 17:24, Frank Wunderlich wrote:
> Am 20. April 2021 17:18:32 MESZ schrieb Daniel Lezcano 
> :
>>
>> Hi Frank,
> 
>> The no_hwmon usage is a bit fuzzy in the thermal core code.
> 
> Maybe add depency in Kconfig? Else we can get undefined symbols on linking
> 
> regards Frank

Nope, there are the stubs in thermal_hwmon.h



-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


Re: [PATCH v2 2/2] thermal: power_allocator: update once cooling devices when temp is low

2021-04-20 Thread Daniel Lezcano
On 20/04/2021 16:21, Lukasz Luba wrote:
> Hi Daniel,
> 
> On 4/20/21 2:30 PM, Daniel Lezcano wrote:
>> On 19/04/2021 10:45, Lukasz Luba wrote:
> 
> [snip]
> 
>>> -    instance->cdev->updated = false;
>>> +    if (update)
>>> +    instance->cdev->updated = false;
>>> +
>>>   mutex_unlock(>cdev->lock);
>>> -    (instance->cdev);
>>> +
>>> +    if (update)
>>> +    thermal_cdev_update(instance->cdev);
>>
>> This cdev update has something bad IMHO. It is protected by a mutex but
>> the 'updated' field is left unprotected before calling
>> thermal_cdev_update().
>>
>> It is not the fault of this code but how the cooling device are updated
>> and how it interacts with the thermal instances.
>>
>> IMO, part of the core code needs to revisited.
> 
> I agree, but please check my comments below.
> 
>>
>> This change tight a bit more the knot.
>>
>> Would it make sense to you if we create a function eg.
>> __thermal_cdev_update()
> 
> I'm not sure if I assume it right that the function would only have the:
> list_for_each_entry(instance, >thermal_instances, cdev_node)
> 
> loop from the thermal_cdev_update(). But if it has only this loop then
> it's too little.
> 
>>
>> And then we have:
>>
>> void thermal_cdev_update(struct thermal_cooling_device *cdev)
>> {
>>  mutex_lock(>lock);
>>  /* cooling device is updated*/
>>  if (cdev->updated) {
>>  mutex_unlock(>lock);
>>  return;
>>  }
>>
>> __thermal_cdev_update(cdev);
>>
>>  thermal_cdev_set_cur_state(cdev, target);
> 
> Here we are actually setting the 'target' state via:
> cdev->ops->set_cur_state(cdev, target)
> 
> then we notify, then updating stats.
> 
>>
>>  cdev->updated = true;
>>  mutex_unlock(>lock);
>>  trace_cdev_update(cdev, target);
> 
> Also this trace is something that I'm using in my tests...

Yeah, I noticed right after sending the comments. All that should be
moved in the lockless function.

So this function becomes:

void thermal_cdev_update(struct thermal_cooling_device *cdev)
{
mutex_lock(>lock);
if (!cdev->updated) {
__thermal_cdev_update(cdev);
cdev->updated = true;
}
mutex_unlock(>lock);

dev_dbg(>device, "set to state %lu\n", target);
}

We end up with the trace_cdev_update(cdev, target) inside the mutex
section but that should be fine.

>>  dev_dbg(>device, "set to state %lu\n", target);
>> }
>>
>> And in this file we do instead:
>>
>> -    instance->cdev->updated = false;
>> +    if (update)
>> +    __thermal_cdev_update(instance->cdev);
>>    mutex_unlock(>cdev->lock);
>> -    thermal_cdev_update(instance->cdev);
> 
> Without the line above, we are not un-throttling the devices.

Is it still true with the amended function thermal_cdev_update() ?


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


Re: Aw: Re: [PATCH] thermal: mediatek: add sensors-support

2021-04-20 Thread Daniel Lezcano


Hi Frank,

On 20/04/2021 16:59, Frank Wunderlich wrote:
> Hi,
> 
>> Gesendet: Dienstag, 20. April 2021 um 14:07 Uhr
>> Von: "Daniel Lezcano" 
> 
>> No #ifdef in C file.
> ...
> 
>> devm_thermal_add_hwmon_sysfs() ?
> 
> based on your comments this should be enough/right?
> 
> #if IS_ENABLED(CONFIG_THERMAL_HWMON)
> tzdev->tzp->no_hwmon = false;> ret = 
> devm_thermal_add_hwmon_sysfs(tzdev);
> if (ret)
> dev_err(>dev, "error in thermal_add_hwmon_sysfs");
> #endif
> 
> if yes i send out v2, at least it works on my device

just the following lines should work:

ret = devm_thermal_add_hwmon_sysfs(tzdev);
if (ret)
dev_err(>dev, "error in thermal_add_hwmon_sysfs");


The no_hwmon usage is a bit fuzzy in the thermal core code.


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


Re: [PATCH v2 2/2] thermal: power_allocator: update once cooling devices when temp is low

2021-04-20 Thread Daniel Lezcano
On 19/04/2021 10:45, Lukasz Luba wrote:
> The cooling device state change generates an event, also when there is no
> need, because temperature is low and device is not throttled. Avoid to
> unnecessary update the cooling device which means also not sending event.
> The cooling device state has not changed because the temperature is still
> below the first activation trip point value, so we can do this.
> Add a tracking mechanism to make sure it updates cooling devices only
> once - when the temperature dropps below first trip point.
> 
> Reported-by: Daniel Lezcano 
> Signed-off-by: Lukasz Luba 
> ---
>  drivers/thermal/gov_power_allocator.c | 14 ++
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/thermal/gov_power_allocator.c 
> b/drivers/thermal/gov_power_allocator.c
> index d393409fb786..f379f1aaa3b5 100644
> --- a/drivers/thermal/gov_power_allocator.c
> +++ b/drivers/thermal/gov_power_allocator.c
> @@ -571,7 +571,7 @@ static void reset_pid_controller(struct 
> power_allocator_params *params)
>   params->prev_err = 0;
>  }
>  
> -static void allow_maximum_power(struct thermal_zone_device *tz)
> +static void allow_maximum_power(struct thermal_zone_device *tz, bool update)
>  {
>   struct thermal_instance *instance;
>   struct power_allocator_params *params = tz->governor_data;
> @@ -594,9 +594,13 @@ static void allow_maximum_power(struct 
> thermal_zone_device *tz)
>*/
>   cdev->ops->get_requested_power(cdev, _power);
>  
> - instance->cdev->updated = false;
> + if (update)
> + instance->cdev->updated = false;
> +
>   mutex_unlock(>cdev->lock);
> - (instance->cdev);
> +
> + if (update)
> + thermal_cdev_update(instance->cdev);

This cdev update has something bad IMHO. It is protected by a mutex but
the 'updated' field is left unprotected before calling
thermal_cdev_update().

It is not the fault of this code but how the cooling device are updated
and how it interacts with the thermal instances.

IMO, part of the core code needs to revisited.

This change tight a bit more the knot.

Would it make sense to you if we create a function eg.
__thermal_cdev_update()

And then we have:

void thermal_cdev_update(struct thermal_cooling_device *cdev)
{
mutex_lock(>lock);
/* cooling device is updated*/
if (cdev->updated) {
mutex_unlock(>lock);
return;
}

__thermal_cdev_update(cdev);

thermal_cdev_set_cur_state(cdev, target);

cdev->updated = true;
mutex_unlock(>lock);
trace_cdev_update(cdev, target);
dev_dbg(>device, "set to state %lu\n", target);
}

And in this file we do instead:

-   instance->cdev->updated = false;
+   if (update)
+   __thermal_cdev_update(instance->cdev);
mutex_unlock(>cdev->lock);
-   thermal_cdev_update(instance->cdev);

>   }
>   mutex_unlock(>lock);
>  }
> @@ -710,6 +714,7 @@ static int power_allocator_throttle(struct 
> thermal_zone_device *tz, int trip)
>   int ret;
>   int switch_on_temp, control_temp;
>   struct power_allocator_params *params = tz->governor_data;
> + bool update;
>  
>   /*
>* We get called for every trip point but we only need to do
> @@ -721,9 +726,10 @@ static int power_allocator_throttle(struct 
> thermal_zone_device *tz, int trip)
>   ret = tz->ops->get_trip_temp(tz, params->trip_switch_on,
>_on_temp);
>   if (!ret && (tz->temperature < switch_on_temp)) {
> + update = (tz->last_temperature >= switch_on_temp);
>   tz->passive = 0;
>   reset_pid_controller(params);
> - allow_maximum_power(tz);
> + allow_maximum_power(tz, update);
>   return 0;
>   }
>  
> 


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


Re: [PATCH] thermal: mediatek: add sensors-support

2021-04-20 Thread Daniel Lezcano
On 20/03/2021 09:06, Frank Wunderlich wrote:
> From: Frank Wunderlich 
> 
> add HWMON-support to mediateks thermanl driver to allow lm-sensors
> userspace tools read soc temperature
> 
> Signed-off-by: Frank Wunderlich 
> ---
>  drivers/thermal/mtk_thermal.c | 22 ++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
> index 149c6d7fd5a0..e22d77d57458 100644
> --- a/drivers/thermal/mtk_thermal.c
> +++ b/drivers/thermal/mtk_thermal.c
> @@ -23,6 +23,8 @@
>  #include 
>  #include 
>  
> +#include "thermal_hwmon.h"
> +
>  /* AUXADC Registers */
>  #define AUXADC_CON1_SET_V0x008
>  #define AUXADC_CON1_CLR_V0x00c
> @@ -983,6 +985,13 @@ static void mtk_thermal_release_periodic_ts(struct 
> mtk_thermal *mt,
>   writel((tmp & (~0x10e)), mt->thermal_base + TEMP_MSRCTL1);
>  }
>  
> +static void mtk_thermal_hwmon_action(void *data)
> +{
> + struct thermal_zone_device *zone = data;
> +
> + thermal_remove_hwmon_sysfs(zone);
> +}
> +
>  static int mtk_thermal_probe(struct platform_device *pdev)
>  {
>   int ret, i, ctrl_id;
> @@ -1087,6 +1096,19 @@ static int mtk_thermal_probe(struct platform_device 
> *pdev)
>   goto err_disable_clk_peri_therm;
>   }
>  
> +#ifdef CONFIG_THERMAL_HWMON

No #ifdef in C file.

> + tzdev->tzp->no_hwmon = false;
> + ret = thermal_add_hwmon_sysfs(tzdev);
> + if (ret)
> + dev_err(>dev, "error in thermal_add_hwmon_sysfs");
> +
> + ret = devm_add_action(>dev, mtk_thermal_hwmon_action, tzdev);

devm_thermal_add_hwmon_sysfs() ?

> + if (ret) {
> + dev_err(>dev, "error in devm_add_action");
> + mtk_thermal_hwmon_action(tzdev);
> + }
> +#endif
> +
>   return 0;
>  
>  err_disable_clk_peri_therm:
> 


-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


Re: [PATCH v5] dma-buf: Add DmaBufTotal counter in meminfo

2021-04-20 Thread Daniel Vetter
On Tue, Apr 20, 2021 at 09:26:00AM +, peter.enderb...@sony.com wrote:
> On 4/20/21 10:58 AM, Daniel Vetter wrote:
> > On Sat, Apr 17, 2021 at 06:38:35PM +0200, Peter Enderborg wrote:
> >> This adds a total used dma-buf memory. Details
> >> can be found in debugfs, however it is not for everyone
> >> and not always available. dma-buf are indirect allocated by
> >> userspace. So with this value we can monitor and detect
> >> userspace applications that have problems.
> >>
> >> Signed-off-by: Peter Enderborg 
> > So there have been tons of discussions around how to track dma-buf and
> > why, and I really need to understand the use-cass here first I think. proc
> > uapi is as much forever as anything else, and depending what you're doing
> > this doesn't make any sense at all:
> >
> > - on most linux systems dma-buf are only instantiated for shared buffer.
> >   So there this gives you a fairly meaningless number and not anything
> >   reflecting gpu memory usage at all.
> >
> > - on Android all buffers are allocated through dma-buf afaik. But there
> >   we've recently had some discussions about how exactly we should track
> >   all this, and the conclusion was that most of this should be solved by
> >   cgroups long term. So if this is for Android, then I don't think adding
> >   random quick stop-gaps to upstream is a good idea (because it's a pretty
> >   long list of patches that have come up on this).
> >
> > So what is this for?
> 
> For the overview. dma-buf today only have debugfs for info. Debugfs
> is not allowed by google to use in andoid. So this aggregate the information
> so we can get information on what going on on the system. 
> 
> And the LKML standard respond to that is "SHOW ME THE CODE".

Yes. Except this extends to how exactly this is supposed to be used in
userspace and acted upon.

> When the top memgc has a aggregated information on dma-buf it is maybe
> a better source to meminfo. But then it also imply that dma-buf requires 
> memcg.
> 
> And I dont see any problem to replace this with something better with it is 
> ready.

The thing is, this is uapi. Once it's merged we cannot, ever, replace it.
It must be kept around forever, or a very close approximation thereof. So
merging this with the justification that we can fix it later on or replace
isn't going to happen.
-Daniel

> 
> > -Daniel
> >
> >> ---
> >>  drivers/dma-buf/dma-buf.c | 12 
> >>  fs/proc/meminfo.c |  5 -
> >>  include/linux/dma-buf.h   |  1 +
> >>  3 files changed, 17 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> >> index f264b70c383e..4dc37cd4293b 100644
> >> --- a/drivers/dma-buf/dma-buf.c
> >> +++ b/drivers/dma-buf/dma-buf.c
> >> @@ -37,6 +37,7 @@ struct dma_buf_list {
> >>  };
> >>  
> >>  static struct dma_buf_list db_list;
> >> +static atomic_long_t dma_buf_global_allocated;
> >>  
> >>  static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int 
> >> buflen)
> >>  {
> >> @@ -79,6 +80,7 @@ static void dma_buf_release(struct dentry *dentry)
> >>if (dmabuf->resv == (struct dma_resv *)[1])
> >>dma_resv_fini(dmabuf->resv);
> >>  
> >> +  atomic_long_sub(dmabuf->size, _buf_global_allocated);
> >>module_put(dmabuf->owner);
> >>kfree(dmabuf->name);
> >>kfree(dmabuf);
> >> @@ -586,6 +588,7 @@ struct dma_buf *dma_buf_export(const struct 
> >> dma_buf_export_info *exp_info)
> >>mutex_lock(_list.lock);
> >>list_add(>list_node, _list.head);
> >>mutex_unlock(_list.lock);
> >> +  atomic_long_add(dmabuf->size, _buf_global_allocated);
> >>  
> >>return dmabuf;
> >>  
> >> @@ -1346,6 +1349,15 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct 
> >> dma_buf_map *map)
> >>  }
> >>  EXPORT_SYMBOL_GPL(dma_buf_vunmap);
> >>  
> >> +/**
> >> + * dma_buf_allocated_pages - Return the used nr of pages
> >> + * allocated for dma-buf
> >> + */
> >> +long dma_buf_allocated_pages(void)
> >> +{
> >> +  return atomic_long_read(_buf_global_allocated) >> PAGE_SHIFT;
> >> +}
> >> +
> >>  #ifdef CONFIG_DEBUG_FS
> >>  static int dma_buf_debug_show(struct seq_file *s, void *unused)
> >>  {
> >> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> >> index 6f

Re: [PATCH 2/2] drm/gma500: remove trailing whitespaces

2021-04-20 Thread Daniel Vetter
On Mon, Apr 19, 2021 at 10:18:07AM +0200, Krzysztof Kozlowski wrote:
> Remove trailing whitespaces.  No functional change.
> 
> Signed-off-by: Krzysztof Kozlowski 

Both patches applied to drm-misc-next, thanks.
-Daniel

> ---
>  drivers/gpu/drm/gma500/backlight.c|  4 +--
>  drivers/gpu/drm/gma500/cdv_intel_dp.c | 50 +--
>  2 files changed, 26 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/gpu/drm/gma500/backlight.c 
> b/drivers/gpu/drm/gma500/backlight.c
> index 35600d070cb5..9e90258541a4 100644
> --- a/drivers/gpu/drm/gma500/backlight.c
> +++ b/drivers/gpu/drm/gma500/backlight.c
> @@ -42,7 +42,7 @@ void gma_backlight_disable(struct drm_device *dev)
>   dev_priv->backlight_device->props.brightness = 0;
>   do_gma_backlight_set(dev);
>   }
> -#endif   
> +#endif
>  }
>  
>  void gma_backlight_set(struct drm_device *dev, int v)
> @@ -54,7 +54,7 @@ void gma_backlight_set(struct drm_device *dev, int v)
>   dev_priv->backlight_device->props.brightness = v;
>   do_gma_backlight_set(dev);
>   }
> -#endif   
> +#endif
>  }
>  
>  int gma_backlight_init(struct drm_device *dev)
> diff --git a/drivers/gpu/drm/gma500/cdv_intel_dp.c 
> b/drivers/gpu/drm/gma500/cdv_intel_dp.c
> index 6d3ada39ff86..595b765ecc71 100644
> --- a/drivers/gpu/drm/gma500/cdv_intel_dp.c
> +++ b/drivers/gpu/drm/gma500/cdv_intel_dp.c
> @@ -245,7 +245,7 @@ i2c_dp_aux_add_bus(struct i2c_adapter *adapter)
>  if (W && !in_dbg_master()) msleep(W);   \
>  }   \
>  ret__;  \
> -})  
> +})
>  
>  #define wait_for(COND, MS) _wait_for(COND, MS, 1)
>  
> @@ -386,7 +386,7 @@ static void cdv_intel_edp_panel_vdd_on(struct gma_encoder 
> *intel_encoder)
>   if (intel_dp->panel_on) {
>   DRM_DEBUG_KMS("Skip VDD on because of panel on\n");
>   return;
> - }   
> + }
>   DRM_DEBUG_KMS("\n");
>  
>   pp = REG_READ(PP_CONTROL);
> @@ -433,7 +433,7 @@ static bool cdv_intel_edp_panel_on(struct gma_encoder 
> *intel_encoder)
>   DRM_DEBUG_KMS("Error in Powering up eDP panel, status %x\n", 
> REG_READ(PP_STATUS));
>   intel_dp->panel_on = false;
>   } else
> - intel_dp->panel_on = true;  
> + intel_dp->panel_on = true;
>   msleep(intel_dp->panel_power_up_delay);
>  
>   return false;
> @@ -449,7 +449,7 @@ static void cdv_intel_edp_panel_off (struct gma_encoder 
> *intel_encoder)
>  
>   pp = REG_READ(PP_CONTROL);
>  
> - if ((pp & POWER_TARGET_ON) == 0) 
> + if ((pp & POWER_TARGET_ON) == 0)
>   return;
>  
>   intel_dp->panel_on = false;
> @@ -464,7 +464,7 @@ static void cdv_intel_edp_panel_off (struct gma_encoder 
> *intel_encoder)
>   DRM_DEBUG_KMS("PP_STATUS %x\n", REG_READ(PP_STATUS));
>  
>   if (wait_for((REG_READ(PP_STATUS) & idle_off_mask) == 0, 1000)) {
> - DRM_DEBUG_KMS("Error in turning off Panel\n");  
> + DRM_DEBUG_KMS("Error in turning off Panel\n");
>   }
>  
>   msleep(intel_dp->panel_power_cycle_delay);
> @@ -535,7 +535,7 @@ cdv_intel_dp_mode_valid(struct drm_connector *connector,
>   if (cdv_intel_dp_link_required(mode->clock, 24)
>   > cdv_intel_dp_max_data_rate(max_link_clock, max_lanes))
>   return MODE_CLOCK_HIGH;
> - 
> +
>   }
>   if (mode->clock < 1)
>   return MODE_CLOCK_LOW;
> @@ -606,7 +606,7 @@ cdv_intel_dp_aux_ch(struct gma_encoder *encoder,
>   for (i = 0; i < send_bytes; i += 4)
>   REG_WRITE(ch_data + i,
>  pack_aux(send + i, send_bytes - i));
> - 
> +
>   /* Send the command and wait for it to complete */
>   REG_WRITE(ch_ctl,
>  DP_AUX_CH_CTL_SEND_BUSY |
> @@ -623,7 +623,7 @@ cdv_intel_dp_aux_ch(struct gma_encoder *encoder,
>   break;
>   udelay(100);
>   }
> - 
> +
>   /* Clear done status and any errors */
>   REG_WRITE(ch_ctl,
>  status |
> @@ -659,7 +659,7 @@ cdv_intel_dp_aux_ch(struct gma_encoder *encoder,
> DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
>   if (recv_bytes > recv_size)
>   recv_bytes =

Re: [PATCH v5] dma-buf: Add DmaBufTotal counter in meminfo

2021-04-20 Thread Daniel Vetter
On Sat, Apr 17, 2021 at 06:38:35PM +0200, Peter Enderborg wrote:
> This adds a total used dma-buf memory. Details
> can be found in debugfs, however it is not for everyone
> and not always available. dma-buf are indirect allocated by
> userspace. So with this value we can monitor and detect
> userspace applications that have problems.
> 
> Signed-off-by: Peter Enderborg 

So there have been tons of discussions around how to track dma-buf and
why, and I really need to understand the use-cass here first I think. proc
uapi is as much forever as anything else, and depending what you're doing
this doesn't make any sense at all:

- on most linux systems dma-buf are only instantiated for shared buffer.
  So there this gives you a fairly meaningless number and not anything
  reflecting gpu memory usage at all.

- on Android all buffers are allocated through dma-buf afaik. But there
  we've recently had some discussions about how exactly we should track
  all this, and the conclusion was that most of this should be solved by
  cgroups long term. So if this is for Android, then I don't think adding
  random quick stop-gaps to upstream is a good idea (because it's a pretty
  long list of patches that have come up on this).

So what is this for?
-Daniel

> ---
>  drivers/dma-buf/dma-buf.c | 12 
>  fs/proc/meminfo.c |  5 -
>  include/linux/dma-buf.h   |  1 +
>  3 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> index f264b70c383e..4dc37cd4293b 100644
> --- a/drivers/dma-buf/dma-buf.c
> +++ b/drivers/dma-buf/dma-buf.c
> @@ -37,6 +37,7 @@ struct dma_buf_list {
>  };
>  
>  static struct dma_buf_list db_list;
> +static atomic_long_t dma_buf_global_allocated;
>  
>  static char *dmabuffs_dname(struct dentry *dentry, char *buffer, int buflen)
>  {
> @@ -79,6 +80,7 @@ static void dma_buf_release(struct dentry *dentry)
>   if (dmabuf->resv == (struct dma_resv *)[1])
>   dma_resv_fini(dmabuf->resv);
>  
> + atomic_long_sub(dmabuf->size, _buf_global_allocated);
>   module_put(dmabuf->owner);
>   kfree(dmabuf->name);
>   kfree(dmabuf);
> @@ -586,6 +588,7 @@ struct dma_buf *dma_buf_export(const struct 
> dma_buf_export_info *exp_info)
>   mutex_lock(_list.lock);
>   list_add(>list_node, _list.head);
>   mutex_unlock(_list.lock);
> + atomic_long_add(dmabuf->size, _buf_global_allocated);
>  
>   return dmabuf;
>  
> @@ -1346,6 +1349,15 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, struct 
> dma_buf_map *map)
>  }
>  EXPORT_SYMBOL_GPL(dma_buf_vunmap);
>  
> +/**
> + * dma_buf_allocated_pages - Return the used nr of pages
> + * allocated for dma-buf
> + */
> +long dma_buf_allocated_pages(void)
> +{
> + return atomic_long_read(_buf_global_allocated) >> PAGE_SHIFT;
> +}
> +
>  #ifdef CONFIG_DEBUG_FS
>  static int dma_buf_debug_show(struct seq_file *s, void *unused)
>  {
> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> index 6fa761c9cc78..ccc7c40c8db7 100644
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -16,6 +16,7 @@
>  #ifdef CONFIG_CMA
>  #include 
>  #endif
> +#include 
>  #include 
>  #include "internal.h"
>  
> @@ -145,7 +146,9 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
>   show_val_kb(m, "CmaFree:",
>   global_zone_page_state(NR_FREE_CMA_PAGES));
>  #endif
> -
> +#ifdef CONFIG_DMA_SHARED_BUFFER
> + show_val_kb(m, "DmaBufTotal:", dma_buf_allocated_pages());
> +#endif
>   hugetlb_report_meminfo(m);
>  
>   arch_report_meminfo(m);
> diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> index efdc56b9d95f..5b05816bd2cd 100644
> --- a/include/linux/dma-buf.h
> +++ b/include/linux/dma-buf.h
> @@ -507,4 +507,5 @@ int dma_buf_mmap(struct dma_buf *, struct vm_area_struct 
> *,
>unsigned long);
>  int dma_buf_vmap(struct dma_buf *dmabuf, struct dma_buf_map *map);
>  void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map);
> +long dma_buf_allocated_pages(void);
>  #endif /* __DMA_BUF_H__ */
> -- 
> 2.17.1
> 
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


Re: [PATCH 27/40] drm/ttm/ttm_device: Demote kernel-doc abuses

2021-04-20 Thread Daniel Vetter
On Fri, Apr 16, 2021 at 05:32:52PM +0200, Christian König wrote:
> Am 16.04.21 um 16:37 schrieb Lee Jones:
> > Fixes the following W=1 kernel build warning(s):
> > 
> >   drivers/gpu/drm/ttm/ttm_device.c:42: warning: Function parameter or 
> > member 'ttm_global_mutex' not described in 'DEFINE_MUTEX'
> >   drivers/gpu/drm/ttm/ttm_device.c:42: warning: expecting prototype for 
> > ttm_global_mutex(). Prototype was for DEFINE_MUTEX() instead
> >   drivers/gpu/drm/ttm/ttm_device.c:112: warning: Function parameter or 
> > member 'ctx' not described in 'ttm_global_swapout'
> >   drivers/gpu/drm/ttm/ttm_device.c:112: warning: Function parameter or 
> > member 'gfp_flags' not described in 'ttm_global_swapout'
> >   drivers/gpu/drm/ttm/ttm_device.c:112: warning: expecting prototype for A 
> > buffer object shrink method that tries to swap out the first(). Prototype 
> > was for ttm_global_swapout() instead
> > 
> > Cc: Christian Koenig 
> > Cc: Huang Rui 
> > Cc: David Airlie 
> > Cc: Daniel Vetter 
> > Cc: dri-de...@lists.freedesktop.org
> > Signed-off-by: Lee Jones 
> 
> Reviewed-by: Christian König 

Can you pls also land all the patches you reviewed from Lee into
drm-misc-next? Just so they wont' get lost. Will all head in for 5.14.
-Daniel
> 
> > ---
> >   drivers/gpu/drm/ttm/ttm_device.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/ttm/ttm_device.c 
> > b/drivers/gpu/drm/ttm/ttm_device.c
> > index 9b787b3caeb50..a8bec8358350d 100644
> > --- a/drivers/gpu/drm/ttm/ttm_device.c
> > +++ b/drivers/gpu/drm/ttm/ttm_device.c
> > @@ -36,7 +36,7 @@
> >   #include "ttm_module.h"
> > -/**
> > +/*
> >* ttm_global_mutex - protecting the global state
> >*/
> >   DEFINE_MUTEX(ttm_global_mutex);
> > @@ -104,7 +104,7 @@ static int ttm_global_init(void)
> > return ret;
> >   }
> > -/**
> > +/*
> >* A buffer object shrink method that tries to swap out the first
> >* buffer object on the global::swap_lru list.
> >*/
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


Re: [PATCH v4] dma-buf: Add DmaBufTotal counter in meminfo

2021-04-20 Thread Daniel Vetter
On Sat, Apr 17, 2021 at 01:54:08PM +0200, Christian König wrote:
> Am 17.04.21 um 13:20 schrieb peter.enderb...@sony.com:
> > On 4/17/21 12:59 PM, Christian König wrote:
> > > Am 17.04.21 um 12:40 schrieb Peter Enderborg:
> > > > This adds a total used dma-buf memory. Details
> > > > can be found in debugfs, however it is not for everyone
> > > > and not always available. dma-buf are indirect allocated by
> > > > userspace. So with this value we can monitor and detect
> > > > userspace applications that have problems.
> > > > 
> > > > Signed-off-by: Peter Enderborg 
> > > Reviewed-by: Christian König 
> > > 
> > > How do you want to upstream this?
> > I don't understand that question. The patch applies on Torvalds 5.12-rc7,
> > but I guess 5.13 is what we work on right now.
> 
> Yeah, but how do you want to get it into Linus tree?
> 
> I can push it together with other DMA-buf patches through drm-misc-next and
> then Dave will send it to Linus for inclusion in 5.13.

Small correction, we've already frozen for the merge window so this will
land in 5.14.
-Daniel

> 
> But could be that you are pushing multiple changes towards Linus through
> some other branch. In this case I'm fine if you pick that way instead if you
> want to keep your patches together for some reason.
> 
> Christian.
> 
> > 
> > > > ---
> > > >    drivers/dma-buf/dma-buf.c | 13 +
> > > >    fs/proc/meminfo.c |  5 -
> > > >    include/linux/dma-buf.h   |  1 +
> > > >    3 files changed, 18 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
> > > > index f264b70c383e..197e5c45dd26 100644
> > > > --- a/drivers/dma-buf/dma-buf.c
> > > > +++ b/drivers/dma-buf/dma-buf.c
> > > > @@ -37,6 +37,7 @@ struct dma_buf_list {
> > > >    };
> > > >      static struct dma_buf_list db_list;
> > > > +static atomic_long_t dma_buf_global_allocated;
> > > >      static char *dmabuffs_dname(struct dentry *dentry, char *buffer, 
> > > > int buflen)
> > > >    {
> > > > @@ -79,6 +80,7 @@ static void dma_buf_release(struct dentry *dentry)
> > > >    if (dmabuf->resv == (struct dma_resv *)[1])
> > > >    dma_resv_fini(dmabuf->resv);
> > > >    +    atomic_long_sub(dmabuf->size, _buf_global_allocated);
> > > >    module_put(dmabuf->owner);
> > > >    kfree(dmabuf->name);
> > > >    kfree(dmabuf);
> > > > @@ -586,6 +588,7 @@ struct dma_buf *dma_buf_export(const struct 
> > > > dma_buf_export_info *exp_info)
> > > >    mutex_lock(_list.lock);
> > > >    list_add(>list_node, _list.head);
> > > >    mutex_unlock(_list.lock);
> > > > +    atomic_long_add(dmabuf->size, _buf_global_allocated);
> > > >      return dmabuf;
> > > >    @@ -1346,6 +1349,16 @@ void dma_buf_vunmap(struct dma_buf *dmabuf, 
> > > > struct dma_buf_map *map)
> > > >    }
> > > >    EXPORT_SYMBOL_GPL(dma_buf_vunmap);
> > > >    +/**
> > > > + * dma_buf_allocated_pages - Return the used nr of pages
> > > > + * allocated for dma-buf
> > > > + */
> > > > +long dma_buf_allocated_pages(void)
> > > > +{
> > > > +    return atomic_long_read(_buf_global_allocated) >> PAGE_SHIFT;
> > > > +}
> > > > +EXPORT_SYMBOL_GPL(dma_buf_allocated_pages);
> > > > +
> > > >    #ifdef CONFIG_DEBUG_FS
> > > >    static int dma_buf_debug_show(struct seq_file *s, void *unused)
> > > >    {
> > > > diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> > > > index 6fa761c9cc78..ccc7c40c8db7 100644
> > > > --- a/fs/proc/meminfo.c
> > > > +++ b/fs/proc/meminfo.c
> > > > @@ -16,6 +16,7 @@
> > > >    #ifdef CONFIG_CMA
> > > >    #include 
> > > >    #endif
> > > > +#include 
> > > >    #include 
> > > >    #include "internal.h"
> > > >    @@ -145,7 +146,9 @@ static int meminfo_proc_show(struct seq_file *m, 
> > > > void *v)
> > > >    show_val_kb(m, "CmaFree:    ",
> > > >    global_zone_page_state(NR_FREE_CMA_PAGES));
> > > >    #endif
> > > > -
> > > > +#ifdef CONFIG_DMA_SHARED_BUFFER
> > > > +    show_val_kb(m, "DmaBufTotal:    ", dma_buf_allocated_pages());
> > > > +#endif
> > > >    hugetlb_report_meminfo(m);
> > > >      arch_report_meminfo(m);
> > > > diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h
> > > > index efdc56b9d95f..5b05816bd2cd 100644
> > > > --- a/include/linux/dma-buf.h
> > > > +++ b/include/linux/dma-buf.h
> > > > @@ -507,4 +507,5 @@ int dma_buf_mmap(struct dma_buf *, struct 
> > > > vm_area_struct *,
> > > >     unsigned long);
> > > >    int dma_buf_vmap(struct dma_buf *dmabuf, struct dma_buf_map *map);
> > > >    void dma_buf_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map);
> > > > +long dma_buf_allocated_pages(void);
> > > >    #endif /* __DMA_BUF_H__ */
> 
> ___
> dri-devel mailing list
> dri-de...@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


Re: [PATCH bpf-next v2 3/4] libbpf: add low level TC-BPF API

2021-04-19 Thread Daniel Borkmann

On 4/19/21 11:43 PM, Toke Høiland-Jørgensen wrote:

Daniel Borkmann  writes:

On 4/19/21 2:18 PM, Kumar Kartikeya Dwivedi wrote:

This adds functions that wrap the netlink API used for adding,
manipulating, and removing traffic control filters. These functions
operate directly on the loaded prog's fd, and return a handle to the
filter using an out parameter named id.

The basic featureset is covered to allow for attaching, manipulation of
properties, and removal of filters. Some additional features like
TCA_BPF_POLICE and TCA_RATE for tc_cls have been omitted. These can
added on top later by extending the bpf_tc_cls_opts struct.

Support for binding actions directly to a classifier by passing them in
during filter creation has also been omitted for now. These actions have
an auto clean up property because their lifetime is bound to the filter
they are attached to. This can be added later, but was omitted for now
as direct action mode is a better alternative to it, which is enabled by
default.

An API summary:

bpf_tc_act_{attach, change, replace} may be used to attach, change, and


typo on bpf_tc_act_{...} ?
 ^^^

replace SCHED_CLS bpf classifier. The protocol field can be set as 0, in
which case it is subsitituted as ETH_P_ALL by default.


Do you have an actual user that needs anything other than ETH_P_ALL? Why is it
even needed? Why not stick to just ETH_P_ALL?


The behavior of the three functions is as follows:

attach = create filter if it does not exist, fail otherwise
change = change properties of the classifier of existing filter
replace = create filter, and replace any existing filter


This touches on tc oddities quite a bit. Why do we need to expose them? Can't we
simplify/abstract this e.g. i) create or update instance, ii) delete instance,
iii) get instance ? What concrete use case do you have that you need those three
above?


bpf_tc_cls_detach may be used to detach existing SCHED_CLS
filter. The bpf_tc_cls_attach_id object filled in during attach,
change, or replace must be passed in to the detach functions for them to
remove the filter and its attached classififer correctly.

bpf_tc_cls_get_info is a helper that can be used to obtain attributes
for the filter and classififer. The opts structure may be used to
choose the granularity of search, such that info for a specific filter
corresponding to the same loaded bpf program can be obtained. By
default, the first match is returned to the user.

Examples:

struct bpf_tc_cls_attach_id id = {};
struct bpf_object *obj;
struct bpf_program *p;
int fd, r;

obj = bpf_object_open("foo.o");
if (IS_ERR_OR_NULL(obj))
return PTR_ERR(obj);

p = bpf_object__find_program_by_title(obj, "classifier");
if (IS_ERR_OR_NULL(p))
return PTR_ERR(p);

if (bpf_object__load(obj) < 0)
return -1;

fd = bpf_program__fd(p);

r = bpf_tc_cls_attach(fd, if_nametoindex("lo"),
  BPF_TC_CLSACT_INGRESS,
  NULL, );
if (r < 0)
return r;

... which is roughly equivalent to (after clsact qdisc setup):
# tc filter add dev lo ingress bpf obj foo.o sec classifier da

... as direct action mode is always enabled.

If a user wishes to modify existing options on an attached classifier,
bpf_tc_cls_change API may be used.

Only parameters class_id can be modified, the rest are filled in to
identify the correct filter. protocol can be left out if it was not
chosen explicitly (defaulting to ETH_P_ALL).

Example:

/* Optional parameters necessary to select the right filter */
DECLARE_LIBBPF_OPTS(bpf_tc_cls_opts, opts,
.handle = id.handle,
.priority = id.priority,
.chain_index = id.chain_index)


Why do we need chain_index as part of the basic API?


opts.class_id = TC_H_MAKE(1UL << 16, 12);
r = bpf_tc_cls_change(fd, if_nametoindex("lo"),
  BPF_TC_CLSACT_INGRESS,
  , );


Also, I'm not sure whether the prefix should even be named  bpf_tc_cls_*() tbh,
yes, despite being "low level" api. I think in the context of bpf we should stop
regarding this as 'classifier' and 'action' objects since it's really just a
single entity and not separate ones. It's weird enough to explain this concept
to new users and if a libbpf based api could cleanly abstract it, I would be all
for it. I don't think we need to map 1:1 the old tc legacy even in the low level
api, tbh, as it feels backwards. I think the 'handle' & 'priority' bits are 
okay,
but I would remove the others.


Hmm, I'm OK with dropping the TC oddities (including the cls_ in the
name), but I think we should be documenting it so that users that do
come from TC will not be completel

Re: [PATCH bpf-next v2 3/4] libbpf: add low level TC-BPF API

2021-04-19 Thread Daniel Borkmann

On 4/19/21 2:18 PM, Kumar Kartikeya Dwivedi wrote:

This adds functions that wrap the netlink API used for adding,
manipulating, and removing traffic control filters. These functions
operate directly on the loaded prog's fd, and return a handle to the
filter using an out parameter named id.

The basic featureset is covered to allow for attaching, manipulation of
properties, and removal of filters. Some additional features like
TCA_BPF_POLICE and TCA_RATE for tc_cls have been omitted. These can
added on top later by extending the bpf_tc_cls_opts struct.

Support for binding actions directly to a classifier by passing them in
during filter creation has also been omitted for now. These actions have
an auto clean up property because their lifetime is bound to the filter
they are attached to. This can be added later, but was omitted for now
as direct action mode is a better alternative to it, which is enabled by
default.

An API summary:

bpf_tc_act_{attach, change, replace} may be used to attach, change, and


typo on bpf_tc_act_{...} ?
   ^^^

replace SCHED_CLS bpf classifier. The protocol field can be set as 0, in
which case it is subsitituted as ETH_P_ALL by default.


Do you have an actual user that needs anything other than ETH_P_ALL? Why is it
even needed? Why not stick to just ETH_P_ALL?


The behavior of the three functions is as follows:

attach = create filter if it does not exist, fail otherwise
change = change properties of the classifier of existing filter
replace = create filter, and replace any existing filter


This touches on tc oddities quite a bit. Why do we need to expose them? Can't we
simplify/abstract this e.g. i) create or update instance, ii) delete instance,
iii) get instance ? What concrete use case do you have that you need those three
above?


bpf_tc_cls_detach may be used to detach existing SCHED_CLS
filter. The bpf_tc_cls_attach_id object filled in during attach,
change, or replace must be passed in to the detach functions for them to
remove the filter and its attached classififer correctly.

bpf_tc_cls_get_info is a helper that can be used to obtain attributes
for the filter and classififer. The opts structure may be used to
choose the granularity of search, such that info for a specific filter
corresponding to the same loaded bpf program can be obtained. By
default, the first match is returned to the user.

Examples:

struct bpf_tc_cls_attach_id id = {};
struct bpf_object *obj;
struct bpf_program *p;
int fd, r;

obj = bpf_object_open("foo.o");
if (IS_ERR_OR_NULL(obj))
return PTR_ERR(obj);

p = bpf_object__find_program_by_title(obj, "classifier");
if (IS_ERR_OR_NULL(p))
return PTR_ERR(p);

if (bpf_object__load(obj) < 0)
return -1;

fd = bpf_program__fd(p);

r = bpf_tc_cls_attach(fd, if_nametoindex("lo"),
  BPF_TC_CLSACT_INGRESS,
  NULL, );
if (r < 0)
return r;

... which is roughly equivalent to (after clsact qdisc setup):
   # tc filter add dev lo ingress bpf obj foo.o sec classifier da

... as direct action mode is always enabled.

If a user wishes to modify existing options on an attached classifier,
bpf_tc_cls_change API may be used.

Only parameters class_id can be modified, the rest are filled in to
identify the correct filter. protocol can be left out if it was not
chosen explicitly (defaulting to ETH_P_ALL).

Example:

/* Optional parameters necessary to select the right filter */
DECLARE_LIBBPF_OPTS(bpf_tc_cls_opts, opts,
.handle = id.handle,
.priority = id.priority,
.chain_index = id.chain_index)


Why do we need chain_index as part of the basic API?


opts.class_id = TC_H_MAKE(1UL << 16, 12);
r = bpf_tc_cls_change(fd, if_nametoindex("lo"),
  BPF_TC_CLSACT_INGRESS,
  , );


Also, I'm not sure whether the prefix should even be named  bpf_tc_cls_*() tbh,
yes, despite being "low level" api. I think in the context of bpf we should stop
regarding this as 'classifier' and 'action' objects since it's really just a
single entity and not separate ones. It's weird enough to explain this concept
to new users and if a libbpf based api could cleanly abstract it, I would be all
for it. I don't think we need to map 1:1 the old tc legacy even in the low level
api, tbh, as it feels backwards. I think the 'handle' & 'priority' bits are 
okay,
but I would remove the others.


if (r < 0)
return r;

struct bpf_tc_cls_info info = {};
r = bpf_tc_cls_get_info(fd, if_nametoindex("lo"),
BPF_TC_CLSACT_INGRESS,
, );
if (r < 0)
return r;

assert(info.class_id == 

Re: [PATCH RESEND 3/4] docs: Add HiSilicon PTT device driver documentation

2021-04-19 Thread Daniel Thompson
On Sat, Apr 17, 2021 at 06:17:10PM +0800, Yicong Yang wrote:
> Document the introduction and usage of HiSilicon PTT device driver.
> 
> Signed-off-by: Yicong Yang 
> ---
>  Documentation/trace/hisi-ptt.rst | 326 
> +++
>  1 file changed, 326 insertions(+)
>  create mode 100644 Documentation/trace/hisi-ptt.rst
> 
> diff --git a/Documentation/trace/hisi-ptt.rst 
> b/Documentation/trace/hisi-ptt.rst
> new file mode 100644
> index 000..f093846
> --- /dev/null
> +++ b/Documentation/trace/hisi-ptt.rst
> @@ -0,0 +1,326 @@
> [...]
> +On Kunpeng 930 SoC, the PCIe Root Complex is composed of several
> +PCIe cores. Each PCIe core includes several Root Ports and a PTT
> +RCiEP, like below. The PTT device is capable of tuning and
> +tracing the link of the PCIe core.
> +::
> +  +--Core 0---+
> +  |   |   [   PTT   ] |
> +  |   |   [Root Port]---[Endpoint]
> +  |   |   [Root Port]---[Endpoint]
> +  |   |   [Root Port]---[Endpoint]
> +Root Complex  |--Core 1---+
> +  |   |   [   PTT   ] |
> +  |   |   [Root Port]---[ Switch ]---[Endpoint]
> +  |   |   [Root Port]---[Endpoint] `-[Endpoint]
> +  |   |   [Root Port]---[Endpoint]
> +  +---+
> +
> +The PTT device driver cannot be loaded if debugfs is not mounted.

This can't be right can it? Obviously debugfs must be enabled but why
mounted?


> +Each PTT device will be presented under /sys/kernel/debugfs/hisi_ptt
> +as its root directory, with name of its BDF number.
> +::
> +
> +/sys/kernel/debug/hisi_ptt/::.
> +
> +Tune
> +
> +
> +PTT tune is designed for monitoring and adjusting PCIe link parameters 
> (events).
> +Currently we support events in 4 classes. The scope of the events
> +covers the PCIe core to which the PTT device belongs.
> +
> +Each event is presented as a file under $(PTT root dir)/$(BDF)/tune, and
> +mostly a simple open/read/write/close cycle will be used to tune
> +the event.
> +::
> +$ cd /sys/kernel/debug/hisi_ptt/$(BDF)/tune
> +$ ls
> +qos_tx_cplqos_tx_npqos_tx_p
> +tx_path_rx_req_alloc_buf_level
> +tx_path_tx_req_alloc_buf_level
> +$ cat qos_tx_dp
> +1
> +$ echo 2 > qos_tx_dp
> +$ cat qos_tx_dp
> +2
> +
> +Current value (numerical value) of the event can be simply read
> +from the file, and the desired value written to the file to tune.

I saw that this RFC asks about whether debugfs is an appropriate
interface for the *tracing* capability of the platform. Have similar
questions been raised about the tuning interfaces?

It looks to me like tuning could be handled entirely using sysfs
attributes. I think trying to handle these mostly decoupled feature
in the same place is likely to be a mistake.


Daniel.


Re: [PATCH] [v4, 1/1] clocksource/drivers/timer-mediatek: optimize systimer irq clear flow on shutdown

2021-04-19 Thread Daniel Lezcano
On 09/04/2021 11:22, Fengquan Chen wrote:
> mtk_syst_clkevt_shutdown is called after irq disabled in suspend flow,
> clear any pending systimer irq when shutdown to avoid suspend aborted
> due to timer irq pending
> 
> Also as for systimer in mediatek socs, there must be firstly enable
> timer before clear systimer irq
> 
> Fixes: e3af677607d9("clocksource/drivers/timer-mediatek: Add support for 
> system timer")
> Signed-off-by: Fengquan Chen 
> 
> ---
>  drivers/clocksource/timer-mediatek.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/clocksource/timer-mediatek.c 
> b/drivers/clocksource/timer-mediatek.c
> index 9318edc..6461fd3 100644
> --- a/drivers/clocksource/timer-mediatek.c
> +++ b/drivers/clocksource/timer-mediatek.c
> @@ -60,9 +60,9 @@
>   * SYST_CON_EN: Clock enable. Shall be set to
>   *   - Start timer countdown.
>   *   - Allow timeout ticks being updated.
> - *   - Allow changing interrupt functions.
> + *   - Allow changing interrupt status,like clear irq pending.
>   *
> - * SYST_CON_IRQ_EN: Set to allow interrupt.
> + * SYST_CON_IRQ_EN: Set to enable interrupt.
>   *
>   * SYST_CON_IRQ_CLR: Set to clear interrupt.
>   */
> @@ -75,6 +75,7 @@
>  static void mtk_syst_ack_irq(struct timer_of *to)
>  {
>   /* Clear and disable interrupt */
> + writel(SYST_CON_EN, SYST_CON_REG(to));
>   writel(SYST_CON_IRQ_CLR | SYST_CON_EN, SYST_CON_REG(to));
>  }

IIRC, there is a hardware issue here. If it is the case, please describe
it and refer to an errata if any.

Also Evan Benn commented your code and asked a couple of questions [1],
please answer before reposting a new version.

Comments ignored == patch ignored

> @@ -111,6 +112,9 @@ static int mtk_syst_clkevt_next_event(unsigned long ticks,
>  
>  static int mtk_syst_clkevt_shutdown(struct clock_event_device *clkevt)
>  {
> + /* Clear any irq */
> + mtk_syst_ack_irq(to_timer_of(clkevt));
> +
>   /* Disable timer */
>   writel(0, SYST_CON_REG(to_timer_of(clkevt)));

Please check out the patch sent by Evan Benn [2], if you agree, ack it.

Thanks

  -- Daniel

[1] https://patchwork.kernel.org/comment/24059277/
[2]
https://lore.kernel.org/linux-arm-kernel/20210412132200.v3.1.I1d9917047de06715da16e1620759f703fcfdcbcb@changeid/

-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog


Re: [PATCH v3] drivers/clocksource/mediatek: Ack and disable interrupts on suspend

2021-04-19 Thread Daniel Lezcano
On 12/04/2021 05:22, Evan Benn wrote:
> Interrupts are disabled during suspend before this driver disables its
> timers. ARM trusted firmware will abort suspend if the timer irq is
> pending, so ack and disable the timer interrupt during suspend.
> 
> Signed-off-by: Evan Benn 
> ---
> 
> Changes in v3:
> Move the ACK from the shutdown to the suspend function.
> 
> Changes in v2:
> Remove the patch that splits the drivers into 2 files.
> 
>  drivers/clocksource/timer-mediatek.c | 23 +++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/clocksource/timer-mediatek.c 
> b/drivers/clocksource/timer-mediatek.c
> index 9318edcd8963..1ae8fee639bf 100644
> --- a/drivers/clocksource/timer-mediatek.c
> +++ b/drivers/clocksource/timer-mediatek.c
> @@ -241,6 +241,27 @@ static void mtk_gpt_enable_irq(struct timer_of *to, u8 
> timer)
>  timer_of_base(to) + GPT_IRQ_EN_REG);
>  }
>  
> +static void mtk_gpt_resume(struct clock_event_device *clk)
> +{
> + struct timer_of *to = to_timer_of(clk);
> +
> + mtk_gpt_enable_irq(to, TIMER_CLK_EVT);
> +}
> +
> +static void mtk_gpt_suspend(struct clock_event_device *clk)
> +{
> + struct timer_of *to = to_timer_of(clk);
> +
> + /* Disable all interrupts */
> + writel(0x0, timer_of_base(to) + GPT_IRQ_EN_REG);
> +
> + /* This is called with interrupts disabled,

Please fix the comment style:

/*
 * This is called with interrupts disabled
 * so ...
 * ...
 */

Other than than that I'll be happy to pick it.

> +  * so we need to ack any interrupt that is pending
> +  * Or for example ATF will prevent a suspend from completing.
> +  */
> + writel(0x3f, timer_of_base(to) + GPT_IRQ_ACK_REG);
> +}
> +
>  static struct timer_of to = {
>   .flags = TIMER_OF_IRQ | TIMER_OF_BASE | TIMER_OF_CLOCK,
>  
> @@ -286,6 +307,8 @@ static int __init mtk_gpt_init(struct device_node *node)
>   to.clkevt.set_state_oneshot = mtk_gpt_clkevt_shutdown;
>   to.clkevt.tick_resume = mtk_gpt_clkevt_shutdown;
>   to.clkevt.set_next_event = mtk_gpt_clkevt_next_event;
> + to.clkevt.suspend = mtk_gpt_suspend;
> + to.clkevt.resume = mtk_gpt_resume;
>   to.of_irq.handler = mtk_gpt_interrupt;
>  
>   ret = timer_of_init(node, );
> 


-- 
 Linaro.org │ Open source software for ARM SoCs

Follow Linaro:   Facebook |
 Twitter |
 Blog


[ANNOUNCE] 4.4.267-rt221

2021-04-18 Thread Daniel Wagner
Hello RT-list!

I'm pleased to announce the 4.4.267-rt221 stable release.

This is just an update to the latest stable release. No RT
specific changes.

Known issue:

  - locktorture reports a might_sleep warning for spin_locks test

You can get this release via the git tree at:

  git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-stable-rt.git

  branch: v4.4-rt
  Head SHA1: e65ae24c8623270657748609d1bf099019dd2635

Or to build 4.4.267-rt221 directly, the following patches should be applied:

  https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.4.tar.xz

  https://www.kernel.org/pub/linux/kernel/v4.x/patch-4.4.267.xz

Enjoy!
Daniel

Changes from v4.4.262-rt219:
---

Adrian Hunter (1):
  perf auxtrace: Fix auxtrace queue conflict

Alexander Aring (8):
  net: ieee802154: nl-mac: fix check on panid
  net: ieee802154: fix nl802154 del llsec key
  net: ieee802154: fix nl802154 del llsec dev
  net: ieee802154: fix nl802154 add llsec key
  net: ieee802154: fix nl802154 del llsec devkey
  net: ieee802154: forbid monitor for set llsec params
  net: ieee802154: forbid monitor for del llsec seclevel
  net: ieee802154: stop dump llsec params for monitors

Alexander Gordeev (1):
  s390/cpcmd: fix inline assembly register clobbering

Alexey Dobriyan (1):
  scsi: qla2xxx: Fix broken #endif placement

Angelo Dureghello (1):
  can: flexcan: flexcan_chip_freeze(): fix chip freeze for missing bitrate

Arnaldo Carvalho de Melo (1):
  perf map: Tighten snprintf() string precision to pass gcc check on some 
32-bit arches

Arnd Bergmann (2):
  x86/build: Turn off -fcf-protection for realmode targets
  drm/imx: imx-ldb: fix out of bounds array access warning

Atul Gopinathan (2):
  staging: rtl8192e: Fix incorrect source in memcpy()
  staging: rtl8192e: Change state information from u16 to u8

Benjamin Rood (1):
  ASoC: sgtl5000: set DAP_AVC_CTRL register to correct default value on 
probe

Borislav Petkov (1):
  x86/tlb: Flush global mappings when KAISER is disabled

Claudiu Manoil (1):
  gianfar: Handle error code at MAC address change

Dan Carpenter (1):
  scsi: lpfc: Fix some error codes in debugfs

Daniel Wagner (4):
  Merge tag 'v4.4.263' into v4.4-rt
  Linux 4.4.263-rt220
  Merge tag 'v4.4.267' into v4.4-rt
  Linux 4.4.267-rt221

David Brazdil (1):
  selinux: vsock: Set SID for socket returned by accept()

Denis Efremov (1):
  sun/niu: fix wrong RXMAC_BC_FRM_CNT_COUNT count

Dinghao Liu (2):
  e1000e: Fix error handling in e1000_set_d0_lplu_state_82571
  extcon: Fix error handling in extcon_dev_register

Doug Brown (1):
  appletalk: Fix skb allocation size in loopback case

Du Cheng (1):
  cfg80211: remove WARN_ON() in cfg80211_sme_connect

Eric Dumazet (3):
  macvlan: macvlan_count_rx() needs to be aware of preemption
  net: sched: validate stab values
  sch_red: fix off-by-one checks in red_check_params()

Filipe Manana (1):
  btrfs: fix race when cloning extent buffer during rewind of an old root

Florian Fainelli (1):
  net: dsa: bcm_sf2: Qualify phydev->dev_flags based on port

Florian Westphal (1):
  netfilter: x_tables: fix compat match/target pad out-of-bound write

Frank Sorenson (1):
  NFS: Correct size calculation for create reply length

Greg Kroah-Hartman (5):
  Linux 4.4.263
  Linux 4.4.264
  Linux 4.4.265
  Linux 4.4.266
  Linux 4.4.267

Grygorii Strashko (1):
  bus: omap_l3_noc: mark l3 irqs as IRQF_NO_THREAD

Gwendal Grignou (1):
  platform/chrome: cros_ec_dev - Fix security issue

Hans de Goede (2):
  ASoC: rt5640: Fix dac- and adc- vol-tlv values being off by a factor of 10
  ASoC: rt5651: Fix dac- and adc- vol-tlv values being off by a factor of 10

Heiko Carstens (1):
  init/Kconfig: make COMPILE_TEST depend on !S390

Heiko Thiery (1):
  net: fec: ptp: avoid register access when ipg clock is disabled

Helge Deller (1):
  parisc: parisc-agp requires SBA IOMMU driver

Hui Wang (1):
  ALSA: hda/realtek: call alc_update_headset_mode() in hp_automute_hook

Ikjoon Jang (1):
  ALSA: usb-audio: Apply sample rate quirk to Logitech Connect

Ilya Lipnitskiy (1):
  mm: fix race by making init_zero_pfn() early_initcall

J. Bruce Fields (2):
  nfs: we don't support removing system.nfs4_acl
  rpc: fix NULL dereference on kmalloc failure

Jack Qiu (1):
  fs: direct-io: fix missing sdio->boundary

Jakub Kicinski (1):
  ipv6: weaken the v4mapped source check

Jan Beulich (1):
  xen-blkback: don't leak persistent grants from xen_blkbk_map()

Jan Kara (3):
  ext4: handle error of ext4_setup_system_zone() on remount
  ext4: don't allow overlapping system zones
  ext4: check journal inode extents more carefully

Jia-Ju Bai (1):
  net: tehuti: fix error return code in bdx_probe()

Jim Lin (1):
  usb: gadget: configfs: Fix KASAN use-after-free

Joe Korty (1):

Re: [PATCH v7 2/9] reboot: thermal: Export hardware protection shutdown

2021-04-16 Thread Daniel Lezcano
On 14/04/2021 07:52, Matti Vaittinen wrote:
> Thermal core contains a logic for safety shutdown. System is attempted to
> be powered off if temperature exceeds safety limits.
> 
> Currently this can be also utilized by regulator subsystem as a final
> protection measure if PMICs report dangerous over-voltage, over-current or
> over-temperature and if per regulator counter measures fail or do not
> exist.
> 
> Move this logic to kernel/reboot.c and export the functionality for other
> subsystems to use. Also replace the mutex with a spinlock to allow using
> the function from any context.
> 
> Also the EMIF bus code has implemented a safety shut-down. EMIF does not
> attempt orderly_poweroff at all. Thus the EMIF code is not converted to use
> this new function.
> 
> Signed-off-by: Matti Vaittinen 
> ---
> Changelog
>  v7:
>   - new patch
> 
> Please note - this patch has received only a minimal amount of testing.
> (The new API call was tested to shut-down my system at driver probe but
> no odd corner-cases have been tested).
> 
> Any testing for thermal shutdown is appreciated.
> ---
>  drivers/thermal/thermal_core.c | 63 ++---
>  include/linux/reboot.h |  1 +
>  kernel/reboot.c| 86 ++

Please send a patch implementing the reboot/shutdown and then another
one replacing the thermal shutdown code by a call to the new API.

>  3 files changed, 91 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 996c038f83a4..b1444845af38 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -36,10 +36,8 @@ static LIST_HEAD(thermal_governor_list);
>  
>  static DEFINE_MUTEX(thermal_list_lock);
>  static DEFINE_MUTEX(thermal_governor_lock);
> -static DEFINE_MUTEX(poweroff_lock);
>  
>  static atomic_t in_suspend;
> -static bool power_off_triggered;
>  
>  static struct thermal_governor *def_governor;
>  
> @@ -327,70 +325,18 @@ static void handle_non_critical_trips(struct 
> thermal_zone_device *tz, int trip)
>  def_governor->throttle(tz, trip);
>  }
>  
> -/**
> - * thermal_emergency_poweroff_func - emergency poweroff work after a known 
> delay
> - * @work: work_struct associated with the emergency poweroff function
> - *
> - * This function is called in very critical situations to force
> - * a kernel poweroff after a configurable timeout value.
> - */
> -static void thermal_emergency_poweroff_func(struct work_struct *work)
> -{
> - /*
> -  * We have reached here after the emergency thermal shutdown
> -  * Waiting period has expired. This means orderly_poweroff has
> -  * not been able to shut off the system for some reason.
> -  * Try to shut down the system immediately using kernel_power_off
> -  * if populated
> -  */
> - WARN(1, "Attempting kernel_power_off: Temperature too high\n");
> - kernel_power_off();
> -
> - /*
> -  * Worst of the worst case trigger emergency restart
> -  */
> - WARN(1, "Attempting emergency_restart: Temperature too high\n");
> - emergency_restart();
> -}
> -
> -static DECLARE_DELAYED_WORK(thermal_emergency_poweroff_work,
> - thermal_emergency_poweroff_func);
> -
> -/**
> - * thermal_emergency_poweroff - Trigger an emergency system poweroff
> - *
> - * This may be called from any critical situation to trigger a system 
> shutdown
> - * after a known period of time. By default this is not scheduled.
> - */
> -static void thermal_emergency_poweroff(void)
> +void thermal_zone_device_critical(struct thermal_zone_device *tz)
>  {
> - int poweroff_delay_ms = CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS;
>   /*
>* poweroff_delay_ms must be a carefully profiled positive value.
> -  * Its a must for thermal_emergency_poweroff_work to be scheduled
> +  * Its a must for forced_emergency_poweroff_work to be scheduled.
>*/
> - if (poweroff_delay_ms <= 0)
> - return;
> - schedule_delayed_work(_emergency_poweroff_work,
> -   msecs_to_jiffies(poweroff_delay_ms));
> -}
> + int poweroff_delay_ms = CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS;
>  
> -void thermal_zone_device_critical(struct thermal_zone_device *tz)
> -{
>   dev_emerg(>device, "%s: critical temperature reached, "
> "shutting down\n", tz->type);
>  
> - mutex_lock(_lock);
> - if (!power_off_triggered) {
> - /*
> -  * Queue a backup emergency shutdown in the event of
> -  * orderly_poweroff failure
> -  */
> - thermal_emergency_poweroff();
> - orderly_poweroff(true);
> - power_off_triggered = true;
> - }
> - mutex_unlock(_lock);
> + hw_protection_shutdown("Temperature too high", poweroff_delay_ms);
>  }
>  EXPORT_SYMBOL(thermal_zone_device_critical);
>  
> @@ -1549,7 +1495,6 

Re: [PATCH v7 2/9] reboot: thermal: Export hardware protection shutdown

2021-04-16 Thread Daniel Lezcano
On 14/04/2021 07:52, Matti Vaittinen wrote:
> Thermal core contains a logic for safety shutdown. System is attempted to
> be powered off if temperature exceeds safety limits.
> 
> Currently this can be also utilized by regulator subsystem as a final
> protection measure if PMICs report dangerous over-voltage, over-current or
> over-temperature and if per regulator counter measures fail or do not
> exist.
> 
> Move this logic to kernel/reboot.c and export the functionality for other
> subsystems to use. Also replace the mutex with a spinlock to allow using
> the function from any context.
> 
> Also the EMIF bus code has implemented a safety shut-down. EMIF does not
> attempt orderly_poweroff at all. Thus the EMIF code is not converted to use
> this new function.
> 
> Signed-off-by: Matti Vaittinen 
> ---
> Changelog
>  v7:
>   - new patch
> 
> Please note - this patch has received only a minimal amount of testing.
> (The new API call was tested to shut-down my system at driver probe but
> no odd corner-cases have been tested).
> 
> Any testing for thermal shutdown is appreciated.

You can test it easily by enabling the option CONFIG_THERMAL_EMULATION

Then in any thermal zone:

Assuming the critical temp is below the one specified in the command:

echo 10 > /sys/class/thermal/thermal_zone0/emul_temp

> ---
>  drivers/thermal/thermal_core.c | 63 ++---
>  include/linux/reboot.h |  1 +
>  kernel/reboot.c| 86 ++
>  3 files changed, 91 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 996c038f83a4..b1444845af38 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -36,10 +36,8 @@ static LIST_HEAD(thermal_governor_list);
>  
>  static DEFINE_MUTEX(thermal_list_lock);
>  static DEFINE_MUTEX(thermal_governor_lock);
> -static DEFINE_MUTEX(poweroff_lock);
>  
>  static atomic_t in_suspend;
> -static bool power_off_triggered;
>  
>  static struct thermal_governor *def_governor;
>  
> @@ -327,70 +325,18 @@ static void handle_non_critical_trips(struct 
> thermal_zone_device *tz, int trip)
>  def_governor->throttle(tz, trip);
>  }
>  
> -/**
> - * thermal_emergency_poweroff_func - emergency poweroff work after a known 
> delay
> - * @work: work_struct associated with the emergency poweroff function
> - *
> - * This function is called in very critical situations to force
> - * a kernel poweroff after a configurable timeout value.
> - */
> -static void thermal_emergency_poweroff_func(struct work_struct *work)
> -{
> - /*
> -  * We have reached here after the emergency thermal shutdown
> -  * Waiting period has expired. This means orderly_poweroff has
> -  * not been able to shut off the system for some reason.
> -  * Try to shut down the system immediately using kernel_power_off
> -  * if populated
> -  */
> - WARN(1, "Attempting kernel_power_off: Temperature too high\n");
> - kernel_power_off();
> -
> - /*
> -  * Worst of the worst case trigger emergency restart
> -  */
> - WARN(1, "Attempting emergency_restart: Temperature too high\n");
> - emergency_restart();
> -}
> -
> -static DECLARE_DELAYED_WORK(thermal_emergency_poweroff_work,
> - thermal_emergency_poweroff_func);
> -
> -/**
> - * thermal_emergency_poweroff - Trigger an emergency system poweroff
> - *
> - * This may be called from any critical situation to trigger a system 
> shutdown
> - * after a known period of time. By default this is not scheduled.
> - */
> -static void thermal_emergency_poweroff(void)
> +void thermal_zone_device_critical(struct thermal_zone_device *tz)
>  {
> - int poweroff_delay_ms = CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS;
>   /*
>* poweroff_delay_ms must be a carefully profiled positive value.
> -  * Its a must for thermal_emergency_poweroff_work to be scheduled
> +  * Its a must for forced_emergency_poweroff_work to be scheduled.
>*/
> - if (poweroff_delay_ms <= 0)
> - return;
> - schedule_delayed_work(_emergency_poweroff_work,
> -   msecs_to_jiffies(poweroff_delay_ms));
> -}
> + int poweroff_delay_ms = CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS;
>  
> -void thermal_zone_device_critical(struct thermal_zone_device *tz)
> -{
>   dev_emerg(>device, "%s: critical temperature reached, "
> "shutting down\n", tz->type);
>  
> - mutex_lock(_lock);
> - if (!power_off_triggered) {
> - /*
> -  * Queue a backup emergency shutdown in the event of
> -  * orderly_poweroff failure
> -  */
> - thermal_emergency_poweroff();
> - orderly_poweroff(true);
> - power_off_triggered = true;
> - }
> - mutex_unlock(_lock);
> + hw_protection_shutdown("Temperature too high", 

[PATCH 3/3] ARM: dts: mstar: Add a dts for M5Stack UnitV2

2021-04-16 Thread Daniel Palmer
M5Stack are releasing a new widget based on the
SigmaStar SSD202D. We have some support for the
SSD202D so lets add a dts for it.

Link: https://m5stack-store.myshopify.com/products/unitv2-ai-camera-gc2145
Signed-off-by: Daniel Palmer 
---
 arch/arm/boot/dts/Makefile|  1 +
 .../dts/mstar-infinity2m-ssd202d-unitv2.dts   | 25 +++
 2 files changed, 26 insertions(+)
 create mode 100644 arch/arm/boot/dts/mstar-infinity2m-ssd202d-unitv2.dts

diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index 8e5d4ab4e75e..66ddc7d0bd03 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -1397,6 +1397,7 @@ dtb-$(CONFIG_ARCH_MILBEAUT) += milbeaut-m10v-evb.dtb
 dtb-$(CONFIG_ARCH_MSTARV7) += \
mstar-infinity-msc313-breadbee_crust.dtb \
mstar-infinity2m-ssd202d-ssd201htv2.dtb \
+   mstar-infinity2m-ssd202d-unitv2.dtb \
mstar-infinity3-msc313e-breadbee.dtb \
mstar-mercury5-ssc8336n-midrived08.dtb
 dtb-$(CONFIG_ARCH_ASPEED) += \
diff --git a/arch/arm/boot/dts/mstar-infinity2m-ssd202d-unitv2.dts 
b/arch/arm/boot/dts/mstar-infinity2m-ssd202d-unitv2.dts
new file mode 100644
index ..a81684002e45
--- /dev/null
+++ b/arch/arm/boot/dts/mstar-infinity2m-ssd202d-unitv2.dts
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 thingy.jp.
+ * Author: Daniel Palmer 
+ */
+
+/dts-v1/;
+#include "mstar-infinity2m-ssd202d.dtsi"
+
+/ {
+   model = "UnitV2";
+   compatible = "m5stack,unitv2", "mstar,infinity2m";
+
+   aliases {
+   serial0 = _uart;
+   };
+
+   chosen {
+   stdout-path = "serial0:115200n8";
+   };
+};
+
+_uart {
+   status = "okay";
+};
-- 
2.31.0



[PATCH 2/3] dt-bindings: arm: mstar: Add compatible for M5Stack UnitV2

2021-04-16 Thread Daniel Palmer
Add a compatible for the M5Stack UnitV2 that is based on the
SigmaStar SSD202D (inifinity2m).

Signed-off-by: Daniel Palmer 
---
 Documentation/devicetree/bindings/arm/mstar/mstar.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/arm/mstar/mstar.yaml 
b/Documentation/devicetree/bindings/arm/mstar/mstar.yaml
index 61d08c473eb8..a316eef1b728 100644
--- a/Documentation/devicetree/bindings/arm/mstar/mstar.yaml
+++ b/Documentation/devicetree/bindings/arm/mstar/mstar.yaml
@@ -24,6 +24,7 @@ properties:
 items:
   - enum:
   - honestar,ssd201htv2 # Honestar SSD201_HT_V2 devkit
+  - m5stack,unitv2 # M5Stack UnitV2
   - const: mstar,infinity2m
 
   - description: infinity3 boards
-- 
2.31.0



[PATCH 0/3] ARM: mstar: Add initial support for M5Stack UnitV2

2021-04-16 Thread Daniel Palmer
This series adds basic support for the soon to be released M5Stack
UnitV2 based on the SigmaStar SSD202D.

With the rest of the commits in my tree the SPI NAND, ethernet, USB etc
should work so the UnitV2 should be fully usable with a mainline-ish
kernel.

Hopefully this will encourage someone else to help with cleaning
up and pushing the commits for these SoCs.

Link: https://m5stack-store.myshopify.com/products/unitv2-ai-camera-gc2145

Daniel Palmer (3):
  dt-bindings: vendor-prefixes: Add vendor prefix for M5Stack
  dt-bindings: arm: mstar: Add compatible for M5Stack UnitV2
  ARM: dts: mstar: Add a dts for M5Stack UnitV2

 .../devicetree/bindings/arm/mstar/mstar.yaml  |  1 +
 .../devicetree/bindings/vendor-prefixes.yaml  |  2 ++
 arch/arm/boot/dts/Makefile|  1 +
 .../dts/mstar-infinity2m-ssd202d-unitv2.dts   | 25 +++
 4 files changed, 29 insertions(+)
 create mode 100644 arch/arm/boot/dts/mstar-infinity2m-ssd202d-unitv2.dts

-- 
2.31.0



[PATCH 1/3] dt-bindings: vendor-prefixes: Add vendor prefix for M5Stack

2021-04-16 Thread Daniel Palmer
M5Stack make various modules for STEM, Makers, IoT.
Their UnitV2 is based on a SigmaStar SSD202D SoC which
we already have some minimal support for so add a
prefix in preparation for UnitV2 board support.

Link: https://m5stack.com/
Signed-off-by: Daniel Palmer 
---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml 
b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index f6064d84a424..7129fe3b9144 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -651,6 +651,8 @@ patternProperties:
 description: Liebherr-Werk Nenzing GmbH
   "^lxa,.*":
 description: Linux Automation GmbH
+  "^m5stack,.*":
+description: M5Stack
   "^macnica,.*":
 description: Macnica Americas
   "^mantix,.*":
-- 
2.31.0



Re: [PATCH] Documentation: kunit: Update kunit_tool page

2021-04-16 Thread Daniel Latypov
On Thu, Apr 15, 2021 at 8:40 PM David Gow  wrote:
>
> The kunit_tool documentation page was pretty minimal, and a bit
> outdated. Update it and flesh it out a bit.
>
> In particular,
> - Mention that .kunitconfig is now in the build directory
> - Describe the use of --kunitconfig to specify a different config
>   framgent
> - Mention the split functionality (i.e., commands other than 'run')
> - Describe --raw_output and kunit.py parse
> - Mention the globbing support
> - Provide a quick overview of other options, including --build_dir and
>   --alltests
>
> Note that this does overlap a little with the new running_tips page. I
> don't think it's a problem having both: this page is supposed to be a
> bit more of a reference, rather than a list of useful tips, so the fact
> that they both describe the same features isn't a problem.
>
> Signed-off-by: David Gow 

Reviewed-by: Daniel Latypov 

Looks good to me. I completely forgot to update this page when adding
blobs about the new features in running_tips.rst...
Two minor, optional nits.

> ---
>  Documentation/dev-tools/kunit/kunit-tool.rst | 132 ++-
>  1 file changed, 128 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/dev-tools/kunit/kunit-tool.rst 
> b/Documentation/dev-tools/kunit/kunit-tool.rst
> index 29ae2fee8123..0b45affcd65c 100644
> --- a/Documentation/dev-tools/kunit/kunit-tool.rst
> +++ b/Documentation/dev-tools/kunit/kunit-tool.rst
> @@ -22,14 +22,19 @@ not require any virtualization support: it is just a 
> regular program.
>  What is a .kunitconfig?
>  ===
>
> -It's just a defconfig that kunit_tool looks for in the base directory.
> +It's just a defconfig that kunit_tool looks for in the build directory.

nit: should we mention this is .kunit here?
We don't mention this till the very bottom right now, which seems suboptimal.

I assume most people are going to still be fiddling with that
.kunitconfig rather than passing in --kunitconfig (I know I am).

>  kunit_tool uses it to generate a .config as you might expect. In addition, it
>  verifies that the generated .config contains the CONFIG options in the
>  .kunitconfig; the reason it does this is so that it is easy to be sure that a
>  CONFIG that enables a test actually ends up in the .config.
>
> -How do I use kunit_tool?
> -
> +It's also possible to pass a separate .kunitconfig fragment to kunit_tool,
> +which is useful if you have several different groups of tests you wish
> +to run independently, or if you want to use pre-defined test configs for
> +certain subsystems.
> +
> +Getting Started with kunit_tool
> +===
>
>  If a kunitconfig is present at the root directory, all you have to do is:
>
> @@ -48,10 +53,129 @@ However, you most likely want to use it with the 
> following options:
>
>  .. note::
> This command will work even without a .kunitconfig file: if no
> -.kunitconfig is present, a default one will be used instead.
> +   .kunitconfig is present, a default one will be used instead.
> +
> +If you wish to use a different .kunitconfig file (such as one provided for
> +testing a particular subsystem), you can pass it as an option.
> +
> +.. code-block:: bash
> +
> +   ./tools/testing/kunit/kunit.py run --kunitconfig=fs/ext4/.kunitconfig
>
>  For a list of all the flags supported by kunit_tool, you can run:
>
>  .. code-block:: bash
>
> ./tools/testing/kunit/kunit.py run --help
> +
> +Configuring, Building, and Running Tests
> +
> +
> +It's also possible to run just parts of the KUnit build process 
> independently,
> +which is useful if you want to make manual changes to part of the process.
> +
> +A .config can be generated from a .kunitconfig by using the ``config`` 
> argument
> +when running kunit_tool:
> +
> +.. code-block:: bash
> +
> +   ./tools/testing/kunit/kunit.py config
> +
> +Similarly, if you just want to build a KUnit kernel from the current .config,
> +you can use the ``build`` argument:
> +
> +.. code-block:: bash
> +
> +   ./tools/testing/kunit/kunit.py build
> +
> +And, if you already have a built UML kernel with built-in KUnit tests, you 
> can
> +run the kernel and display the test results with the ``exec`` argument:
> +
> +.. code-block:: bash
> +
> +   ./tools/testing/kunit/kunit.py exec
> +
> +The ``run`` command which is discussed above is equivalent to running all 
> three
> +of these in sequence.
> +
> +All of these commands accept a number of optional command-line arguments. The
> +``--help`` flag will give a complete list of these, or keep readi

[PATCH v2] kunit: add unit test for filtering suites by names

2021-04-16 Thread Daniel Latypov
This adds unit tests for kunit_filter_subsuite() and
kunit_filter_suites().

Note: what the executor means by "subsuite" is the array of suites
corresponding to each test file.

This patch lightly refactors executor.c to avoid the use of global
variables to make it testable.
It also includes a clever `kfree_at_end()` helper that makes this test
easier to write than it otherwise would have been.

Tested by running just the new tests using itself
$ ./tools/testing/kunit/kunit.py run '*exec*'

Signed-off-by: Daniel Latypov 
Reviewed-by: David Gow 
---
v1 -> v2:
* Fix missing free in kfree_subsuites_at_end()
---
 lib/kunit/executor.c  |  26 
 lib/kunit/executor_test.c | 133 ++
 2 files changed, 148 insertions(+), 11 deletions(-)
 create mode 100644 lib/kunit/executor_test.c

diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c
index 15832ed44668..96a4ae983786 100644
--- a/lib/kunit/executor.c
+++ b/lib/kunit/executor.c
@@ -19,7 +19,7 @@ MODULE_PARM_DESC(filter_glob,
"Filter which KUnit test suites run at boot-time, e.g. list*");
 
 static struct kunit_suite * const *
-kunit_filter_subsuite(struct kunit_suite * const * const subsuite)
+kunit_filter_subsuite(struct kunit_suite * const * const subsuite, const char 
*filter_glob)
 {
int i, n = 0;
struct kunit_suite **filtered;
@@ -52,19 +52,14 @@ struct suite_set {
struct kunit_suite * const * const *end;
 };
 
-static struct suite_set kunit_filter_suites(void)
+static struct suite_set kunit_filter_suites(const struct suite_set *suite_set,
+   const char *filter_glob)
 {
int i;
struct kunit_suite * const **copy, * const *filtered_subsuite;
struct suite_set filtered;
 
-   const size_t max = __kunit_suites_end - __kunit_suites_start;
-
-   if (!filter_glob) {
-   filtered.start = __kunit_suites_start;
-   filtered.end = __kunit_suites_end;
-   return filtered;
-   }
+   const size_t max = suite_set->end - suite_set->start;
 
copy = kmalloc_array(max, sizeof(*filtered.start), GFP_KERNEL);
filtered.start = copy;
@@ -74,7 +69,7 @@ static struct suite_set kunit_filter_suites(void)
}
 
for (i = 0; i < max; ++i) {
-   filtered_subsuite = 
kunit_filter_subsuite(__kunit_suites_start[i]);
+   filtered_subsuite = kunit_filter_subsuite(suite_set->start[i], 
filter_glob);
if (filtered_subsuite)
*copy++ = filtered_subsuite;
}
@@ -98,8 +93,13 @@ static void kunit_print_tap_header(struct suite_set 
*suite_set)
 int kunit_run_all_tests(void)
 {
struct kunit_suite * const * const *suites;
+   struct suite_set suite_set = {
+   .start = __kunit_suites_start,
+   .end = __kunit_suites_end,
+   };
 
-   struct suite_set suite_set = kunit_filter_suites();
+   if (filter_glob)
+   suite_set = kunit_filter_suites(_set, filter_glob);
 
kunit_print_tap_header(_set);
 
@@ -115,4 +115,8 @@ int kunit_run_all_tests(void)
return 0;
 }
 
+#if IS_BUILTIN(CONFIG_KUNIT_TEST)
+#include "executor_test.c"
+#endif
+
 #endif /* IS_BUILTIN(CONFIG_KUNIT) */
diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c
new file mode 100644
index ..cdbe54b16501
--- /dev/null
+++ b/lib/kunit/executor_test.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * KUnit test for the KUnit executor.
+ *
+ * Copyright (C) 2021, Google LLC.
+ * Author: Daniel Latypov 
+ */
+
+#include 
+
+static void kfree_at_end(struct kunit *test, const void *to_free);
+static struct kunit_suite *alloc_fake_suite(struct kunit *test,
+   const char *suite_name);
+
+static void filter_subsuite_test(struct kunit *test)
+{
+   struct kunit_suite *subsuite[3] = {NULL, NULL, NULL};
+   struct kunit_suite * const *filtered;
+
+   subsuite[0] = alloc_fake_suite(test, "suite1");
+   subsuite[1] = alloc_fake_suite(test, "suite2");
+
+   /* Want: suite1, suite2, NULL -> suite2, NULL */
+   filtered = kunit_filter_subsuite(subsuite, "suite2*");
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, filtered);
+   kfree_at_end(test, filtered);
+
+   KUNIT_ASSERT_NOT_ERR_OR_NULL(test, filtered[0]);
+   KUNIT_EXPECT_STREQ(test, (const char *)filtered[0]->name, "suite2");
+
+   KUNIT_EXPECT_FALSE(test, filtered[1]);
+}
+
+static void filter_subsuite_to_empty_test(struct kunit *test)
+{
+   struct kunit_suite *subsuite[3] = {NULL, NULL, NULL};
+   struct kunit_suite * const *filtered;
+
+   subsuite[0] = alloc_fake_suite(test, "suite1");
+   subsuite[1] = alloc_fake_suite(test, "suite2");
+
+   filtered = kunit_filter_subsuite(subsuite, "n

  1   2   3   4   5   6   7   8   9   10   >