[STYLE] swap_sampler module
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 23 Oct 2013 11:34:36 +0000 (15:34 +0400)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Wed, 23 Oct 2013 12:45:39 +0000 (12:45 +0000)
Change-Id: I4333453d7cd30dd22e5567e83b22de5cf07ab3b7
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
sampler/swap_sampler_module.c

index d2c9413..5b4f077 100644 (file)
@@ -53,7 +53,6 @@ unsigned int dbi_timer_quantum = 0;
 static DEFINE_PER_CPU(struct hrtimer, dbi_hrtimer);
 static int dbi_hrtimer_running;
 #else
-//struct timer_list dbi_timer;
 static DEFINE_PER_CPU(struct timer_list, dbi_timer);
 static int dbi_timer_running;
 #endif
@@ -64,194 +63,206 @@ static BLOCKING_NOTIFIER_HEAD(swap_sampler_notifier_list);
 #ifdef CONFIG_HIGH_RES_TIMERS
 static enum hrtimer_restart dbi_hrtimer_notify(struct hrtimer *hrtimer)
 {
-    if (current)
-        sample_msg(task_pt_regs(current));
+       if (current)
+               sample_msg(task_pt_regs(current));
 
-    hrtimer_forward_now(hrtimer, ns_to_ktime(dbi_timer_quantum));
-    return HRTIMER_RESTART;
+       hrtimer_forward_now(hrtimer, ns_to_ktime(dbi_timer_quantum));
+
+       return HRTIMER_RESTART;
 }
 
 static void __dbi_hrtimer_start(void *unused)
 {
-    struct hrtimer *hrtimer = &__get_cpu_var(dbi_hrtimer);
+       struct hrtimer *hrtimer = &__get_cpu_var(dbi_hrtimer);
+
+       if (!dbi_hrtimer_running)
+               return;
 
-    if (!dbi_hrtimer_running)
-        return;
-    hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-    hrtimer->function = dbi_hrtimer_notify;
-    hrtimer_start(hrtimer, ns_to_ktime(dbi_timer_quantum), HRTIMER_MODE_REL_PINNED);
+       hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+       hrtimer->function = dbi_hrtimer_notify;
+       hrtimer_start(hrtimer, ns_to_ktime(dbi_timer_quantum),
+                     HRTIMER_MODE_REL_PINNED);
 }
 
 static int dbi_hrtimer_start(void)
 {
-    get_online_cpus();
-    dbi_hrtimer_running = 1;
-    on_each_cpu(__dbi_hrtimer_start, NULL, 1);
-    put_online_cpus();
+       get_online_cpus();
+       dbi_hrtimer_running = 1;
+       on_each_cpu(__dbi_hrtimer_start, NULL, 1);
+       put_online_cpus();
 
-    return E_SS_SUCCESS;
+       return E_SS_SUCCESS;
 }
 
 static void __dbi_hrtimer_stop(int cpu)
 {
-    struct hrtimer *hrtimer = &per_cpu(dbi_hrtimer, cpu);
+       struct hrtimer *hrtimer = &per_cpu(dbi_hrtimer, cpu);
+
+       if (!dbi_hrtimer_running)
+               return;
 
-    if (!dbi_hrtimer_running)
-        return;
-    hrtimer_cancel(hrtimer);
+       hrtimer_cancel(hrtimer);
 }
 
 static void dbi_hrtimer_stop(void)
 {
-    int cpu;
+       int cpu;
 
-    get_online_cpus();
-    for_each_online_cpu(cpu)
-        __dbi_hrtimer_stop(cpu);
-    dbi_hrtimer_running = 0;
-    put_online_cpus();
+       get_online_cpus();
+
+       for_each_online_cpu(cpu)
+               __dbi_hrtimer_stop(cpu);
+
+       dbi_hrtimer_running = 0;
+       put_online_cpus();
 }
 
 #else
 
 void dbi_write_sample_data(unsigned long data)
 {
-    struct timer_list *timer = (struct timer_list *)data;
+       struct timer_list *timer = (struct timer_list *)data;
 
-    if (current)
-        sample_msg(task_pt_regs(current));
+       if (current)
+               sample_msg(task_pt_regs(current));
 
-    // TODO: test pinning
-    mod_timer_pinned(timer, jiffies + dbi_timer_quantum);
+       /* TODO: test pinning */
+       mod_timer_pinned(timer, jiffies + dbi_timer_quantum);
 }
 
 static void __dbi_timer_start(void *unused)
 {
-    struct timer_list *timer = &__get_cpu_var(dbi_timer);
-
-    if (!dbi_timer_running)
-        return;
-    init_timer(timer);
-    timer->data = timer;
-    timer->function = dbi_write_sample_data;
-    // TODO: test pinning
-    mod_timer_pinned(timer, jiffies + dbi_timer_quantum);
+       struct timer_list *timer = &__get_cpu_var(dbi_timer);
+
+       if (!dbi_timer_running)
+               return;
+
+       init_timer(timer);
+       timer->data = timer;
+       timer->function = dbi_write_sample_data;
+
+       /* TODO: test pinning */
+       mod_timer_pinned(timer, jiffies + dbi_timer_quantum);
 }
 
 static int dbi_timer_start(void)
 {
-    get_online_cpus();
-    dbi_timer_running = 1;
-    on_each_cpu(__dbi_timer_start, NULL, 1);
-    put_online_cpus();
-    return E_SS_SUCCESS;
+       get_online_cpus();
+       dbi_timer_running = 1;
+       on_each_cpu(__dbi_timer_start, NULL, 1);
+       put_online_cpus();
+
+       return E_SS_SUCCESS;
 }
 
 static void __dbi_timer_stop(int cpu)
 {
-    struct timer_list *timer = &per_cpu(dbi_timer, cpu);
+       struct timer_list *timer = &per_cpu(dbi_timer, cpu);
 
-    if (!dbi_timer_running)
-        return;
-    del_timer_sync(timer);
+       if (!dbi_timer_running)
+               return;
+       del_timer_sync(timer);
 }
 
 static void dbi_timer_stop(void)
 {
-    int cpu;
+       int cpu;
 
-    get_online_cpus();
-    for_each_online_cpu(cpu)
-        __dbi_timer_stop(cpu);
-    dbi_timer_running = 0;
-    put_online_cpus();
+       get_online_cpus();
+
+       for_each_online_cpu(cpu)
+               __dbi_timer_stop(cpu);
+
+       dbi_timer_running = 0;
+       put_online_cpus();
 }
 
 #endif
 
 static int __cpuinit dbi_cpu_notify(struct notifier_block *self,
-                     unsigned long action, void *hcpu)
+                                   unsigned long action, void *hcpu)
 {
-    long cpu = (long) hcpu;
+       long cpu = (long) hcpu;
 
-    switch (action) {
-    case CPU_ONLINE:
-    case CPU_ONLINE_FROZEN:
+       switch (action) {
+       case CPU_ONLINE:
+       case CPU_ONLINE_FROZEN:
 #ifdef CONFIG_HIGH_RES_TIMERS
-        smp_call_function_single(cpu, __dbi_hrtimer_start, NULL, 1);
+               smp_call_function_single(cpu, __dbi_hrtimer_start, NULL, 1);
 #else
-        smp_call_function_single(cpu, __dbi_timer_start, NULL, 1);
+               smp_call_function_single(cpu, __dbi_timer_start, NULL, 1);
 #endif
-        break;
-    case CPU_DEAD:
-    case CPU_DEAD_FROZEN:
+               break;
+       case CPU_DEAD:
+       case CPU_DEAD_FROZEN:
 #ifdef CONFIG_HIGH_RES_TIMERS
-        __dbi_hrtimer_stop(cpu);
+               __dbi_hrtimer_stop(cpu);
 #else
-        __dbi_timer_stop(cpu);
+               __dbi_timer_stop(cpu);
 #endif
-        break;
-    }
-    return NOTIFY_OK;
+               break;
+       }
+
+       return NOTIFY_OK;
 }
 
 static struct notifier_block __refdata dbi_cpu_notifier = {
-    .notifier_call = dbi_cpu_notify,
+       .notifier_call = dbi_cpu_notify,
 };
 
 int swap_sampler_start(unsigned int timer_quantum)
 {
-    if (timer_quantum <= 0)
-        return -E_SS_WRONG_QUANTUM;
+       if (timer_quantum <= 0)
+               return -E_SS_WRONG_QUANTUM;
 
-    dbi_timer_quantum = timer_quantum * 1000 * 1000;
+       dbi_timer_quantum = timer_quantum * 1000 * 1000;
 
-    if (!try_module_get(THIS_MODULE))
-        print_err("Error of try_module_get() for sampling module\n");
+       if (!try_module_get(THIS_MODULE))
+               print_err("Error of try_module_get() for sampling module\n");
 
 #ifdef CONFIG_HIGH_RES_TIMERS
-    dbi_hrtimer_start();
+       dbi_hrtimer_start();
 #else
-    dbi_timer_start();
+       dbi_timer_start();
 #endif
 
-    return E_SS_SUCCESS;
+       return E_SS_SUCCESS;
 }
 EXPORT_SYMBOL_GPL(swap_sampler_start);
 
 int swap_sampler_stop(void)
 {
 #ifdef CONFIG_HIGH_RES_TIMERS
-    dbi_hrtimer_stop();
+       dbi_hrtimer_stop();
 #else
-    dbi_timer_stop();
+       dbi_timer_stop();
 #endif
-    module_put(THIS_MODULE);
+       module_put(THIS_MODULE);
 
-    return E_SS_SUCCESS;
+       return E_SS_SUCCESS;
 }
 EXPORT_SYMBOL_GPL(swap_sampler_stop);
 
 static int __init sampler_init(void)
 {
-    int retval;
+       int retval;
 
-    retval = register_hotcpu_notifier(&dbi_cpu_notifier);
-    if (retval) {
-        print_err("Error of register_hotcpu_notifier()\n");
-        return retval;
-    }
+       retval = register_hotcpu_notifier(&dbi_cpu_notifier);
+       if (retval) {
+               print_err("Error of register_hotcpu_notifier()\n");
+               return retval;
+       }
 
-    print_msg("Sample ininitialization success\n");
+       print_msg("Sample ininitialization success\n");
 
-    return E_SS_SUCCESS;
+       return E_SS_SUCCESS;
 }
 
 static void __exit sampler_exit(void)
 {
-    unregister_hotcpu_notifier(&dbi_cpu_notifier);
+       unregister_hotcpu_notifier(&dbi_cpu_notifier);
 
-    print_msg("Sampler uninitialized\n");
+       print_msg("Sampler uninitialized\n");
 }
 
 module_init(sampler_init);