Skip to contentSkip to conversation

powerpc/time: Export boot_tb and log initial timebase at boot

PATCH In review Kajol Jain 3 participants 5 messages Feb 4, 2025 – Feb 8, 2025 PowerPC

lore
Share & tools
lore

Kajol Jain

author
#0 lore raw

PATCH v2 1/3 powerpc/time: Export boot_tb and log initial timebase at boot

From: Aboorva Devarajan <[email protected]>

- Export boot_tb for external use, this is useful in perf vpa-dtl interface, where boot_tb can be used to convert raw timebase values to it's relative boot timestamp.

- Log the initial timebase at time_init as it is a useful information which can be referred to as needed.

---
 arch/powerpc/include/asm/time.h | 1 +
 arch/powerpc/kernel/time.c      | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/time.h +1 -0
index 9bdd8080299b..b6fc5df01d53 100644
@@ -23,6 +23,7 @@ extern u64 decrementer_max;
 extern unsigned long tb_ticks_per_jiffy;
 extern unsigned long tb_ticks_per_usec;
 extern unsigned long tb_ticks_per_sec;
+extern u64 boot_tb;
 extern struct clock_event_device decrementer_clockevent;
 extern u64 decrementer_max;
 
arch/powerpc/kernel/time.c +3 -1
index 0727332ad86f..6e8548f0e48f 100644
@@ -137,7 +137,8 @@ EXPORT_SYMBOL_GPL(rtc_lock);
 
 static u64 tb_to_ns_scale __read_mostly;
 static unsigned tb_to_ns_shift __read_mostly;
-static u64 boot_tb __read_mostly;
+u64 boot_tb __read_mostly;
+EXPORT_SYMBOL_GPL(boot_tb);
 
 extern struct timezone sys_tz;
 static long timezone_offset;
@@ -943,6 +944,7 @@ void __init time_init(void)
 	tb_to_ns_shift = shift;
 	/* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
 	boot_tb = get_tb();
+	pr_debug("%s: timebase at boot: %llu\n", __func__, (unsigned long long)boot_tb);
 
 	/* If platform provided a timezone (pmac), we correct the time */
 	if (timezone_offset) {
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v2 2/3 powerpc/vpa_dtl: Add interface to expose vpa dtl counters via perf

The pseries Shared Processor Logical Partition(SPLPAR) machines can retrieve a log of dispatch and preempt events from the hypervisor using data from Disptach Trace Log(DTL) buffer. With this information, user can retrieve when and why each dispatch & preempt has occurred. Added an interface to expose the Virtual Processor Area(VPA) DTL counters via perf.

The following events are available and exposed in sysfs:

vpa_dtl/dtl_cede/ - Trace voluntary (OS initiated) virtual processor waits vpa_dtl/dtl_preempt/ - Trace time slice preempts vpa_dtl/dtl_fault/ - Trace virtual partition memory page faults. vpa_dtl/dtl_all/ - Trace all (dtl_cede/dtl_preempt/dtl_fault)

Added interface defines supported event list, config fields for the event attributes and their corresponding bit values which are exported via sysfs. User could use the standard perf tool to access perf events exposed via vpa-dtl pmu.

The VPA DTL PMU counters do not interrupt on overflow or generate any PMI interrupts. Therefore, the kernel needs to poll the counters, added hrtimer code to do that. The timer interval can be provided by user via sample_period field in nano seconds.

Result on power10 SPLPAR system with 656 cpu threads.
In the below perf record command with vpa_dtl pmu, -c option is used to provide sample_period whch corresponding to 1000000000ns i.e; 1sec and the workload time is also 1 second, hence we are getting 656 samples:

[command] perf record -a -R -e vpa_dtl/dtl_all/ -c 1000000000 sleep 1 [ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.828 MB perf.data (656 samples) ]

There is one hrtimer added per vpa-dtl pmu thread. Code added to handle addition of dtl buffer data in the raw sample. Since DTL does not provide IP address for a sample and it just have traces on reason of dispatch/preempt, we directly saving DTL buffer data to perf.data file as raw sample. For each hrtimer restart call, interface will dump all the new dtl entries added to dtl buffer as a raw sample.

To ensure there are no other conflicting dtl users (example: debugfs dtl or /proc/powerpc/vcpudispatch_stats), interface added code to use "down_write_trylock" call to take the dtl_access_lock. The dtl_access_lock is defined in dtl.h file. Also added global reference count variable called "dtl_global_refc", to ensure dtl data can be captured per-cpu. Code also added global lock called "dtl_global_lock" to avoid race condition.

---

Changelog:

v1 -> v2
- Rebase patches on top latest upstream kernel
- Remove the cpu online/offline code and directly allocating and deallocating memory of dtl_cache in event_init/event_del function respectively.
- Also include boot_tb variable as part of raw sample to convert timebase value into relative system time.
- Also add check for CONFIG_PPC_SPLPAR

 arch/powerpc/perf/Makefile  |   2 +-
 arch/powerpc/perf/vpa-dtl.c | 421 ++++++++++++++++++++++++++++++++++++
 2 files changed, 422 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/perf/vpa-dtl.c
arch/powerpc/perf/Makefile +1 -1
index ac2cf58d62db..623168572685 100644
@@ -14,7 +14,7 @@ obj-$(CONFIG_PPC_POWERNV)	+= imc-pmu.o
 obj-$(CONFIG_FSL_EMB_PERF_EVENT) += core-fsl-emb.o
 obj-$(CONFIG_FSL_EMB_PERF_EVENT_E500) += e500-pmu.o e6500-pmu.o
 
-obj-$(CONFIG_HV_PERF_CTRS) += hv-24x7.o hv-gpci.o hv-common.o
+obj-$(CONFIG_HV_PERF_CTRS) += hv-24x7.o hv-gpci.o hv-common.o vpa-dtl.o
 
 obj-$(CONFIG_VPA_PMU) += vpa-pmu.o
 
arch/powerpc/perf/vpa-dtl.c new file +421 -0

421 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#2 lore raw

PATCH v2 3/3 docs: ABI: sysfs-bus-event_source-devices-vpa-dtl: Document sysfs event format entries for vpa_dtl pmu

In reply to Kajol Jain

Details are added for the vpa_dtl pmu event and format attributes in the ABI documentation.

---
 .../sysfs-bus-event_source-devices-vpa-dtl    | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-event_source-devices-vpa-dtl
Documentation/ABI/testing/sysfs-bus-event_source-devices-vpa-dtl new file +25 -0
new file mode 100644
index 000000000000..39882e0e852d
@@ -0,0 +1,25 @@
+What:           /sys/bus/event_source/devices/vpa_dtl/format
+Date:           January 2025
+Contact:        Linux on PowerPC Developer List <[email protected]>
+Description:    Read-only. Attribute group to describe the magic bits
+                that go into perf_event_attr.config for a particular pmu.
+                (See ABI/testing/sysfs-bus-event_source-devices-format).
+
+                Each attribute under this group defines a bit range of the
+                perf_event_attr.config. Supported attribute are listed
+                below::
+
+				event  = "config:0-7"  - event ID
+
+		For example::
+
+		  dtl_cede = "event=0x1"
+
+What:           /sys/bus/event_source/devices/vpa_dtl/events
+Date:           January 2025
+Contact:        Linux on PowerPC Developer List <[email protected]>
+Description:	(RO) Attribute group to describe performance monitoring events
+                for the Virtual Processor Dispatch Trace Log. Each attribute in
+		this group describes a single performance monitoring event
+		supported by vpa_dtl pmu.  The name of the file is the name of
+		the event (See ABI/testing/sysfs-bus-event_source-devices-events).
Signature · 1 line
2.43.0
#3 lore raw
In reply to Kajol Jain

Le 04/02/2025 à 07:39, Kajol Jain a écrit :

Quoted 5 lines

From: Aboorva Devarajan <[email protected]>

- Export boot_tb for external use, this is useful in perf vpa-dtl interface, where boot_tb can be used to convert raw timebase values to it's relative boot timestamp.

A modification of boot_tb can be catastrophic. I would not export it as is as it doesn't need to be modified, would be better to provide it through an accessor, for instance a function called get_boot_tb()

By the way, it is only modified by time_init() which is an __init function, so boot_tb should be marked __ro_after_init instead of __read_mostly, then in that case it would be more acceptable to export it.

Quoted 45 lines

- Log the initial timebase at time_init as it is a useful information which can be referred to as needed.

---
  arch/powerpc/include/asm/time.h | 1 +
  arch/powerpc/kernel/time.c      | 4 +++-
  2 files changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/time.h +1 -0
index 9bdd8080299b..b6fc5df01d53 100644
@@ -23,6 +23,7 @@ extern u64 decrementer_max;
  extern unsigned long tb_ticks_per_jiffy;
  extern unsigned long tb_ticks_per_usec;
  extern unsigned long tb_ticks_per_sec;
+extern u64 boot_tb;
  extern struct clock_event_device decrementer_clockevent;
  extern u64 decrementer_max;
 
arch/powerpc/kernel/time.c +3 -1
index 0727332ad86f..6e8548f0e48f 100644
@@ -137,7 +137,8 @@ EXPORT_SYMBOL_GPL(rtc_lock);
 
  static u64 tb_to_ns_scale __read_mostly;
  static unsigned tb_to_ns_shift __read_mostly;
-static u64 boot_tb __read_mostly;
+u64 boot_tb __read_mostly;
+EXPORT_SYMBOL_GPL(boot_tb);
 
  extern struct timezone sys_tz;
  static long timezone_offset;
@@ -943,6 +944,7 @@ void __init time_init(void)
  	tb_to_ns_shift = shift;
  	/* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
  	boot_tb = get_tb();
+	pr_debug("%s: timebase at boot: %llu\n", __func__, (unsigned long long)boot_tb);
 
  	/* If platform provided a timezone (pmac), we correct the time */
  	if (timezone_offset) {
#4 lore raw

On Tue, 2025-02-04 at 11:28 +0100, Christophe Leroy wrote:

Hi Christophe,

Quoted 8 lines · Kajol Jain
Quoted 5 lines

From: Aboorva Devarajan <[email protected]>

- Export boot_tb for external use, this is useful in perf vpa-dtl interface, where boot_tb can be used to convert raw timebase values to it's relative boot timestamp.

Quoted 7 lines

A modification of boot_tb can be catastrophic. I would not export it as is as it doesn't need to be modified, would be better to provide it through an accessor, for instance a function called get_boot_tb()

By the way, it is only modified by time_init() which is an __init function, so boot_tb should be marked __ro_after_init instead of __read_mostly, then in that case it would be more acceptable to export it.

Thanks for the review and suggestions. Yes boot_tb is just initialized once and is never updated again, I’ll update the patch to mark it __ro_after_init. I’ll also use an accessor function (get_boot_tb()) instead of exporting it, as it will be clean and maintainable.

Will send a v3 with the updates.

Regards,
Aboorva

Quoted 45 lines
Quoted 45 lines

- Log the initial timebase at time_init as it is a useful information which can be referred to as needed.

---
  arch/powerpc/include/asm/time.h | 1 +
  arch/powerpc/kernel/time.c      | 4 +++-
  2 files changed, 4 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/time.h +1 -0
index 9bdd8080299b..b6fc5df01d53 100644
@@ -23,6 +23,7 @@ extern u64 decrementer_max;
  extern unsigned long tb_ticks_per_jiffy;
  extern unsigned long tb_ticks_per_usec;
  extern unsigned long tb_ticks_per_sec;
+extern u64 boot_tb;
  extern struct clock_event_device decrementer_clockevent;
  extern u64 decrementer_max;
 
arch/powerpc/kernel/time.c +3 -1
index 0727332ad86f..6e8548f0e48f 100644
@@ -137,7 +137,8 @@ EXPORT_SYMBOL_GPL(rtc_lock);
 
  static u64 tb_to_ns_scale __read_mostly;
  static unsigned tb_to_ns_shift __read_mostly;
-static u64 boot_tb __read_mostly;
+u64 boot_tb __read_mostly;
+EXPORT_SYMBOL_GPL(boot_tb);
 
  extern struct timezone sys_tz;
  static long timezone_offset;
@@ -943,6 +944,7 @@ void __init time_init(void)
  	tb_to_ns_shift = shift;
  	/* Save the current timebase to pretty up CONFIG_PRINTK_TIME */
  	boot_tb = get_tb();
+	pr_debug("%s: timebase at boot: %llu\n", __func__, (unsigned long long)boot_tb);
 
  	/* If platform provided a timezone (pmac), we correct the time */
  	if (timezone_offset) {