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

From: Stephane Eranian
Date: Thu Jun 23 2011 - 07:44:45 EST


On Thu, Jun 23, 2011 at 1:40 PM, Don Zickus <dzickus@xxxxxxxxxx> wrote:
> On Thu, Jun 23, 2011 at 03:07:06PM +0400, Cyrill Gorcunov wrote:
>> On Thu, Jun 23, 2011 at 01:54:39PM +0400, Cyrill Gorcunov wrote:
>> ...
>> > >
>> > > No new hidden event, just a x86_pmu + a per-arch callbacks.
>> >
>> > Looks quite good for me, Don? (i'll cook some draft patch for review meanwhile).
>> >
>> > Â Â Cyrill
>>
>> Since we are going to make __weak linking anyway maybe something like below
>> fit even beter? (untested)
>
> I don't think the compiler knows what platform you are running on and may
> just blindly link your new p4 function for all x86s, which is probably not
> what you want.
>
Don, is right. You need the level of indirection I had in my outline patch.

You also don't need the:
+ if (wd_attr->type != PERF_TYPE_HARDWARE ||
+ wd_attr->attr.config != PERF_COUNT_HW_CPU_CYCLES)
+ return;

In the p4 callback given you know your coming in for the watchdog.

> Cheers,
> Don
>
>>
>> Â Â Â Cyrill
>> ---
>> Âarch/x86/kernel/cpu/perf_event_p4.c | Â 26 ++++++++++++++++++++++++++
>> Âkernel/watchdog.c          |  Â3 +++
>> Â2 files changed, 29 insertions(+)
>>
>> 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,32 @@ static int p4_validate_raw_event(struct
>> Â Â Â return 0;
>> Â}
>>
>> +void hw_nmi_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.
>> + Â Â Â*/
>> +   if (wd_attr->type    != PERF_TYPE_HARDWARE ||
>> + Â Â Â Âwd_attr->attr.config != PERF_COUNT_HW_CPU_CYCLES)
>> + Â Â Â Â Â Â return;
>> +
>> +   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();
>> Index: linux-2.6.git/kernel/watchdog.c
>> ===================================================================
>> --- linux-2.6.git.orig/kernel/watchdog.c
>> +++ linux-2.6.git/kernel/watchdog.c
>> @@ -355,6 +355,8 @@ static int watchdog(void *unused)
>>
>>
>> Â#ifdef CONFIG_HARDLOCKUP_DETECTOR
>> +void __weak hw_nmi_watchdog_set_attr(struct perf_event_attr *wd_attr) { }
>> +
>> Âstatic int watchdog_nmi_enable(int cpu)
>> Â{
>> Â Â Â struct perf_event_attr *wd_attr;
>> @@ -371,6 +373,7 @@ static int watchdog_nmi_enable(int cpu)
>> Â Â Â /* 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);
>> Â Â Â 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");
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/