Re: [RFC -tip] perf, x86: Add PERF_COUNT_HW_NMI_WATCHDOG event v2

From: Stephane Eranian
Date: Thu Jun 23 2011 - 08:31:22 EST


Yes.


On Thu, Jun 23, 2011 at 2:26 PM, Cyrill Gorcunov <gorcunov@xxxxxxxxx> wrote:
> On Thu, Jun 23, 2011 at 04:07:32PM +0400, Cyrill Gorcunov wrote:
>> On Thu, Jun 23, 2011 at 02:03:50PM +0200, Stephane Eranian wrote:
>> ...
>> > >
>> > No, first level in watchdog.c, the other callback has to be implemented
>> > from x86_pmu as you had it.
>> >
> Something like below I suppose
>
> Â Â Â ÂCyrill
> ---
> Âarch/x86/kernel/cpu/perf_event.c  Â|  Â7 +++++++
> Âarch/x86/kernel/cpu/perf_event_p4.c | Â 26 ++++++++++++++++++++++++++
> Âkernel/watchdog.c          |  Â6 +++++-
> Â3 files changed, 38 insertions(+), 1 deletion(-)
>
> Index: linux-2.6.git/arch/x86/kernel/cpu/perf_event.c
> ===================================================================
> --- linux-2.6.git.orig/arch/x86/kernel/cpu/perf_event.c
> +++ linux-2.6.git/arch/x86/kernel/cpu/perf_event.c
> @@ -233,6 +233,7 @@ struct x86_pmu {
>    Âvoid      Â(*enable_all)(int added);
>    Âvoid      Â(*enable)(struct perf_event *);
>    Âvoid      Â(*disable)(struct perf_event *);
> +    void      Â(*hw_watchdog_set_attr)(struct perf_event_attr *attr);
>    Âint       (*hw_config)(struct perf_event *event);
>    Âint       (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign);
>    Âunsigned    Âeventsel;
> @@ -315,6 +316,12 @@ static u64 __read_mostly hw_cache_extra_
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â[PERF_COUNT_HW_CACHE_OP_MAX]
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â[PERF_COUNT_HW_CACHE_RESULT_MAX];
>
> +void hw_nmi_watchdog_set_attr(struct perf_event_attr *wd_attr)
> +{
> + Â Â Â if (x86_pmu.hw_watchdog_set_attr)
> + Â Â Â Â Â Â Â x86_pmu.hw_watchdog_set_attr(wd_attr);
> +}
> +
> Â/*
> Â* Propagate event elapsed time into the generic event.
> Â* Can only be executed on the CPU where the event is active.
> Index: linux-2.6.git/arch/x86/kernel/cpu/perf_event_p4.c
> ===================================================================
> --- linux-2.6.git.orig/arch/x86/kernel/cpu/perf_event_p4.c
> +++ linux-2.6.git/arch/x86/kernel/cpu/perf_event_p4.c
> @@ -705,6 +705,31 @@ static int p4_validate_raw_event(struct
> Â Â Â Âreturn 0;
> Â}
>
> +static void p4_hw_watchdog_set_attr(struct perf_event_attr *wd_attr)
> +{
> + Â Â Â /*
> + Â Â Â Â* Watchdog ticks are special on Netburst, we use
> + Â Â Â Â* that named "non-sleeping" ticks as recommended
> + Â Â Â Â* by Intel SDM Vol3b.
> + Â Â Â Â*/
> +    WARN_ON_ONCE(wd_attr->type   Â!= PERF_TYPE_HARDWARE ||
> +          Âwd_attr->config  Â!= PERF_COUNT_HW_CPU_CYCLES);
> +
> +    wd_attr->type  = PERF_TYPE_RAW;
> + Â Â Â wd_attr->config =
> + Â Â Â Â Â Â Â p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_EXECUTION_EVENT) Â Â Â Â Â Â |
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS0) Â Â Â Â Â Â|
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS1) Â Â Â Â Â Â|
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS2) Â Â Â Â Â Â|
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, NBOGUS3) Â Â Â Â Â Â|
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS0) Â Â Â Â Â Â |
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS1) Â Â Â Â Â Â |
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS2) Â Â Â Â Â Â |
> + Â Â Â Â Â Â Â Â Â Â Â P4_ESCR_EMASK_BIT(P4_EVENT_EXECUTION_EVENT, BOGUS3)) Â Â Â Â Â Â|
> + Â Â Â Â Â Â Â p4_config_pack_cccr(P4_CCCR_THRESHOLD(15) | P4_CCCR_COMPLEMENT Â Â Â Â Â|
> + Â Â Â Â Â Â Â Â Â Â Â P4_CCCR_COMPARE);
> +}
> +
> Âstatic int p4_hw_config(struct perf_event *event)
> Â{
> Â Â Â Âint cpu = get_cpu();
> @@ -1179,6 +1204,7 @@ static __initconst const struct x86_pmu
>    Â.cntval_bits      Â= ARCH_P4_CNTRVAL_BITS,
>    Â.cntval_mask      Â= ARCH_P4_CNTRVAL_MASK,
>    Â.max_period       = (1ULL << (ARCH_P4_CNTRVAL_BITS - 1)) - 1,
> +    .hw_watchdog_set_attr  = p4_hw_watchdog_set_attr,
>    Â.hw_config       Â= p4_hw_config,
>    Â.schedule_events    Â= p4_pmu_schedule_events,
> Â Â Â Â/*
> Index: linux-2.6.git/kernel/watchdog.c
> ===================================================================
> --- linux-2.6.git.orig/kernel/watchdog.c
> +++ linux-2.6.git/kernel/watchdog.c
> @@ -200,6 +200,8 @@ static int is_softlockup(unsigned long t
> Â}
>
> Â#ifdef CONFIG_HARDLOCKUP_DETECTOR
> +void __weak hw_nmi_watchdog_set_attr(struct perf_event_attr *wd_attr) { }
> +
> Âstatic struct perf_event_attr wd_hw_attr = {
>    Â.type      = PERF_TYPE_HARDWARE,
>    Â.config     = PERF_COUNT_HW_CPU_CYCLES,
> @@ -368,9 +370,11 @@ static int watchdog_nmi_enable(int cpu)
> Â Â Â Âif (event != NULL)
> Â Â Â Â Â Â Â Âgoto out_enable;
>
> - Â Â Â /* Try to register using hardware perf events */
> Â Â Â Âwd_attr = &wd_hw_attr;
> Â Â Â Âwd_attr->sample_period = hw_nmi_get_sample_period(watchdog_thresh);
> + Â Â Â hw_nmi_watchdog_set_attr(wd_attr);
> +
> + Â Â Â /* Try to register using hardware perf events */
> Â Â Â Âevent = perf_event_create_kernel_counter(wd_attr, cpu, NULL, watchdog_overflow_callback);
> Â Â Â Âif (!IS_ERR(event)) {
> Â Â Â Â Â Â Â Âprintk(KERN_INFO "NMI watchdog enabled, takes one hw-pmu counter.\n");
>
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i