Skip to contentSkip to conversation

sched/cputime: Mark function as __maybe_unused

PATCH In review Alex Dewar 4 participants 6 messages Aug 18, 2020 – Aug 19, 2020 Scheduler

lore
Share & tools
lore

Alex Dewar

author
#0 lore raw

PATCH 1/1 sched/cputime: Mark function as __maybe_unused

Depending on config options, account_other_time() may not be called anywhere. Add __maybe_unused flag to fix clang warning.

---
 kernel/sched/cputime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cputime.c +1 -1
index 5a55d2300452..43ede0d6661c 100644
@@ -252,7 +252,7 @@ static __always_inline u64 steal_account_process_time(u64 maxtime)
 /*
  * Account how much elapsed time was spent in steal, irq, or softirq time.
  */
-static inline u64 account_other_time(u64 max)
+static inline u64 __maybe_unused account_other_time(u64 max)
 {
 	u64 accounted;
 
Signature · 1 line
2.28.0
#1 lore raw
Quoted 3 lines · Alex Dewar

Depending on config options, account_other_time() may not be called anywhere. Add __maybe_unused flag to fix clang warning.

Just curious, would moving this definition to be within an existing preprocessor guard for a particular config also fix the issue? If so, prefer that. If not, __maybe_unused is the way to go.

Quoted 26 lines
---
 kernel/sched/cputime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cputime.c +1 -2
index 5a55d2300452..43ede0d6661c 100644
@@ -252,7 +252,7 @@ static __always_inline u64 steal_account_process_time(u64 maxtime)
 /*
  * Account how much elapsed time was spent in steal, irq, or softirq time.
  */
-static inline u64 account_other_time(u64 max)
+static inline u64 __maybe_unused account_other_time(u64 max)
 {
        u64 accounted;
 
--

2.28.0

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200818170337.805624-1-alex.dewar90%40gmail.com.

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#2 lore raw
Quoted 8 lines · Nick Desaulniers
Quoted 3 lines · Alex Dewar

Depending on config options, account_other_time() may not be called anywhere. Add __maybe_unused flag to fix clang warning.

Just curious, would moving this definition to be within an existing preprocessor guard for a particular config also fix the issue? If so, prefer that. If not, __maybe_unused is the way to go.

I don't think that'd work here: it's used within an "#ifdef CONFIG_IRQ_TIME_ACCOUNTING" block and a separate "#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN" one. We could do:

	#if defined(CONFIG_IRQ_TIME_ACCOUNTING) ||
	    defined(CONFIG_VIRT_CPU_ACCOUNTING)
		...

... but that might be a bit ugly.

Quoted 33 lines
Quoted 27 lines
---
 kernel/sched/cputime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cputime.c +1 -2
index 5a55d2300452..43ede0d6661c 100644
@@ -252,7 +252,7 @@ static __always_inline u64 steal_account_process_time(u64 maxtime)
 /*
  * Account how much elapsed time was spent in steal, irq, or softirq time.
  */
-static inline u64 account_other_time(u64 max)
+static inline u64 __maybe_unused account_other_time(u64 max)
 {
        u64 accounted;
 
--

2.28.0

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200818170337.805624-1-alex.dewar90%40gmail.com.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#3 lore raw
Quoted 11 lines · Alex Dewar
Quoted 8 lines · Nick Desaulniers
Quoted 3 lines · Alex Dewar

Depending on config options, account_other_time() may not be called anywhere. Add __maybe_unused flag to fix clang warning.

Just curious, would moving this definition to be within an existing preprocessor guard for a particular config also fix the issue? If so, prefer that. If not, __maybe_unused is the way to go.

Quoted 7 lines

I don't think that'd work here: it's used within an "#ifdef CONFIG_IRQ_TIME_ACCOUNTING" block and a separate "#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN" one. We could do:

        #if defined(CONFIG_IRQ_TIME_ACCOUNTING) ||
            defined(CONFIG_VIRT_CPU_ACCOUNTING)
                ...

... but that might be a bit ugly.

Yeah, ok, in that case it's fine. One issue with __maybe_unused is that this function will stick around forever if all call sites get removed. But when the preprocessor checks start getting hairy, __maybe_unused is maybe simpler.

Quoted 34 lines
Quoted 34 lines
Quoted 24 lines
---
 kernel/sched/cputime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cputime.c +1 -2
index 5a55d2300452..43ede0d6661c 100644
@@ -252,7 +252,7 @@ static __always_inline u64 steal_account_process_time(u64 maxtime)
 /*
  * Account how much elapsed time was spent in steal, irq, or softirq time.
  */
-static inline u64 account_other_time(u64 max)
+static inline u64 __maybe_unused account_other_time(u64 max)
 {
        u64 accounted;
 
--

2.28.0

Quoted 4 lines

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200818170337.805624-1-alex.dewar90%40gmail.com.

--
Thanks,
~Nick Desaulniers

Signature · 2 lines
Thanks,
~Nick Desaulniers
reviewer Acked-by
#4 lore raw
Quoted 20 lines · On Tue, 18 Aug 2020 13:02:26 -0700 Nick Desaulniers <[email protected]>…
Quoted 11 lines · Alex Dewar
Quoted 8 lines · Nick Desaulniers
Quoted 3 lines · Alex Dewar

Depending on config options, account_other_time() may not be called anywhere. Add __maybe_unused flag to fix clang warning.

Just curious, would moving this definition to be within an existing preprocessor guard for a particular config also fix the issue? If so, prefer that. If not, __maybe_unused is the way to go.

Quoted 7 lines

I don't think that'd work here: it's used within an "#ifdef CONFIG_IRQ_TIME_ACCOUNTING" block and a separate "#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN" one. We could do:

        #if defined(CONFIG_IRQ_TIME_ACCOUNTING) ||
            defined(CONFIG_VIRT_CPU_ACCOUNTING)
                ...

... but that might be a bit ugly.

Quoted 4 lines

Yeah, ok, in that case it's fine. One issue with __maybe_unused is that this function will stick around forever if all call sites get removed. But when the preprocessor checks start getting hairy, __maybe_unused is maybe simpler.

For the reasons you state above, I'm almost thinking ugly may be better. :-/

But there's other places that have the "maybe_unused" in the scheduler code for basically the same reasons, thus I guess it's OK.

-- Steve

Quoted 39 lines
Quoted 34 lines
Quoted 34 lines
Quoted 24 lines
---
 kernel/sched/cputime.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/cputime.c +1 -2
index 5a55d2300452..43ede0d6661c 100644
@@ -252,7 +252,7 @@ static __always_inline u64 steal_account_process_time(u64 maxtime)
 /*
  * Account how much elapsed time was spent in steal, irq, or softirq time.
  */
-static inline u64 account_other_time(u64 max)
+static inline u64 __maybe_unused account_other_time(u64 max)
 {
        u64 accounted;
 
--

2.28.0

Quoted 4 lines

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200818170337.805624-1-alex.dewar90%40gmail.com.

--
Thanks,
~Nick Desaulniers

#5 lore raw
In reply to Nick Desaulniers
Quoted 20 lines · Nick Desaulniers
Quoted 11 lines · Alex Dewar
Quoted 8 lines · Nick Desaulniers
Quoted 3 lines · Alex Dewar

Depending on config options, account_other_time() may not be called anywhere. Add __maybe_unused flag to fix clang warning.

Just curious, would moving this definition to be within an existing preprocessor guard for a particular config also fix the issue? If so, prefer that. If not, __maybe_unused is the way to go.

Quoted 7 lines

I don't think that'd work here: it's used within an "#ifdef CONFIG_IRQ_TIME_ACCOUNTING" block and a separate "#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN" one. We could do:

        #if defined(CONFIG_IRQ_TIME_ACCOUNTING) ||
            defined(CONFIG_VIRT_CPU_ACCOUNTING)
                ...

... but that might be a bit ugly.

Quoted 4 lines

Yeah, ok, in that case it's fine. One issue with __maybe_unused is that this function will stick around forever if all call sites get removed. But when the preprocessor checks start getting hairy, __maybe_unused is maybe simpler.

Urgh, also, I have vague memories that we made it 'static inline' to avoid all this. Should we instead mark it __always_inline ?

Also; I detest the placement of __maybe_unused, it is not a return value, but a git-grep showed me it is wide-spread :/