Skip to contentSkip to conversation

drivers/perf: riscv: Remove redundant macro check

PATCH Applied Xiao Wang 5 participants 9 messages Jul 8, 2024 – Sep 17, 2024

Subsystems (3)
lore
Share & tools
lore

Xiao Wang

author
#0 lore raw

PATCH 1/1 drivers/perf: riscv: Remove redundant macro check

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/perf/riscv_pmu.c +0 -2
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	userpg->cap_user_time_short = 0;
 	userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
 	/*
 	 * The counters are 64-bit but the priv spec doesn't mandate all the
 	 * bits to be implemented: that's why, counter width can vary based on
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	 */
 	if (userpg->cap_user_rdpmc)
 		userpg->pmc_width = to_riscv_pmu(event->pmu)->ctr_get_width(event->hw.idx) + 1;
-#endif
 
 	do {
 		rd = sched_clock_read_begin(&seq);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · Xiao Wang

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

Did you investigate why this define was added? Why do you think that it is redundant, rather than checking the incorrect config option?

Cheers,
Conor.

Quoted 34 lines
---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/perf/riscv_pmu.c +0 -2
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	userpg->cap_user_time_short = 0;
 	userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
 	/*
 	 * The counters are 64-bit but the priv spec doesn't mandate all the
 	 * bits to be implemented: that's why, counter width can vary based on
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	 */
 	if (userpg->cap_user_rdpmc)
 		userpg->pmc_width = to_riscv_pmu(event->pmu)->ctr_get_width(event->hw.idx) + 1;
-#endif
 
 	do {
 		rd = sched_clock_read_begin(&seq);
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw
Quoted 6 lines · Conor Dooley
Quoted 2 lines · Xiao Wang

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

Did you investigate why this define was added? Why do you think that it is redundant, rather than checking the incorrect config option?

This file is only compiled with CONFIG_RISCV_PMU:

# drivers/perf/Makefile
obj-$(CONFIG_RISCV_PMU) += riscv_pmu.o

So having this check does seem redundant. I am copying Alex as it looks like he wrote this.

- Charlie

Quoted 38 lines

Cheers,
Conor.

Quoted 34 lines
---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/perf/riscv_pmu.c +0 -2
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	userpg->cap_user_time_short = 0;
 	userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
 	/*
 	 * The counters are 64-bit but the priv spec doesn't mandate all the
 	 * bits to be implemented: that's why, counter width can vary based on
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	 */
 	if (userpg->cap_user_rdpmc)
 		userpg->pmc_width = to_riscv_pmu(event->pmu)->ctr_get_width(event->hw.idx) + 1;
-#endif
 
 	do {
 		rd = sched_clock_read_begin(&seq);
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw
Quoted 9 lines · Charlie Jenkins
Quoted 6 lines · Conor Dooley
Quoted 2 lines · Xiao Wang

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

Did you investigate why this define was added? Why do you think that it is redundant, rather than checking the incorrect config option?

This file is only compiled with CONFIG_RISCV_PMU:

I might be ill, but I can still read. I was not disagreeing with Xiao that the condition is redundant as written - I want to know whether they made sure that this check was intentionally using CONFIG_RISCV_PMU in the first place, or if another option should have been here instead.

Quoted 48 lines

# drivers/perf/Makefile
obj-$(CONFIG_RISCV_PMU) += riscv_pmu.o

So having this check does seem redundant. I am copying Alex as it looks like he wrote this.

- Charlie

Quoted 38 lines

Cheers,
Conor.

Quoted 34 lines
---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/perf/riscv_pmu.c +0 -2
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	userpg->cap_user_time_short = 0;
 	userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
 	/*
 	 * The counters are 64-bit but the priv spec doesn't mandate all the
 	 * bits to be implemented: that's why, counter width can vary based on
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	 */
 	if (userpg->cap_user_rdpmc)
 		userpg->pmc_width = to_riscv_pmu(event->pmu)->ctr_get_width(event->hw.idx) + 1;
-#endif
 
 	do {
 		rd = sched_clock_read_begin(&seq);
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#4 lore raw
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Charlie Jenkins
Quoted 6 lines · Conor Dooley
Quoted 2 lines · Xiao Wang

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

Did you investigate why this define was added? Why do you think that it is redundant, rather than checking the incorrect config option?

Quoted 6 lines
Quoted 1 line

This file is only compiled with CONFIG_RISCV_PMU:

I might be ill, but I can still read. I was not disagreeing with Xiao that the condition is redundant as written - I want to know whether they made sure that this check was intentionally using CONFIG_RISCV_PMU in the first place, or if another option should have been here instead.

Makes sense! Looking through the lists I see this RFC from Atish where he introduced a different config option for this "CONFIG_RISCV_PMU_COMMON"[1]. I wonder if something got confused in the development of these two patches.

Link:
https://lore.kernel.org/lkml/[email protected]/
[1]

- Charlie

Quoted 49 lines
Quoted 49 lines

# drivers/perf/Makefile
obj-$(CONFIG_RISCV_PMU) += riscv_pmu.o

So having this check does seem redundant. I am copying Alex as it looks like he wrote this.

- Charlie

Quoted 38 lines

Cheers,
Conor.

Quoted 34 lines
---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/perf/riscv_pmu.c +0 -2
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	userpg->cap_user_time_short = 0;
 	userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
 	/*
 	 * The counters are 64-bit but the priv spec doesn't mandate all the
 	 * bits to be implemented: that's why, counter width can vary based on
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	 */
 	if (userpg->cap_user_rdpmc)
 		userpg->pmc_width = to_riscv_pmu(event->pmu)->ctr_get_width(event->hw.idx) + 1;
-#endif
 
 	do {
 		rd = sched_clock_read_begin(&seq);
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#5 lore raw
Quoted 17 lines · Charlie Jenkins
Quoted 9 lines · Conor Dooley
Quoted 8 lines · Charlie Jenkins
Quoted 6 lines · Conor Dooley
Quoted 2 lines · Xiao Wang

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

Did you investigate why this define was added? Why do you think that it is redundant, rather than checking the incorrect config option?

Quoted 6 lines
Quoted 1 line

This file is only compiled with CONFIG_RISCV_PMU:

I might be ill, but I can still read. I was not disagreeing with Xiao that the condition is redundant as written - I want to know whether they made sure that this check was intentionally using CONFIG_RISCV_PMU in the first place, or if another option should have been here instead.

Quoted 4 lines

Makes sense! Looking through the lists I see this RFC from Atish where he introduced a different config option for this "CONFIG_RISCV_PMU_COMMON"[1]. I wonder if something got confused in the development of these two patches.

Perhaps.. What I was worried about was the wrong option being here (maybe that it should have been RISCV_PMU_SBI or similar) and depending on how the kernel is configured, userspace would get the wrong info here. But maybe it is innocuous your theory would suggest, and there's nothing to worry about. But that's for someone with a functioning brain to figure out ;)

Cheers,
Conor.

Quoted 48 lines

Link:
https://lore.kernel.org/lkml/[email protected]/
[1]

Quoted 41 lines
Quoted 41 lines

# drivers/perf/Makefile
obj-$(CONFIG_RISCV_PMU) += riscv_pmu.o

So having this check does seem redundant. I am copying Alex as it looks like he wrote this.

Quoted 34 lines
Quoted 34 lines
---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/perf/riscv_pmu.c +0 -2
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	userpg->cap_user_time_short = 0;
 	userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
 	/*
 	 * The counters are 64-bit but the priv spec doesn't mandate all the
 	 * bits to be implemented: that's why, counter width can vary based on
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct perf_event *event,
 	 */
 	if (userpg->cap_user_rdpmc)
 		userpg->pmc_width = to_riscv_pmu(event->pmu)->ctr_get_width(event->hw.idx) + 1;
-#endif
 
 	do {
 		rd = sched_clock_read_begin(&seq);
Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by
#6 lore raw
Quoted 19 lines · Conor Dooley
Quoted 17 lines · Charlie Jenkins
Quoted 15 lines · Conor Dooley
Quoted 9 lines · Charlie Jenkins
Quoted 6 lines · Conor Dooley
Quoted 2 lines · Xiao Wang

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

Did you investigate why this define was added? Why do you think that it is redundant, rather than checking the incorrect config option?

This file is only compiled with CONFIG_RISCV_PMU:

I might be ill, but I can still read. I was not disagreeing with Xiao that the condition is redundant as written - I want to know whether they made sure that this check was intentionally using CONFIG_RISCV_PMU in the first place, or if another option should have been here instead.

Quoted 5 lines
Quoted 4 lines

Makes sense! Looking through the lists I see this RFC from Atish where he introduced a different config option for this "CONFIG_RISCV_PMU_COMMON"[1]. I wonder if something got confused in the development of these two patches.

Nope. That's not related as the above series is a complete revamp of PMU infrastructure
and far from being merged.

Quoted 7 lines

Perhaps.. What I was worried about was the wrong option being here (maybe that it should have been RISCV_PMU_SBI or similar) and depending on how the kernel is configured, userspace would get the wrong info here. But maybe it is innocuous your theory would suggest, and there's nothing to worry about. But that's for someone with a functioning brain to figure out ;)

This macro has been there since v3 of the original series.
https://lore.kernel.org/lkml/[email protected]/

Ideally, this should have been RISCV_PMU_SBI as ctr_get_width was not defined earlier for legacy.
However, that was fixed here
https://lore.kernel.org/lkml/[email protected]/

So we can remove the macro check here.

Quoted 51 lines

Cheers,
Conor.

Quoted 48 lines

Link:
https://lore.kernel.org/lkml/[email protected]/
[1]

Quoted 41 lines
Quoted 41 lines

# drivers/perf/Makefile
obj-$(CONFIG_RISCV_PMU) += riscv_pmu.o

So having this check does seem redundant. I am copying Alex as it looks like he wrote this.

Quoted 34 lines
Quoted 34 lines
---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
drivers/perf/riscv_pmu.c +0 -3
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct perf_event *event,
      userpg->cap_user_time_short = 0;
      userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
      /*
       * The counters are 64-bit but the priv spec doesn't mandate all the
       * bits to be implemented: that's why, counter width can vary based on
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct perf_event *event,
       */
      if (userpg->cap_user_rdpmc)
              userpg->pmc_width = to_riscv_pmu(event->pmu)->ctr_get_width(event->hw.idx) + 1;
-#endif
 
      do {
              rd = sched_clock_read_begin(&seq);
--

2.25.1

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Signature · 2 lines
Regards,
Atish
#7 lore raw
Quoted 64 lines

-----Original Message-----
From: Atish Patra <[email protected]>
Sent: Wednesday, July 10, 2024 5:44 AM
To: Conor Dooley <[email protected]>
Cc: Charlie Jenkins <[email protected]>; Wang, Xiao W <[email protected]>; Alexandre Ghiti <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH] drivers/perf: riscv: Remove redundant macro check

Quoted 7 lines · Conor Dooley
Quoted 5 lines · Charlie Jenkins
Quoted 4 lines · Conor Dooley
Quoted 3 lines · Charlie Jenkins
Quoted 2 lines · Conor Dooley
Quoted 1 line · Xiao Wang

The macro CONFIG_RISCV_PMU must have been defined when

riscv_pmu.c gets

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

compiled, so this patch removes the redundant check.

Did you investigate why this define was added? Why do you think

that it

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

is redundant, rather than checking the incorrect config option?

This file is only compiled with CONFIG_RISCV_PMU:

I might be ill, but I can still read. I was not disagreeing with Xiao that the condition is redundant as written - I want to know whether they made sure that this check was intentionally using CONFIG_RISCV_PMU in

the

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

first place, or if another option should have been here instead.

Makes sense! Looking through the lists I see this RFC from Atish where he introduced a different config option for this "CONFIG_RISCV_PMU_COMMON"[1]. I wonder if something got

confused in the

Quoted 2 lines
Quoted 1 line

development of these two patches.

Nope. That's not related as the above series is a complete revamp of PMU infrastructure
and far from being merged.

Quoted 7 lines

Perhaps.. What I was worried about was the wrong option being here (maybe that it should have been RISCV_PMU_SBI or similar) and depending on how the kernel is configured, userspace would get the wrong info here. But maybe it is innocuous your theory would suggest, and there's nothing to worry about. But that's for someone with a functioning brain to figure out ;)

This macro has been there since v3 of the original series.
https://lore.kernel.org/lkml/20230802080328.1213905-8-
[email protected]/

Ideally, this should have been RISCV_PMU_SBI as ctr_get_width was not defined earlier for legacy.
However, that was fixed here
https://lore.kernel.org/lkml/20240227170002.188671-3-
[email protected]/

Quoted 4 lines

So we can remove the macro check here.

Thanks for all the comments from Conor, Charlie and Atish.
From userspace perspective (e.g. tools/lib/perf/mmap.c), if cap_user_rdpmc is enabled, then pmc_width should be set. It's independent of arch and config options.

BRs,
Xiao

Quoted 63 lines
Quoted 6 lines

Cheers,
Conor.

Quoted 3 lines

Link:
https://lore.kernel.org/lkml/20240217005738.3744121-12-

[email protected]/

Quoted 14 lines
Quoted 14 lines

[1]

Quoted 12 lines
Quoted 12 lines

# drivers/perf/Makefile
obj-$(CONFIG_RISCV_PMU) += riscv_pmu.o

So having this check does seem redundant. I am copying Alex as it looks like he wrote this.

Quoted 6 lines
Quoted 6 lines
---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

drivers/perf/riscv_pmu.c void arch_perf_update_userpage(struct

Quoted 5 lines
drivers/perf/riscv_pmu.c +0 -0
index 0a02e85a8951..7644147d50b4 100644
@@ -39,7 +39,6 @@ void arch_perf_update_userpage(struct

perf_event *event,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/perf/riscv_pmu.c void arch_perf_update_userpage(struct · line 43

Quoted 6 lines
drivers/perf/riscv_pmu.c +0 -1
      userpg->cap_user_time_short = 0;
      userpg->cap_user_rdpmc = riscv_perf_user_access(event);
 
-#ifdef CONFIG_RISCV_PMU
      /*
       * The counters are 64-bit but the priv spec doesn't mandate all

the

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/perf/riscv_pmu.c void arch_perf_update_userpage(struct · line 44

Quoted 1 line
drivers/perf/riscv_pmu.c +0 -0
       * bits to be implemented: that's why, counter width can vary

based on

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/perf/riscv_pmu.c void arch_perf_update_userpage(struct

Quoted 1 line
drivers/perf/riscv_pmu.c +0 -0
@@ -47,7 +46,6 @@ void arch_perf_update_userpage(struct

perf_event *event,

Quoted 19 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/perf/riscv_pmu.c void arch_perf_update_userpage(struct · line 48

Quoted 3 lines
drivers/perf/riscv_pmu.c +0 -0
       */
      if (userpg->cap_user_rdpmc)
              userpg->pmc_width = to_riscv_pmu(event->pmu)-

ctr_get_width(event->hw.idx) + 1;

Quoted 15 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 12 lines
drivers/perf/riscv_pmu.c +0 -2
-#endif
 
      do {
              rd = sched_clock_read_begin(&seq);
--

2.25.1

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

--
Regards,
Atish

#8 lore raw
In reply to Xiao Wang
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 7 lines · On Mon, 8 Jul 2024 20:12:24 +0800 you wrote:

The macro CONFIG_RISCV_PMU must have been defined when riscv_pmu.c gets compiled, so this patch removes the redundant check.

---
 drivers/perf/riscv_pmu.c | 2 --
 1 file changed, 2 deletions(-)

Here is the summary with links:
- drivers/perf: riscv: Remove redundant macro check

    https://git.kernel.org/riscv/c/1e206fad765b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html