misc: tegra-profiler: add sched samples
Igor Nabirushkin [Thu, 5 Jun 2014 07:08:55 +0000 (11:08 +0400)]
Tegra Profiler: capture task starting being scheduled on a core.
Add sched in/out samples.

Bug 1520808

Change-Id: I2c62e5c1918bdba0fc997d79d8aeb3b7b63530f0
Signed-off-by: Igor Nabirushkin <inabirushkin@nvidia.com>
Reviewed-on: http://git-master/r/419352
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Tested-by: Daniel Horowitz <dhorowitz@nvidia.com>
Tested-by: Maxim Morin <mmorin@nvidia.com>

drivers/misc/tegra-profiler/comm.c
drivers/misc/tegra-profiler/hrt.c
drivers/misc/tegra-profiler/version.h
include/linux/tegra_profiler.h

index 428059a..17f5c3c 100644 (file)
@@ -338,6 +338,10 @@ static ssize_t read_sample(char __user *buffer, size_t max_length)
                length_extra = record.additional_sample.extra_length;
                break;
 
+       case QUADD_RECORD_TYPE_SCHED:
+               length_extra = 0;
+               break;
+
        default:
                goto out;
        }
index 13b131b..80f85b2 100644 (file)
@@ -183,6 +183,31 @@ void quadd_put_sample(struct quadd_record_data *data,
        atomic64_inc(&hrt.counter_samples);
 }
 
+static void
+put_sched_sample(struct task_struct *task, int is_sched_in)
+{
+       unsigned int cpu, flags;
+       struct quadd_record_data record;
+       struct quadd_sched_data *s = &record.sched;
+
+       record.record_type = QUADD_RECORD_TYPE_SCHED;
+
+       cpu = quadd_get_processor_id(NULL, &flags);
+       s->cpu = cpu;
+       s->lp_mode = (flags & QUADD_CPUMODE_TEGRA_POWER_CLUSTER_LP) ? 1 : 0;
+
+       s->sched_in = is_sched_in ? 1 : 0;
+       s->time = quadd_get_time();
+       s->pid = task->pid;
+
+       s->reserved = 0;
+
+       s->data[0] = 0;
+       s->data[1] = 0;
+
+       quadd_put_sample(&record, NULL, 0);
+}
+
 static int get_sample_data(struct quadd_sample_data *sample,
                           struct pt_regs *regs,
                           struct task_struct *task)
@@ -453,6 +478,8 @@ void __quadd_task_sched_in(struct task_struct *prev,
 */
 
        if (is_profile_process(task)) {
+               put_sched_sample(task, 1);
+
                add_active_thread(cpu_ctx, task->pid, task->tgid);
                atomic_inc(&cpu_ctx->nr_active);
 
@@ -503,6 +530,8 @@ void __quadd_task_sched_out(struct task_struct *prev,
                        if (ctx->pmu)
                                ctx->pmu->stop();
                }
+
+               put_sched_sample(prev, 0);
        }
 }
 
index d3913ff..20f5e20 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef __QUADD_VERSION_H
 #define __QUADD_VERSION_H
 
-#define QUADD_MODULE_VERSION           "1.73"
+#define QUADD_MODULE_VERSION           "1.74"
 #define QUADD_MODULE_BRANCH            "Dev"
 
 #endif /* __QUADD_VERSION_H */
index b0dcced..f4c58a0 100644 (file)
@@ -19,7 +19,7 @@
 
 #include <linux/ioctl.h>
 
-#define QUADD_SAMPLES_VERSION  27
+#define QUADD_SAMPLES_VERSION  28
 #define QUADD_IO_VERSION       12
 
 #define QUADD_IO_VERSION_DYNAMIC_RB            5
@@ -40,6 +40,7 @@
 #define QUADD_SAMPLE_VERSION_UNWIND_MIXED      25
 #define QUADD_SAMPLE_VERSION_UNW_ENTRY_TYPE    26
 #define QUADD_SAMPLE_VERSION_USE_ARCH_TIMER    27
+#define QUADD_SAMPLE_VERSION_SCHED_SAMPLES     28
 
 #define QUADD_MAX_COUNTERS     32
 #define QUADD_MAX_PROCESS      64
@@ -126,6 +127,7 @@ enum quadd_record_type {
        QUADD_RECORD_TYPE_HEADER,
        QUADD_RECORD_TYPE_POWER_RATE,
        QUADD_RECORD_TYPE_ADDITIONAL_SAMPLE,
+       QUADD_RECORD_TYPE_SCHED,
 };
 
 enum quadd_event_source {
@@ -238,6 +240,18 @@ struct quadd_additional_sample {
        u16 extra_length;
 };
 
+struct quadd_sched_data {
+       u32 pid;
+       u64 time;
+
+       u32     cpu:6,
+               lp_mode:1,
+               sched_in:1,
+               reserved:24;
+
+       u32 data[2];
+};
+
 enum {
        QM_DEBUG_SAMPLE_TYPE_SCHED_IN = 1,
        QM_DEBUG_SAMPLE_TYPE_SCHED_OUT,
@@ -302,6 +316,7 @@ struct quadd_record_data {
                struct quadd_debug_data         debug;
                struct quadd_header_data        hdr;
                struct quadd_power_rate_data    power_rate;
+               struct quadd_sched_data         sched;
                struct quadd_additional_sample  additional_sample;
        };
 } __aligned(4);