cpuidle: haltpoll: Add trace points for guest_halt_poll_ns grow/shrink
Subsystems (2)
PATCH v2 1/1 cpuidle: haltpoll: Add trace points for guest_halt_poll_ns grow/shrink
Add trace points as are implemented in KVM host halt polling. This helps tune guest halt polling params.
--- drivers/cpuidle/governors/haltpoll.c | 15 ++++++++----- include/trace/events/power.h | 33 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-)
drivers/cpuidle/governors/haltpoll.c +10 -5
@@ -19,6 +19,7 @@#include <linux/sched.h> #include <linux/module.h> #include <linux/kvm_para.h> +#include <trace/events/power.h> static unsigned int guest_halt_poll_ns__read_mostly =200000 ;module_param (guest_halt_poll_ns, uint,0644 );
@@ -77,13 +78,16 @@ static int haltpoll_select(struct cpuidle_driver *drv,static void adjust_poll_limit (struct cpuidle_device *dev,u64 block_ns) { -unsigned int val; +unsigned int val, old; -/* Grow cpu_halt_poll_us if -* cpu_halt_poll_us < block_ns < guest_halt_poll_us + val = dev->poll_limit_ns; + old = val; + +/* Grow poll_limit_ns if +* poll_limit_ns < block_ns < guest_halt_poll_ns */ if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) { - val = dev->poll_limit_ns * guest_halt_poll_grow; + val *= guest_halt_poll_grow;if (val < guest_halt_poll_grow_start) val = guest_halt_poll_grow_start;
@@ -91,16 +95,17 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) val = guest_halt_poll_ns; dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_grow (smp_processor_id (), val, old); }else if (block_ns > guest_halt_poll_ns && guest_halt_poll_allow_shrink) {unsigned int shrink = guest_halt_poll_shrink; - val = dev->poll_limit_ns;if (shrink ==0 ) val =0 ;else val /= shrink; dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_shrink (smp_processor_id (), val, old); } }
include/trace/events/power.h +33 -0
@@ -500,6 +500,39 @@ DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request,TP_ARGS (name, type, new_value) ); + +TRACE_EVENT (guest_halt_poll_ns, + + TP_PROTO(bool grow, unsigned int cpu_id, + unsigned int new, unsigned int old), + +TP_ARGS (grow, cpu_id, new, old), + +TP_STRUCT__entry ( + __field(bool, grow) + __field(unsigned int, cpu_id) + __field(unsigned int, new) + __field(unsigned int, old) + ), + +TP_fast_assign ( + __entry->grow = grow; + __entry->cpu_id = cpu_id; + __entry->new = new; + __entry->old = old; + ), + +TP_printk ("cpu %u: halt_poll_ns %u (%s %u)" , + __entry->cpu_id, + __entry->new, + __entry->grow ?"grow" :"shrink" , + __entry->old) +); + +#define trace_guest_halt_poll_ns_grow (cpu_id, new, old) \ + trace_guest_halt_poll_ns(true, cpu_id, new, old) +#define trace_guest_halt_poll_ns_shrink (cpu_id, new, old) \ + trace_guest_halt_poll_ns(false, cpu_id, new, old)#endif /* _TRACE_POWER_H */ /* This part must be outside protection */
Signature · 1 line
2.36.1
Steven Rostedt
maintainerdrivers/cpuidle/governors/haltpoll.c static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) · line 98
Quoted 5 lines · On Mon, 23 May 2022 23:53:32 +0000 Eiichi Tsukata <[email protected]>…
drivers/cpuidle/governors/haltpoll.c +1
-0@@ -91,16 +95,17 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) val = guest_halt_poll_ns; dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_grow (smp_processor_id (), val, old);
Why are you passing in smp_processor_id()?
Quoted 30 lines
drivers/cpuidle/governors/haltpoll.c +1
-1}else if (block_ns > guest_halt_poll_ns && guest_halt_poll_allow_shrink) {unsigned int shrink = guest_halt_poll_shrink; - val = dev->poll_limit_ns;if (shrink ==0 ) val =0 ;else val /= shrink; dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_shrink (smp_processor_id (), val, old); } }include/trace/events/power.h +8
-0@@ -500,6 +500,39 @@ DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request,TP_ARGS (name, type, new_value) ); + +TRACE_EVENT(guest_halt_poll_ns, + + TP_PROTO(bool grow, unsigned int cpu_id, + unsigned int new, unsigned int old), + + TP_ARGS(grow, cpu_id, new, old), +
include/trace/events/power.h DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request, · line 520
Quoted 10 lines
include/trace/events/power.h +10
-0+TP_STRUCT__entry ( +__field (bool ,grow ) + __field(unsigned int, cpu_id) + __field(unsigned int, new) + __field(unsigned int, old) + ), + +TP_fast_assign ( + __entry->grow = grow; + __entry->cpu_id = cpu_id;
You are wasting space to save the cpu_id, as the trace event already knows what CPU it occurred on.
# echo 1 > events/sched/enable
# cat trace
# TASK-PID CPU# ||||| TIMESTAMP FUNCTION
# | | | ||||| | |
systemd-1 [004] ..... 15.872715: ftrace_boot_snapshot: ** Boot snapshot taken **
systemd-1 [001] ..... 22.555418: initcall_start: func=fuse_len_args+0x0/0x30 [fuse]
systemd-1 [001] ..... 22.555425: initcall_finish: func=fuse_len_args+0x0/0x30 [fuse] ret=0
modprobe-643 [006] ..... 26.737355: initcall_start: func=wmidev_evaluate_method+0x46/0x100 [wmi]
modprobe-643 [006] ..... 26.742491: initcall_finish: func=wmidev_evaluate_method+0x46/0x100 [wmi] ret=0-- Steve
Quoted 11 lines
include/trace/events/power.h +11
-0+ __entry->new = new; + __entry->old = old; + ), + +TP_printk ("cpu %u: halt_poll_ns %u (%s %u)" , + __entry->cpu_id, + __entry->new, + __entry->grow ?"grow" :"shrink" , + __entry->old) +); +
Hi Steven
Quoted 67 lines · Steven Rostedt
drivers/cpuidle/governors/haltpoll.c static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) · line 98
Quoted 5 lines · On Mon, 23 May 2022 23:53:32 +0000 Eiichi Tsukata <[email protected]>…
drivers/cpuidle/governors/haltpoll.c +1
-0@@ -91,16 +95,17 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) val = guest_halt_poll_ns; dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_grow (smp_processor_id (), val, old);Why are you passing in
smp_processor_id()?Quoted 30 lines
drivers/cpuidle/governors/haltpoll.c +1
-1}else if (block_ns > guest_halt_poll_ns && guest_halt_poll_allow_shrink) {unsigned int shrink = guest_halt_poll_shrink; - val = dev->poll_limit_ns;if (shrink ==0 ) val =0 ;else val /= shrink; dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_shrink (smp_processor_id (), val, old); } }include/trace/events/power.h +8
-0@@ -500,6 +500,39 @@ DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request,TP_ARGS (name, type, new_value) ); + +TRACE_EVENT(guest_halt_poll_ns, + + TP_PROTO(bool grow, unsigned int cpu_id, + unsigned int new, unsigned int old), + + TP_ARGS(grow, cpu_id, new, old), +include/trace/events/power.h DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request, · line 520
Quoted 10 lines
include/trace/events/power.h +10
-0+TP_STRUCT__entry ( +__field (bool ,grow ) + __field(unsigned int, cpu_id) + __field(unsigned int, new) + __field(unsigned int, old) + ), + +TP_fast_assign ( + __entry->grow = grow; + __entry->cpu_id = cpu_id;You are wasting space to save the
cpu_id, as the trace event already knows what CPU it occurred on.# echo 1 > events/sched/enable # cat trace # TASK-PID CPU# ||||| TIMESTAMP FUNCTION # | | | ||||| | | systemd-1 [004] ..... 15.872715: ftrace_boot_snapshot: ** Boot snapshot taken ** systemd-1 [001] ..... 22.555418: initcall_start: func=fuse_len_args+0x0/0x30 [fuse] systemd-1 [001] ..... 22.555425: initcall_finish: func=fuse_len_args+0x0/0x30 [fuse] ret=0 modprobe-643 [006] ..... 26.737355: initcall_start: func=wmidev_evaluate_method+0x46/0x100 [wmi] modprobe-643 [006] ..... 26.742491: initcall_finish: func=wmidev_evaluate_method+0x46/0x100 [wmi] ret=0
Quoted 1 line
-- Steve
Thanks for your suggestion.
I added cpu_id as there is a similar precedent “trace_cpu_idle” but I think we can remove cpu_id. Will fix it in v3.
Eiichi
Quoted 43 lines · Eiichi Tsukata
Add trace points as are implemented in KVM host halt polling. This helps tune guest halt polling params.
Signed-off-by Eiichi Tsukata <[email protected]>--- drivers/cpuidle/governors/haltpoll.c | 15 ++++++++----- include/trace/events/power.h | 33 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-)drivers/cpuidle/governors/haltpoll.c +8
-4@@ -19,6 +19,7 @@#include <linux/sched.h> #include <linux/module.h> #include <linux/kvm_para.h> +#include <trace/events/power.h> static unsigned int guest_halt_poll_ns__read_mostly =200000 ;module_param (guest_halt_poll_ns, uint,0644 );@@ -77,13 +78,16 @@ static int haltpoll_select(struct cpuidle_driver *drv,static void adjust_poll_limit (struct cpuidle_device *dev,u64 block_ns) { -unsigned int val; +unsigned int val, old; -/* Grow cpu_halt_poll_us if -* cpu_halt_poll_us < block_ns < guest_halt_poll_us + val = dev->poll_limit_ns; + old = val; + +/* Grow poll_limit_ns if +* poll_limit_ns < block_ns < guest_halt_poll_ns */ if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) { - val = dev->poll_limit_ns * guest_halt_poll_grow; + val *= guest_halt_poll_grow;if (val < guest_halt_poll_grow_start) val = guest_halt_poll_grow_start;
drivers/cpuidle/governors/haltpoll.c static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) · line 96
Quoted 2 lines
drivers/cpuidle/governors/haltpoll.c +0
-0@@ -91,16 +95,17 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) val = guest_halt_poll_ns;
Can do it before the assignment:
trace_guest_halt_poll_ns_grow(val, dev->poll_limit_ns);
Quoted 64 lines
drivers/cpuidle/governors/haltpoll.c +2
-1dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_grow (smp_processor_id (), val, old); }else if (block_ns > guest_halt_poll_ns && guest_halt_poll_allow_shrink) {unsigned int shrink = guest_halt_poll_shrink; - val = dev->poll_limit_ns;if (shrink ==0 ) val =0 ;else val /= shrink; dev->poll_limit_ns = val; +trace_guest_halt_poll_ns_shrink (smp_processor_id (), val, old); } }include/trace/events/power.h +33
-0@@ -500,6 +500,39 @@ DEFINE_EVENT(dev_pm_qos_request, dev_pm_qos_remove_request,TP_ARGS (name, type, new_value) ); + +TRACE_EVENT (guest_halt_poll_ns, + + TP_PROTO(bool grow, unsigned int cpu_id, + unsigned int new, unsigned int old), + +TP_ARGS (grow, cpu_id, new, old), + +TP_STRUCT__entry ( + __field(bool, grow) + __field(unsigned int, cpu_id) + __field(unsigned int, new) + __field(unsigned int, old) + ), + +TP_fast_assign ( + __entry->grow = grow; + __entry->cpu_id = cpu_id; + __entry->new = new; + __entry->old = old; + ), + +TP_printk ("cpu %u: halt_poll_ns %u (%s %u)" , + __entry->cpu_id, + __entry->new, + __entry->grow ?"grow" :"shrink" , + __entry->old) +); + +#define trace_guest_halt_poll_ns_grow (cpu_id, new, old) \ + trace_guest_halt_poll_ns(true, cpu_id, new, old) +#define trace_guest_halt_poll_ns_shrink (cpu_id, new, old) \ + trace_guest_halt_poll_ns(false, cpu_id, new, old)#endif /* _TRACE_POWER_H */ /* This part must be outside protection */ Signature · 1 line
2.36.1
Hi Marcelo
Quoted 51 lines · Marcelo Tosatti
Quoted 43 lines · Eiichi Tsukata
Add trace points as are implemented in KVM host halt polling. This helps tune guest halt polling params.
Signed-off-by Eiichi Tsukata <[email protected]>---
drivers/cpuidle/governors/haltpoll.c| 15 ++++++++-----include/trace/events/power.h| 33 ++++++++++++++++++++++++++++2 files changed, 43 insertions(+), 5 deletions(-)drivers/cpuidle/governors/haltpoll.c +8
-4@@ -19,6 +19,7 @@#include <linux/sched.h> #include <linux/module.h> #include <linux/kvm_para.h> +#include <trace/events/power.h> static unsigned int guest_halt_poll_ns__read_mostly =200000 ;module_param (guest_halt_poll_ns, uint,0644 );@@ -77,13 +78,16 @@ static int haltpoll_select(struct cpuidle_driver *drv,static void adjust_poll_limit (struct cpuidle_device *dev,u64 block_ns) { -unsigned int val; +unsigned int val, old; -/* Grow cpu_halt_poll_us if -* cpu_halt_poll_us < block_ns < guest_halt_poll_us + val = dev->poll_limit_ns; + old = val; + +/* Grow poll_limit_ns if +* poll_limit_ns < block_ns < guest_halt_poll_ns */ if (block_ns > dev->poll_limit_ns && block_ns <= guest_halt_poll_ns) { - val = dev->poll_limit_ns * guest_halt_poll_grow; + val *= guest_halt_poll_grow;if (val < guest_halt_poll_grow_start) val = guest_halt_poll_grow_start;drivers/cpuidle/governors/haltpoll.c static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) · line 96
Quoted 2 lines
drivers/cpuidle/governors/haltpoll.c +0
-0@@ -91,16 +95,17 @@ static void adjust_poll_limit(struct cpuidle_device *dev, u64 block_ns) val = guest_halt_poll_ns;Can do it before the assignment:
Quoted 1 line
trace_guest_halt_poll_ns_grow(val, dev->poll_limit_ns);
Sure. Will fix it in v4.
Thanks
Eiichi