From patchwork Thu Jun 23 05:12:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 2189 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id A04BE23F08 for ; Thu, 23 Jun 2011 05:06:54 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3BCB6A182AF for ; Thu, 23 Jun 2011 05:06:54 +0000 (UTC) Received: by vws16 with SMTP id 16so1671025vws.11 for ; Wed, 22 Jun 2011 22:06:53 -0700 (PDT) Received: by 10.52.100.72 with SMTP id ew8mr2075280vdb.247.1308805613735; Wed, 22 Jun 2011 22:06:53 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs4581vdc; Wed, 22 Jun 2011 22:06:53 -0700 (PDT) Received: by 10.52.32.68 with SMTP id g4mr2036686vdi.216.1308805612837; Wed, 22 Jun 2011 22:06:52 -0700 (PDT) Received: from mail-qw0-f50.google.com (mail-qw0-f50.google.com [209.85.216.50]) by mx.google.com with ESMTPS id i41si669526vck.134.2011.06.22.22.06.51 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Jun 2011 22:06:51 -0700 (PDT) Received-SPF: pass (google.com: domain of amitdanielk@gmail.com designates 209.85.216.50 as permitted sender) client-ip=209.85.216.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of amitdanielk@gmail.com designates 209.85.216.50 as permitted sender) smtp.mail=amitdanielk@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by qwe5 with SMTP id 5so909855qwe.37 for ; Wed, 22 Jun 2011 22:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer; bh=qlqEBE04ucFRwTgKw2lJfoOy30lMtvcdIW/jdjMyocE=; b=Nu3rD7Wsh8nmbTXHceVjHorpZ4NcLSNlCFBHrD9nEuQ968IaAE0HzFn1X6JlHdhbQv qNyaA2wXn5Ed1jVO1YbmrBgXeQ0M5o+aPhPKGS3chhhqPxwJckhpMiq8nqUM88PcHcYP UC1Kz9ITKAEPle6zyxG5mhumNT2M5DaOW3aog= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; b=Kn0FCLs7edVRVGssohNRxsEhC9KHCdhH33vlDmavNiZGkpYMG/5LhBk8ImlKha0nK0 LkMhb/si2tQL/8G7OCF0TOw7itSa+ZN/Sh/OoiMwtjD/A4G0EyhiP/UoO0puvt+8EDyj /ty9t29o6/xKgR/cTM64pHoG0gmKKVKuogH8Y= Received: by 10.224.138.13 with SMTP id y13mr982789qat.350.1308805611350; Wed, 22 Jun 2011 22:06:51 -0700 (PDT) Received: from localhost.localdomain ([115.113.119.130]) by mx.google.com with ESMTPS id d2sm968953qcs.21.2011.06.22.22.06.47 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Jun 2011 22:06:50 -0700 (PDT) Sender: amit kachhap From: Amit Daniel Kachhap To: arjan@linux.intel.com, kristen@linux.intel.com, power@bughost.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org, amit.kachhap@linaro.org Subject: [PATCH powertop2.0] Modification to fix the removal of lock_depth field Date: Thu, 23 Jun 2011 10:42:00 +0530 Message-Id: <1308805920-18203-1-git-send-email-amit.kachhap@linaro.org> X-Mailer: git-send-email 1.7.1 lock_depth field is removed from the power frequency events in the new linux kernel(2.6.38 onwards). So this creates issue to retrieve the lower members of the trace data. To fix this problem 2 separate structures are created and their use depends upon the format of the power_frequency events. These changes have been tested to work fine with both old and new kernels as well as on x86 and ARM platform. Signed-off-by: Amit Daniel Kachhap --- This patch is for powertop2.0 and fixes the issue of frequency reported as always 0 in kernel from 2.6.38 onwards. cpu/cpu.cpp | 7 +--- perf/perf_bundle.cpp | 98 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 82 insertions(+), 23 deletions(-) diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp index b901b87..1193d7b 100644 --- a/cpu/cpu.cpp +++ b/cpu/cpu.cpp @@ -742,11 +742,8 @@ void w_display_cpu_pstates(void) struct power_entry { -#ifndef __i386__ - int dummy; -#endif - int64_t type; - int64_t value; + uint64_t type; + uint64_t value; } __attribute__((packed)); diff --git a/perf/perf_bundle.cpp b/perf/perf_bundle.cpp index 2276c3a..f4c8912 100644 --- a/perf/perf_bundle.cpp +++ b/perf/perf_bundle.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "perf_bundle.h" #include "perf_event.h" @@ -110,11 +111,30 @@ void perf_bundle::add_event(const char *event_name) } } } - +static int lock_depth = 0; void perf_bundle::start(void) { unsigned int i; class perf_event *ev; + char line[1023]; + FILE *file; + char filename[PATH_MAX]; + + /*check the format of power_frequency event*/ + strcpy(filename, + "/sys/kernel/debug/tracing/events/power/power_frequency/format"); + if (!lock_depth) { + file = fopen(filename, "r"); + if (file) { + while (fgets(line, 1023,file) != NULL) { + if (strstr(line, "lock_depth")) { + lock_depth = 1; + break; + } + } + fclose(file); + } + } for (i = 0; i < events.size(); i++) { ev = events[i]; @@ -154,34 +174,57 @@ void perf_bundle::clear(void) records.resize(0); } - -struct trace_entry { +/*Trace entry for the common fields of perf events*/ +struct trace_entry_common { uint64_t time; uint32_t cpu; uint32_t res; __u32 size; +} __attribute__((packed)); + +/*Trace entry for the fields specific to each perf events. +* lock_depth field to support old kernels*/ +struct trace_data_lockdepth { unsigned short type; unsigned char flags; unsigned char preempt_count; int pid; int lock_depth; +#ifndef __i386__ + int filler; +#endif } __attribute__((packed));; +/*Trace entry for the fields specific to each perf events*/ +struct trace_data_normal { + unsigned short type; + unsigned char flags; + unsigned char preempt_count; + int pid; +} __attribute__((packed));; -struct perf_sample { +struct perf_sample_normal { struct perf_event_header header; - struct trace_entry trace; + struct trace_entry_common trace_common; + struct trace_data_normal trace_data; unsigned char data[0]; } __attribute__((packed)); +struct perf_sample_lockdepth { + struct perf_event_header header; + struct trace_entry_common trace_common; + struct trace_data_lockdepth trace_data; + unsigned char data[0]; +} __attribute__((packed));; + static uint64_t timestamp(perf_event_header *event) { - struct perf_sample *sample; + struct perf_sample_lockdepth *sample; if (event->type != PERF_RECORD_SAMPLE) return 0; - sample = (struct perf_sample *)event; + sample = (struct perf_sample_lockdepth *)event; #if 0 int i; @@ -207,7 +250,7 @@ static uint64_t timestamp(perf_event_header *event) printf("%02x ", *(x+i)); printf("\n"); #endif - return sample->trace.time; + return sample->trace_common.time; } @@ -235,16 +278,35 @@ void perf_bundle::process(void) sort(records.begin(), records.end(), event_sort_function); for (i = 0; i < records.size(); i++) { - struct perf_sample *sample; - - sample = (struct perf_sample *)records[i]; - if (!sample) - continue; - - if (sample->header.type != PERF_RECORD_SAMPLE) - continue; - - handle_trace_point(sample->trace.type, &sample->data, sample->trace.cpu, sample->trace.time, sample->trace.flags); + /*Check for lock_depth */ + if (lock_depth) { + struct perf_sample_lockdepth *sample = + (struct perf_sample_lockdepth *)records[i]; + if (!sample) + continue; + + if (sample->header.type != PERF_RECORD_SAMPLE) + continue; + + handle_trace_point(sample->trace_data.type, + &sample->data, sample->trace_common.cpu, + sample->trace_common.time, + sample->trace_data.flags); + } + else { + struct perf_sample_normal *sample = + (struct perf_sample_normal *)records[i]; + if (!sample) + continue; + + if (sample->header.type != PERF_RECORD_SAMPLE) + continue; + + handle_trace_point(sample->trace_data.type, + &sample->data, sample->trace_common.cpu, + sample->trace_common.time, + sample->trace_data.flags); + } } }