drivers: power: report battery voltage in AOSP compatible format
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / kernel / hrtimer.c
index 0308557a6330498ff9e7a33ab892f329ad7209ec..03c39c893f67dc82059652a3fe405eba3fa62b57 100644 (file)
 #include <linux/sched/sysctl.h>
 #include <linux/sched/rt.h>
 #include <linux/timer.h>
+#include <linux/freezer.h>
 
 #include <asm/uaccess.h>
 
 #include <trace/events/timer.h>
 
+#include <linux/mt_sched_mon.h>
+
+//#define MTK_HRTIME_DEBUG     /*MTK debug func*/
 /*
  * The timer bases:
  *
@@ -245,6 +249,11 @@ again:
                        goto again;
                }
                timer->base = new_base;
+       } else {
+               if (cpu != this_cpu && hrtimer_check_target(timer, new_base)) {
+                       cpu = this_cpu;
+                       goto again;
+               }
        }
        return new_base;
 }
@@ -988,17 +997,19 @@ int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
        struct hrtimer_clock_base *base, *new_base;
        unsigned long flags;
        int ret, leftmost;
-
+    /*add MTK debug log for ALPS01804694*/
+    if(timer->function == NULL) {
+               pr_alert("add hrtimer but do nothing");
+               dump_stack();
+    }
+       
        base = lock_hrtimer_base(timer, &flags);
 
        /* Remove an active timer from the queue: */
        ret = remove_hrtimer(timer, base);
 
-       /* Switch the timer base, if necessary: */
-       new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
-
        if (mode & HRTIMER_MODE_REL) {
-               tim = ktime_add_safe(tim, new_base->get_time());
+               tim = ktime_add_safe(tim, base->get_time());
                /*
                 * CONFIG_TIME_LOW_RES is a temporary way for architectures
                 * to signal that they simply return xtime in
@@ -1013,6 +1024,9 @@ int __hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
 
        hrtimer_set_expires_range_ns(timer, tim, delta_ns);
 
+       /* Switch the timer base, if necessary: */
+       new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
+
        timer_stats_hrtimer_set_start_info(timer);
 
        leftmost = enqueue_hrtimer(timer, new_base);
@@ -1247,6 +1261,31 @@ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp)
 }
 EXPORT_SYMBOL_GPL(hrtimer_get_res);
 
+#ifdef MTK_HRTIME_DEBUG
+static void dump_hrtimer_callinfo(struct hrtimer *timer)
+{
+
+  char symname[KSYM_NAME_LEN];
+  if (lookup_symbol_name((unsigned long)(timer->function), symname) < 0) {
+  pr_err("timer info1: state/%lx, func/%pK\n",
+  timer->state, timer->function);
+  } else {
+  pr_err("timer info2: state/%lx, func/%s\n",
+  timer->state, symname);
+  }
+  #ifdef CONFIG_TIMER_STATS
+  if (lookup_symbol_name((unsigned long)(timer->start_site),
+  symname) < 0) {
+  pr_err("timer stats1: pid/%d(%s), site/%pK\n",
+  timer->start_pid, timer->start_comm, timer->start_site);
+  } else {
+  pr_err("timer stats2: pid/%d(%s), site/%s\n",
+  timer->start_pid, timer->start_comm, symname);
+  }
+  #endif
+}
+#endif
 static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
 {
        struct hrtimer_clock_base *base = timer->base;
@@ -1268,7 +1307,10 @@ static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
         */
        raw_spin_unlock(&cpu_base->lock);
        trace_hrtimer_expire_entry(timer, now);
+
+       mt_trace_hrt_start(fn);
        restart = fn(timer);
+       mt_trace_hrt_end(fn);
        trace_hrtimer_expire_exit(timer);
        raw_spin_lock(&cpu_base->lock);
 
@@ -1560,7 +1602,7 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod
                        t->task = NULL;
 
                if (likely(t->task))
-                       schedule();
+                       freezable_schedule();
 
                hrtimer_cancel(&t->timer);
                mode = HRTIMER_MODE_ABS;